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 #ifdef HAVE_CONFIG_H
0030 #include "config.h"
0031 #endif
0032 
0033 #include "tmacros.h"
0034 #include <rtems/stringto.h>
0035 #include <limits.h>
0036 #include <math.h>
0037 
0038 #include <stdio.h>
0039 
0040 const char rtems_test_name[] = "STRINGTO 1";
0041 
0042 /* forward declarations to avoid warnings */
0043 rtems_task Init(rtems_task_argument argument);
0044 
0045 #define __STRING(x)     #x              /* stringify without expanding x */
0046 #define __XSTRING(x)    __STRING(x)     /* expand x, then stringify */
0047 
0048 static int get_base_10_or_16(const char *s)
0049 {
0050   return (s[0] == '0' && s[1] == 'x') ? 16 : 10;
0051 }
0052 
0053 /* c99 has LLONG_MAX instead of LONG_LONG_MAX */
0054 #ifndef LONG_LONG_MAX
0055 #define LONG_LONG_MAX   LLONG_MAX
0056 #endif
0057 /* c99 has LLONG_MIN instead of LONG_LONG_MIN */
0058 #ifndef LONG_LONG_MIN
0059 #define LONG_LONG_MIN   LLONG_MIN
0060 #endif
0061 
0062 /* Test pointer conversions */
0063 #define TEST_STRING_TO_TYPE          void *
0064 #define TEST_STRING_TO_NAME          test_rtems_string_to_pointer
0065 #define STRING_TO_NAME_METHOD        rtems_string_to_pointer
0066 #define STRING_TO_NAME_METHOD_STRING "rtems_string_to_pointer"
0067 #define STRING_TO_POINTER
0068 #include "stringto_test_template.h"
0069 
0070 /* Test unsigned char conversions */
0071 #define TEST_STRING_TO_TYPE          unsigned char
0072 #define TEST_STRING_TO_NAME          test_rtems_string_to_unsigned_char
0073 #define STRING_TO_NAME_METHOD        rtems_string_to_unsigned_char
0074 #define STRING_TO_NAME_METHOD_STRING "rtems_string_to_unsigned_char"
0075 #define TEST_TOO_LARGE_STRING        "987654321123456789123456789"
0076 #define TEST_TOO_LARGE_FOR_UCHAR     "256" 
0077 #define STRING_TO_INTEGER
0078 #include "stringto_test_template.h"
0079 
0080 /* Test integer conversions */
0081 #define TEST_STRING_TO_TYPE          int
0082 #define STRING_TO_MAX                INT_MAX
0083 #define STRING_TO_MAX_STRING         __XSTRING(INT_MAX)
0084 #define TEST_STRING_TO_NAME          test_rtems_string_to_int
0085 #define STRING_TO_NAME_METHOD        rtems_string_to_int
0086 #define STRING_TO_NAME_METHOD_STRING "rtems_string_to_int"
0087 #define TEST_TOO_LARGE_STRING        "987654321123456789123456789"
0088 #define TEST_TOO_SMALL_STRING        "-98765432198765432123456789"
0089 #define STRING_TO_INTEGER
0090 #include "stringto_test_template.h"
0091 
0092 /* Test unsigned int conversions */
0093 #define TEST_STRING_TO_TYPE          unsigned int
0094 #define TEST_STRING_TO_NAME          test_rtems_string_to_unsigned_int
0095 #define STRING_TO_NAME_METHOD        rtems_string_to_unsigned_int
0096 #define STRING_TO_NAME_METHOD_STRING "rtems_string_to_unsigned_int"
0097 #define TEST_TOO_LARGE_STRING        "987654321123456789123456789"
0098 #define STRING_TO_INTEGER
0099 #include "stringto_test_template.h"
0100 
0101 /* Test long conversions */
0102 #define TEST_STRING_TO_TYPE          long
0103 #define STRING_TO_MAX                LONG_MAX
0104 #define STRING_TO_MAX_STRING         __XSTRING(LONG_MAX)
0105 #define TEST_STRING_TO_NAME          test_rtems_string_to_long
0106 #define STRING_TO_NAME_METHOD        rtems_string_to_long
0107 #define STRING_TO_NAME_METHOD_STRING "rtems_string_to_long"
0108 #define TEST_TOO_LARGE_STRING        "987654321123456789123456789"
0109 #define TEST_TOO_SMALL_STRING        "-98765432198765432123456789"
0110 #define STRING_TO_INTEGER
0111 #include "stringto_test_template.h"
0112 
0113 /* Test unsigned long conversions */
0114 #define TEST_STRING_TO_TYPE          unsigned long
0115 #define TEST_STRING_TO_NAME          test_rtems_string_to_unsigned_long
0116 #define STRING_TO_NAME_METHOD        rtems_string_to_unsigned_long
0117 #define STRING_TO_NAME_METHOD_STRING "rtems_string_to_unsigned_long"
0118 #define TEST_TOO_LARGE_STRING        "987654321123456789123456789"
0119 #define STRING_TO_INTEGER
0120 #include "stringto_test_template.h"
0121 
0122 /* Test long long conversions */
0123 #define TEST_STRING_TO_TYPE          long long
0124 #define STRING_TO_MAX                LONG_LONG_MAX
0125 #define STRING_TO_MAX_STRING         __XSTRING(LONG_LONG_MAX)
0126 #define TEST_STRING_TO_NAME          test_rtems_string_to_long_long
0127 #define STRING_TO_NAME_METHOD        rtems_string_to_long_long
0128 #define STRING_TO_NAME_METHOD_STRING "rtems_string_to_long_long"
0129 #define TEST_TOO_LARGE_STRING        "987654321123456789123456789"
0130 #define TEST_TOO_SMALL_STRING        "-98765432198765432123456789"
0131 #define STRING_TO_INTEGER
0132 #include "stringto_test_template.h"
0133 
0134 /* Test unsigned long long conversions */
0135 #define TEST_STRING_TO_TYPE          unsigned long long
0136 #define TEST_STRING_TO_NAME          test_rtems_string_to_unsigned_long_long
0137 #define STRING_TO_NAME_METHOD        rtems_string_to_unsigned_long_long
0138 #define STRING_TO_NAME_METHOD_STRING "rtems_string_to_unsigned_long_long"
0139 #define TEST_TOO_LARGE_STRING        "987654321123456789123456789"
0140 #define STRING_TO_INTEGER
0141 #include "stringto_test_template.h"
0142 
0143 /* Test float conversions */
0144 #define TEST_STRING_TO_TYPE          float
0145 #define TEST_STRING_TO_NAME          test_rtems_string_to_float
0146 #define STRING_TO_NAME_METHOD        rtems_string_to_float
0147 #define STRING_TO_NAME_METHOD_STRING "rtems_string_to_float"
0148 #define TEST_TOO_LARGE_STRING        "9.87654321123456789123456789E10240"
0149 #define TEST_TOO_SMALL_STRING        "-9.87654321123456789123456789E10240"
0150 #define STRING_TO_FLOAT
0151 #include "stringto_test_template.h"
0152 
0153 /* Test double conversions */
0154 #define TEST_STRING_TO_TYPE          double
0155 #define TEST_STRING_TO_NAME          test_rtems_string_to_double
0156 #define STRING_TO_NAME_METHOD        rtems_string_to_double
0157 #define STRING_TO_NAME_METHOD_STRING "rtems_string_to_double"
0158 #define TEST_TOO_LARGE_STRING        "9.87654321123456789123456789E10240"
0159 #define TEST_TOO_SMALL_STRING        "-9.87654321123456789123456789E10240"
0160 #define STRING_TO_FLOAT
0161 #include "stringto_test_template.h"
0162 
0163 rtems_task Init(
0164   rtems_task_argument ignored
0165 )
0166 {
0167   TEST_BEGIN();
0168   test_rtems_string_to_pointer();
0169   test_rtems_string_to_unsigned_char();
0170   test_rtems_string_to_int();
0171   test_rtems_string_to_unsigned_int();
0172   test_rtems_string_to_long();
0173   test_rtems_string_to_unsigned_long();
0174   test_rtems_string_to_long_long();
0175   test_rtems_string_to_unsigned_long_long();
0176 
0177   test_rtems_string_to_float();
0178   test_rtems_string_to_double();
0179   TEST_END();
0180   rtems_test_exit(0);
0181 }
0182 
0183 /* NOTICE: the clock driver is explicitly disabled */
0184 #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
0185 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0186 
0187 #define CONFIGURE_MAXIMUM_TASKS            1
0188 
0189 #define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT
0190 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0191 
0192 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0193 
0194 #define CONFIGURE_INIT
0195 #include <rtems/confdefs.h>