source: rtems/testsuites/libtests/stringto01/stringto_test_template.h @ 7920a24c

4.115
Last change on this file since 7920a24c was 7920a24c, checked in by Joel Sherrill <joel.sherrill@…>, on 07/29/11 at 20:29:13

2011-07-29 Pawel Zagorski <pzagor@…>

PR 1865/tests

  • stringto01/Makefile.am, stringto01/init.c, stringto01/stringto01.doc, stringto01/stringto01.scn, stringto01/stringto_test_template.h: Improve coverage of string conversion routines.
  • Property mode set to 100644
File size: 6.4 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2009.
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 *  $Id$
10 */
11
12#if defined(STRING_TO_POINTER)
13  #define GOOD_VALUE        0x123
14  #define GOOD_VALUE_STRING "0x123"
15  #define BAD_VALUE_STRING  "xxx"
16#elif defined(STRING_TO_INTEGER)
17  #define GOOD_VALUE        123
18  #define GOOD_VALUE_STRING "123"
19  #define BAD_VALUE_STRING  "YYY"
20#elif defined(STRING_TO_FLOAT)
21  #define GOOD_VALUE        1.23
22  #define GOOD_VALUE_STRING "1.23"
23  #define BAD_VALUE_STRING  "zzz"
24#else
25  #error "what type are we testing?"
26#endif
27
28void TEST_STRING_TO_NAME(void)
29{
30  TEST_STRING_TO_TYPE  value;
31  rtems_status_code    status;
32  char                *endptr;
33
34  puts( "\nTesting " STRING_TO_NAME_METHOD_STRING );
35
36  /* Null pointer for return value */
37  puts(
38    STRING_TO_NAME_METHOD_STRING
39    " - NULL return value - RTEMS_INVALID_ADDRESS"
40  );
41  #if defined(STRING_TO_INTEGER)
42    status = STRING_TO_NAME_METHOD( GOOD_VALUE_STRING, NULL, &endptr, 10 );
43  #elif defined(STRING_TO_POINTER) || defined(STRING_TO_FLOAT)
44    status = STRING_TO_NAME_METHOD( GOOD_VALUE_STRING, NULL, &endptr );
45  #endif
46  rtems_test_assert( status == RTEMS_INVALID_ADDRESS );
47
48  /* Basic conversion works for return value, return end pointer */
49  puts(
50    STRING_TO_NAME_METHOD_STRING " - " GOOD_VALUE_STRING
51    " NULL endptr return value - RTEMS_SUCCESSFUL"
52  );
53  #if defined(STRING_TO_INTEGER)
54    status = STRING_TO_NAME_METHOD( GOOD_VALUE_STRING, &value, NULL, 10 );
55  #elif defined(STRING_TO_POINTER) || defined(STRING_TO_FLOAT)
56    status = STRING_TO_NAME_METHOD( GOOD_VALUE_STRING, &value, NULL );
57  #endif
58  rtems_test_assert( status == RTEMS_SUCCESSFUL );
59  rtems_test_assert( value == (TEST_STRING_TO_TYPE)GOOD_VALUE );
60
61  #if defined(STRING_TO_MAX)
62    /* Basic conversion works for return value */
63    endptr = NULL;
64    puts(
65      STRING_TO_NAME_METHOD_STRING " - MAXIMUM VALUE"
66      " w/endptr return value - RTEMS_SUCCESSFUL"
67    );
68    #if defined(STRING_TO_INTEGER)
69      status = STRING_TO_NAME_METHOD(
70        STRING_TO_MAX_STRING, &value, &endptr, 10 );
71    #elif defined(STRING_TO_POINTER) || defined(STRING_TO_FLOAT)
72      status = STRING_TO_NAME_METHOD( STRING_TO_MAX_STRING, &value, &endptr );
73    #endif
74    rtems_test_assert( status == RTEMS_SUCCESSFUL );
75    rtems_test_assert( endptr );
76    rtems_test_assert( value == (TEST_STRING_TO_TYPE)STRING_TO_MAX );
77  #endif
78
79  /* Basic conversion works for return value */
80  endptr = NULL;
81  puts(
82    STRING_TO_NAME_METHOD_STRING " - " GOOD_VALUE_STRING
83    " w/endptr return value - RTEMS_SUCCESSFUL"
84  );
85  #if defined(STRING_TO_INTEGER)
86    status = STRING_TO_NAME_METHOD( GOOD_VALUE_STRING, &value, &endptr, 10 );
87  #elif defined(STRING_TO_POINTER) || defined(STRING_TO_FLOAT)
88    status = STRING_TO_NAME_METHOD( GOOD_VALUE_STRING, &value, &endptr );
89  #endif
90  rtems_test_assert( status == RTEMS_SUCCESSFUL );
91  rtems_test_assert( endptr );
92  rtems_test_assert( value == (TEST_STRING_TO_TYPE)GOOD_VALUE );
93
94  /* Bad conversion works for return value */
95  endptr = NULL;
96  puts(
97    STRING_TO_NAME_METHOD_STRING " - " BAD_VALUE_STRING
98    " w/endptr return value - RTEMS_NOT_DEFINED"
99  );
100  #if defined(STRING_TO_INTEGER)
101    status = STRING_TO_NAME_METHOD( BAD_VALUE_STRING, &value, &endptr, 10 );
102  #elif defined(STRING_TO_POINTER) || defined(STRING_TO_FLOAT)
103    status = STRING_TO_NAME_METHOD( BAD_VALUE_STRING, &value, &endptr );
104  #endif
105  rtems_test_assert( status == RTEMS_NOT_DEFINED );
106  rtems_test_assert( endptr );
107
108  /* Conversion of empty string */
109  endptr = NULL;
110  value = 0;
111  puts(
112    STRING_TO_NAME_METHOD_STRING
113    " - empty string - w/endptr return value - RTEMS_NOT_DEFINED"
114  );
115  #if defined(STRING_TO_INTEGER)
116    status = STRING_TO_NAME_METHOD( "", &value, &endptr, 10 );
117  #elif defined(STRING_TO_POINTER) || defined(STRING_TO_FLOAT)
118    status = STRING_TO_NAME_METHOD( "", &value, &endptr );
119  #endif
120  rtems_test_assert( status == RTEMS_NOT_DEFINED );
121  rtems_test_assert( endptr );
122  rtems_test_assert( value == (TEST_STRING_TO_TYPE)0 );
123
124  /* Conversion of number that is too large */
125  #if defined(TEST_TOO_LARGE_STRING)
126    endptr = NULL;
127    value = 0;
128    puts(
129    STRING_TO_NAME_METHOD_STRING " - overflow - RTEMS_INVALID_NUMBER" );
130    #if defined(STRING_TO_INTEGER)
131      status = STRING_TO_NAME_METHOD(
132                 TEST_TOO_LARGE_STRING, &value, &endptr, 10 );
133    #elif defined(STRING_TO_POINTER) || defined(STRING_TO_FLOAT)
134      status = STRING_TO_NAME_METHOD( TEST_TOO_LARGE_STRING, &value, &endptr );
135    #endif
136    if ( status != RTEMS_INVALID_NUMBER )
137      printf( "ERROR = %s\n", rtems_status_text(status) );
138    rtems_test_assert( status == RTEMS_INVALID_NUMBER );
139    rtems_test_assert( endptr );
140  #endif
141
142
143  /* Conversion of number that is too large for unsigned char */
144  #if defined(TEST_TOO_LARGE_FOR_UCHAR)
145    endptr = NULL;
146    value = 0;
147    puts(
148    STRING_TO_NAME_METHOD_STRING " - overflow - RTEMS_INVALID_NUMBER" );
149    #if defined(STRING_TO_INTEGER)
150      status = STRING_TO_NAME_METHOD(
151                 TEST_TOO_LARGE_FOR_UCHAR, &value, &endptr, 10 );
152    #endif
153    if ( status != RTEMS_INVALID_NUMBER )
154      printf( "ERROR = %s\n", rtems_status_text(status) );
155    rtems_test_assert( status == RTEMS_INVALID_NUMBER );
156    rtems_test_assert( endptr );
157  #endif
158
159  /* Conversion of number that is too small */
160  #if defined(TEST_TOO_SMALL_STRING)
161    endptr = NULL;
162    value = 0;
163    puts( STRING_TO_NAME_METHOD_STRING "- RTEMS_INVALID_NUMBER" );
164    #if defined(STRING_TO_INTEGER)
165      status = STRING_TO_NAME_METHOD(
166                 TEST_TOO_SMALL_STRING, &value, &endptr, 10 );
167    #elif defined(STRING_TO_POINTER) || defined(STRING_TO_FLOAT)
168      status = STRING_TO_NAME_METHOD( TEST_TOO_SMALL_STRING, &value, &endptr );
169    #endif
170    rtems_test_assert( status == RTEMS_INVALID_NUMBER );
171    rtems_test_assert( endptr );
172  #endif
173}
174
175/* Now undefined everything that instantiates this */
176#undef TEST_STRING_TO_TYPE
177#undef TEST_STRING_TO_NAME
178#undef STRING_TO_NAME_METHOD
179#undef STRING_TO_NAME_METHOD_STRING
180#undef STRING_TO_INTEGER
181#undef STRING_TO_POINTER
182#undef STRING_TO_FLOAT
183#undef STRING_TO_MAX
184#undef STRING_TO_MAX_STRING
185#undef GOOD_VALUE
186#undef GOOD_VALUE_STRING
187#undef BAD_VALUE_STRING
188#undef TEST_TOO_LARGE_STRING
189#undef TEST_TOO_SMALL_STRING
190#undef TEST_TOO_LARGE_FOR_UCHAR
Note: See TracBrowser for help on using the repository browser.