diff --git a/src/webcfg_metadata.c b/src/webcfg_metadata.c index 9d315c8e..21844295 100644 --- a/src/webcfg_metadata.c +++ b/src/webcfg_metadata.c @@ -28,16 +28,6 @@ /*----------------------------------------------------------------------------*/ /* Data Structures */ /*----------------------------------------------------------------------------*/ -typedef struct SubDocSupportMap -{ - char name[256];//portforwarding or wlan - char support[8];//true or false; - #ifdef WEBCONFIG_BIN_SUPPORT - char rbus_listener[8];//true or false - char dest[64]; //comp destination eg. webconfig.pam.portforwarding - #endif - struct SubDocSupportMap *next; -}SubDocSupportMap_t; /*----------------------------------------------------------------------------*/ /* File Scoped Variables */ @@ -53,9 +43,6 @@ SupplementaryDocs_t *g_spInfoTail = NULL; /* Function Prototypes */ /*----------------------------------------------------------------------------*/ void displaystruct(); -SubDocSupportMap_t * get_global_sdInfoHead(void); -SubDocSupportMap_t * get_global_sdInfoTail(void); -SupplementaryDocs_t * get_global_spInfoTail(void); /*----------------------------------------------------------------------------*/ /* External Functions */ /*----------------------------------------------------------------------------*/ diff --git a/src/webcfg_metadata.h b/src/webcfg_metadata.h index 424676f4..45e8f05e 100644 --- a/src/webcfg_metadata.h +++ b/src/webcfg_metadata.h @@ -36,6 +36,27 @@ typedef struct SupplementaryDocs char *name; struct SupplementaryDocs *next; }SupplementaryDocs_t; + +typedef struct SubDocSupportMap +{ + char name[256];//portforwarding or wlan + char support[8];//true or false; + #ifdef WEBCONFIG_BIN_SUPPORT + char rbus_listener[8];//true or false + char dest[64]; //comp destination eg. webconfig.pam.portforwarding + #endif + struct SubDocSupportMap *next; +}SubDocSupportMap_t; + +SubDocSupportMap_t * get_global_sdInfoHead(void); +SubDocSupportMap_t * get_global_sdInfoTail(void); +SupplementaryDocs_t * get_global_spInfoTail(void); + +extern SubDocSupportMap_t *g_sdInfoHead; +extern SubDocSupportMap_t *g_sdInfoTail; +extern SupplementaryDocs_t *g_spInfoHead; +extern SupplementaryDocs_t *g_spInfoTail; + /*----------------------------------------------------------------------------*/ /* External Functions */ /*----------------------------------------------------------------------------*/ @@ -53,6 +74,7 @@ char * getsupportedVersion(); char * getsupplementaryDocs(); void supplementaryDocs(); void delete_supplementary_list(); +void displaystruct(); SupplementaryDocs_t * get_global_spInfoHead(void); WEBCFG_STATUS isSupplementaryDoc(char *subDoc); #endif diff --git a/tests/test_metadata.c b/tests/test_metadata.c index ff9be311..57c51f1b 100644 --- a/tests/test_metadata.c +++ b/tests/test_metadata.c @@ -62,11 +62,18 @@ void test_initWebcfgProperties() { char buf[512] = {'\0'}; snprintf(buf,sizeof(buf),"WEBCONFIG_SUPPORTED_DOCS_BIT=00000000000000000000000000000000|00000000000000000000000000000000"); - writeToFile(WEBCFG_PROPERTIES_FILE, buf, strlen(buf)); + int out = writeToFile(WEBCFG_PROPERTIES_FILE, buf, strlen(buf)); + CU_ASSERT_EQUAL(out, 1); initWebcfgProperties(WEBCFG_PROPERTIES_FILE); + snprintf(buf,sizeof(buf),"WEBCONFIG_DOC_SCHEMA_VERSION=1234-v0,2345-v0"); - writeToFile(WEBCFG_PROPERTIES_FILE, buf, strlen(buf)); + out = writeToFile(WEBCFG_PROPERTIES_FILE, buf, strlen(buf)); + CU_ASSERT_EQUAL(out, 1); initWebcfgProperties(WEBCFG_PROPERTIES_FILE); + + snprintf(buf,sizeof(buf),"WEBCONFIG_SUBDOC_MAP=privatessid:1:true,homessid:2:true,radio:3:false"); + writeToFile(WEBCFG_PROPERTIES_FILE, buf, strlen(buf)); + initWebcfgProperties(WEBCFG_PROPERTIES_FILE); } void err_initWebcfgProperties() @@ -83,22 +90,27 @@ void test_supportedDocs() setsupportedDocs("00000001000000000000000000000001"); docs = getsupportedDocs(); printf("docs: %s\n",docs); + CU_ASSERT_STRING_EQUAL(docs, "00000001000000000000000000000001"); free(docs); setsupportedDocs("00000000000000000000000000000000"); docs = getsupportedDocs(); printf("docs: %s\n",docs); + CU_ASSERT_STRING_EQUAL(docs, "00000000000000000000000000000000"); free(docs); setsupportedDocs("00000000000000000000000000000000|10010001000000000000000000000011"); docs = getsupportedDocs(); printf("docs: %s\n",docs); + CU_ASSERT_STRING_EQUAL(docs, "00000000000000000000000000000000|10010001000000000000000000000011"); free(docs); setsupportedDocs(""); docs = getsupportedDocs(); printf("docs: %s\n",docs); + CU_ASSERT_STRING_EQUAL(docs, ""); free(docs); setsupportedDocs(NULL); docs = getsupportedDocs(); printf("docs: %s\n",docs); + CU_ASSERT_EQUAL(docs, NULL); } void test_supportedVersions() @@ -106,29 +118,314 @@ void test_supportedVersions() char *versions = NULL; setsupportedVersion("1234-v0"); versions = getsupportedVersion(); + CU_ASSERT_STRING_EQUAL("1234-v0", versions); printf("versions: %s\n",versions); free(versions); setsupportedVersion("2345-v0,432-v1"); versions = getsupportedVersion(); + CU_ASSERT_STRING_EQUAL("2345-v0,432-v1", versions); printf("versions: %s\n",versions); free(versions); } void test_isSubDocSupported() { + int sup; setsupportedDocs("00000010000000000000000000000011|00001010000000000000000000000010"); - isSubDocSupported("homessid"); - isSubDocSupported("aker"); - isSubDocSupported("privatessid"); - isSubDocSupported("radioreport"); - isSubDocSupported("interfacereport"); + sup = isSubDocSupported("homessid"); + CU_ASSERT_EQUAL(0,sup); + sup = isSubDocSupported("aker"); + CU_ASSERT_NOT_EQUAL(0,sup); + sup = isSubDocSupported("privatessid"); + CU_ASSERT_EQUAL(0,sup); + sup = isSubDocSupported("radioreport"); + CU_ASSERT_NOT_EQUAL(0,sup); + sup = isSubDocSupported("interfacereport"); + CU_ASSERT_EQUAL(1,sup); setsupportedDocs("10000010000000000000000000000011|00001010100000000000000000000010|00000000000000000000000000000000"); - isSubDocSupported("lan"); - isSubDocSupported("wifi"); + sup = isSubDocSupported("lan"); + CU_ASSERT_NOT_EQUAL(0,sup); + sup = isSubDocSupported("wifi"); + CU_ASSERT_EQUAL(1,sup); setsupportedDocs(""); - isSubDocSupported("wan"); + sup = isSubDocSupported("wan"); + CU_ASSERT_NOT_EQUAL(0,sup); setsupportedDocs(NULL); - isSubDocSupported("mesh"); + sup = isSubDocSupported("mesh"); + CU_ASSERT_EQUAL(1,sup); +} + +void test_supplementaryDocs_validInput(void) +{ + char buf[512] = {'\0'}; + snprintf(buf,sizeof(buf),"telemetry"); + setsupplementaryDocs(buf); + char *get = getsupplementaryDocs(); + CU_ASSERT_STRING_EQUAL("telemetry",get); + WebcfgInfo("The get value is %s\n",get); + snprintf(buf,sizeof(buf),"NULL"); + setsupplementaryDocs(buf); + get = getsupplementaryDocs(); + CU_ASSERT_STRING_EQUAL("NULL",get); +} + +void test_get_set_supplementaryDocs(void) +{ + char str[1024] = {'\0'}; + char *value = NULL; + strcpy(str, "WEBCONFIG_SUPPLEMENTARY_DOCS=telemetry"); + if(NULL != (value =strstr(str,"WEBCONFIG_SUPPLEMENTARY_DOCS"))) + { + WebcfgInfo("The value stored is %s\n", value); + value = value + strlen("WEBCONFIG_SUPPLEMENTARY_DOCS="); + value[strlen(value)] = '\0'; + setsupplementaryDocs(value); + value = NULL; + } + char *get = getsupplementaryDocs(); + WebcfgInfo("The get value is %s\n",get); + CU_ASSERT_STRING_EQUAL(get,"telemetry"); +} + +void test_isSupplementaryDoc(void) +{ + int result; + char validSubDoc[]="wan"; + char str[1024] = {'\0'}; + char *value = NULL; + strcpy(str, "WEBCONFIG_SUPPLEMENTARY_DOCS=00000000000000000000000000000000|00000000000000000000000000000000"); + if(NULL != (value =strstr(str,"WEBCONFIG_SUPPLEMENTARY_DOCS"))) + { + WebcfgInfo("The value stored is %s\n", value); + value = value + strlen("WEBCONFIG_SUPPLEMENTARY_DOCS="); + value[strlen(value)] = '\0'; + setsupplementaryDocs(value); + value = NULL; + } + char *get = getsupplementaryDocs(); + WebcfgInfo("The get value is %s\n",get); + CU_ASSERT_STRING_EQUAL("00000000000000000000000000000000|00000000000000000000000000000000",get); + result = isSupplementaryDoc(validSubDoc); + CU_ASSERT_EQUAL(1,result); + WebcfgInfo("The result value is %d\n",result); +} + +void test_get_spInfoHead(void) +{ + SupplementaryDocs_t *sd = NULL; + sd = (SupplementaryDocs_t *)malloc(sizeof(SupplementaryDocs_t)); + if(sd != NULL) + { + sd->name="privatessid"; + sd->next=NULL; + } + + SupplementaryDocs_t *sd1 = NULL; + sd1 = (SupplementaryDocs_t *)malloc(sizeof(SupplementaryDocs_t)); + if(sd1 != NULL) + { + sd1->name="wan"; + sd1->next=NULL; + sd->next=sd1; + } + SupplementaryDocs_t *sd2 = NULL; + sd2 = (SupplementaryDocs_t *)malloc(sizeof(SupplementaryDocs_t)); + if(sd2 != NULL) + { + sd2->name="wifi"; + sd1->next=NULL; + sd1->next=sd2; + } + + CU_ASSERT_PTR_NOT_NULL(sd); + g_spInfoHead = sd; + + SupplementaryDocs_t *result = get_global_spInfoHead(); + CU_ASSERT_EQUAL("privatessid",result->name); +} + +void test_get_spInfotail(void) +{ + SupplementaryDocs_t *sd = NULL; + sd = (SupplementaryDocs_t *)malloc(sizeof(SupplementaryDocs_t)); + if(sd != NULL) + { + sd->name="privatessid"; + sd->next=NULL; + } + + SupplementaryDocs_t *sd1 = NULL; + sd1 = (SupplementaryDocs_t *)malloc(sizeof(SupplementaryDocs_t)); + if(sd1 != NULL) + { + sd1->name="wan"; + sd1->next=NULL; + sd->next=sd1; + } + SupplementaryDocs_t *sd2 = NULL; + sd2 = (SupplementaryDocs_t *)malloc(sizeof(SupplementaryDocs_t)); + if(sd2 != NULL) + { + sd2->name="wifi"; + sd1->next=NULL; + sd1->next=sd2; + } + + CU_ASSERT_PTR_NOT_NULL(sd); + g_spInfoTail = sd2; + + SupplementaryDocs_t *result = get_global_spInfoTail(); + CU_ASSERT_EQUAL("wifi",result->name); +} + +void test_displaystruct(void) +{ + SubDocSupportMap_t *test = NULL; + test = (SubDocSupportMap_t *)malloc(sizeof(SubDocSupportMap_t)); + if(test!=NULL) + { + strcpy(test->name,"privatessid"); + strcpy(test->support,"true"); + strcpy(test->rbus_listener,"true"); + strcpy(test->dest,"webconfig.pam.portforwarding"); + test->next=NULL; + } + SubDocSupportMap_t *test2 = NULL; + test2 =(SubDocSupportMap_t *)malloc(sizeof(SubDocSupportMap_t)); + if(test2!=NULL) + { + strcpy(test2->name,"radio"); + strcpy(test2->support,"true"); + strcpy(test2->rbus_listener,"true"); + strcpy(test2->dest,"webconfig.pam.portforwarding"); + test2->next=NULL; + test->next=test2; + } + CU_ASSERT_PTR_NOT_NULL(test); + g_sdInfoHead = test; + g_sdInfoTail = test2; + + displaystruct(); + + SubDocSupportMap_t *tmp = get_global_sdInfoHead(); + WebcfgInfo("The tmp value is %s\n",tmp->name); + CU_ASSERT_PTR_NOT_NULL(tmp); + CU_ASSERT_STRING_EQUAL("privatessid",tmp); + tmp = get_global_sdInfoTail(); + WebcfgInfo("The tmp value is %s\n",tmp->name); + CU_ASSERT_PTR_NOT_NULL(tmp); + CU_ASSERT_STRING_EQUAL("radio",tmp); + +} + +void test_get_destination(void) +{ + char dest[64]; + memset(dest, 0, sizeof(dest)); + SubDocSupportMap_t *test = NULL; + test = (SubDocSupportMap_t *)malloc(sizeof(SubDocSupportMap_t)); + if(test!=NULL) + { + strcpy(test->name,"homessid"); + strcpy(test->support,"true"); + strcpy(test->rbus_listener,"true"); + strcpy(test->dest,"webconfig.pam.portforwarding"); + test->next=NULL; + } + + SubDocSupportMap_t *test2 = NULL; + test2 =(SubDocSupportMap_t *)malloc(sizeof(SubDocSupportMap_t)); + if(test2!=NULL) + { + strcpy(test2->name,"privatessid"); + strcpy(test2->support,"true"); + strcpy(test2->rbus_listener,"true"); + strcpy(test2->dest,"webconfig.pam.portforwarding"); + test2->next=NULL; + test->next=test2; + } + CU_ASSERT_PTR_NOT_NULL(test); + g_sdInfoHead = test; + + //positive scenario + int get_dest = get_destination("homessid",dest); + WebcfgInfo("Return value of get_destination %d\n",get_dest); + CU_ASSERT_EQUAL(0,get_dest); + + get_dest = get_destination("privatessid",dest); + WebcfgInfo("Return value of get_destination %d\n",get_dest); + CU_ASSERT_EQUAL(0,get_dest); + + //negative scenario + get_dest = get_destination("radio",dest); + WebcfgInfo("Return value of get_destination %d\n",get_dest); + CU_ASSERT_EQUAL(1,get_dest); +} + +void test_isRbusListener_true() +{ + SubDocSupportMap_t *test = NULL; + test = (SubDocSupportMap_t *)malloc(sizeof(SubDocSupportMap_t)); + if(test!=NULL) + { + strcpy(test->name,"homessid"); + strcpy(test->support,"true"); + strcpy(test->rbus_listener,"true"); + strcpy(test->dest,"webconfig.pam.portforwarding"); + test->next=NULL; + } + + SubDocSupportMap_t *test2 = NULL; + test2 =(SubDocSupportMap_t *)malloc(sizeof(SubDocSupportMap_t)); + if(test2!=NULL) + { + strcpy(test2->name,"privatessid"); + strcpy(test2->support,"true"); + strcpy(test2->rbus_listener,"true"); + strcpy(test2->dest,"webconfig.pam.portforwarding"); + test2->next=NULL; + test->next=test2; + } + CU_ASSERT_PTR_NOT_NULL(test); + g_sdInfoHead = test; + bool result = isRbusListener("homessid"); + CU_ASSERT_EQUAL(1,result); + result = isRbusListener("privatessid"); + CU_ASSERT_EQUAL(1,result); +} + +void test_isRbusListener_false() +{ +SubDocSupportMap_t *test = NULL; + test = (SubDocSupportMap_t *)malloc(sizeof(SubDocSupportMap_t)); + if(test!=NULL) + { + strcpy(test->name,"homessid"); + strcpy(test->support,"true"); + strcpy(test->rbus_listener,"false"); + strcpy(test->dest,"webconfig.pam.portforwarding"); + test->next=NULL; + } + + SubDocSupportMap_t *test2 = NULL; + test2 =(SubDocSupportMap_t *)malloc(sizeof(SubDocSupportMap_t)); + if(test2!=NULL) + { + strcpy(test2->name,"privatessid"); + strcpy(test2->support,"true"); + strcpy(test2->rbus_listener,"false"); + strcpy(test2->dest,"webconfig.pam.portforwarding"); + test2->next=NULL; + test->next=test2; + } + CU_ASSERT_PTR_NOT_NULL(test); + g_sdInfoHead = test;bool result = isRbusListener("homessid"); + CU_ASSERT_EQUAL(0,result); + result = isRbusListener("privatessid"); + CU_ASSERT_EQUAL(0,result); + //subdoc which is not present + result = isRbusListener("wan"); + CU_ASSERT_EQUAL(0,result); } void add_suites( CU_pSuite *suite ) @@ -139,6 +436,16 @@ void add_suites( CU_pSuite *suite ) CU_add_test( *suite, "Test Supported docs\n", test_supportedDocs); CU_add_test( *suite, "Test Supported versions\n", test_supportedVersions); CU_add_test( *suite, "Test isSubDocSupported\n", test_isSubDocSupported); + CU_add_test( *suite, "Test supplementary docs valid\n", test_supplementaryDocs_validInput); + CU_add_test( *suite, "Test set get supplementaryDocs\n", test_get_set_supplementaryDocs); + CU_add_test( *suite, "Test isSupplementaryDoc\n", test_isSupplementaryDoc); + CU_add_test( *suite, "Test get_spInfoHead\n", test_get_spInfoHead); + CU_add_test( *suite, "Test get_spInfoTail\n", test_get_spInfotail); + CU_add_test( *suite, "Test displaystruct\n", test_displaystruct); + CU_add_test( *suite, "Test get_destination\n", test_get_destination); + CU_add_test( *suite, "Test isRbusListener true\n", test_isRbusListener_true); + CU_add_test( *suite, "Test isRbusListener false\n", test_isRbusListener_false); + } /*----------------------------------------------------------------------------*/