Changes in uspace/lib/c/test/stdlib.c [a4e78743:9d8307a] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/test/stdlib.c
ra4e78743 r9d8307a 63 63 } 64 64 65 /** atoi function */ 66 PCUT_TEST(atoi) 67 { 68 int i; 69 70 i = atoi(" \t42"); 71 PCUT_ASSERT_TRUE(i == 42); 72 } 73 74 /** atol function */ 75 PCUT_TEST(atol) 76 { 77 long li; 78 79 li = atol(" \t42"); 80 PCUT_ASSERT_TRUE(li == 42); 81 } 82 83 /** atoll function */ 84 PCUT_TEST(atoll) 85 { 86 long long lli; 87 88 lli = atoll(" \t42"); 89 PCUT_ASSERT_TRUE(lli == 42); 90 } 91 65 92 /** strtold function */ 66 93 #include <stdio.h> … … 74 101 printf("ld=%.10lf\n", (double)ld); 75 102 PCUT_ASSERT_TRUE(ld == 42.0); 103 } 104 105 /** strtol function */ 106 PCUT_TEST(strtol) 107 { 108 long li; 109 char *ep; 110 111 li = strtol(" \t42x", &ep, 10); 112 PCUT_ASSERT_TRUE(li == 42); 113 PCUT_ASSERT_TRUE(*ep == 'x'); 114 } 115 116 /** strtol function with auto-detected base 10 */ 117 PCUT_TEST(strtol_dec_auto) 118 { 119 long li; 120 char *ep; 121 122 li = strtol(" \t42x", &ep, 0); 123 PCUT_ASSERT_TRUE(li == 42); 124 PCUT_ASSERT_TRUE(*ep == 'x'); 125 } 126 127 /** strtol function with octal number */ 128 PCUT_TEST(strtol_oct) 129 { 130 long li; 131 char *ep; 132 133 li = strtol(" \t052x", &ep, 8); 134 PCUT_ASSERT_TRUE(li == 052); 135 PCUT_ASSERT_TRUE(*ep == 'x'); 136 } 137 138 /** strtol function with octal number with prefix */ 139 #include <stdio.h> 140 PCUT_TEST(strtol_oct_prefix) 141 { 142 long li; 143 char *ep; 144 145 li = strtol(" \t052x", &ep, 0); 146 printf("li=%ld (0%lo)\n", li, li); 147 PCUT_ASSERT_TRUE(li == 052); 148 PCUT_ASSERT_TRUE(*ep == 'x'); 149 } 150 151 /** strtol function with hex number */ 152 PCUT_TEST(strtol_hex) 153 { 154 long li; 155 char *ep; 156 157 li = strtol(" \t2ax", &ep, 16); 158 PCUT_ASSERT_TRUE(li == 0x2a); 159 PCUT_ASSERT_TRUE(*ep == 'x'); 160 } 161 162 /** strtol function with hex number with hex prefix */ 163 PCUT_TEST(strtol_hex_prefixed) 164 { 165 long li; 166 char *ep; 167 168 li = strtol(" \t0x2ax", &ep, 0); 169 PCUT_ASSERT_TRUE(li == 0x2a); 170 PCUT_ASSERT_TRUE(*ep == 'x'); 171 } 172 173 /** strtol function with base 16 and number with 0x prefix */ 174 PCUT_TEST(strtol_base16_prefix) 175 { 176 long li; 177 char *ep; 178 179 li = strtol(" \t0x1y", &ep, 16); 180 printf("li=%ld\n", li); 181 PCUT_ASSERT_TRUE(li == 1); 182 PCUT_ASSERT_TRUE(*ep == 'y'); 183 } 184 185 /** strtol function with base 36 number */ 186 PCUT_TEST(strtol_base36) 187 { 188 long li; 189 char *ep; 190 191 li = strtol(" \tz1.", &ep, 36); 192 PCUT_ASSERT_TRUE(li == 35 * 36 + 1); 193 PCUT_ASSERT_TRUE(*ep == '.'); 76 194 } 77 195
Note:
See TracChangeset
for help on using the changeset viewer.