Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:34

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  COPYRIGHT (c) 1989-2012.
0005  *  On-Line Applications Research Corporation (OAR).
0006  *
0007  * Redistribution and use in source and binary forms, with or without
0008  * modification, are permitted provided that the following conditions
0009  * are met:
0010  * 1. Redistributions of source code must retain the above copyright
0011  *    notice, this list of conditions and the following disclaimer.
0012  * 2. Redistributions in binary form must reproduce the above copyright
0013  *    notice, this list of conditions and the following disclaimer in the
0014  *    documentation and/or other materials provided with the distribution.
0015  *
0016  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0017  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0018  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0019  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0020  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0021  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0022  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0023  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0024  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0025  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0026  * POSSIBILITY OF SUCH DAMAGE.
0027  */
0028 
0029 #if defined(STRING_TO_POINTER)
0030   #define GOOD_VALUE        0x123
0031   #define GOOD_VALUE_STRING "0x123"
0032   #define BAD_VALUE_STRING  "xxx"
0033 #elif defined(STRING_TO_INTEGER)
0034   #define GOOD_VALUE        123
0035   #define GOOD_VALUE_STRING "123"
0036   #define BAD_VALUE_STRING  "YYY"
0037 #elif defined(STRING_TO_FLOAT)
0038   #define GOOD_VALUE        1.23
0039   #define GOOD_VALUE_STRING "1.23"
0040   #define BAD_VALUE_STRING  "zzz"
0041 #else
0042   #error "what type are we testing?"
0043 #endif
0044 
0045 /* forward declarations to avoid warnings */
0046 void TEST_STRING_TO_NAME(void);
0047 
0048 void TEST_STRING_TO_NAME(void)
0049 {
0050   TEST_STRING_TO_TYPE  value;
0051   rtems_status_code    status;
0052   char                *endptr;
0053 
0054   puts( "\nTesting " STRING_TO_NAME_METHOD_STRING );
0055 
0056   /* Null pointer for return value */
0057   puts(
0058     STRING_TO_NAME_METHOD_STRING
0059     " - NULL return value - RTEMS_INVALID_ADDRESS"
0060   );
0061   #if defined(STRING_TO_INTEGER)
0062     status = STRING_TO_NAME_METHOD( GOOD_VALUE_STRING, NULL, &endptr,
0063         get_base_10_or_16( GOOD_VALUE_STRING ) );
0064   #elif defined(STRING_TO_POINTER) || defined(STRING_TO_FLOAT)
0065     status = STRING_TO_NAME_METHOD( GOOD_VALUE_STRING, NULL, &endptr );
0066   #endif
0067   rtems_test_assert( status == RTEMS_INVALID_ADDRESS );
0068 
0069   /* Basic conversion works for return value, return end pointer */
0070   puts(
0071     STRING_TO_NAME_METHOD_STRING " - " GOOD_VALUE_STRING
0072     " NULL endptr return value - RTEMS_SUCCESSFUL"
0073   );
0074   #if defined(STRING_TO_INTEGER)
0075     status = STRING_TO_NAME_METHOD( GOOD_VALUE_STRING, &value, NULL,
0076         get_base_10_or_16( GOOD_VALUE_STRING ) );
0077   #elif defined(STRING_TO_POINTER) || defined(STRING_TO_FLOAT)
0078     status = STRING_TO_NAME_METHOD( GOOD_VALUE_STRING, &value, NULL );
0079   #endif
0080   rtems_test_assert( status == RTEMS_SUCCESSFUL );
0081   rtems_test_assert( value == (TEST_STRING_TO_TYPE)GOOD_VALUE );
0082 
0083   #if defined(STRING_TO_MAX)
0084     /* Basic conversion works for return value */
0085     endptr = NULL;
0086     puts(
0087       STRING_TO_NAME_METHOD_STRING " - MAXIMUM VALUE"
0088       " w/endptr return value - RTEMS_SUCCESSFUL"
0089     );
0090     #if defined(STRING_TO_INTEGER)
0091       status = STRING_TO_NAME_METHOD( STRING_TO_MAX_STRING, &value, &endptr,
0092           get_base_10_or_16( STRING_TO_MAX_STRING ) );
0093     #elif defined(STRING_TO_POINTER) || defined(STRING_TO_FLOAT)
0094       status = STRING_TO_NAME_METHOD( STRING_TO_MAX_STRING, &value, &endptr );
0095     #endif
0096     rtems_test_assert( status == RTEMS_SUCCESSFUL );
0097     rtems_test_assert( endptr );
0098     rtems_test_assert( value == (TEST_STRING_TO_TYPE)STRING_TO_MAX );
0099   #endif
0100 
0101   /* Basic conversion works for return value */
0102   endptr = NULL;
0103   puts(
0104     STRING_TO_NAME_METHOD_STRING " - " GOOD_VALUE_STRING
0105     " w/endptr return value - RTEMS_SUCCESSFUL"
0106   );
0107   #if defined(STRING_TO_INTEGER)
0108     status = STRING_TO_NAME_METHOD( GOOD_VALUE_STRING, &value, &endptr,
0109         get_base_10_or_16( GOOD_VALUE_STRING ) );
0110   #elif defined(STRING_TO_POINTER) || defined(STRING_TO_FLOAT)
0111     status = STRING_TO_NAME_METHOD( GOOD_VALUE_STRING, &value, &endptr );
0112   #endif
0113   rtems_test_assert( status == RTEMS_SUCCESSFUL );
0114   rtems_test_assert( endptr );
0115   rtems_test_assert( value == (TEST_STRING_TO_TYPE)GOOD_VALUE );
0116 
0117   /* Bad conversion works for return value */
0118   endptr = NULL;
0119   puts(
0120     STRING_TO_NAME_METHOD_STRING " - " BAD_VALUE_STRING
0121     " w/endptr return value - RTEMS_NOT_DEFINED"
0122   );
0123   #if defined(STRING_TO_INTEGER)
0124     status = STRING_TO_NAME_METHOD( BAD_VALUE_STRING, &value, &endptr,
0125         get_base_10_or_16( BAD_VALUE_STRING ) );
0126   #elif defined(STRING_TO_POINTER) || defined(STRING_TO_FLOAT)
0127     status = STRING_TO_NAME_METHOD( BAD_VALUE_STRING, &value, &endptr );
0128   #endif
0129   rtems_test_assert( status == RTEMS_NOT_DEFINED );
0130   rtems_test_assert( endptr );
0131 
0132   /* Conversion of empty string */
0133   endptr = NULL;
0134   value = 0;
0135   puts(
0136     STRING_TO_NAME_METHOD_STRING
0137     " - empty string - w/endptr return value - RTEMS_NOT_DEFINED"
0138   );
0139   #if defined(STRING_TO_INTEGER)
0140     status = STRING_TO_NAME_METHOD( "", &value, &endptr,
0141         get_base_10_or_16( "" ) );
0142   #elif defined(STRING_TO_POINTER) || defined(STRING_TO_FLOAT)
0143     status = STRING_TO_NAME_METHOD( "", &value, &endptr );
0144   #endif
0145   rtems_test_assert( status == RTEMS_NOT_DEFINED );
0146   rtems_test_assert( endptr );
0147   rtems_test_assert( value == (TEST_STRING_TO_TYPE)0 );
0148 
0149   /* Conversion of number that is too large */
0150   #if defined(TEST_TOO_LARGE_STRING)
0151     endptr = NULL;
0152     value = 0;
0153     puts(
0154     STRING_TO_NAME_METHOD_STRING " - overflow - RTEMS_INVALID_NUMBER" );
0155     #if defined(STRING_TO_INTEGER)
0156       status = STRING_TO_NAME_METHOD( TEST_TOO_LARGE_STRING, &value, &endptr,
0157           get_base_10_or_16( TEST_TOO_LARGE_STRING ) );
0158     #elif defined(STRING_TO_POINTER) || defined(STRING_TO_FLOAT)
0159       status = STRING_TO_NAME_METHOD( TEST_TOO_LARGE_STRING, &value, &endptr );
0160     #endif
0161     if ( status != RTEMS_INVALID_NUMBER )
0162       printf( "ERROR = %s\n", rtems_status_text(status) );
0163     rtems_test_assert( status == RTEMS_INVALID_NUMBER );
0164     rtems_test_assert( endptr );
0165   #endif
0166 
0167 
0168   /* Conversion of number that is too large for unsigned char */
0169   #if defined(TEST_TOO_LARGE_FOR_UCHAR)
0170     endptr = NULL;
0171     value = 0;
0172     puts(
0173     STRING_TO_NAME_METHOD_STRING " - overflow - RTEMS_INVALID_NUMBER" );
0174     #if defined(STRING_TO_INTEGER)
0175       status = STRING_TO_NAME_METHOD( TEST_TOO_LARGE_FOR_UCHAR, &value,
0176           &endptr, get_base_10_or_16( TEST_TOO_LARGE_FOR_UCHAR ) );
0177     #endif
0178     if ( status != RTEMS_INVALID_NUMBER )
0179       printf( "ERROR = %s\n", rtems_status_text(status) );
0180     rtems_test_assert( status == RTEMS_INVALID_NUMBER );
0181     rtems_test_assert( endptr );
0182   #endif
0183 
0184   /* Conversion of number that is too small */
0185   #if defined(TEST_TOO_SMALL_STRING)
0186     endptr = NULL;
0187     value = 0;
0188     puts( STRING_TO_NAME_METHOD_STRING "- RTEMS_INVALID_NUMBER" );
0189     #if defined(STRING_TO_INTEGER)
0190       status = STRING_TO_NAME_METHOD( TEST_TOO_SMALL_STRING, &value, &endptr,
0191           get_base_10_or_16( TEST_TOO_SMALL_STRING ) );
0192     #elif defined(STRING_TO_POINTER) || defined(STRING_TO_FLOAT)
0193       status = STRING_TO_NAME_METHOD( TEST_TOO_SMALL_STRING, &value, &endptr );
0194     #endif
0195     rtems_test_assert( status == RTEMS_INVALID_NUMBER );
0196     rtems_test_assert( endptr );
0197   #endif
0198 }
0199 
0200 /* Now undefined everything that instantiates this */
0201 #undef TEST_STRING_TO_TYPE
0202 #undef TEST_STRING_TO_NAME
0203 #undef STRING_TO_NAME_METHOD
0204 #undef STRING_TO_NAME_METHOD_STRING
0205 #undef STRING_TO_INTEGER
0206 #undef STRING_TO_POINTER
0207 #undef STRING_TO_FLOAT
0208 #undef STRING_TO_MAX
0209 #undef STRING_TO_MAX_STRING
0210 #undef GOOD_VALUE
0211 #undef GOOD_VALUE_STRING
0212 #undef BAD_VALUE_STRING
0213 #undef TEST_TOO_LARGE_STRING
0214 #undef TEST_TOO_SMALL_STRING
0215 #undef TEST_TOO_LARGE_FOR_UCHAR