1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2012. |
---|
3 | * On-Line Applications Research Corporation (OAR). |
---|
4 | * |
---|
5 | * The license and distribution terms for this file may be |
---|
6 | * found in the file LICENSE in this distribution or at |
---|
7 | * http://www.rtems.org/license/LICENSE. |
---|
8 | */ |
---|
9 | |
---|
10 | #if defined(STRING_TO_POINTER) |
---|
11 | #define GOOD_VALUE 0x123 |
---|
12 | #define GOOD_VALUE_STRING "0x123" |
---|
13 | #define BAD_VALUE_STRING "xxx" |
---|
14 | #elif defined(STRING_TO_INTEGER) |
---|
15 | #define GOOD_VALUE 123 |
---|
16 | #define GOOD_VALUE_STRING "123" |
---|
17 | #define BAD_VALUE_STRING "YYY" |
---|
18 | #elif defined(STRING_TO_FLOAT) |
---|
19 | #define GOOD_VALUE 1.23 |
---|
20 | #define GOOD_VALUE_STRING "1.23" |
---|
21 | #define BAD_VALUE_STRING "zzz" |
---|
22 | #else |
---|
23 | #error "what type are we testing?" |
---|
24 | #endif |
---|
25 | |
---|
26 | /* forward declarations to avoid warnings */ |
---|
27 | void TEST_STRING_TO_NAME(void); |
---|
28 | |
---|
29 | void TEST_STRING_TO_NAME(void) |
---|
30 | { |
---|
31 | TEST_STRING_TO_TYPE value; |
---|
32 | rtems_status_code status; |
---|
33 | char *endptr; |
---|
34 | |
---|
35 | puts( "\nTesting " STRING_TO_NAME_METHOD_STRING ); |
---|
36 | |
---|
37 | /* Null pointer for return value */ |
---|
38 | puts( |
---|
39 | STRING_TO_NAME_METHOD_STRING |
---|
40 | " - NULL return value - RTEMS_INVALID_ADDRESS" |
---|
41 | ); |
---|
42 | #if defined(STRING_TO_INTEGER) |
---|
43 | status = STRING_TO_NAME_METHOD( GOOD_VALUE_STRING, NULL, &endptr, |
---|
44 | get_base_10_or_16( GOOD_VALUE_STRING ) ); |
---|
45 | #elif defined(STRING_TO_POINTER) || defined(STRING_TO_FLOAT) |
---|
46 | status = STRING_TO_NAME_METHOD( GOOD_VALUE_STRING, NULL, &endptr ); |
---|
47 | #endif |
---|
48 | rtems_test_assert( status == RTEMS_INVALID_ADDRESS ); |
---|
49 | |
---|
50 | /* Basic conversion works for return value, return end pointer */ |
---|
51 | puts( |
---|
52 | STRING_TO_NAME_METHOD_STRING " - " GOOD_VALUE_STRING |
---|
53 | " NULL endptr return value - RTEMS_SUCCESSFUL" |
---|
54 | ); |
---|
55 | #if defined(STRING_TO_INTEGER) |
---|
56 | status = STRING_TO_NAME_METHOD( GOOD_VALUE_STRING, &value, NULL, |
---|
57 | get_base_10_or_16( GOOD_VALUE_STRING ) ); |
---|
58 | #elif defined(STRING_TO_POINTER) || defined(STRING_TO_FLOAT) |
---|
59 | status = STRING_TO_NAME_METHOD( GOOD_VALUE_STRING, &value, NULL ); |
---|
60 | #endif |
---|
61 | rtems_test_assert( status == RTEMS_SUCCESSFUL ); |
---|
62 | rtems_test_assert( value == (TEST_STRING_TO_TYPE)GOOD_VALUE ); |
---|
63 | |
---|
64 | #if defined(STRING_TO_MAX) |
---|
65 | /* Basic conversion works for return value */ |
---|
66 | endptr = NULL; |
---|
67 | puts( |
---|
68 | STRING_TO_NAME_METHOD_STRING " - MAXIMUM VALUE" |
---|
69 | " w/endptr return value - RTEMS_SUCCESSFUL" |
---|
70 | ); |
---|
71 | #if defined(STRING_TO_INTEGER) |
---|
72 | status = STRING_TO_NAME_METHOD( STRING_TO_MAX_STRING, &value, &endptr, |
---|
73 | get_base_10_or_16( STRING_TO_MAX_STRING ) ); |
---|
74 | #elif defined(STRING_TO_POINTER) || defined(STRING_TO_FLOAT) |
---|
75 | status = STRING_TO_NAME_METHOD( STRING_TO_MAX_STRING, &value, &endptr ); |
---|
76 | #endif |
---|
77 | rtems_test_assert( status == RTEMS_SUCCESSFUL ); |
---|
78 | rtems_test_assert( endptr ); |
---|
79 | rtems_test_assert( value == (TEST_STRING_TO_TYPE)STRING_TO_MAX ); |
---|
80 | #endif |
---|
81 | |
---|
82 | /* Basic conversion works for return value */ |
---|
83 | endptr = NULL; |
---|
84 | puts( |
---|
85 | STRING_TO_NAME_METHOD_STRING " - " GOOD_VALUE_STRING |
---|
86 | " w/endptr return value - RTEMS_SUCCESSFUL" |
---|
87 | ); |
---|
88 | #if defined(STRING_TO_INTEGER) |
---|
89 | status = STRING_TO_NAME_METHOD( GOOD_VALUE_STRING, &value, &endptr, |
---|
90 | get_base_10_or_16( GOOD_VALUE_STRING ) ); |
---|
91 | #elif defined(STRING_TO_POINTER) || defined(STRING_TO_FLOAT) |
---|
92 | status = STRING_TO_NAME_METHOD( GOOD_VALUE_STRING, &value, &endptr ); |
---|
93 | #endif |
---|
94 | rtems_test_assert( status == RTEMS_SUCCESSFUL ); |
---|
95 | rtems_test_assert( endptr ); |
---|
96 | rtems_test_assert( value == (TEST_STRING_TO_TYPE)GOOD_VALUE ); |
---|
97 | |
---|
98 | /* Bad conversion works for return value */ |
---|
99 | endptr = NULL; |
---|
100 | puts( |
---|
101 | STRING_TO_NAME_METHOD_STRING " - " BAD_VALUE_STRING |
---|
102 | " w/endptr return value - RTEMS_NOT_DEFINED" |
---|
103 | ); |
---|
104 | #if defined(STRING_TO_INTEGER) |
---|
105 | status = STRING_TO_NAME_METHOD( BAD_VALUE_STRING, &value, &endptr, |
---|
106 | get_base_10_or_16( BAD_VALUE_STRING ) ); |
---|
107 | #elif defined(STRING_TO_POINTER) || defined(STRING_TO_FLOAT) |
---|
108 | status = STRING_TO_NAME_METHOD( BAD_VALUE_STRING, &value, &endptr ); |
---|
109 | #endif |
---|
110 | rtems_test_assert( status == RTEMS_NOT_DEFINED ); |
---|
111 | rtems_test_assert( endptr ); |
---|
112 | |
---|
113 | /* Conversion of empty string */ |
---|
114 | endptr = NULL; |
---|
115 | value = 0; |
---|
116 | puts( |
---|
117 | STRING_TO_NAME_METHOD_STRING |
---|
118 | " - empty string - w/endptr return value - RTEMS_NOT_DEFINED" |
---|
119 | ); |
---|
120 | #if defined(STRING_TO_INTEGER) |
---|
121 | status = STRING_TO_NAME_METHOD( "", &value, &endptr, |
---|
122 | get_base_10_or_16( "" ) ); |
---|
123 | #elif defined(STRING_TO_POINTER) || defined(STRING_TO_FLOAT) |
---|
124 | status = STRING_TO_NAME_METHOD( "", &value, &endptr ); |
---|
125 | #endif |
---|
126 | rtems_test_assert( status == RTEMS_NOT_DEFINED ); |
---|
127 | rtems_test_assert( endptr ); |
---|
128 | rtems_test_assert( value == (TEST_STRING_TO_TYPE)0 ); |
---|
129 | |
---|
130 | /* Conversion of number that is too large */ |
---|
131 | #if defined(TEST_TOO_LARGE_STRING) |
---|
132 | endptr = NULL; |
---|
133 | value = 0; |
---|
134 | puts( |
---|
135 | STRING_TO_NAME_METHOD_STRING " - overflow - RTEMS_INVALID_NUMBER" ); |
---|
136 | #if defined(STRING_TO_INTEGER) |
---|
137 | status = STRING_TO_NAME_METHOD( TEST_TOO_LARGE_STRING, &value, &endptr, |
---|
138 | get_base_10_or_16( TEST_TOO_LARGE_STRING ) ); |
---|
139 | #elif defined(STRING_TO_POINTER) || defined(STRING_TO_FLOAT) |
---|
140 | status = STRING_TO_NAME_METHOD( TEST_TOO_LARGE_STRING, &value, &endptr ); |
---|
141 | #endif |
---|
142 | if ( status != RTEMS_INVALID_NUMBER ) |
---|
143 | printf( "ERROR = %s\n", rtems_status_text(status) ); |
---|
144 | rtems_test_assert( status == RTEMS_INVALID_NUMBER ); |
---|
145 | rtems_test_assert( endptr ); |
---|
146 | #endif |
---|
147 | |
---|
148 | |
---|
149 | /* Conversion of number that is too large for unsigned char */ |
---|
150 | #if defined(TEST_TOO_LARGE_FOR_UCHAR) |
---|
151 | endptr = NULL; |
---|
152 | value = 0; |
---|
153 | puts( |
---|
154 | STRING_TO_NAME_METHOD_STRING " - overflow - RTEMS_INVALID_NUMBER" ); |
---|
155 | #if defined(STRING_TO_INTEGER) |
---|
156 | status = STRING_TO_NAME_METHOD( TEST_TOO_LARGE_FOR_UCHAR, &value, |
---|
157 | &endptr, get_base_10_or_16( TEST_TOO_LARGE_FOR_UCHAR ) ); |
---|
158 | #endif |
---|
159 | if ( status != RTEMS_INVALID_NUMBER ) |
---|
160 | printf( "ERROR = %s\n", rtems_status_text(status) ); |
---|
161 | rtems_test_assert( status == RTEMS_INVALID_NUMBER ); |
---|
162 | rtems_test_assert( endptr ); |
---|
163 | #endif |
---|
164 | |
---|
165 | /* Conversion of number that is too small */ |
---|
166 | #if defined(TEST_TOO_SMALL_STRING) |
---|
167 | endptr = NULL; |
---|
168 | value = 0; |
---|
169 | puts( STRING_TO_NAME_METHOD_STRING "- RTEMS_INVALID_NUMBER" ); |
---|
170 | #if defined(STRING_TO_INTEGER) |
---|
171 | status = STRING_TO_NAME_METHOD( TEST_TOO_SMALL_STRING, &value, &endptr, |
---|
172 | get_base_10_or_16( TEST_TOO_SMALL_STRING ) ); |
---|
173 | #elif defined(STRING_TO_POINTER) || defined(STRING_TO_FLOAT) |
---|
174 | status = STRING_TO_NAME_METHOD( TEST_TOO_SMALL_STRING, &value, &endptr ); |
---|
175 | #endif |
---|
176 | rtems_test_assert( status == RTEMS_INVALID_NUMBER ); |
---|
177 | rtems_test_assert( endptr ); |
---|
178 | #endif |
---|
179 | } |
---|
180 | |
---|
181 | /* Now undefined everything that instantiates this */ |
---|
182 | #undef TEST_STRING_TO_TYPE |
---|
183 | #undef TEST_STRING_TO_NAME |
---|
184 | #undef STRING_TO_NAME_METHOD |
---|
185 | #undef STRING_TO_NAME_METHOD_STRING |
---|
186 | #undef STRING_TO_INTEGER |
---|
187 | #undef STRING_TO_POINTER |
---|
188 | #undef STRING_TO_FLOAT |
---|
189 | #undef STRING_TO_MAX |
---|
190 | #undef STRING_TO_MAX_STRING |
---|
191 | #undef GOOD_VALUE |
---|
192 | #undef GOOD_VALUE_STRING |
---|
193 | #undef BAD_VALUE_STRING |
---|
194 | #undef TEST_TOO_LARGE_STRING |
---|
195 | #undef TEST_TOO_SMALL_STRING |
---|
196 | #undef TEST_TOO_LARGE_FOR_UCHAR |
---|