From d6809c029d406d5eaa571a086101c87f409bb5b4 Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 22 May 2018 13:21:37 -0600 Subject: [PATCH 1/5] First unit test --- tests/api.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/api.c b/tests/api.c index 11bcbded3..92381b462 100644 --- a/tests/api.c +++ b/tests/api.c @@ -14730,6 +14730,45 @@ static void test_wc_PKCS7_EncodeEncryptedData (void) #endif } /* END test_wc_PKCS7_EncodeEncryptedData() */ +/*----------------------------------------------------------------------------* + | hash.h Tests + *----------------------------------------------------------------------------*/ +static void test_wc_HashInit(void) +{ + /*enum for holding supported algorithms, #ifndef's restrict if disabled*/ + enum wc_HashType enumArray[] = { + #ifndef NO_MD5 + WC_HASH_TYPE_MD5, + #endif + #ifndef NO_SHA + WC_HASH_TYPE_SHA, + #endif + #ifndef NO_SHA224 + WC_HASH_TYPE_SHA224, + #endif + #ifndef NO_SHA256 + WC_HASH_TYPE_SHA256, + #endif + #ifndef NO_SHA384 + WC_HASH_TYPE_SHA384, + #endif + #ifndef NO_SHA512 + WC_HASH_TYPE_SHA512, + #endif + }; + int enumlen = (sizeof(enumArray))/4;/*dynamically finds the length*/ + printf("the len of enum is: %d\n", enumlen); + /*For loop to test various arguments...*/ + for(int i =0; i < enumlen; i++){ + wc_HashAlg hash; + if(wc_HashInit(&hash, enumArray[i])==BAD_FUNC_ARG){/*checking for bad args*/ + printf("Testing with argument itm# %d with a goodPtr-BAD_FUNC_ARG\n", i); + } + if(wc_HashInit(NULL, enumArray[i])==BAD_FUNC_ARG){/*checking for null ptr*/ + printf("Testing with null pointer itm# %d returned BAD_FUNC_ARG\n", i); + } + }/* end of for loop */ +}/* end of test_wc_HashInit */ /*----------------------------------------------------------------------------* @@ -18876,6 +18915,8 @@ void ApiTest(void) test_wc_PKCS7_EncodeDecodeEnvelopedData(); test_wc_PKCS7_EncodeEncryptedData(); + test_wc_HashInit(); + printf(" End API Tests\n"); } From 58ac951471db2d43ad5970e0c743b7242f3646dc Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 22 May 2018 16:00:40 -0600 Subject: [PATCH 2/5] Changes made- Thank you --- tests/api.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/tests/api.c b/tests/api.c index bfef64625..2700c7a3a 100644 --- a/tests/api.c +++ b/tests/api.c @@ -14824,7 +14824,8 @@ static void test_wc_PKCS7_EncodeEncryptedData (void) NULL, sizeof(decoded)), BAD_FUNC_ARG); AssertIntEQ(wc_PKCS7_DecodeEncryptedData(&pkcs7, encrypted, encryptedSz, decoded, 0), BAD_FUNC_ARG); - /* Test struct fields */ + /* Test + struct fields */ tmpBytePtr = pkcs7.encryptionKey; pkcs7.encryptionKey = NULL; @@ -14853,31 +14854,42 @@ static void test_wc_HashInit(void) #ifndef NO_SHA WC_HASH_TYPE_SHA, #endif - #ifndef NO_SHA224 + #ifndef WOLFSSL_SHA224 WC_HASH_TYPE_SHA224, #endif #ifndef NO_SHA256 WC_HASH_TYPE_SHA256, #endif - #ifndef NO_SHA384 + #ifndef WOLFSSL_SHA384 WC_HASH_TYPE_SHA384, #endif - #ifndef NO_SHA512 + #ifndef WOLFSSL_SHA512 WC_HASH_TYPE_SHA512, #endif }; + int ret = 0; /*0 indicates tests passed, 1 indicates failure*/ int enumlen = (sizeof(enumArray))/4;/*dynamically finds the length*/ - printf("the len of enum is: %d\n", enumlen); + /*For loop to test various arguments...*/ for(int i =0; i < enumlen; i++){ wc_HashAlg hash; if(wc_HashInit(&hash, enumArray[i])==BAD_FUNC_ARG){/*checking for bad args*/ - printf("Testing with argument itm# %d with a goodPtr-BAD_FUNC_ARG\n", i); + ret = 1; } - if(wc_HashInit(NULL, enumArray[i])==BAD_FUNC_ARG){/*checking for null ptr*/ - printf("Testing with null pointer itm# %d returned BAD_FUNC_ARG\n", i); + if(wc_HashInit(NULL, enumArray[i])!=BAD_FUNC_ARG){/*checking for null ptr*/ + ret = 1; } + }/* end of for loop */ + + printf(testingFmt, "wc_HashInit()"); + if(ret==0){/* all tests have passed */ + printf(resultFmt, passed); + } + if(ret==1){/* a test has failed */ + printf(resultFmt, failed); + } + }/* end of test_wc_HashInit */ From 83e67a41976d822e98683661b9364523f0454262 Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 22 May 2018 17:25:22 -0600 Subject: [PATCH 3/5] additional changes made --- tests/api.c | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/tests/api.c b/tests/api.c index 2700c7a3a..725f0c708 100644 --- a/tests/api.c +++ b/tests/api.c @@ -14844,9 +14844,13 @@ static void test_wc_PKCS7_EncodeEncryptedData (void) /*----------------------------------------------------------------------------* | hash.h Tests *----------------------------------------------------------------------------*/ -static void test_wc_HashInit(void) +static int test_wc_HashInit(void) { - /*enum for holding supported algorithms, #ifndef's restrict if disabled*/ + int ret = 0, i; /* 0 indicates tests passed, 1 indicates failure */ + + wc_HashAlg hash; + + /* enum for holding supported algorithms, #ifndef's restrict if disabled */ enum wc_HashType enumArray[] = { #ifndef NO_MD5 WC_HASH_TYPE_MD5, @@ -14866,30 +14870,33 @@ static void test_wc_HashInit(void) #ifndef WOLFSSL_SHA512 WC_HASH_TYPE_SHA512, #endif - }; - int ret = 0; /*0 indicates tests passed, 1 indicates failure*/ - int enumlen = (sizeof(enumArray))/4;/*dynamically finds the length*/ + }; + /* dynamically finds the length */ + int enumlen = (sizeof(enumArray)/sizeof(enum wc_HashType)); - /*For loop to test various arguments...*/ - for(int i =0; i < enumlen; i++){ - wc_HashAlg hash; - if(wc_HashInit(&hash, enumArray[i])==BAD_FUNC_ARG){/*checking for bad args*/ - ret = 1; - } - if(wc_HashInit(NULL, enumArray[i])!=BAD_FUNC_ARG){/*checking for null ptr*/ - ret = 1; - } + /* For loop to test various arguments... */ + for(i = 0; i < enumlen; i++) { + /* check for bad args */ + if(wc_HashInit(&hash, enumArray[i]) == BAD_FUNC_ARG) { + ret = 1; + break; + } + /* check for null ptr */ + if(wc_HashInit(NULL, enumArray[i]) != BAD_FUNC_ARG) { + ret = 1; + break; + } }/* end of for loop */ printf(testingFmt, "wc_HashInit()"); - if(ret==0){/* all tests have passed */ + if(ret==0) { /* all tests have passed */ printf(resultFmt, passed); } - if(ret==1){/* a test has failed */ + if(ret==1) { /* a test has failed */ printf(resultFmt, failed); } - + return ret; }/* end of test_wc_HashInit */ @@ -18919,6 +18926,8 @@ void ApiTest(void) AssertFalse(test_wc_Sha384HmacUpdate()); AssertFalse(test_wc_Sha384HmacFinal()); + AssertIntEQ(test_wc_HashInit(), 0); + AssertIntEQ(test_wc_InitCmac(), 0); AssertIntEQ(test_wc_CmacUpdate(), 0); AssertIntEQ(test_wc_CmacFinal(), 0); @@ -19040,8 +19049,7 @@ void ApiTest(void) test_wc_PKCS7_VerifySignedData(); test_wc_PKCS7_EncodeDecodeEnvelopedData(); test_wc_PKCS7_EncodeEncryptedData(); - - test_wc_HashInit(); + printf(" End API Tests\n"); From 124f45d4495f4bf1034ec8203d2c897d916fac03 Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 22 May 2018 17:45:04 -0600 Subject: [PATCH 4/5] re-upload --- tests/api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/api.c b/tests/api.c index 725f0c708..0bbe02feb 100644 --- a/tests/api.c +++ b/tests/api.c @@ -14848,7 +14848,7 @@ static int test_wc_HashInit(void) { int ret = 0, i; /* 0 indicates tests passed, 1 indicates failure */ - wc_HashAlg hash; + wc_HashAlg hash; /* enum for holding supported algorithms, #ifndef's restrict if disabled */ enum wc_HashType enumArray[] = { From 4fd85853c5017329444ab53568614a28753989bb Mon Sep 17 00:00:00 2001 From: Tim Date: Wed, 23 May 2018 11:57:12 -0600 Subject: [PATCH 5/5] I think I now understand the trailing white space... --- tests/api.c | 57 +++++++++++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/tests/api.c b/tests/api.c index 0bbe02feb..01c3d0b8e 100644 --- a/tests/api.c +++ b/tests/api.c @@ -14824,8 +14824,7 @@ static void test_wc_PKCS7_EncodeEncryptedData (void) NULL, sizeof(decoded)), BAD_FUNC_ARG); AssertIntEQ(wc_PKCS7_DecodeEncryptedData(&pkcs7, encrypted, encryptedSz, decoded, 0), BAD_FUNC_ARG); - /* Test - struct fields */ + /* Test struct fields */ tmpBytePtr = pkcs7.encryptionKey; pkcs7.encryptionKey = NULL; @@ -14841,15 +14840,18 @@ static void test_wc_PKCS7_EncodeEncryptedData (void) #endif } /* END test_wc_PKCS7_EncodeEncryptedData() */ + /*----------------------------------------------------------------------------* | hash.h Tests *----------------------------------------------------------------------------*/ -static int test_wc_HashInit(void) + + +static int test_wc_HashInit(void) { int ret = 0, i; /* 0 indicates tests passed, 1 indicates failure */ - wc_HashAlg hash; - + wc_HashAlg hash; + /* enum for holding supported algorithms, #ifndef's restrict if disabled */ enum wc_HashType enumArray[] = { #ifndef NO_MD5 @@ -14860,44 +14862,44 @@ static int test_wc_HashInit(void) #endif #ifndef WOLFSSL_SHA224 WC_HASH_TYPE_SHA224, - #endif - #ifndef NO_SHA256 - WC_HASH_TYPE_SHA256, - #endif - #ifndef WOLFSSL_SHA384 - WC_HASH_TYPE_SHA384, - #endif - #ifndef WOLFSSL_SHA512 - WC_HASH_TYPE_SHA512, - #endif - }; + #endif + #ifndef NO_SHA256 + WC_HASH_TYPE_SHA256, + #endif + #ifndef WOLFSSL_SHA384 + WC_HASH_TYPE_SHA384, + #endif + #ifndef WOLFSSL_SHA512 + WC_HASH_TYPE_SHA512, + #endif + }; /* dynamically finds the length */ - int enumlen = (sizeof(enumArray)/sizeof(enum wc_HashType)); + int enumlen = (sizeof(enumArray)/sizeof(enum wc_HashType)); /* For loop to test various arguments... */ - for(i = 0; i < enumlen; i++) { + for (i = 0; i < enumlen; i++) { /* check for bad args */ - if(wc_HashInit(&hash, enumArray[i]) == BAD_FUNC_ARG) { + if (wc_HashInit(&hash, enumArray[i]) == BAD_FUNC_ARG) { ret = 1; - break; + break; } /* check for null ptr */ - if(wc_HashInit(NULL, enumArray[i]) != BAD_FUNC_ARG) { + if (wc_HashInit(NULL, enumArray[i]) != BAD_FUNC_ARG) { ret = 1; - break; + break; } - }/* end of for loop */ + } /* end of for loop */ printf(testingFmt, "wc_HashInit()"); - if(ret==0) { /* all tests have passed */ + if (ret==0) { /* all tests have passed */ printf(resultFmt, passed); } - if(ret==1) { /* a test has failed */ + else { /* a test has failed */ printf(resultFmt, failed); } - return ret; -}/* end of test_wc_HashInit */ + return ret; +} /* end of test_wc_HashInit */ /*----------------------------------------------------------------------------* @@ -19050,7 +19052,6 @@ void ApiTest(void) test_wc_PKCS7_EncodeDecodeEnvelopedData(); test_wc_PKCS7_EncodeEncryptedData(); - printf(" End API Tests\n"); }