Debian Codegraph @

ext/safestringlib/unittests/test_strishex_s.c

raw
1 /*------------------------------------------------------------------
2 * test_strishex_s
3 *
4 *
5 *------------------------------------------------------------------
6 */
7
8 #include "test_private.h"
9 #include "safe_str_lib.h"
10
11 #define LEN ( 128 )
12
13
14 int test_strishex_s()
15 {
16 bool rc;
17 uint32_t len;
18 char str[LEN];
19
20 /*--------------------------------------------------*/
21
22 len = 5;
23 rc = strishex_s(NULL, len);
24 if (rc != false) {
25 printf("%s %u Error rc=%u \n",
26 __FUNCTION__, __LINE__, rc );
27 }
28
29 /*--------------------------------------------------*/
30
31 str[0] = '\0';
32 rc = strishex_s(str, 5);
33 if (rc != false) {
34 printf("%s %u Error rc=%u \n",
35 __FUNCTION__, __LINE__, rc );
36 }
37
38 /*--------------------------------------------------*/
39
40 len = 0;
41 rc = strishex_s("1234", len);
42 if (rc != false) {
43 printf("%s %u Error rc=%u \n",
44 __FUNCTION__, __LINE__, rc );
45 }
46
47 /*--------------------------------------------------*/
48
49 len = 99999;
50 rc = strishex_s("1234", len);
51 if (rc != false) {
52 printf("%s %u Error rc=%u \n",
53 __FUNCTION__, __LINE__, rc );
54 }
55
56 /*--------------------------------------------------*/
57
58 len = 9;
59 rc = strishex_s("", len);
60 if (rc != false) {
61 printf("%s %u Error rc=%u \n",
62 __FUNCTION__, __LINE__, rc );
63 }
64
65 /*--------------------------------------------------*/
66
67 strcpy (str, "123456789");
68 len = 6;
69
70 rc = strishex_s(str, len);
71 if (rc != true) {
72 printf("%s %u Error rc=%u \n",
73 __FUNCTION__, __LINE__, rc );
74 }
75
76 /*--------------------------------------------------*/
77
78 strcpy (str, "1");
79 len = strlen(str);
80
81 rc = strishex_s(str, len);
82 if (rc != true) {
83 printf("%s %u Error rc=%u \n",
84 __FUNCTION__, __LINE__, rc );
85 }
86
87 /*--------------------------------------------------*/
88
89 strcpy (str, "12");
90 len = strlen(str);
91
92 rc = strishex_s(str, len);
93 if (rc != true) {
94 printf("%s %u Error rc=%u \n",
95 __FUNCTION__, __LINE__, rc );
96 }
97
98 /*--------------------------------------------------*/
99
100 strcpy (str, "1Af");
101 len = strlen(str);
102
103 rc = strishex_s(str, len);
104 if (rc != true) {
105 printf("%s %u Error rc=%u \n",
106 __FUNCTION__, __LINE__, rc );
107 }
108
109 /*--------------------------------------------------*/
110
111 strcpy (str, "FF");
112 len = strlen(str);
113
114 rc = strishex_s(str, len);
115 if (rc != true) {
116 printf("%s %u Error rc=%u \n",
117 __FUNCTION__, __LINE__, rc );
118 }
119
120 /*--------------------------------------------------*/
121
122 strcpy (str, "1abzd");
123 len = strlen(str);
124
125 /* non hex char in string */
126 rc = strishex_s(str, len);
127 if (rc != false) {
128 printf("%s %u Error rc=%u \n",
129 __FUNCTION__, __LINE__, rc );
130 }
131
132 /*--------------------------------------------------*/
133
134 return (0);
135 }