77#include "gentest_common.h"
88#include "typeaux.h"
99
10- const char gacInput0 [] = "abc def" ;
10+ #define TEXTANDLEN (X ) X, sizeof(X)-1
11+
12+ typedef struct {
13+ const char * sText ;
14+ size_t zLen ;
15+ } STextAndLen ;
16+
17+ const STextAndLen gasInput []= {
18+ {TEXTANDLEN ("abc def" )},
19+ {TEXTANDLEN ("" )}
20+ };
1121
1222uint8_t gau8Input1 [] = {3 , 5 , 7 , 9 };
1323uint8_t gau8Param1 [] = {10 , 0x80 , 0x00 };
1424uint16_t gau16Expected1 [] = {0x8003 , 0x0007 , 0x8005 , 0x0005 , 0x8007 , 0x0003 , 0x8009 , 0x0001 };
1525
16- bool test_bytegen_iter (const char * str ) {
17- SByteGenState sGen = bytegen_init ((uint8_t * ) str , strlen ( str ) );
18- return gentest_check_seq8_equal (gsByteGenFunc , (void * ) & sGen , (uint8_t * ) gacInput0 , strlen ( gacInput0 ) );
26+ bool test_bytegen_iter (const STextAndLen sParam ) {
27+ SByteGenState sGen = bytegen_init ((uint8_t * ) sParam . sText , sParam . zLen );
28+ return gentest_check_seq8_equal (gsByteGenFunc , (void * ) & sGen , (uint8_t * ) sParam . sText , sParam . zLen );
1929}
2030
21- bool test_bytegen_reset (const char * str ) {
31+ bool test_bytegen_reset (const STextAndLen sParam ) {
2232 bool bRet = true;
23- for (unsigned int i = 0 ; i < strlen ( str ) ; ++ i ) {
24- SByteGenState sGen = bytegen_init ((uint8_t * ) str , strlen ( str ) );
33+ for (unsigned int i = 0 ; i < sParam . zLen ; ++ i ) {
34+ SByteGenState sGen = bytegen_init ((uint8_t * ) sParam . sText , sParam . zLen );
2535 gentest_reset_after_steps (& sGen , (FToByteNext ) bytegen_next , (FToXReset ) bytegen_reset , i );
26- bRet &= gentest_check_seq8_equal (gsByteGenFunc , (void * ) & sGen , (uint8_t * ) gacInput0 , strlen ( gacInput0 ) );
36+ bRet &= gentest_check_seq8_equal (gsByteGenFunc , (void * ) & sGen , (uint8_t * ) sParam . sText , sParam . zLen );
2737 }
2838 return bRet ;
2939}
@@ -51,8 +61,10 @@ int main(int argc, char **argv) {
5161 fprintf (stderr , "%s does not require command line arguments\n" , argv [0 ]);
5262 }
5363
54- assert (test_bytegen_iter (gacInput0 ));
55- assert (test_bytegen_reset (gacInput0 ));
64+ assert (test_bytegen_iter (gasInput [0 ]));
65+ assert (test_bytegen_reset (gasInput [0 ]));
66+ assert (test_bytegen_iter (gasInput [1 ]));
67+ assert (test_bytegen_reset (gasInput [1 ]));
5668 assert (test_pwngen_iter (gau8Input1 , ARRAY_SIZE (gau8Input1 ), gau16Expected1 , gau8Param1 [0 ], gau8Param1 [1 ], gau8Param1 [2 ]));
5769 assert (test_pwmgen_reset (gau8Input1 , ARRAY_SIZE (gau8Input1 ), gau16Expected1 , gau8Param1 [0 ], gau8Param1 [1 ], gau8Param1 [2 ]));
5870}
0 commit comments