[57544fb] | 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 | |
---|
| 28 | void 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 | 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 | assert( status == RTEMS_SUCCESSFUL ); |
---|
| 59 | assert( value == (TEST_STRING_TO_TYPE)GOOD_VALUE ); |
---|
| 60 | |
---|
| 61 | /* Basic conversion works for return value */ |
---|
| 62 | endptr = NULL; |
---|
| 63 | puts( |
---|
| 64 | STRING_TO_NAME_METHOD_STRING " - " GOOD_VALUE_STRING |
---|
| 65 | " w/endptr return value - RTEMS_SUCCESSFUL" |
---|
| 66 | ); |
---|
| 67 | #if defined(STRING_TO_INTEGER) |
---|
| 68 | status = STRING_TO_NAME_METHOD( GOOD_VALUE_STRING, &value, &endptr, 10 ); |
---|
| 69 | #elif defined(STRING_TO_POINTER) || defined(STRING_TO_FLOAT) |
---|
| 70 | status = STRING_TO_NAME_METHOD( GOOD_VALUE_STRING, &value, &endptr ); |
---|
| 71 | #endif |
---|
| 72 | assert( status == RTEMS_SUCCESSFUL ); |
---|
| 73 | assert( endptr ); |
---|
| 74 | assert( value == (TEST_STRING_TO_TYPE)GOOD_VALUE ); |
---|
| 75 | |
---|
| 76 | /* Bad conversion works for return value */ |
---|
| 77 | endptr = NULL; |
---|
| 78 | puts( |
---|
| 79 | STRING_TO_NAME_METHOD_STRING " - " BAD_VALUE_STRING |
---|
| 80 | " w/endptr return value - RTEMS_NOT_DEFINED" |
---|
| 81 | ); |
---|
| 82 | #if defined(STRING_TO_INTEGER) |
---|
| 83 | status = STRING_TO_NAME_METHOD( BAD_VALUE_STRING, &value, &endptr, 10 ); |
---|
| 84 | #elif defined(STRING_TO_POINTER) || defined(STRING_TO_FLOAT) |
---|
| 85 | status = STRING_TO_NAME_METHOD( BAD_VALUE_STRING, &value, &endptr ); |
---|
| 86 | #endif |
---|
| 87 | assert( status == RTEMS_NOT_DEFINED ); |
---|
| 88 | assert( endptr ); |
---|
| 89 | |
---|
| 90 | /* Conversion of empty string */ |
---|
| 91 | endptr = NULL; |
---|
| 92 | value = 0; |
---|
| 93 | puts( |
---|
| 94 | STRING_TO_NAME_METHOD_STRING |
---|
| 95 | " - empty string - w/endptr return value - RTEMS_NOT_DEFINED" |
---|
| 96 | ); |
---|
| 97 | #if defined(STRING_TO_INTEGER) |
---|
| 98 | status = STRING_TO_NAME_METHOD( "", &value, &endptr, 10 ); |
---|
| 99 | #elif defined(STRING_TO_POINTER) || defined(STRING_TO_FLOAT) |
---|
| 100 | status = STRING_TO_NAME_METHOD( "", &value, &endptr ); |
---|
| 101 | #endif |
---|
| 102 | assert( status == RTEMS_NOT_DEFINED ); |
---|
| 103 | assert( endptr ); |
---|
| 104 | assert( value == (TEST_STRING_TO_TYPE)0 ); |
---|
| 105 | |
---|
| 106 | /* Conversion of number that is too large */ |
---|
| 107 | #if defined(TEST_TOO_LARGE_STRING) |
---|
| 108 | endptr = NULL; |
---|
| 109 | value = 0; |
---|
| 110 | puts( |
---|
| 111 | STRING_TO_NAME_METHOD_STRING " - overflow - RTEMS_INVALID_NUMBER" ); |
---|
| 112 | #if defined(STRING_TO_INTEGER) |
---|
| 113 | status = STRING_TO_NAME_METHOD( |
---|
| 114 | TEST_TOO_LARGE_STRING, &value, &endptr, 10 ); |
---|
| 115 | #elif defined(STRING_TO_POINTER) || defined(STRING_TO_FLOAT) |
---|
| 116 | status = STRING_TO_NAME_METHOD( TEST_TOO_LARGE_STRING, &value, &endptr ); |
---|
| 117 | #endif |
---|
| 118 | if ( status != RTEMS_INVALID_NUMBER ) |
---|
| 119 | printf( "ERROR = %s\n", rtems_status_text(status) ); |
---|
| 120 | assert( status == RTEMS_INVALID_NUMBER ); |
---|
| 121 | assert( endptr ); |
---|
| 122 | #endif |
---|
| 123 | |
---|
| 124 | /* Conversion of number that is too small */ |
---|
| 125 | #if defined(TEST_TOO_SMALL_STRING) |
---|
| 126 | endptr = NULL; |
---|
| 127 | value = 0; |
---|
| 128 | puts( STRING_TO_NAME_METHOD_STRING "- RTEMS_INVALID_NUMBER" ); |
---|
| 129 | #if defined(STRING_TO_INTEGER) |
---|
| 130 | status = STRING_TO_NAME_METHOD( |
---|
| 131 | TEST_TOO_SMALL_STRING, &value, &endptr, 10 ); |
---|
| 132 | #elif defined(STRING_TO_POINTER) || defined(STRING_TO_FLOAT) |
---|
| 133 | status = STRING_TO_NAME_METHOD( TEST_TOO_SMALL_STRING, &value, &endptr ); |
---|
| 134 | #endif |
---|
| 135 | assert( status == RTEMS_INVALID_NUMBER ); |
---|
| 136 | assert( endptr ); |
---|
| 137 | #endif |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | /* Now undefined everything that instantiates this */ |
---|
| 141 | #undef TEST_STRING_TO_TYPE |
---|
| 142 | #undef TEST_STRING_TO_NAME |
---|
| 143 | #undef STRING_TO_NAME_METHOD |
---|
| 144 | #undef STRING_TO_NAME_METHOD_STRING |
---|
| 145 | #undef STRING_TO_INTEGER |
---|
| 146 | #undef STRING_TO_POINTER |
---|
| 147 | #undef STRING_TO_FLOAT |
---|
| 148 | #undef GOOD_VALUE |
---|
| 149 | #undef GOOD_VALUE_STRING |
---|
| 150 | #undef BAD_VALUE_STRING |
---|
| 151 | #undef TEST_TOO_LARGE_STRING |
---|
| 152 | #undef TEST_TOO_SMALL_STRING |
---|