source: rtems/testsuites/libtests/stringto01/stringto_test_template.h @ 4c86e3d

4.115
Last change on this file since 4c86e3d was 4c86e3d, checked in by Joel Sherrill <joel.sherrill@…>, on 05/11/12 at 17:20:47

libtmtests - Eliminate missing prototype warnings

  • Property mode set to 100644
File size: 6.4 KB
Line 
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.com/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 */
27void TEST_STRING_TO_NAME(void);
28
29void 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, 10 );
44  #elif defined(STRING_TO_POINTER) || defined(STRING_TO_FLOAT)
45    status = STRING_TO_NAME_METHOD( GOOD_VALUE_STRING, NULL, &endptr );
46  #endif
47  rtems_test_assert( status == RTEMS_INVALID_ADDRESS );
48
49  /* Basic conversion works for return value, return end pointer */
50  puts(
51    STRING_TO_NAME_METHOD_STRING " - " GOOD_VALUE_STRING
52    " NULL endptr return value - RTEMS_SUCCESSFUL"
53  );
54  #if defined(STRING_TO_INTEGER)
55    status = STRING_TO_NAME_METHOD( GOOD_VALUE_STRING, &value, NULL, 10 );
56  #elif defined(STRING_TO_POINTER) || defined(STRING_TO_FLOAT)
57    status = STRING_TO_NAME_METHOD( GOOD_VALUE_STRING, &value, NULL );
58  #endif
59  rtems_test_assert( status == RTEMS_SUCCESSFUL );
60  rtems_test_assert( value == (TEST_STRING_TO_TYPE)GOOD_VALUE );
61
62  #if defined(STRING_TO_MAX)
63    /* Basic conversion works for return value */
64    endptr = NULL;
65    puts(
66      STRING_TO_NAME_METHOD_STRING " - MAXIMUM VALUE"
67      " w/endptr return value - RTEMS_SUCCESSFUL"
68    );
69    #if defined(STRING_TO_INTEGER)
70      status = STRING_TO_NAME_METHOD(
71        STRING_TO_MAX_STRING, &value, &endptr, 10 );
72    #elif defined(STRING_TO_POINTER) || defined(STRING_TO_FLOAT)
73      status = STRING_TO_NAME_METHOD( STRING_TO_MAX_STRING, &value, &endptr );
74    #endif
75    rtems_test_assert( status == RTEMS_SUCCESSFUL );
76    rtems_test_assert( endptr );
77    rtems_test_assert( value == (TEST_STRING_TO_TYPE)STRING_TO_MAX );
78  #endif
79
80  /* Basic conversion works for return value */
81  endptr = NULL;
82  puts(
83    STRING_TO_NAME_METHOD_STRING " - " GOOD_VALUE_STRING
84    " w/endptr return value - RTEMS_SUCCESSFUL"
85  );
86  #if defined(STRING_TO_INTEGER)
87    status = STRING_TO_NAME_METHOD( GOOD_VALUE_STRING, &value, &endptr, 10 );
88  #elif defined(STRING_TO_POINTER) || defined(STRING_TO_FLOAT)
89    status = STRING_TO_NAME_METHOD( GOOD_VALUE_STRING, &value, &endptr );
90  #endif
91  rtems_test_assert( status == RTEMS_SUCCESSFUL );
92  rtems_test_assert( endptr );
93  rtems_test_assert( value == (TEST_STRING_TO_TYPE)GOOD_VALUE );
94
95  /* Bad conversion works for return value */
96  endptr = NULL;
97  puts(
98    STRING_TO_NAME_METHOD_STRING " - " BAD_VALUE_STRING
99    " w/endptr return value - RTEMS_NOT_DEFINED"
100  );
101  #if defined(STRING_TO_INTEGER)
102    status = STRING_TO_NAME_METHOD( BAD_VALUE_STRING, &value, &endptr, 10 );
103  #elif defined(STRING_TO_POINTER) || defined(STRING_TO_FLOAT)
104    status = STRING_TO_NAME_METHOD( BAD_VALUE_STRING, &value, &endptr );
105  #endif
106  rtems_test_assert( status == RTEMS_NOT_DEFINED );
107  rtems_test_assert( endptr );
108
109  /* Conversion of empty string */
110  endptr = NULL;
111  value = 0;
112  puts(
113    STRING_TO_NAME_METHOD_STRING
114    " - empty string - w/endptr return value - RTEMS_NOT_DEFINED"
115  );
116  #if defined(STRING_TO_INTEGER)
117    status = STRING_TO_NAME_METHOD( "", &value, &endptr, 10 );
118  #elif defined(STRING_TO_POINTER) || defined(STRING_TO_FLOAT)
119    status = STRING_TO_NAME_METHOD( "", &value, &endptr );
120  #endif
121  rtems_test_assert( status == RTEMS_NOT_DEFINED );
122  rtems_test_assert( endptr );
123  rtems_test_assert( value == (TEST_STRING_TO_TYPE)0 );
124
125  /* Conversion of number that is too large */
126  #if defined(TEST_TOO_LARGE_STRING)
127    endptr = NULL;
128    value = 0;
129    puts(
130    STRING_TO_NAME_METHOD_STRING " - overflow - RTEMS_INVALID_NUMBER" );
131    #if defined(STRING_TO_INTEGER)
132      status = STRING_TO_NAME_METHOD(
133                 TEST_TOO_LARGE_STRING, &value, &endptr, 10 );
134    #elif defined(STRING_TO_POINTER) || defined(STRING_TO_FLOAT)
135      status = STRING_TO_NAME_METHOD( TEST_TOO_LARGE_STRING, &value, &endptr );
136    #endif
137    if ( status != RTEMS_INVALID_NUMBER )
138      printf( "ERROR = %s\n", rtems_status_text(status) );
139    rtems_test_assert( status == RTEMS_INVALID_NUMBER );
140    rtems_test_assert( endptr );
141  #endif
142
143
144  /* Conversion of number that is too large for unsigned char */
145  #if defined(TEST_TOO_LARGE_FOR_UCHAR)
146    endptr = NULL;
147    value = 0;
148    puts(
149    STRING_TO_NAME_METHOD_STRING " - overflow - RTEMS_INVALID_NUMBER" );
150    #if defined(STRING_TO_INTEGER)
151      status = STRING_TO_NAME_METHOD(
152                 TEST_TOO_LARGE_FOR_UCHAR, &value, &endptr, 10 );
153    #endif
154    if ( status != RTEMS_INVALID_NUMBER )
155      printf( "ERROR = %s\n", rtems_status_text(status) );
156    rtems_test_assert( status == RTEMS_INVALID_NUMBER );
157    rtems_test_assert( endptr );
158  #endif
159
160  /* Conversion of number that is too small */
161  #if defined(TEST_TOO_SMALL_STRING)
162    endptr = NULL;
163    value = 0;
164    puts( STRING_TO_NAME_METHOD_STRING "- RTEMS_INVALID_NUMBER" );
165    #if defined(STRING_TO_INTEGER)
166      status = STRING_TO_NAME_METHOD(
167                 TEST_TOO_SMALL_STRING, &value, &endptr, 10 );
168    #elif defined(STRING_TO_POINTER) || defined(STRING_TO_FLOAT)
169      status = STRING_TO_NAME_METHOD( TEST_TOO_SMALL_STRING, &value, &endptr );
170    #endif
171    rtems_test_assert( status == RTEMS_INVALID_NUMBER );
172    rtems_test_assert( endptr );
173  #endif
174}
175
176/* Now undefined everything that instantiates this */
177#undef TEST_STRING_TO_TYPE
178#undef TEST_STRING_TO_NAME
179#undef STRING_TO_NAME_METHOD
180#undef STRING_TO_NAME_METHOD_STRING
181#undef STRING_TO_INTEGER
182#undef STRING_TO_POINTER
183#undef STRING_TO_FLOAT
184#undef STRING_TO_MAX
185#undef STRING_TO_MAX_STRING
186#undef GOOD_VALUE
187#undef GOOD_VALUE_STRING
188#undef BAD_VALUE_STRING
189#undef TEST_TOO_LARGE_STRING
190#undef TEST_TOO_SMALL_STRING
191#undef TEST_TOO_LARGE_FOR_UCHAR
Note: See TracBrowser for help on using the repository browser.