From 6718dee0ec9604893c9732a8d689eb6ab8957b7e Mon Sep 17 00:00:00 2001 From: Amin Ben Romdhane Date: Wed, 7 Feb 2024 11:19:30 +0100 Subject: [PATCH] Gitlab CI/CD: combine cmocka test cases --- .gitlab-ci.yml | 29 - gitlab-ci/functional-api-test.sh | 23 - gitlab-ci/functional-test.sh | 23 - libbbfdm/dmtree/tr181/device.h | 2 - test/cmocka/.gitignore | 4 +- test/cmocka/Makefile | 21 +- ...onal_api_test_bbfd.c => bbfdm_unit_test.c} | 0 test/cmocka/functional_test_bbfd.c | 1805 ----------------- test/cmocka/unit_test_bbfd.c | 777 ------- 9 files changed, 4 insertions(+), 2680 deletions(-) delete mode 100755 gitlab-ci/functional-api-test.sh delete mode 100755 gitlab-ci/functional-test.sh rename test/cmocka/{functional_api_test_bbfd.c => bbfdm_unit_test.c} (100%) delete mode 100644 test/cmocka/functional_test_bbfd.c delete mode 100644 test/cmocka/unit_test_bbfd.c diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ebd8f9c1..cbb11c07 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -39,7 +39,6 @@ run_tools_test: script: - "./gitlab-ci/tools-test.sh" - "./gitlab-ci/generate_supported_dm.sh" - artifacts: when: always paths: @@ -47,34 +46,6 @@ run_tools_test: - out/datamodel_hdm.xml - out/datamodel.xls -run_libbbfdm_api_functional_test: - stage: functional_test - image: ${COMMON_IMAGE} - allow_failure: false - script: - - "./gitlab-ci/install-dependencies.sh" - - "./gitlab-ci/setup.sh" - - "./gitlab-ci/functional-api-test.sh" - - artifacts: - when: always - paths: - - functional-api-test-coverage.xml - -run_libbbfdm_functional_test: - stage: functional_test - image: ${COMMON_IMAGE} - allow_failure: false - script: - - "./gitlab-ci/install-dependencies.sh" - - "./gitlab-ci/setup.sh" - - "./gitlab-ci/functional-test.sh" - - artifacts: - when: always - paths: - - functional-test-coverage.xml - run_libbbfdm_memory_test: stage: functional_test image: ${COMMON_IMAGE} diff --git a/gitlab-ci/functional-api-test.sh b/gitlab-ci/functional-api-test.sh deleted file mode 100755 index ddaacbab..00000000 --- a/gitlab-ci/functional-api-test.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash - -echo "Functional API Tests" -pwd -source ./gitlab-ci/shared.sh - -supervisorctl status all - -echo "Running the functional API test cases" -make clean -C test/cmocka/ -make functional-api-test -C test/cmocka/ -check_ret $? - -supervisorctl stop all -supervisorctl status - -#report part -#GitLab-CI output -gcovr -r . 2> /dev/null #throw away stderr -# Artefact -gcovr -r . 2> /dev/null --xml -o ./functional-api-test-coverage.xml - -echo "Functional API Test :: PASS" diff --git a/gitlab-ci/functional-test.sh b/gitlab-ci/functional-test.sh deleted file mode 100755 index 43525774..00000000 --- a/gitlab-ci/functional-test.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash - -echo "Functional Tests" -pwd -source ./gitlab-ci/shared.sh - -supervisorctl status all - -echo "Running the functional test cases" -make clean -C test/cmocka/ -make functional-test -C test/cmocka/ -check_ret $? - -supervisorctl stop all -supervisorctl status - -#report part -#GitLab-CI output -gcovr -r . 2> /dev/null #throw away stderr -# Artefact -gcovr -r . 2> /dev/null --xml -o ./functional-test-coverage.xml - -echo "Functional Test :: PASS" diff --git a/libbbfdm/dmtree/tr181/device.h b/libbbfdm/dmtree/tr181/device.h index df3524f8..35992acf 100644 --- a/libbbfdm/dmtree/tr181/device.h +++ b/libbbfdm/dmtree/tr181/device.h @@ -15,8 +15,6 @@ #include "libbbfdm-api/dmcommon.h" -extern DM_MAP_OBJ tDynamicObj[]; - extern DMOBJ tDeviceObj[]; extern DMLEAF tDeviceParams[]; diff --git a/test/cmocka/.gitignore b/test/cmocka/.gitignore index b6dc4956..f7f02c24 100644 --- a/test/cmocka/.gitignore +++ b/test/cmocka/.gitignore @@ -1,3 +1 @@ -functional_test_bbfd -functional_api_test_bbfd -unit_test_bbfd +bbfdm_unit_test diff --git a/test/cmocka/Makefile b/test/cmocka/Makefile index ba51980a..d205a21a 100644 --- a/test/cmocka/Makefile +++ b/test/cmocka/Makefile @@ -1,33 +1,18 @@ CC = gcc CFLAGS = -g -Wall -Werror LDFLAGS = -lcmocka -lbbfdm-api -lbbfdm -UNIT_TESTS = unit_test_bbfd -FUNCTIONAL_TESTS = functional_test_bbfd -FUNCTIONAL_API_TESTS = functional_api_test_bbfd +UNIT_TESTS = bbfdm_unit_test VALGRIND = valgrind --leak-check=full --show-reachable=no \ --show-leak-kinds=all --errors-for-leak-kinds=all \ --error-exitcode=1 --track-origins=yes -unit_test_bbfd: unit_test_bbfd.o - $(CC) -o $@ $^ $(LDFLAGS) - -functional_test_bbfd: functional_test_bbfd.o - $(CC) -o $@ $^ $(LDFLAGS) - -functional_api_test_bbfd: functional_api_test_bbfd.o +bbfdm_unit_test: bbfdm_unit_test.o $(CC) -o $@ $^ $(LDFLAGS) unit-test: $(UNIT_TESTS) $(foreach testprog, $(UNIT_TESTS), sudo $(VALGRIND) ./$(testprog);) -functional-test: $(FUNCTIONAL_TESTS) - $(foreach testprog, $(FUNCTIONAL_TESTS), sudo $(VALGRIND) ./$(testprog);) - -functional-api-test: $(FUNCTIONAL_API_TESTS) - $(foreach testprog, $(FUNCTIONAL_API_TESTS), sudo $(VALGRIND) ./$(testprog);) - .PHONY: clean clean: - rm -fv *.o $(UNIT_TESTS) $(FUNCTIONAL_TESTS) $(FUNCTIONAL_API_TESTS) - + rm -fv *.o $(UNIT_TESTS) diff --git a/test/cmocka/functional_api_test_bbfd.c b/test/cmocka/bbfdm_unit_test.c similarity index 100% rename from test/cmocka/functional_api_test_bbfd.c rename to test/cmocka/bbfdm_unit_test.c diff --git a/test/cmocka/functional_test_bbfd.c b/test/cmocka/functional_test_bbfd.c deleted file mode 100644 index 6f1ce430..00000000 --- a/test/cmocka/functional_test_bbfd.c +++ /dev/null @@ -1,1805 +0,0 @@ -#include -#include -#include -#include - -#include -#include -#include - -#include "../../libbbfdm/dmtree/tr181/device.h" - -static DMOBJ TR181_ROOT_TREE[] = { -/* OBJ, permission, addobj, delobj, checkdep, browseinstobj, nextdynamicobj, dynamicleaf, nextobj, leaf, linker, bbfdm_type, uniqueKeys*/ -{"Device", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tDeviceObj, tDeviceParams, NULL, BBFDM_BOTH}, -{0} -}; - -static int setup(void **state) -{ - struct dmctx *ctx = calloc(1, sizeof(struct dmctx)); - if (!ctx) - return -1; - - bbf_ctx_init(ctx, TR181_ROOT_TREE); - - *state = ctx; - - return 0; -} - -static int teardown_commit(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - - bbf_entry_restart_services(NULL, true); - bbf_ctx_clean(ctx); - free(ctx); - - return 0; -} - -static int group_init(void **state) -{ - bbf_global_init(TR181_ROOT_TREE, "/etc/bbfdm/plugins"); - return 0; -} - -static int group_teardown(void **state) -{ - bbf_global_clean(TR181_ROOT_TREE); - return 0; -} - -static void validate_parameter(struct dmctx *ctx, const char *name, const char *value, const char *type) -{ - struct dm_parameter *n; - - - list_for_each_entry(n, &ctx->list_parameter, list) { - - // check the returned path - assert_string_equal(n->name, name); - - // check the returned value - assert_string_equal(n->data, value); - - // check the returned type - assert_string_equal(n->type, type); - } - - bbf_ctx_clean_sub(ctx); - bbf_ctx_init_sub(ctx, TR181_ROOT_TREE); -} - -static void test_api_bbfdm_get_set_standard_parameter(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - int fault = 0; - - // get value ==> expected "0" error - ctx->in_param = "Device.WiFi.Radio.1.Channel"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter : name, type, value - validate_parameter(ctx, "Device.WiFi.Radio.1.Channel", "36", "xsd:unsignedInt"); - - // Set Wrong Value ==> expected "9007" error - ctx->in_param = "Device.WiFi.Radio.1.Channel"; - ctx->in_value = "64t"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, FAULT_9007); - - // set value ==> expected "0" error - ctx->in_param = "Device.WiFi.Radio.1.Channel"; - ctx->in_value = "100"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, 0); - - // get value ==> expected "0" error - ctx->in_param = "Device.WiFi.Radio.1.Channel"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter after setting to 64: name, type, value - validate_parameter(ctx, "Device.WiFi.Radio.1.Channel", "100", "xsd:unsignedInt"); -} - -static void test_api_bbfdm_get_set_json_parameter(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - int fault = 0; - - // get value ==> expected "0" error - ctx->in_param = "Device.WiFi.X_IOPSYS_EU_Radio.1.Noise"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter : name, type, value - validate_parameter(ctx, "Device.WiFi.X_IOPSYS_EU_Radio.1.Noise", "-87", "xsd:int"); - - // get value ==> expected "0" error - ctx->in_param = "Device.WiFi.X_IOPSYS_EU_Radio.2.Noise"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter : name, type, value - validate_parameter(ctx, "Device.WiFi.X_IOPSYS_EU_Radio.2.Noise", "-85", "xsd:int"); - - // get value ==> expected "0" error - ctx->in_param = "Device.WiFi.X_IOPSYS_EU_Radio.2.Band"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter : name, type, value - validate_parameter(ctx, "Device.WiFi.X_IOPSYS_EU_Radio.2.Band", "2.4GHz", "xsd:string"); - - // get value ==> expected "0" error - ctx->in_param = "Device.WiFi.X_IOPSYS_EU_Radio.1.Stats.BytesSent"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter : name, type, value - validate_parameter(ctx, "Device.WiFi.X_IOPSYS_EU_Radio.1.Stats.BytesSent", "14418177", "xsd:unsignedInt"); - - // get value ==> expected "0" error - ctx->in_param = "Device.WiFi.X_IOPSYS_EU_Radio.2.Stats.BytesSent"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter : name, type, value - validate_parameter(ctx, "Device.WiFi.X_IOPSYS_EU_Radio.2.Stats.BytesSent", "14417451", "xsd:unsignedInt"); -} - -static void test_api_bbfdm_get_set_json_v1_parameter(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - char *value = NULL; - int fault = 0; - - // get value ==> expected "0" error - ctx->in_param = "Device.UCI_TEST_V1.Password"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter : name, type, value - validate_parameter(ctx, "Device.UCI_TEST_V1.Password", "", "xsd:string"); - - // set value ==> expected "0" error - ctx->in_param = "Device.UCI_TEST_V1.Password"; - ctx->in_value = "iopsys_test"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, 0); - - // get value ==> expected "0" error - ctx->in_param = "Device.UCI_TEST_V1.Password"; - ctx->dm_type = BBFDM_CWMP; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter : name, type, value - validate_parameter(ctx, "Device.UCI_TEST_V1.Password", "", "xsd:string"); - - // get value ==> expected "0" error - ctx->in_param = "Device.UCI_TEST_V1.Password"; - ctx->dm_type = BBFDM_USP; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter : name, type, value - validate_parameter(ctx, "Device.UCI_TEST_V1.Password", "iopsys_test", "xsd:string"); - - // validate uci config - fault = dmuci_get_option_value_string("users", "user", "password_required", &value); - assert_int_equal(fault, 0); - assert_string_equal(value, "iopsys_test"); - - // get value ==> expected "0" error - ctx->in_param = "Device.UCI_TEST_V1.OWSDNumberOfEntries"; - ctx->dm_type = BBFDM_BOTH; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter : name, type, value - validate_parameter(ctx, "Device.UCI_TEST_V1.OWSDNumberOfEntries", "3", "xsd:unsignedInt"); - - // set value ==> expected "9008" error - ctx->in_param = "Device.UCI_TEST_V1.OWSDNumberOfEntries"; - ctx->in_value = "5"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, FAULT_9008); - - // get value ==> expected "0" error - ctx->in_param = "Device.UCI_TEST_V1.OWSD.2.IPv6"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter : name, type, value - validate_parameter(ctx, "Device.UCI_TEST_V1.OWSD.2.IPv6", "off", "xsd:string"); - - // set value ==> expected "0" error - ctx->in_param = "Device.UCI_TEST_V1.OWSD.2.IPv6"; - ctx->in_value = "on"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, 0); - - // get value ==> expected "0" error - ctx->in_param = "Device.UCI_TEST_V1.OWSD.2.IPv6"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter : name, type, value - validate_parameter(ctx, "Device.UCI_TEST_V1.OWSD.2.IPv6", "on", "xsd:string"); - - // get value ==> expected "0" error - ctx->in_param = "Device.UCI_TEST_V1.OWSD.1.Port"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter : name, type, value - validate_parameter(ctx, "Device.UCI_TEST_V1.OWSD.1.Port", "80", "xsd:unsignedInt"); - - // set value ==> expected "9007" error - ctx->in_param = "Device.UCI_TEST_V1.OWSD.1.Port"; - ctx->in_value = "65536"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, FAULT_9007); - - // set value ==> expected "0" error - ctx->in_param = "Device.UCI_TEST_V1.OWSD.1.Port"; - ctx->in_value = "8081"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, 0); - - // get value ==> expected "0" error - ctx->in_param = "Device.UCI_TEST_V1.OWSD.1.Port"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter : name, type, value - validate_parameter(ctx, "Device.UCI_TEST_V1.OWSD.1.Port", "8081", "xsd:unsignedInt"); - - // get value ==> expected "0" error - ctx->in_param = "Device.UCI_TEST_V1.OWSD.3.Password"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter : name, type, value - validate_parameter(ctx, "Device.UCI_TEST_V1.OWSD.3.Password", "", "xsd:string"); - - // set value ==> expected "0" error - ctx->in_param = "Device.UCI_TEST_V1.OWSD.3.Password"; - ctx->in_value = "owsd_pwd"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, 0); - - // get value ==> expected "0" error - ctx->in_param = "Device.UCI_TEST_V1.OWSD.3.Password"; - ctx->dm_type = BBFDM_CWMP; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter : name, type, value - validate_parameter(ctx, "Device.UCI_TEST_V1.OWSD.3.Password", "", "xsd:string"); - - // get value ==> expected "0" error - ctx->in_param = "Device.UCI_TEST_V1.OWSD.3.Password"; - ctx->dm_type = BBFDM_USP; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter : name, type, value - validate_parameter(ctx, "Device.UCI_TEST_V1.OWSD.3.Password", "owsd_pwd", "xsd:string"); - - // validate uci config - fault = dmuci_get_option_value_string("owsd", "@owsd_listen[2]", "password", &value); - assert_int_equal(fault, 0); - assert_string_equal(value, "owsd_pwd"); - - // get value ==> expected "0" error - ctx->in_param = "Device.UBUS_TEST_V1.Uptime"; - ctx->dm_type = BBFDM_BOTH; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter : name, type, value - validate_parameter(ctx, "Device.UBUS_TEST_V1.Uptime", "5859", "xsd:string"); - - // set value ==> expected "0" error - ctx->in_param = "Device.UBUS_TEST_V1.Uptime"; - ctx->in_value = "lan"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, 0); - - // get value ==> expected "0" error - ctx->in_param = "Device.UBUS_TEST_V1.InterfaceNumberOfEntries"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter : name, type, value - validate_parameter(ctx, "Device.UBUS_TEST_V1.InterfaceNumberOfEntries", "10", "xsd:unsignedInt"); - - // set value ==> expected "9008" error - ctx->in_param = "Device.UBUS_TEST_V1.InterfaceNumberOfEntries"; - ctx->in_value = "5"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, FAULT_9008); - - // get value ==> expected "0" error - ctx->in_param = "Device.UBUS_TEST_V1.Interface.3.MacAddress"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter : name, type, value - validate_parameter(ctx, "Device.UBUS_TEST_V1.Interface.3.MacAddress", "60:8d:26:c4:96:f7", "xsd:string"); - - // set value ==> expected "9008" error - ctx->in_param = "Device.UBUS_TEST_V1.Interface.3.MacAddress"; - ctx->in_value = "49:d4:40:71:7e:55"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, FAULT_9008); - - // get value ==> expected "0" error - ctx->in_param = "Device.UBUS_TEST_V1.Interface.4.Ifname"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter : name, type, value - validate_parameter(ctx, "Device.UBUS_TEST_V1.Interface.4.Ifname", "eth4", "xsd:string"); - - // set value ==> expected "9008" error - ctx->in_param = "Device.UBUS_TEST_V1.Interface.4.Ifname"; - ctx->in_value = "lan5"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, FAULT_9008); - - // get value ==> expected "0" error - ctx->in_param = "Device.UBUS_TEST_V1.Interface.2.Media"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter : name, type, value - validate_parameter(ctx, "Device.UBUS_TEST_V1.Interface.2.Media", "IEEE 802_3AB_GIGABIT_ETHERNET", "xsd:string"); - - // set value ==> expected "9008" error - ctx->in_param = "Device.UBUS_TEST_V1.Interface.2.Media"; - ctx->in_value = "IEEE 802_11AX_5_GHZ"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, FAULT_9008); - - // get value ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_URLFilter.Profile.1.Name"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter : name, type, value - validate_parameter(ctx, "Device.X_IOPSYS_EU_URLFilter.Profile.1.Name", "homeoffice", "xsd:string"); - - // set value ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_URLFilter.Profile.1.Name"; - ctx->in_value = "home+office test"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, 0); - - // get value ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_URLFilter.Profile.1.Name"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter : name, type, value - validate_parameter(ctx, "Device.X_IOPSYS_EU_URLFilter.Profile.1.Name", "home+office test", "xsd:string"); - - // set value ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_URLFilter.Profile.1.Name"; - ctx->in_value = "office_test"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, 0); - - // get value ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_URLFilter.Profile.1.Name"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter : name, type, value - validate_parameter(ctx, "Device.X_IOPSYS_EU_URLFilter.Profile.1.Name", "office_test", "xsd:string"); -} - -static void test_api_bbfdm_get_set_library_parameter(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - int fault = 0; - - // get value ==> expected "0" error - ctx->in_param = "Device.WiFi.SSID.1.Enable"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter : name, type, value - validate_parameter(ctx, "Device.WiFi.SSID.1.Enable", "1", "xsd:boolean"); - - // Set Wrong Value ==> expected "9007" error - ctx->in_param = "Device.WiFi.SSID.1.Enable"; - ctx->in_value = "truee"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, FAULT_9007); - - // set value ==> expected "0" error - ctx->in_param = "Device.WiFi.SSID.1.Enable"; - ctx->in_value = "0"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, 0); - - // get value ==> expected "0" error - ctx->in_param = "Device.WiFi.SSID.1.Enable"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter after setting to 0: name, type, value - validate_parameter(ctx, "Device.WiFi.SSID.1.Enable", "0", "xsd:boolean"); -} - -static void test_api_bbfdm_get_set_standard_parameter_alias(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - int fault = 0; - - ctx->instance_mode = INSTANCE_MODE_ALIAS; - - // get value ==> expected "0" error - ctx->in_param = "Device.WiFi.Radio.[cpe-1].Channel"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter : name, type, value - validate_parameter(ctx, "Device.WiFi.Radio.[cpe-1].Channel", "100", "xsd:unsignedInt"); - - // Set Wrong Value ==> expected "9007" error - ctx->in_param = "Device.WiFi.Radio.[cpe-1].Channel"; - ctx->in_value = "64t"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, FAULT_9007); - - // set value ==> expected "0" error - ctx->in_param = "Device.WiFi.Radio.[cpe-1].Channel"; - ctx->in_value = "52"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, 0); - - // get value ==> expected "0" error - ctx->in_param = "Device.WiFi.Radio.[cpe-1].Channel"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter after setting to 64: name, type, value - validate_parameter(ctx, "Device.WiFi.Radio.[cpe-1].Channel", "52", "xsd:unsignedInt"); - - // set value ==> expected "0" error - ctx->in_param = "Device.WiFi.Radio.[cpe-1].Alias"; - ctx->in_value = "iopsys_test"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, 0); - - // get value ==> expected "0" error - ctx->in_param = "Device.WiFi.Radio.[iopsys_test].Alias"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter after setting to 64: name, type, value - validate_parameter(ctx, "Device.WiFi.Radio.[iopsys_test].Alias", "iopsys_test", "xsd:string"); - - // set value ==> expected "0" error - ctx->in_param = "Device.WiFi.Radio.[iopsys_test].Channel"; - ctx->in_value = "116"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, 0); - - // get value ==> expected "0" error - ctx->in_param = "Device.WiFi.Radio.[iopsys_test].Channel"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter after setting to 64: name, type, value - validate_parameter(ctx, "Device.WiFi.Radio.[iopsys_test].Channel", "116", "xsd:unsignedInt"); -} - -static void test_api_bbfdm_input_value_validation_json_parameter(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - int fault = 0; - - /* - * Validate Boolean parameters - */ - - // Set Wrong Value ==> expected "9007" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.Enable"; - ctx->in_value = "64t"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, FAULT_9007); - - // Set Wrong Value ==> expected "9007" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.Enable"; - ctx->in_value = "truee"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, FAULT_9007); - - // set value ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.Enable"; - ctx->in_value = "true"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, 0); - - // get value ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.Enable"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter after setting to true: name, type, value - validate_parameter(ctx, "Device.X_IOPSYS_EU_TEST.1.Enable", "1", "xsd:boolean"); - - /* - * Validate unsignedInt parameters - */ - - // Mapping without range: Set Wrong Value ==> expected "9007" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.Nbr_Retries"; - ctx->in_value = "64t"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, FAULT_9007); - - // set value ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.Nbr_Retries"; - ctx->in_value = "15600"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, 0); - - // get value ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.Nbr_Retries"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter after setting to true: name, type, value - validate_parameter(ctx, "Device.X_IOPSYS_EU_TEST.1.Nbr_Retries", "15600", "xsd:unsignedInt"); - - // Mapping with range: Set Wrong Value out of range ==> expected "9007" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.Port"; - ctx->in_value = "1050"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, FAULT_9007); - - // Mapping with range: set value in the first range [0-1000] ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.Port"; - ctx->in_value = "1000"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, 0); - - // get value ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.Port"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter after setting to true: name, type, value - validate_parameter(ctx, "Device.X_IOPSYS_EU_TEST.1.Port", "1000", "xsd:unsignedInt"); - - // Mapping with range: set value in the second range [15000-65535] ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.Port"; - ctx->in_value = "20546"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, 0); - - // get value ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.Port"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter after setting to true: name, type, value - validate_parameter(ctx, "Device.X_IOPSYS_EU_TEST.1.Port", "20546", "xsd:unsignedInt"); - - /* - * Validate int parameters - */ - - // Mapping with range (only min): Set Wrong Value ==> expected "9007" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.Min_value"; - ctx->in_value = "-300"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, FAULT_9007); - - // set value ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.Min_value"; - ctx->in_value = "-273"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, 0); - - // get value ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.Min_value"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter after setting to true: name, type, value - validate_parameter(ctx, "Device.X_IOPSYS_EU_TEST.1.Min_value", "-273", "xsd:int"); - - // Mapping with range (only max): Set Wrong Value out of range ==> expected "9007" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.Max_value"; - ctx->in_value = "280"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, FAULT_9007); - - // Mapping with range: set value in the first range [0-1000] ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.Max_value"; - ctx->in_value = "274"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, 0); - - // get value ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.Max_value"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter after setting to true: name, type, value - validate_parameter(ctx, "Device.X_IOPSYS_EU_TEST.1.Max_value", "274", "xsd:int"); - - // Mapping with range: Set Wrong Value out of range ==> expected "9007" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.Value"; - ctx->in_value = "-3"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, FAULT_9007); - - // Mapping with range: set value in the first range [-10:-5] ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.Value"; - ctx->in_value = "-7"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, 0); - - // get value ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.Value"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter after setting to true: name, type, value - validate_parameter(ctx, "Device.X_IOPSYS_EU_TEST.1.Value", "-7", "xsd:int"); - - // Mapping with range: set value in the second range [-1:10] ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.Value"; - ctx->in_value = "1"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, 0); - - // get value ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.Value"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter after setting to true: name, type, value - validate_parameter(ctx, "Device.X_IOPSYS_EU_TEST.1.Value", "1", "xsd:int"); - - /* - * Validate unsignedLong parameters - */ - - // Mapping without range: Set Wrong Value ==> expected "9007" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.Nbr_bytes"; - ctx->in_value = "64t"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, FAULT_9007); - - // set value ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.Nbr_bytes"; - ctx->in_value = "15600"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, 0); - - // get value ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.Nbr_bytes"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter after setting to true: name, type, value - validate_parameter(ctx, "Device.X_IOPSYS_EU_TEST.1.Nbr_bytes", "15600", "xsd:unsignedLong"); - - // Mapping with range: Set Wrong Value out of range ==> expected "9007" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.Nbr_packets"; - ctx->in_value = "499"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, FAULT_9007); - - // Mapping with range: set value in the first range [0-100] ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.Nbr_packets"; - ctx->in_value = "99"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, 0); - - // get value ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.Nbr_packets"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter after setting to true: name, type, value - validate_parameter(ctx, "Device.X_IOPSYS_EU_TEST.1.Nbr_packets", "99", "xsd:unsignedLong"); - - // Mapping with range: set value in the second range [500-3010] ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.Nbr_packets"; - ctx->in_value = "1024"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, 0); - - // get value ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.Nbr_packets"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter after setting to true: name, type, value - validate_parameter(ctx, "Device.X_IOPSYS_EU_TEST.1.Nbr_packets", "1024", "xsd:unsignedLong"); - - /* - * Validate long parameters - */ - - // Mapping without range: Set Wrong Value ==> expected "9007" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.MaxTxPower"; - ctx->in_value = "-300t"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, FAULT_9007); - - // set value ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.MaxTxPower"; - ctx->in_value = "-273"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, 0); - - // get value ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.MaxTxPower"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter after setting to true: name, type, value - validate_parameter(ctx, "Device.X_IOPSYS_EU_TEST.1.MaxTxPower", "-273", "xsd:long"); - - // Mapping with range: Set Wrong Value out of range ==> expected "9007" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.TransmitPowerLimit"; - ctx->in_value = "-91"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, FAULT_9007); - - // Mapping with range: set value in the first range [-90:36] ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.TransmitPowerLimit"; - ctx->in_value = "274"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, 0); - - // get value ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.TransmitPowerLimit"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter after setting to true: name, type, value - validate_parameter(ctx, "Device.X_IOPSYS_EU_TEST.1.TransmitPowerLimit", "274", "xsd:long"); - - // Mapping with range: Set Wrong Value out of range ==> expected "9007" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.TransmitPowerLimit"; - ctx->in_value = "37"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, FAULT_9007); - - // Mapping with range: set value in the first range [70:360] ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.TransmitPowerLimit"; - ctx->in_value = "70"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, 0); - - // get value ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.TransmitPowerLimit"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter after setting to true: name, type, value - validate_parameter(ctx, "Device.X_IOPSYS_EU_TEST.1.TransmitPowerLimit", "70", "xsd:long"); - - /* - * Validate dateTime parameters - */ - - // Set Wrong Value ==> expected "9007" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.AssociationTime"; - ctx->in_value = "2030-01-01T11:22:33.2Z"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, FAULT_9007); - - // Set Wrong Value ==> expected "9007" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.AssociationTime"; - ctx->in_value = "2022-01-01T12:20:22.2222Z"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, FAULT_9007); - - // set value ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.AssociationTime"; - ctx->in_value = "2022-01-01T12:20:22Z"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, 0); - - // get value ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.AssociationTime"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter after setting to true: name, type, value - validate_parameter(ctx, "Device.X_IOPSYS_EU_TEST.1.AssociationTime", "2022-01-01T12:20:22Z", "xsd:dateTime"); - - /* - * Validate hexBinary parameters - */ - - // Mapping without range: Set Wrong Value ==> expected "9007" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.ButtonColor"; - ctx->in_value = "64t"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, FAULT_9007); - - // set value ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.ButtonColor"; - ctx->in_value = "64ab78cef12"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, 0); - - // get value ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.ButtonColor"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter after setting to true: name, type, value - validate_parameter(ctx, "Device.X_IOPSYS_EU_TEST.1.ButtonColor", "64ab78cef12", "xsd:hexBinary"); - - // Mapping with range: Set Wrong Value out of range ==> expected "9007" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.TextColor"; - ctx->in_value = "am123"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, FAULT_9007); - - // Mapping with range: set value in the first range [3-3] ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.TextColor"; - ctx->in_value = "123abc"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, 0); - - // get value ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.TextColor"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter after setting to true: name, type, value - validate_parameter(ctx, "Device.X_IOPSYS_EU_TEST.1.TextColor", "123abc", "xsd:hexBinary"); - - // Mapping with range: set value in the second range [5-5] ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.TextColor"; - ctx->in_value = "12345abcde"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, 0); - - // get value ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.TextColor"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter after setting to true: name, type, value - validate_parameter(ctx, "Device.X_IOPSYS_EU_TEST.1.TextColor", "12345abcde", "xsd:hexBinary"); - - // Mapping without range: Set Wrong Value ==> expected "9007" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.BackgroundColor"; - ctx->in_value = "12345abce"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, FAULT_9007); - - // set value ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.BackgroundColor"; - ctx->in_value = "45a1bd"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, 0); - - // get value ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.BackgroundColor"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter after setting to true: name, type, value - validate_parameter(ctx, "Device.X_IOPSYS_EU_TEST.1.BackgroundColor", "45a1bd", "xsd:hexBinary"); - - /* - * Validate string parameters - */ - - // Set Wrong Value ==> expected "9007" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.Interface"; - ctx->in_value = "64"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, FAULT_9007); - - // set value ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.Interface"; - ctx->in_value = "wan"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, 0); - - // get value ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.Interface"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter after setting to true: name, type, value - validate_parameter(ctx, "Device.X_IOPSYS_EU_TEST.1.Interface", "wan", "xsd:string"); - - // Set Wrong Value ==> expected "9007" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.IPAddr"; - ctx->in_value = "192.168.1.789"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, FAULT_9007); - - // Set value ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.IPAddr"; - ctx->in_value = "192.168.117.45"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, 0); - - // get value ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.IPAddr"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter after setting to true: name, type, value - validate_parameter(ctx, "Device.X_IOPSYS_EU_TEST.1.IPAddr", "192.168.117.45", "xsd:string"); - - // Set Wrong Value ==> expected "9007" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.Protocol"; - ctx->in_value = "OMA-D"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, FAULT_9007); - - // set value ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.Protocol"; - ctx->in_value = "OMA-DM"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, 0); - - // get value ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.Protocol"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter after setting to true: name, type, value - validate_parameter(ctx, "Device.X_IOPSYS_EU_TEST.1.Protocol", "OMA-DM", "xsd:string"); - - // set value ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.Description"; - ctx->in_value = "bbf validate test"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, 0); - - // get value ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.Description"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter after setting to true: name, type, value - validate_parameter(ctx, "Device.X_IOPSYS_EU_TEST.1.Description", "bbf validate test", "xsd:string"); - - /* - * Validate list string parameters - */ - - // Set Wrong Value ==> expected "9007" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.FailureReasons"; - ctx->in_value = "te,be,re,yu"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, FAULT_9007); - - // Set Wrong Value ==> expected "9007" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.FailureReasons"; - ctx->in_value = "ExcessiveDelay,InsufficientBuffers"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, FAULT_9007); - - // set value ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.FailureReasons"; - ctx->in_value = "LowRate,Other"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, 0); - - // get value ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.FailureReasons"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter after setting to true: name, type, value - validate_parameter(ctx, "Device.X_IOPSYS_EU_TEST.1.FailureReasons", "LowRate,Other", "xsd:string"); - - // Set Wrong Value ==> expected "9007" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.SupportedOperatingChannelBandwidths"; - ctx->in_value = "200MHz,10MHz"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, FAULT_9007); - - // Set Wrong Value ==> expected "9007" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.SupportedOperatingChannelBandwidths"; - ctx->in_value = "ExcessiveDelay,InsufficientBuffers"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, FAULT_9007); - - // set value ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.SupportedOperatingChannelBandwidths"; - ctx->in_value = "40MHz,80+80MHz"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, 0); - - // get value ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.SupportedOperatingChannelBandwidths"; - ctx->in_value = ""; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter after setting to true: name, type, value - ctx->in_param = ""; - validate_parameter(ctx, "Device.X_IOPSYS_EU_TEST.1.SupportedOperatingChannelBandwidths", "40MHz,80+80MHz", "xsd:string"); - - /* - * Validate list int parameters - */ - - // Set Wrong Value ==> expected "9007" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.TransmitPowerSupported"; - ctx->in_value = "-5,-3,99,120"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, FAULT_9007); - - // Set Wrong Value ==> expected "9007" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.TransmitPowerSupported"; - ctx->in_value = "-1,9,990"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, FAULT_9007); - - // set value ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.TransmitPowerSupported"; - ctx->in_value = "-1,9,100"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, 0); - - // get value ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.TransmitPowerSupported"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter after setting to true: name, type, value - validate_parameter(ctx, "Device.X_IOPSYS_EU_TEST.1.TransmitPowerSupported", "-1,9,100", "xsd:string"); - - /* - * Validate list unsignedInt parameters - */ - - // Set Wrong Value ==> expected "9007" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.PriorityRegeneration"; - ctx->in_value = "8,1,2,3"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, FAULT_9007); - - // Set Wrong Value ==> expected "9007" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.PriorityRegeneration"; - ctx->in_value = "1,2,3,4,5,6,7,8"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, FAULT_9007); - - // set value ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.PriorityRegeneration"; - ctx->in_value = "0,1,2,3,4,5,6,7"; - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, 0); - - // get value ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.PriorityRegeneration"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - // validate parameter after setting to true: name, type, value - validate_parameter(ctx, "Device.X_IOPSYS_EU_TEST.1.PriorityRegeneration", "0,1,2,3,4,5,6,7", "xsd:string"); -} - -static void test_api_bbfdm_add_del_standard_object(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - int fault = 0; - - // Get name object ==> expected "0" error - ctx->in_param = "Device.Users.User."; - ctx->nextlevel = true; - fault = bbf_entry_method(ctx, BBF_GET_NAME); - assert_int_equal(fault, 0); - - // add object ==> expected "0" error - ctx->in_param = "Device.Users.User."; - fault = bbf_entry_method(ctx, BBF_ADD_OBJECT); - assert_int_equal(fault, 0); - - // check the new instance - assert_non_null(ctx->addobj_instance); - assert_string_equal(ctx->addobj_instance, "2"); - - // delete object ==> expected "0" error - ctx->in_param = "Device.Users.User.2."; - fault = bbf_entry_method(ctx, BBF_DEL_OBJECT); - assert_int_equal(fault, 0); - - // Get name object after deleting instance 2 ==> expected "9005" error - ctx->in_param = "Device.Users.User.2."; - ctx->nextlevel = true; - fault = bbf_entry_method(ctx, BBF_GET_NAME); - assert_int_equal(fault, FAULT_9005); - - // delete all object ==> expected "0" error - ctx->in_param = "Device.Users.User."; - fault = bbf_entry_method(ctx, BBF_DEL_OBJECT); - assert_int_equal(fault, 0); - - // Get name object after deleting all instances ==> expected "9005" error - ctx->in_param = "Device.Users.User.1."; - ctx->nextlevel = true; - fault = bbf_entry_method(ctx, BBF_GET_NAME); - assert_int_equal(fault, FAULT_9005); -} - -static void test_api_bbfdm_add_del_json_object(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - int fault = 0; - - // Get name object ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_Dropbear."; - ctx->nextlevel = true; - fault = bbf_entry_method(ctx, BBF_GET_NAME); - assert_int_equal(fault, 0); - - // add object ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_Dropbear."; - fault = bbf_entry_method(ctx, BBF_ADD_OBJECT); - assert_int_equal(fault, 0); - - // check the new instance - assert_non_null(ctx->addobj_instance); - assert_string_equal(ctx->addobj_instance, "2"); - - // delete object ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_Dropbear.2."; - fault = bbf_entry_method(ctx, BBF_DEL_OBJECT); - assert_int_equal(fault, 0); - - // Get name object after deleting instance 2 ==> expected "9005" error - ctx->in_param = "Device.X_IOPSYS_EU_Dropbear.2."; - ctx->nextlevel = true; - fault = bbf_entry_method(ctx, BBF_GET_NAME); - assert_int_equal(fault, FAULT_9005); - - // delete all object ==> expected "0" error - ctx->in_param = "Device.X_IOPSYS_EU_Dropbear."; - fault = bbf_entry_method(ctx, BBF_DEL_OBJECT); - assert_int_equal(fault, 0); - - // Get name object after deleting all instances ==> expected "9005" error - ctx->in_param = "Device.X_IOPSYS_EU_Dropbear.1."; - ctx->nextlevel = true; - fault = bbf_entry_method(ctx, BBF_GET_NAME); - assert_int_equal(fault, FAULT_9005); -} - -static void test_api_bbfdm_add_del_json_v1_object(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - int fault = 0; - - // Get name object ==> expected "0" error - ctx->in_param = "Device.UCI_TEST_V1.OWSD."; - ctx->nextlevel = true; - fault = bbf_entry_method(ctx, BBF_GET_NAME); - assert_int_equal(fault, 0); - - // add object ==> expected "0" error - ctx->in_param = "Device.UCI_TEST_V1.OWSD."; - fault = bbf_entry_method(ctx, BBF_ADD_OBJECT); - assert_int_equal(fault, 0); - - // check the new instance - assert_non_null(ctx->addobj_instance); - assert_string_equal(ctx->addobj_instance, "4"); - - // delete object ==> expected "0" error - ctx->in_param = "Device.UCI_TEST_V1.OWSD.2."; - fault = bbf_entry_method(ctx, BBF_DEL_OBJECT); - assert_int_equal(fault, 0); - - // Get name object after deleting instance 2 ==> expected "9005" error - ctx->in_param = "Device.UCI_TEST_V1.OWSD.2."; - ctx->nextlevel = true; - fault = bbf_entry_method(ctx, BBF_GET_NAME); - assert_int_equal(fault, FAULT_9005); - - // delete all object ==> expected "0" error - ctx->in_param = "Device.UCI_TEST_V1.OWSD."; - fault = bbf_entry_method(ctx, BBF_DEL_OBJECT); - assert_int_equal(fault, 0); - - // Get name object after deleting all instances ==> expected "9005" error - ctx->in_param = "Device.UCI_TEST_V1.OWSD.1."; - ctx->nextlevel = true; - fault = bbf_entry_method(ctx, BBF_GET_NAME); - assert_int_equal(fault, FAULT_9005); - - // add object ==> expected "9005" error - ctx->in_param = "Device.UBUS_TEST_V1.Interface."; - fault = bbf_entry_method(ctx, BBF_ADD_OBJECT); - assert_int_equal(fault, FAULT_9005); - - // delete all object ==> expected "9005" error - ctx->in_param = "Device.UBUS_TEST_V1.Interface."; - fault = bbf_entry_method(ctx, BBF_DEL_OBJECT); - assert_int_equal(fault, FAULT_9005); -} - -static void test_api_bbfdm_add_del_library_object(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - int fault = 0; - - // Get name object ==> expected "0" error - ctx->in_param = "Device.WiFi.AccessPoint."; - ctx->nextlevel = true; - fault = bbf_entry_method(ctx, BBF_GET_NAME); - assert_int_equal(fault, 0); - - // Get name object ==> expected "0" error - ctx->in_param = "Device.WiFi.SSID."; - ctx->nextlevel = true; - fault = bbf_entry_method(ctx, BBF_GET_NAME); - assert_int_equal(fault, 0); - - // add object ==> expected "0" error - ctx->in_param = "Device.WiFi.SSID."; - fault = bbf_entry_method(ctx, BBF_ADD_OBJECT); - assert_int_equal(fault, 0); - - // check the new instance - assert_non_null(ctx->addobj_instance); - assert_string_equal(ctx->addobj_instance, "4"); - - // delete object ==> expected "0" error - ctx->in_param = "Device.WiFi.SSID.2."; - fault = bbf_entry_method(ctx, BBF_DEL_OBJECT); - assert_int_equal(fault, 0); - - // Get name object after deleting instance 2 ==> expected "9005" error - ctx->in_param = "Device.WiFi.SSID.2."; - ctx->nextlevel = true; - fault = bbf_entry_method(ctx, BBF_GET_NAME); - assert_int_equal(fault, FAULT_9005); - - // delete all object ==> expected "0" error - ctx->in_param = "Device.WiFi.SSID."; - fault = bbf_entry_method(ctx, BBF_DEL_OBJECT); - assert_int_equal(fault, 0); - - // Get name object after deleting all instances ==> expected "9005" error - ctx->in_param = "Device.WiFi.SSID.1."; - ctx->nextlevel = true; - fault = bbf_entry_method(ctx, BBF_GET_NAME); - assert_int_equal(fault, FAULT_9005); -} - -static void test_api_bbfdm_valid_standard_operate(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - struct dm_parameter *n; - int fault = 0; - - ctx->in_param = "Device.IP.Diagnostics.IPPing()"; - ctx->in_value = "{\"Host\":\"iopsys.eu\",\"NumberOfRepetitions\":\"1\",\"Timeout\":\"5000\",\"DataBlockSize\":\"64\"}"; - - fault = bbf_entry_method(ctx, BBF_OPERATE); - assert_int_equal(fault, 0); - - list_for_each_entry(n, &ctx->list_parameter, list) { - if (DM_STRCMP(n->name, "Status") == 0) { - assert_string_equal(n->data, "Complete"); - assert_string_equal(n->type, "xsd:string"); - } else if (DM_STRCMP(n->name, "IPAddressUsed") == 0) { - assert_string_equal(n->data, ""); - assert_string_equal(n->type, "xsd:string"); - } else if (DM_STRCMP(n->name, "SuccessCount") == 0) { - assert_string_equal(n->data, "1"); - assert_string_equal(n->type, "xsd:unsignedInt"); - } else if (DM_STRCMP(n->name, "FailureCount") == 0) { - assert_string_equal(n->data, "0"); - assert_string_equal(n->type, "xsd:unsignedInt"); - } else { - assert_string_not_equal(n->data, "0"); - assert_string_equal(n->type, "xsd:unsignedInt"); - } - } -} - -static void test_api_bbfdm_valid_standard_list_operate(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - struct dm_parameter *n; - int fault = 0, i = 0; - - ctx->in_param = "Device."; - ctx->dm_type = BBFDM_USP; - ctx->nextlevel = false; - ctx->iscommand = true; - ctx->isevent = false; - ctx->isinfo = false; - - fault = bbf_entry_method(ctx, BBF_SCHEMA); - assert_int_equal(fault, 0); - - list_for_each_entry(n, &ctx->list_parameter, list) { - - if (DM_STRCMP(n->name, "Device.FactoryReset()") == 0) { - assert_string_equal(n->type, "xsd:command"); - assert_string_equal(n->additional_data, "sync"); - assert_null(n->data); - } - - if (DM_STRCMP(n->name, "Device.DeviceInfo.VendorLogFile.{i}.Upload()") == 0) { - assert_string_equal(n->type, "xsd:command"); - assert_string_equal(n->additional_data, "async"); - operation_args *args = (operation_args *)n->data; - assert_non_null(args); - const char **command_in = args->in; - const char **command_out = args->out; - assert_non_null(command_in); - assert_null(command_out); - - for (i = 0; command_in[i] != NULL; i++) { - switch (i) { - case 0: - assert_string_equal(command_in[i], "URL"); - break; - case 1: - assert_string_equal(command_in[i], "Username"); - break; - case 2: - assert_string_equal(command_in[i], "Password"); - break; - } - } - assert_int_equal(i, 3); - } - - if (DM_STRCMP(n->name, "Device.WiFi.NeighboringWiFiDiagnostic()") == 0) { - assert_string_equal(n->type, "xsd:command"); - assert_string_equal(n->additional_data, "async"); - operation_args *args = (operation_args *)n->data; - assert_non_null(args); - const char **command_in = args->in; - const char **command_out = args->out; - assert_null(command_in); - assert_non_null(command_out); - - for (i = 0; command_out[i] != NULL; i++) { - switch (i) { - case 0: - assert_string_equal(command_out[i], "Status"); - break; - case 1: - assert_string_equal(command_out[i], "Result.{i}.Radio"); - break; - case 2: - assert_string_equal(command_out[i], "Result.{i}.SSID"); - break; - } - } - assert_int_equal(i, 18); - } - } -} - -static void test_api_bbfdm_valid_library_operate(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - struct dm_parameter *n; - int fault = 0; - - ctx->in_param = "Device.X_IOPSYS_EU_PingTEST.Run()"; - ctx->in_value = "{\"Host\":\"iopsys.eu\"}"; - - fault = bbf_entry_method(ctx, BBF_OPERATE); - assert_int_equal(fault, 0); - - list_for_each_entry(n, &ctx->list_parameter, list) { - assert_string_not_equal(n->data, "0"); - assert_string_equal(n->type, "xsd:unsignedInt"); - }} - -static void test_api_bbfdm_valid_library_list_operate(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - struct dm_parameter *n; - int fault = 0, i = 0; - - ctx->in_param = "Device."; - ctx->dm_type = BBFDM_USP; - ctx->nextlevel = false; - ctx->iscommand = true; - ctx->isevent = false; - ctx->isinfo = false; - - fault = bbf_entry_method(ctx, BBF_SCHEMA); - assert_int_equal(fault, 0); - - list_for_each_entry(n, &ctx->list_parameter, list) { - - if (DM_STRCMP(n->name, "Device.X_IOPSYS_EU_Reboot()") == 0) { - assert_string_equal(n->type, "xsd:command"); - assert_string_equal(n->additional_data, "sync"); - assert_null(n->data); - } - - if (DM_STRCMP(n->name, "Device.X_IOPSYS_EU_PingTEST.Run()") == 0) { - assert_string_equal(n->type, "xsd:command"); - assert_string_equal(n->additional_data, "async"); - operation_args *args = (operation_args *)n->data; - assert_non_null(args); - const char **command_in = args->in; - const char **command_out = args->out; - assert_non_null(command_in); - assert_non_null(command_out); - - for (i = 0; command_in[i] != NULL; i++) { - switch (i) { - case 0: - assert_string_equal(command_in[i], "Host"); - break; - } - } - assert_int_equal(i, 1); - - for (i = 0; command_out[i] != NULL; i++) { - switch (i) { - case 0: - assert_string_equal(command_out[i], "AverageResponseTime"); - break; - case 1: - assert_string_equal(command_out[i], "MinimumResponseTime"); - break; - case 2: - assert_string_equal(command_out[i], "MaximumResponseTime"); - break; - } - } - assert_int_equal(i, 3); - } - } -} - -static void test_api_bbfdm_valid_json_operate(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - struct dm_parameter *n; - int fault = 0; - - ctx->in_param = "Device.X_IOPSYS_EU_TEST.1.Status()"; - - fault = bbf_entry_method(ctx, BBF_OPERATE); - assert_int_equal(fault, 0); - - list_for_each_entry(n, &ctx->list_parameter, list) { - assert_string_equal(n->name, "Result"); - assert_string_equal(n->data, "Success"); - assert_string_equal(n->type, "xsd:string"); - } -} - -static void test_api_bbfdm_valid_json_list_operate(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - struct dm_parameter *n; - int fault = 0, i = 0; - - ctx->in_param = "Device."; - ctx->dm_type = BBFDM_USP; - ctx->nextlevel = false; - ctx->iscommand = true; - ctx->isevent = false; - ctx->isinfo = false; - - fault = bbf_entry_method(ctx, BBF_SCHEMA); - assert_int_equal(fault, 0); - - list_for_each_entry(n, &ctx->list_parameter, list) { - - if (DM_STRCMP(n->name, "Device.X_IOPSYS_EU_TEST.{i}.Status()") == 0) { - assert_string_equal(n->type, "xsd:command"); - assert_string_equal(n->additional_data, "async"); - operation_args *args = (operation_args *)n->data; - assert_non_null(args); - const char **command_in = args->in; - const char **command_out = args->out; - assert_non_null(command_in); - assert_non_null(command_out); - - for (i = 0; command_in[i] != NULL; i++) { - switch (i) { - case 0: - assert_string_equal(command_in[i], "Option"); - break; - } - } - assert_int_equal(i, 1); - - for (i = 0; command_out[i] != NULL; i++) { - switch (i) { - case 0: - assert_string_equal(command_out[i], "Result"); - break; - } - } - assert_int_equal(i, 1); - } - } -} - -static void test_api_bbfdm_valid_json_v1_operate(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - struct dm_parameter *n; - int fault = 0; - - ctx->in_param = "Device.UBUS_TEST_V1.Interface.3.Status()"; - - fault = bbf_entry_method(ctx, BBF_OPERATE); - assert_int_equal(fault, 0); - - list_for_each_entry(n, &ctx->list_parameter, list) { - assert_string_equal(n->name, "Result"); - assert_string_equal(n->data, "Success"); - assert_string_equal(n->type, "xsd:string"); - } -} - -static void test_api_bbfdm_valid_json_v1_list_operate(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - struct dm_parameter *n; - int fault = 0, i = 0; - - ctx->in_param = "Device."; - ctx->dm_type = BBFDM_USP; - ctx->nextlevel = false; - ctx->iscommand = true; - ctx->isevent = false; - ctx->isinfo = false; - - fault = bbf_entry_method(ctx, BBF_SCHEMA); - assert_int_equal(fault, 0); - - list_for_each_entry(n, &ctx->list_parameter, list) { - - if (DM_STRCMP(n->name, "Device.UBUS_TEST_V1.Interface.{i}.Status()") == 0) { - assert_string_equal(n->type, "xsd:command"); - assert_string_equal(n->additional_data, "async"); - operation_args *args = (operation_args *)n->data; - assert_non_null(args); - const char **command_in = args->in; - const char **command_out = args->out; - assert_non_null(command_in); - assert_non_null(command_out); - - for (i = 0; command_in[i] != NULL; i++) { - switch (i) { - case 0: - assert_string_equal(command_in[i], "Option"); - break; - case 1: - assert_string_equal(command_out[i], "Value"); - break; - } - } - assert_int_equal(i, 2); - - for (i = 0; command_out[i] != NULL; i++) { - switch (i) { - case 0: - assert_string_equal(command_out[i], "Result"); - break; - case 1: - assert_string_equal(command_out[i], "Value"); - break; - } - } - assert_int_equal(i, 2); - } - } -} - -static void test_api_bbfdm_valid_library_event(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - struct dm_parameter *n; - int fault = 0, idx = 0; - - ctx->in_param = "Device."; - ctx->dm_type = BBFDM_USP; - ctx->nextlevel = false; - ctx->iscommand = false; - ctx->isevent = true; - ctx->isinfo = false; - - fault = bbf_entry_method(ctx, BBF_SCHEMA); - assert_int_equal(fault, 0); - - list_for_each_entry(n, &ctx->list_parameter, list) { - - if (DM_STRCMP(n->name, "Device.X_IOPSYS_EU_WakeUp!") == 0) { - assert_string_equal(n->type, "xsd:event"); - assert_null(n->data); - } - - if (DM_STRCMP(n->name, "Device.X_IOPSYS_EU_Boot!") == 0) { - assert_string_equal(n->type, "xsd:event"); - event_args *args = (event_args *)n->data; - assert_non_null(args); - const char **event_param = args->param; - assert_non_null(event_param); - for (int i = 0; event_param[i] != NULL; i++) { - switch (i) { - case 0: - assert_string_equal(event_param[i], "CommandKey"); - break; - case 1: - assert_string_equal(event_param[i], "Cause"); - break; - case 2: - assert_string_equal(event_param[i], "FirmwareUpdated"); - break; - case 3: - assert_string_equal(event_param[i], "ParameterMap"); - break; - } - } - } - - idx++; - } - - assert_int_equal(idx, 9); -} - -static void test_api_bbfdm_valid_json_event(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - struct dm_parameter *n; - int fault = 0, idx = 0; - - ctx->in_param = "Device."; - ctx->dm_type = BBFDM_USP; - ctx->nextlevel = false; - ctx->iscommand = false; - ctx->isevent = true; - ctx->isinfo = false; - - fault = bbf_entry_method(ctx, BBF_SCHEMA); - assert_int_equal(fault, 0); - - list_for_each_entry(n, &ctx->list_parameter, list) { - - if (DM_STRCMP(n->name, "Device.X_IOPSYS_EU_TEST.{i}.Periodic!") == 0) { - assert_string_equal(n->type, "xsd:event"); - assert_null(n->data); - } - - if (DM_STRCMP(n->name, "Device.X_IOPSYS_EU_TEST.{i}.Push!") == 0) { - assert_string_equal(n->type, "xsd:event"); - event_args *args = (event_args *)n->data; - assert_non_null(args); - const char **event_param = args->param; - assert_non_null(event_param); - for (int i = 0; event_param[i] != NULL; i++) { - switch (i) { - case 0: - assert_string_equal(event_param[i], "Data"); - break; - case 1: - assert_string_equal(event_param[i], "Status"); - break; - } - } - } - - idx++; - } - - assert_int_equal(idx, 9); -} - -static void test_api_bbfdm_valid_json_v1_event(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - struct dm_parameter *n; - int fault = 0, idx = 0; - - ctx->in_param = "Device."; - ctx->dm_type = BBFDM_USP; - ctx->nextlevel = false; - ctx->iscommand = false; - ctx->isevent = true; - ctx->isinfo = false; - - fault = bbf_entry_method(ctx, BBF_SCHEMA); - assert_int_equal(fault, 0); - - list_for_each_entry(n, &ctx->list_parameter, list) { - if (DM_STRCMP(n->name, "Device.UBUS_TEST_V1.Interface.{i}.Periodic!") == 0) { - assert_string_equal(n->type, "xsd:event"); - assert_null(n->data); - } - - if (DM_STRCMP(n->name, "Device.UBUS_TEST_V1.Interface.{i}.Push!") == 0) { - assert_string_equal(n->type, "xsd:event"); - event_args *args = (event_args *)n->data; - assert_non_null(args); - const char **event_param = args->param; - assert_non_null(event_param); - for (int i = 0; event_param[i] != NULL; i++) { - switch (i) { - case 0: - assert_string_equal(event_param[i], "Data"); - break; - case 1: - assert_string_equal(event_param[i], "Status"); - break; - case 2: - assert_string_equal(event_param[i], "Value"); - break; - } - } - } - - idx++; - } - - assert_int_equal(idx, 9); -} - -int main(void) -{ - const struct CMUnitTest tests[] = { - // Get/Set Value method test cases - cmocka_unit_test_setup_teardown(test_api_bbfdm_get_set_standard_parameter, setup, teardown_commit), - cmocka_unit_test_setup_teardown(test_api_bbfdm_get_set_json_parameter, setup, teardown_commit), - cmocka_unit_test_setup_teardown(test_api_bbfdm_get_set_json_v1_parameter, setup, teardown_commit), - cmocka_unit_test_setup_teardown(test_api_bbfdm_get_set_library_parameter, setup, teardown_commit), - cmocka_unit_test_setup_teardown(test_api_bbfdm_get_set_standard_parameter_alias, setup, teardown_commit), - cmocka_unit_test_setup_teardown(test_api_bbfdm_input_value_validation_json_parameter, setup, teardown_commit), - - // Add/Delete Object method test cases - cmocka_unit_test_setup_teardown(test_api_bbfdm_add_del_standard_object, setup, teardown_commit), - cmocka_unit_test_setup_teardown(test_api_bbfdm_add_del_json_object, setup, teardown_commit), - cmocka_unit_test_setup_teardown(test_api_bbfdm_add_del_json_v1_object, setup, teardown_commit), - cmocka_unit_test_setup_teardown(test_api_bbfdm_add_del_library_object, setup, teardown_commit), - - // Operate method test cases - cmocka_unit_test_setup_teardown(test_api_bbfdm_valid_standard_operate, setup, teardown_commit), - cmocka_unit_test_setup_teardown(test_api_bbfdm_valid_standard_list_operate, setup, teardown_commit), - cmocka_unit_test_setup_teardown(test_api_bbfdm_valid_library_operate, setup, teardown_commit), - cmocka_unit_test_setup_teardown(test_api_bbfdm_valid_library_list_operate, setup, teardown_commit), - cmocka_unit_test_setup_teardown(test_api_bbfdm_valid_json_operate, setup, teardown_commit), - cmocka_unit_test_setup_teardown(test_api_bbfdm_valid_json_list_operate, setup, teardown_commit), - cmocka_unit_test_setup_teardown(test_api_bbfdm_valid_json_v1_operate, setup, teardown_commit), - cmocka_unit_test_setup_teardown(test_api_bbfdm_valid_json_v1_list_operate, setup, teardown_commit), - - // Event method test cases - cmocka_unit_test_setup_teardown(test_api_bbfdm_valid_library_event, setup, teardown_commit), - cmocka_unit_test_setup_teardown(test_api_bbfdm_valid_json_event, setup, teardown_commit), - cmocka_unit_test_setup_teardown(test_api_bbfdm_valid_json_v1_event, setup, teardown_commit), - }; - - return cmocka_run_group_tests(tests, group_init, group_teardown); -} - - diff --git a/test/cmocka/unit_test_bbfd.c b/test/cmocka/unit_test_bbfd.c deleted file mode 100644 index 1b640b97..00000000 --- a/test/cmocka/unit_test_bbfd.c +++ /dev/null @@ -1,777 +0,0 @@ -#include -#include -#include -#include - -#include -#include -#include - -#include "../../libbbfdm/dmtree/tr181/device.h" - -static DMOBJ TR181_ROOT_TREE[] = { -/* OBJ, permission, addobj, delobj, checkdep, browseinstobj, nextdynamicobj, dynamicleaf, nextobj, leaf, linker, bbfdm_type, uniqueKeys*/ -{"Device", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tDeviceObj, tDeviceParams, NULL, BBFDM_BOTH}, -{0} -}; - -static int setup(void **state) -{ - struct dmctx *ctx = calloc(1, sizeof(struct dmctx)); - if (!ctx) - return -1; - - bbf_ctx_init(ctx, TR181_ROOT_TREE); - - *state = ctx; - - return 0; -} - -static int teardown_commit(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - - bbf_entry_restart_services(NULL, true); - bbf_ctx_clean(ctx); - free(ctx); - - return 0; -} - -static int teardown_revert(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - - bbf_entry_revert_changes(NULL); - bbf_ctx_clean(ctx); - free(ctx); - - return 0; -} - -static int group_init(void **state) -{ - bbf_global_init(TR181_ROOT_TREE, "/etc/bbfdm/plugins"); - return 0; -} - -static int group_teardown(void **state) -{ - bbf_global_clean(TR181_ROOT_TREE); - return 0; -} - -static void test_api_bbfdm_get_value_object(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - struct dm_parameter *first_entry; - int fault = 0; - - ctx->in_param = "Device."; - - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - first_entry = list_first_entry(&ctx->list_parameter, struct dm_parameter, list); - assert_true(&first_entry->list != &ctx->list_parameter); -} - -static void test_api_bbfdm_get_value_parameter(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - struct dm_parameter *first_entry; - int fault = 0; - - ctx->in_param = "Device.WiFi.Radio.1.Alias"; - - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - first_entry = list_first_entry(&ctx->list_parameter, struct dm_parameter, list); - assert_true(&first_entry->list != &ctx->list_parameter); -} - -static void test_api_bbfdm_get_value_empty(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - struct dm_parameter *first_entry; - int fault = 0; - - ctx->in_param = ""; - - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - first_entry = list_first_entry(&ctx->list_parameter, struct dm_parameter, list); - assert_true(&first_entry->list != &ctx->list_parameter); -} - -static void test_api_bbfdm_get_value_wrong_object_path(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - struct dm_parameter *first_entry; - int fault = 0; - - ctx->in_param = "Device.DSLL."; - - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, FAULT_9005); - - first_entry = list_first_entry(&ctx->list_parameter, struct dm_parameter, list); - assert_true(&first_entry->list == &ctx->list_parameter); -} - -static void test_api_bbfdm_get_value_wrong_parameter_path(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - struct dm_parameter *first_entry; - int fault = 0; - - ctx->in_param = "Device.Users.User.1.Enabl"; - - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, FAULT_9005); - - first_entry = list_first_entry(&ctx->list_parameter, struct dm_parameter, list); - assert_true(&first_entry->list == &ctx->list_parameter); -} - -static void test_api_bbfdm_get_value_object_alias(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - struct dm_parameter *first_entry; - int fault = 0; - - ctx->in_param = "Device."; - ctx->instance_mode = INSTANCE_MODE_ALIAS; - - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - first_entry = list_first_entry(&ctx->list_parameter, struct dm_parameter, list); - assert_true(&first_entry->list != &ctx->list_parameter); -} - -static void test_api_bbfdm_get_value_parameter_alias(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - struct dm_parameter *first_entry; - int fault = 0; - - ctx->in_param = "Device.WiFi.Radio.[cpe-1].Alias"; - ctx->instance_mode = INSTANCE_MODE_ALIAS; - - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - first_entry = list_first_entry(&ctx->list_parameter, struct dm_parameter, list); - assert_true(&first_entry->list != &ctx->list_parameter); -} - -static void test_api_bbfdm_get_name_object(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - struct dm_parameter *first_entry; - int fault = 0; - - ctx->in_param = "Device."; - ctx->nextlevel = false; - - fault = bbf_entry_method(ctx, BBF_GET_NAME); - assert_int_equal(fault, 0); - - first_entry = list_first_entry(&ctx->list_parameter, struct dm_parameter, list); - assert_true(&first_entry->list != &ctx->list_parameter); -} - -static void test_api_bbfdm_get_name_parameter(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - struct dm_parameter *first_entry; - int fault = 0; - - ctx->in_param = "Device.WiFi.Radio.1.Enable"; - ctx->nextlevel = false; - - fault = bbf_entry_method(ctx, BBF_GET_NAME); - assert_int_equal(fault, 0); - - first_entry = list_first_entry(&ctx->list_parameter, struct dm_parameter, list); - assert_true(&first_entry->list != &ctx->list_parameter); -} - -static void test_api_bbfdm_get_name_dot(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - struct dm_parameter *first_entry; - int fault = 0; - - ctx->in_param = "."; - ctx->nextlevel = false; - - fault = bbf_entry_method(ctx, BBF_GET_NAME); - assert_int_equal(fault, FAULT_9005); - - first_entry = list_first_entry(&ctx->list_parameter, struct dm_parameter, list); - assert_true(&first_entry->list == &ctx->list_parameter); -} - -static void test_api_bbfdm_get_name_wrong_object_path(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - struct dm_parameter *first_entry; - int fault = 0; - - ctx->in_param = "Device.WiFii."; - ctx->nextlevel = false; - - fault = bbf_entry_method(ctx, BBF_GET_NAME); - assert_int_equal(fault, FAULT_9005); - - first_entry = list_first_entry(&ctx->list_parameter, struct dm_parameter, list); - assert_true(&first_entry->list == &ctx->list_parameter); -} - -static void test_api_bbfdm_get_name_parameter_alias(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - struct dm_parameter *first_entry; - int fault = 0; - - ctx->in_param = "Device.WiFi.Radio.[cpe-1].Enable"; - ctx->instance_mode = INSTANCE_MODE_ALIAS; - ctx->nextlevel = false; - - fault = bbf_entry_method(ctx, BBF_GET_NAME); - assert_int_equal(fault, 0); - - first_entry = list_first_entry(&ctx->list_parameter, struct dm_parameter, list); - assert_true(&first_entry->list != &ctx->list_parameter); -} - -static void test_api_bbfdm_set_value_object(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - int fault = 0; - - ctx->in_param = "Device.Users.User."; - ctx->in_value = "test"; - - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, FAULT_9005); -} - -static void test_api_bbfdm_set_value_parameter(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - int fault = 0; - - ctx->in_param = "Device.Users.User.1.Username"; - ctx->in_value = "test"; - - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, 0); -} - -static void test_api_bbfdm_set_value_empty(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - int fault = 0; - - ctx->in_param = ""; - ctx->in_value = "test"; - - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, FAULT_9005); -} - -static void test_api_bbfdm_set_value_wrong_parameter_path(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - int fault = 0; - - ctx->in_param = "Device.Users.User.Username"; - ctx->in_value = "test"; - - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, FAULT_9005); -} - -static void test_api_bbfdm_set_value_parameter_non_writable(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - int fault = 0; - - ctx->in_param = "Device.WiFi.Radio.1.Status"; - ctx->in_value = "Enabled"; - - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, FAULT_9008); -} - -static void test_api_bbfdm_set_value_parameter_wrong_value(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - int fault = 0; - - ctx->in_param = "Device.WiFi.Radio.1.Enable"; - ctx->in_value = "truee"; - - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, FAULT_9007); -} - -static void test_api_bbfdm_set_value_parameter_alias(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - int fault = 0; - - ctx->in_param = "Device.Users.User.[cpe-1].Username"; - ctx->in_value = "test"; - ctx->instance_mode = INSTANCE_MODE_ALIAS; - - fault = bbf_entry_method(ctx, BBF_SET_VALUE); - assert_int_equal(fault, 0); -} - -static void test_api_bbfdm_add_object(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - int fault = 0; - - ctx->in_param = "Device.Users.User."; - - fault = bbf_entry_method(ctx, BBF_ADD_OBJECT); - assert_int_equal(fault, 0); - - assert_non_null(ctx->addobj_instance); - assert_string_not_equal(ctx->addobj_instance, "0"); -} - -static void test_api_bbfdm_add_wrong_object(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - int fault = 0; - - ctx->in_param = "Device.WiFi.Users."; - - fault = bbf_entry_method(ctx, BBF_ADD_OBJECT); - assert_int_equal(fault, FAULT_9005); - - assert_null(ctx->addobj_instance); -} - -static void test_api_bbfdm_add_object_non_writable(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - int fault = 0; - - ctx->in_param = "Device.WiFi.Radio."; - - fault = bbf_entry_method(ctx, BBF_ADD_OBJECT); - assert_int_equal(fault, FAULT_9005); - - assert_null(ctx->addobj_instance); -} - -static void test_api_bbfdm_add_object_empty(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - int fault = 0; - - ctx->in_param = ""; - - fault = bbf_entry_method(ctx, BBF_ADD_OBJECT); - assert_int_equal(fault, FAULT_9005); - - assert_null(ctx->addobj_instance); -} - -static void test_api_bbfdm_delete_object(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - int fault = 0; - - ctx->in_param = "Device.WiFi.SSID.1."; - - fault = bbf_entry_method(ctx, BBF_DEL_OBJECT); - assert_int_equal(fault, 0); -} - -static void test_api_bbfdm_delete_object_all_instances(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - int fault = 0; - - ctx->in_param = "Device.Users.User."; - - fault = bbf_entry_method(ctx, BBF_DEL_OBJECT); - assert_int_equal(fault, 0); -} - -static void test_api_bbfdm_delete_wrong_object(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - int fault = 0; - - ctx->in_param = "Device.WiFi.SSID"; - - fault = bbf_entry_method(ctx, BBF_DEL_OBJECT); - assert_int_equal(fault, FAULT_9005); -} - -static void test_api_bbfdm_delete_object_non_writable(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - int fault = 0; - - ctx->in_param = "Device.Hosts.Host."; - - fault = bbf_entry_method(ctx, BBF_DEL_OBJECT); - assert_int_equal(fault, FAULT_9005); -} - -static void test_api_bbfdm_delete_object_empty(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - int fault = 0; - - ctx->in_param = ""; - - fault = bbf_entry_method(ctx, BBF_DEL_OBJECT); - assert_int_equal(fault, FAULT_9005); -} - -static void test_api_bbfdm_valid_operate(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - int fault = 0; - - ctx->in_param = "Device.WiFi.AccessPoint.1.Security.Reset()"; - - fault = bbf_entry_method(ctx, BBF_OPERATE); - assert_int_equal(fault, 0); -} - -static void test_api_bbfdm_wrong_operate(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - int fault = 0; - - ctx->in_param = "Device.IP.Diagnostics.IPing()"; - - fault = bbf_entry_method(ctx, BBF_OPERATE); - assert_int_equal(fault, USP_FAULT_INVALID_PATH); -} - -static void test_api_bbfdm_get_list_operate(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - struct dm_parameter *first_entry; - int fault = 0; - - ctx->in_param = "Device."; - ctx->dm_type = BBFDM_USP; - ctx->nextlevel = false; - ctx->iscommand = true; - ctx->isevent = false; - ctx->isinfo = false; - - fault = bbf_entry_method(ctx, BBF_SCHEMA); - assert_int_equal(fault, 0); - - first_entry = list_first_entry(&ctx->list_parameter, struct dm_parameter, list); - assert_true(&first_entry->list != &ctx->list_parameter); -} - -static void test_api_bbfdm_get_list_event(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - struct dm_parameter *first_entry; - int fault = 0; - - ctx->in_param = "Device."; - ctx->dm_type = BBFDM_USP; - ctx->nextlevel = false; - ctx->iscommand = false; - ctx->isevent = true; - ctx->isinfo = false; - - fault = bbf_entry_method(ctx, BBF_SCHEMA); - assert_int_equal(fault, 0); - - first_entry = list_first_entry(&ctx->list_parameter, struct dm_parameter, list); - assert_true(&first_entry->list != &ctx->list_parameter); -} - -static void test_api_bbfdm_get_schema(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - struct dm_parameter *first_entry; - int fault = 0; - - ctx->in_param = "Device."; - ctx->dm_type = BBFDM_USP; - ctx->nextlevel = false; - ctx->iscommand = true; - ctx->isevent = true; - ctx->isinfo = true; - - fault = bbf_entry_method(ctx, BBF_SCHEMA); - assert_int_equal(fault, 0); - - first_entry = list_first_entry(&ctx->list_parameter, struct dm_parameter, list); - assert_true(&first_entry->list != &ctx->list_parameter); -} - -static void test_api_bbfdm_get_instances_object(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - struct dm_parameter *first_entry; - int fault = 0; - - ctx->in_param = "Device."; - ctx->nextlevel = false; - - fault = bbf_entry_method(ctx, BBF_INSTANCES); - assert_int_equal(fault, 0); - - first_entry = list_first_entry(&ctx->list_parameter, struct dm_parameter, list); - assert_true(&first_entry->list != &ctx->list_parameter); -} - -static void test_api_bbfdm_get_instances_wrong_object(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - struct dm_parameter *first_entry; - int fault = 0; - - ctx->in_param = "Device.WiFii."; - ctx->nextlevel = false; - - fault = bbf_entry_method(ctx, BBF_INSTANCES); - assert_int_equal(fault, FAULT_9005); - - first_entry = list_first_entry(&ctx->list_parameter, struct dm_parameter, list); - assert_true(&first_entry->list == &ctx->list_parameter); -} - -static void test_api_bbfdm_get_instances_without_next_level(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - struct dm_parameter *first_entry; - int fault = 0; - - ctx->in_param = "Device.WiFi."; - ctx->nextlevel = false; - - fault = bbf_entry_method(ctx, BBF_INSTANCES); - assert_int_equal(fault, 0); - - first_entry = list_first_entry(&ctx->list_parameter, struct dm_parameter, list); - assert_true(&first_entry->list != &ctx->list_parameter); -} - -static void test_api_bbfdm_json_get_value(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - struct dm_parameter *first_entry; - int fault = 0; - - /* - * Test of JSON Object Path - */ - ctx->in_param = "Device.X_IOPSYS_EU_Dropbear."; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - first_entry = list_first_entry(&ctx->list_parameter, struct dm_parameter, list); - assert_true(&first_entry->list != &ctx->list_parameter); - - bbf_ctx_clean_sub(ctx); - bbf_ctx_init(ctx, TR181_ROOT_TREE); - - /* - * Test of JSON Parameter Path - */ - ctx->in_param = "Device.UserInterface.Enable"; - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - first_entry = list_first_entry(&ctx->list_parameter, struct dm_parameter, list); - assert_true(&first_entry->list != &ctx->list_parameter); - - bbf_ctx_clean_sub(ctx); - bbf_ctx_init(ctx, TR181_ROOT_TREE); -} - -static void test_api_bbfdm_json_add_object(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - int fault = 0; - - ctx->in_param = "Device.X_IOPSYS_EU_Dropbear."; - - fault = bbf_entry_method(ctx, BBF_ADD_OBJECT); - assert_int_equal(fault, 0); - - assert_non_null(ctx->addobj_instance); - assert_string_not_equal(ctx->addobj_instance, "0"); -} - -static void test_api_bbfdm_json_delete_object(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - int fault = 0; - - ctx->in_param = "Device.X_IOPSYS_EU_Dropbear.1."; - - fault = bbf_entry_method(ctx, BBF_DEL_OBJECT); - assert_int_equal(fault, 0); - - ctx->in_param = "Device.X_IOPSYS_EU_Dropbear."; - - fault = bbf_entry_method(ctx, BBF_DEL_OBJECT); - assert_int_equal(fault, 0); -} - -static void test_api_bbfdm_library_get_value(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - struct dm_parameter *first_entry; - int fault = 0; - - ctx->in_param = "Device.X_IOPSYS_EU_Syslog."; - - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - first_entry = list_first_entry(&ctx->list_parameter, struct dm_parameter, list); - assert_true(&first_entry->list != &ctx->list_parameter); - - bbf_ctx_clean_sub(ctx); - bbf_ctx_init(ctx, TR181_ROOT_TREE); - - ctx->in_param = "Device.WiFi.SSID.1.Enable"; - - fault = bbf_entry_method(ctx, BBF_GET_VALUE); - assert_int_equal(fault, 0); - - first_entry = list_first_entry(&ctx->list_parameter, struct dm_parameter, list); - assert_true(&first_entry->list != &ctx->list_parameter); - - bbf_ctx_clean_sub(ctx); -} - -static void test_api_bbfdm_library_add_object(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - int fault = 0; - - ctx->in_param = "Device.WiFi.SSID."; - - fault = bbf_entry_method(ctx, BBF_ADD_OBJECT); - assert_int_equal(fault, 0); - - assert_non_null(ctx->addobj_instance); - assert_string_not_equal(ctx->addobj_instance, "0"); -} - -static void test_api_bbfdm_library_delete_object(void **state) -{ - struct dmctx *ctx = (struct dmctx *) *state; - int fault = 0; - - ctx->in_param = "Device.WiFi.SSID.1."; - - fault = bbf_entry_method(ctx, BBF_DEL_OBJECT); - assert_int_equal(fault, 0); - - ctx->in_param = "Device.WiFi.SSID."; - - fault = bbf_entry_method(ctx, BBF_DEL_OBJECT); - assert_int_equal(fault, 0); -} - -int main(void) -{ - const struct CMUnitTest tests[] = { - - // Get Value method test cases - cmocka_unit_test_setup_teardown(test_api_bbfdm_get_value_object, setup, teardown_commit), - cmocka_unit_test_setup_teardown(test_api_bbfdm_get_value_parameter, setup, teardown_commit), - cmocka_unit_test_setup_teardown(test_api_bbfdm_get_value_empty, setup, teardown_commit), - cmocka_unit_test_setup_teardown(test_api_bbfdm_get_value_wrong_object_path, setup, teardown_revert), - cmocka_unit_test_setup_teardown(test_api_bbfdm_get_value_wrong_parameter_path, setup, teardown_revert), - cmocka_unit_test_setup_teardown(test_api_bbfdm_get_value_object_alias, setup, teardown_commit), - cmocka_unit_test_setup_teardown(test_api_bbfdm_get_value_parameter_alias, setup, teardown_commit), - - // Get Name method test cases - cmocka_unit_test_setup_teardown(test_api_bbfdm_get_name_object, setup, teardown_commit), - cmocka_unit_test_setup_teardown(test_api_bbfdm_get_name_parameter, setup, teardown_commit), - cmocka_unit_test_setup_teardown(test_api_bbfdm_get_name_dot, setup, teardown_revert), - cmocka_unit_test_setup_teardown(test_api_bbfdm_get_name_wrong_object_path, setup, teardown_revert), - cmocka_unit_test_setup_teardown(test_api_bbfdm_get_name_parameter_alias, setup, teardown_commit), - - // Set Value method test cases - cmocka_unit_test_setup_teardown(test_api_bbfdm_set_value_object, setup, teardown_revert), - cmocka_unit_test_setup_teardown(test_api_bbfdm_set_value_parameter, setup, teardown_commit), - cmocka_unit_test_setup_teardown(test_api_bbfdm_set_value_empty, setup, teardown_revert), - cmocka_unit_test_setup_teardown(test_api_bbfdm_set_value_wrong_parameter_path, setup, teardown_revert), - cmocka_unit_test_setup_teardown(test_api_bbfdm_set_value_parameter_non_writable, setup, teardown_revert), - cmocka_unit_test_setup_teardown(test_api_bbfdm_set_value_parameter_wrong_value, setup, teardown_revert), - cmocka_unit_test_setup_teardown(test_api_bbfdm_set_value_parameter_alias, setup, teardown_commit), - - // Add Object method test cases - cmocka_unit_test_setup_teardown(test_api_bbfdm_add_object, setup, teardown_commit), - cmocka_unit_test_setup_teardown(test_api_bbfdm_add_wrong_object, setup, teardown_revert), - cmocka_unit_test_setup_teardown(test_api_bbfdm_add_object_non_writable, setup, teardown_revert), - cmocka_unit_test_setup_teardown(test_api_bbfdm_add_object_empty, setup, teardown_revert), - - // Delete Object method test cases - cmocka_unit_test_setup_teardown(test_api_bbfdm_delete_object, setup, teardown_revert), - cmocka_unit_test_setup_teardown(test_api_bbfdm_delete_object_all_instances, setup, teardown_commit), - cmocka_unit_test_setup_teardown(test_api_bbfdm_delete_wrong_object, setup, teardown_revert), - cmocka_unit_test_setup_teardown(test_api_bbfdm_delete_object_non_writable, setup, teardown_revert), - cmocka_unit_test_setup_teardown(test_api_bbfdm_delete_object_empty, setup, teardown_revert), - - // Get Instances method test cases - cmocka_unit_test_setup_teardown(test_api_bbfdm_get_instances_object, setup, teardown_commit), - cmocka_unit_test_setup_teardown(test_api_bbfdm_get_instances_wrong_object, setup, teardown_revert), - cmocka_unit_test_setup_teardown(test_api_bbfdm_get_instances_without_next_level, setup, teardown_revert), - - // Operate method test cases - cmocka_unit_test_setup_teardown(test_api_bbfdm_valid_operate, setup, teardown_commit), - cmocka_unit_test_setup_teardown(test_api_bbfdm_wrong_operate, setup, teardown_commit), - - // Get List Operate method test cases - cmocka_unit_test_setup_teardown(test_api_bbfdm_get_list_operate, setup, teardown_commit), - - // Get List Operate method test cases - cmocka_unit_test_setup_teardown(test_api_bbfdm_get_list_event, setup, teardown_commit), - - // Get Schema method test cases - cmocka_unit_test_setup_teardown(test_api_bbfdm_get_schema, setup, teardown_commit), - - // JSON: Get Value method test cases - cmocka_unit_test_setup_teardown(test_api_bbfdm_json_get_value, setup, teardown_commit), - - // JSON: Add Object method test cases - cmocka_unit_test_setup_teardown(test_api_bbfdm_json_add_object, setup, teardown_commit), - - // JSON: Delete Object method test cases - cmocka_unit_test_setup_teardown(test_api_bbfdm_json_delete_object, setup, teardown_commit), - - // Library: Get Value method test cases - cmocka_unit_test_setup_teardown(test_api_bbfdm_library_get_value, setup, teardown_commit), - - // Library: Add Object method test cases - cmocka_unit_test_setup_teardown(test_api_bbfdm_library_add_object, setup, teardown_commit), - - // Library: Delete Object method test cases - cmocka_unit_test_setup_teardown(test_api_bbfdm_library_delete_object, setup, teardown_commit), - }; - - return cmocka_run_group_tests(tests, group_init, group_teardown); -}