Changeset 4556

Show
Ignore:
Timestamp:
02/09/07 18:21:29 (2 years ago)
Author:
morris
Message:

Some more tests

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • libwired/trunk/libwired/base/wi-base.h

    r4540 r4556  
    6464 
    6565#if __LP64__ 
    66 #define WI_32                                           0 
    6766#define WI_64                                           1 
    6867 
     
    7170#else 
    7271#define WI_32                                           1 
    73 #define WI_64                                           0 
    7472 
    7573typedef int32_t                                         wi_integer_t; 
     
    177175 
    178176         
    179 typedef uint32_t                                      wi_boolean_t; 
     177typedef int32_t                                               wi_boolean_t; 
    180178 
    181179#ifndef true 
  • libwired/trunk/libwired/base/wi-tests.h

    r4540 r4556  
    3434#define WI_TEST_EXPORT                          WI_EXPORT 
    3535 
    36 #define WI_TEST_FAIL(fmt, ...)                                                                 
    37         WI_ASSERT(0, fmt, ## __VA_ARGS__);                                                     
     36#define WI_TEST_FAIL(fmt, ...)                                                                                 
     37        WI_ASSERT(0, fmt, ## __VA_ARGS__);                                                                     
    3838 
    39 #define WI_TEST_ASSERT_EQUALS(a1, a2, fmt, ...)                                 \ 
    40         WI_STMT_START                                                                                           \ 
    41                 typeof(a1)              v1 = (a1);                                                              \ 
    42                 typeof(a2)              v2 = (a2);                                                              \ 
    43                                                                                                                                 \ 
    44                 WI_ASSERT(v1 == v2,                                                                             \ 
    45                                   "'" WI_STRINGIFY(v1) "' should be equal to '" WI_STRINGIFY(v2) "': " fmt,     \ 
    46                                   ## __VA_ARGS__);                                                              \ 
     39#define WI_TEST_ASSERT_EQUALS(a1, a2, fmt, ...)                                                 \ 
     40        WI_STMT_START                                                                                                           \ 
     41                typeof(a1)                      v1 = (a1);                                                                      \ 
     42                typeof(a2)                      v2 = (a2);                                                                      \ 
     43                                                                                                                                                \ 
     44                WI_ASSERT(v1 == v2,                                                                                             \ 
     45                                  "'%s' should be equal to '%s': " fmt,                                 \ 
     46                                  #a1, #a2,                                                                                             \ 
     47                                  ## __VA_ARGS__);                                                                              \ 
    4748        WI_STMT_END 
    4849 
    49  
    50 #define WI_TEST_ASSERT_EQUAL_INSTANCES(a1, a2, fmt, ...)                \ 
    51         WI_STMT_START                                                                                           \ 
    52                 wi_runtime_instance_t   *i1 = (a1);                                             \ 
    53                 wi_runtime_instance_t   *i2 = (a2);                                             \ 
    54                                                                                                                                 \ 
    55                 WI_ASSERT(wi_is_equal(i1, i2),                                                  \ 
    56                                   "'%@' should be equal to '%@': " fmt,                 \ 
    57                                   i1, i2, ## __VA_ARGS__);                                              \ 
     50#define WI_TEST_ASSERT_EQUALS_WITH_ACCURACY(a1, a2, epsilon, fmt, ...)  \ 
     51        WI_STMT_START                                                                                                           \ 
     52                typeof(a1)                      v1 = (a1);                                                                      \ 
     53                typeof(a2)                      v2 = (a2);                                                                      \ 
     54                typeof(epsilon)         e = (epsilon);                                                          \ 
     55                                                                                                                                                \ 
     56                WI_ASSERT(WI_MAX(v1, v2) - WI_MIN(v1, v2) < e,                                  \ 
     57                                  "'%s' should be equal to '%s': " fmt,                                 \ 
     58                                  #a1, #a2,                                                                                             \ 
     59                                  ## __VA_ARGS__);                                                                              \ 
    5860        WI_STMT_END 
    5961 
    60 #define WI_TEST_ASSERT_NOT_NULL(a1, fmt, ...)                                   \ 
    61         WI_ASSERT((a1) != NULL, "'" WI_STRINGIFY(a1) "' should not be NULL: " fmt, (a1), ## __VA_ARGS__); 
     62#define WI_TEST_ASSERT_EQUAL_INSTANCES(a1, a2, fmt, ...)                                \ 
     63        WI_STMT_START                                                                                                           \ 
     64                wi_runtime_instance_t   *i1 = (a1);                                                             \ 
     65                wi_runtime_instance_t   *i2 = (a2);                                                             \ 
     66                                                                                                                                                \ 
     67                WI_ASSERT(wi_is_equal(i1, i2),                                                                  \ 
     68                                  "'%@' should be equal to '%@': " fmt,                                 \ 
     69                                  i1, i2, ## __VA_ARGS__);                                                              \ 
     70        WI_STMT_END 
    6271 
    63 #define WI_TEST_ASSERT_TRUE(a1, fmt, ...)                                             \ 
    64         WI_ASSERT((a1), "'" WI_STRINGIFY(a1) "' should be true: " fmt, a1, ## __VA_ARGS__); 
     72#define WI_TEST_ASSERT_NOT_NULL(a1, fmt, ...)                                                 \ 
     73        WI_ASSERT((a1) != NULL, "'%s' should not be NULL: " fmt, #a1, ## __VA_ARGS__); 
    6574 
    66 #define WI_TEST_ASSERT_FALSE(a1, fmt, ...)                                              \ 
    67         WI_ASSERT(!(a1), "'" WI_STRINGIFY(a1) "' should be false: " fmt, a1, ## __VA_ARGS__); 
     75#define WI_TEST_ASSERT_TRUE(a1, fmt, ...)                                                               \ 
     76        WI_ASSERT((a1), "'%s' should be true: " fmt, #a1, ## __VA_ARGS__); 
     77 
     78#define WI_TEST_ASSERT_FALSE(a1, fmt, ...)                                                              \ 
     79        WI_ASSERT(!(a1), "'%s' should be false: " fmt, #a1, ## __VA_ARGS__); 
    6880 
    6981 
  • libwired/trunk/libwired/data/wi-string.c

    r4540 r4556  
    14751475         
    14761476        if(string->string == ep || *ep != '\0' || errno == ERANGE) 
    1477                 return 0
     1477                return 0U
    14781478         
    14791479        return (uint32_t) ul; 
     
    14901490         
    14911491        if(string->string == ep || *ep != '\0' || errno == ERANGE) 
    1492                 return 0
     1492                return 0LL
    14931493         
    14941494        return (int64_t) ll; 
  • libwired/trunk/test/tests/wi-string-tests.c

    r4542 r4556  
    3030 
    3131WI_TEST_EXPORT void                                     wi_test_string_case(void); 
     32WI_TEST_EXPORT void                                     wi_test_string_conversions(void); 
    3233WI_TEST_EXPORT void                                     wi_test_string_paths(void); 
    3334 
     
    4142                wi_string_uppercase_string(WI_STR("abc")), WI_STR("ABC"), 
    4243                "wi_string_uppercase_string()"); 
     44} 
     45 
     46 
     47 
     48void wi_test_string_conversions(void) { 
     49        WI_TEST_ASSERT_EQUALS( 
     50                wi_string_bool(WI_STR("yes")), 
     51                true, 
     52                "wi_string_bool()"); 
     53 
     54        WI_TEST_ASSERT_EQUALS( 
     55                wi_string_bool(WI_STR("no")), 
     56                false, 
     57                "wi_string_bool()"); 
     58         
     59        WI_TEST_ASSERT_EQUALS( 
     60                wi_string_int32(WI_STR("2147483647")), 
     61                2147483647, 
     62                "wi_string_int32()"); 
     63         
     64        WI_TEST_ASSERT_EQUALS( 
     65                wi_string_int32(WI_STR("2147483648")), 
     66                0, 
     67                "wi_string_int32()"); 
     68         
     69        WI_TEST_ASSERT_EQUALS( 
     70                wi_string_uint32(WI_STR("4294967295")), 
     71                4294967295U, 
     72                "wi_string_uint32()"); 
     73 
     74        WI_TEST_ASSERT_EQUALS( 
     75                wi_string_uint32(WI_STR("4294967296")), 
     76                0U, 
     77                "wi_string_uint32()"); 
     78         
     79        WI_TEST_ASSERT_EQUALS( 
     80                wi_string_int64(WI_STR("9223372036854775807")), 
     81                9223372036854775807LL, 
     82                "wi_string_int64()"); 
     83         
     84        WI_TEST_ASSERT_EQUALS( 
     85                wi_string_int64(WI_STR("9223372036854775808")), 
     86                0LL, 
     87                "wi_string_int64()"); 
     88         
     89        WI_TEST_ASSERT_EQUALS( 
     90                wi_string_uint64(WI_STR("18446744073709551615")), 
     91                18446744073709551615ULL, 
     92                "wi_string_uint64()"); 
     93 
     94        WI_TEST_ASSERT_EQUALS( 
     95                wi_string_uint64(WI_STR("18446744073709551616")), 
     96                0ULL, 
     97                "wi_string_uint64()"); 
     98         
     99#ifdef WI_32 
     100        WI_TEST_ASSERT_EQUALS( 
     101                wi_string_integer(WI_STR("2147483647")), 
     102                2147483647, 
     103                "wi_string_integer()"); 
     104         
     105        WI_TEST_ASSERT_EQUALS( 
     106                wi_string_integer(WI_STR("2147483648")), 
     107                0, 
     108                "wi_string_integer()"); 
     109         
     110        WI_TEST_ASSERT_EQUALS( 
     111                wi_string_uinteger(WI_STR("4294967295")), 
     112                4294967295U, 
     113                "wi_string_uinteger()"); 
     114 
     115        WI_TEST_ASSERT_EQUALS( 
     116                wi_string_uinteger(WI_STR("4294967296")), 
     117                0U, 
     118                "wi_string_uinteger()"); 
     119#else 
     120        WI_TEST_ASSERT_EQUALS( 
     121                wi_string_integer(WI_STR("9223372036854775807")), 
     122                9223372036854775807LL, 
     123                "wi_string_integer()"); 
     124         
     125        WI_TEST_ASSERT_EQUALS( 
     126                wi_string_integer(WI_STR("9223372036854775808")), 
     127                0LL, 
     128                "wi_string_integer()"); 
     129         
     130        WI_TEST_ASSERT_EQUALS( 
     131                wi_string_uinteger(WI_STR("18446744073709551615")), 
     132                18446744073709551615ULL, 
     133                "wi_string_uinteger()"); 
     134 
     135        WI_TEST_ASSERT_EQUALS( 
     136                wi_string_uinteger(WI_STR("18446744073709551616")), 
     137                0ULL, 
     138                "wi_string_uinteger()"); 
     139#endif 
     140         
     141        WI_TEST_ASSERT_EQUALS_WITH_ACCURACY( 
     142                wi_string_float(WI_STR("3.40282346e38")), 
     143                3.40282346e38F, 
     144                0.0001, 
     145                "wi_string_float()"); 
     146 
     147        WI_TEST_ASSERT_EQUALS_WITH_ACCURACY( 
     148                wi_string_float(WI_STR("3.40282347e38")), 
     149                0.0F, 
     150                0.0001, 
     151                "wi_string_float()"); 
     152         
     153        WI_TEST_ASSERT_EQUALS_WITH_ACCURACY( 
     154                wi_string_double(WI_STR("1.7976931348623155e308")), 
     155                1.7976931348623155e308, 
     156                0.0001, 
     157                "wi_string_double()"); 
     158 
     159        WI_TEST_ASSERT_EQUALS_WITH_ACCURACY( 
     160                wi_string_double(WI_STR("1.7976931348623159e308")), 
     161                0.0, 
     162                0.0001, 
     163                "wi_string_double()"); 
    43164} 
    44165