00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include <gtest/gtest.h>
00031
00032 #include <swri_string_util/string_util.h>
00033
00034 TEST(StringUtilTests, ToDouble_0)
00035 {
00036 double value = -1;
00037 EXPECT_TRUE(swri_string_util::ToDouble("0", value));
00038 EXPECT_FLOAT_EQ(0, value);
00039
00040 value = -1;
00041 EXPECT_TRUE(swri_string_util::ToDouble(".0", value));
00042 EXPECT_FLOAT_EQ(0, value);
00043
00044 value = -1;
00045 EXPECT_TRUE(swri_string_util::ToDouble("0.0", value));
00046 EXPECT_FLOAT_EQ(0, value);
00047
00048 value = -1;
00049 EXPECT_TRUE(swri_string_util::ToDouble("0.00", value));
00050 EXPECT_FLOAT_EQ(0, value);
00051
00052 value = -1;
00053 EXPECT_TRUE(swri_string_util::ToDouble("0.0e0", value));
00054 EXPECT_FLOAT_EQ(0, value);
00055
00056 value = -1;
00057 EXPECT_TRUE(swri_string_util::ToDouble("0.0e-0", value));
00058 EXPECT_FLOAT_EQ(0, value);
00059
00060 value = -1;
00061 EXPECT_TRUE(swri_string_util::ToDouble("0.0e+0", value));
00062 EXPECT_FLOAT_EQ(0, value);
00063
00064 value = -1;
00065 EXPECT_TRUE(swri_string_util::ToDouble("+0", value));
00066 EXPECT_FLOAT_EQ(0, value);
00067
00068 value = -1;
00069 EXPECT_TRUE(swri_string_util::ToDouble("+.0", value));
00070 EXPECT_FLOAT_EQ(0, value);
00071
00072 value = -1;
00073 EXPECT_TRUE(swri_string_util::ToDouble("+0.0", value));
00074 EXPECT_FLOAT_EQ(0, value);
00075
00076 value = -1;
00077 EXPECT_TRUE(swri_string_util::ToDouble("+0.00", value));
00078 EXPECT_FLOAT_EQ(0, value);
00079
00080 value = -1;
00081 EXPECT_TRUE(swri_string_util::ToDouble("+0.0e0", value));
00082 EXPECT_FLOAT_EQ(0, value);
00083
00084 value = -1;
00085 EXPECT_TRUE(swri_string_util::ToDouble("+0.0e-0", value));
00086 EXPECT_FLOAT_EQ(0, value);
00087
00088 value = -1;
00089 EXPECT_TRUE(swri_string_util::ToDouble("+0.0e+0", value));
00090 EXPECT_FLOAT_EQ(0, value);
00091
00092 value = -1;
00093 EXPECT_TRUE(swri_string_util::ToDouble("-0", value));
00094 EXPECT_FLOAT_EQ(0, value);
00095
00096 value = -1;
00097 EXPECT_TRUE(swri_string_util::ToDouble("-.0", value));
00098 EXPECT_FLOAT_EQ(0, value);
00099
00100 value = -1;
00101 EXPECT_TRUE(swri_string_util::ToDouble("-0.0", value));
00102 EXPECT_FLOAT_EQ(0, value);
00103
00104 value = -1;
00105 EXPECT_TRUE(swri_string_util::ToDouble("-0.00", value));
00106 EXPECT_FLOAT_EQ(0, value);
00107
00108 value = -1;
00109 EXPECT_TRUE(swri_string_util::ToDouble("-0.0e0", value));
00110 EXPECT_FLOAT_EQ(0, value);
00111
00112 value = -1;
00113 EXPECT_TRUE(swri_string_util::ToDouble("-0.0e-0", value));
00114 EXPECT_FLOAT_EQ(0, value);
00115
00116 value = -1;
00117 EXPECT_TRUE(swri_string_util::ToDouble("-0.0e+0", value));
00118 EXPECT_FLOAT_EQ(0, value);
00119
00120 value = -1;
00121 EXPECT_TRUE(swri_string_util::ToDouble(" 0", value));
00122 EXPECT_FLOAT_EQ(0, value);
00123
00124 value = -1;
00125 EXPECT_TRUE(swri_string_util::ToDouble(" .0", value));
00126 EXPECT_FLOAT_EQ(0, value);
00127
00128 value = -1;
00129 EXPECT_TRUE(swri_string_util::ToDouble(" 0.0", value));
00130 EXPECT_FLOAT_EQ(0, value);
00131
00132 value = -1;
00133 EXPECT_TRUE(swri_string_util::ToDouble(" 0.00", value));
00134 EXPECT_FLOAT_EQ(0, value);
00135
00136 value = -1;
00137 EXPECT_TRUE(swri_string_util::ToDouble(" 0.0e0", value));
00138 EXPECT_FLOAT_EQ(0, value);
00139
00140 value = -1;
00141 EXPECT_TRUE(swri_string_util::ToDouble(" 0.0e-0", value));
00142 EXPECT_FLOAT_EQ(0, value);
00143
00144 value = -1;
00145 EXPECT_TRUE(swri_string_util::ToDouble(" 0.0e+0", value));
00146 EXPECT_FLOAT_EQ(0, value);
00147
00148 value = -1;
00149 EXPECT_TRUE(swri_string_util::ToDouble(" +0", value));
00150 EXPECT_FLOAT_EQ(0, value);
00151
00152 value = -1;
00153 EXPECT_TRUE(swri_string_util::ToDouble(" +.0", value));
00154 EXPECT_FLOAT_EQ(0, value);
00155
00156 value = -1;
00157 EXPECT_TRUE(swri_string_util::ToDouble(" +0.0", value));
00158 EXPECT_FLOAT_EQ(0, value);
00159
00160 value = -1;
00161 EXPECT_TRUE(swri_string_util::ToDouble(" +0.00", value));
00162 EXPECT_FLOAT_EQ(0, value);
00163
00164 value = -1;
00165 EXPECT_TRUE(swri_string_util::ToDouble(" +0.0e0", value));
00166 EXPECT_FLOAT_EQ(0, value);
00167
00168 value = -1;
00169 EXPECT_TRUE(swri_string_util::ToDouble(" +0.0e-0", value));
00170 EXPECT_FLOAT_EQ(0, value);
00171
00172 value = -1;
00173 EXPECT_TRUE(swri_string_util::ToDouble(" +0.0e+0", value));
00174 EXPECT_FLOAT_EQ(0, value);
00175
00176 value = -1;
00177 EXPECT_TRUE(swri_string_util::ToDouble(" -0", value));
00178 EXPECT_FLOAT_EQ(0, value);
00179
00180 value = -1;
00181 EXPECT_TRUE(swri_string_util::ToDouble(" -.0", value));
00182 EXPECT_FLOAT_EQ(0, value);
00183
00184 value = -1;
00185 EXPECT_TRUE(swri_string_util::ToDouble(" -0.0", value));
00186 EXPECT_FLOAT_EQ(0, value);
00187
00188 value = -1;
00189 EXPECT_TRUE(swri_string_util::ToDouble(" -0.00", value));
00190 EXPECT_FLOAT_EQ(0, value);
00191
00192 value = -1;
00193 EXPECT_TRUE(swri_string_util::ToDouble(" -0.0e0", value));
00194 EXPECT_FLOAT_EQ(0, value);
00195
00196 value = -1;
00197 EXPECT_TRUE(swri_string_util::ToDouble(" -0.0e-0", value));
00198 EXPECT_FLOAT_EQ(0, value);
00199
00200 value = -1;
00201 EXPECT_TRUE(swri_string_util::ToDouble(" -0.0e+0", value));
00202 EXPECT_FLOAT_EQ(0, value);
00203 }
00204
00205 TEST(StringUtilTests, ToDouble_1)
00206 {
00207 double value = 0;
00208 EXPECT_TRUE(swri_string_util::ToDouble("1", value));
00209 EXPECT_FLOAT_EQ(1, value);
00210
00211 value = 0;
00212 EXPECT_TRUE(swri_string_util::ToDouble("1.", value));
00213 EXPECT_FLOAT_EQ(1, value);
00214
00215 value = 0;
00216 EXPECT_TRUE(swri_string_util::ToDouble("1.0", value));
00217 EXPECT_FLOAT_EQ(1, value);
00218
00219 value = 0;
00220 EXPECT_TRUE(swri_string_util::ToDouble("1.00", value));
00221 EXPECT_FLOAT_EQ(1, value);
00222
00223 value = 0;
00224 EXPECT_TRUE(swri_string_util::ToDouble("1.0e0", value));
00225 EXPECT_FLOAT_EQ(1, value);
00226
00227 value = 0;
00228 EXPECT_TRUE(swri_string_util::ToDouble("1.0e-0", value));
00229 EXPECT_FLOAT_EQ(1, value);
00230
00231 value = 0;
00232 EXPECT_TRUE(swri_string_util::ToDouble("1.0e+0", value));
00233 EXPECT_FLOAT_EQ(1, value);
00234
00235 value = 0;
00236 EXPECT_TRUE(swri_string_util::ToDouble("+1", value));
00237 EXPECT_FLOAT_EQ(1, value);
00238
00239 value = 0;
00240 EXPECT_TRUE(swri_string_util::ToDouble("+1.", value));
00241 EXPECT_FLOAT_EQ(1, value);
00242
00243 value = 0;
00244 EXPECT_TRUE(swri_string_util::ToDouble("+1.0", value));
00245 EXPECT_FLOAT_EQ(1, value);
00246
00247 value = 0;
00248 EXPECT_TRUE(swri_string_util::ToDouble("+1.00", value));
00249 EXPECT_FLOAT_EQ(1, value);
00250
00251 value = 0;
00252 EXPECT_TRUE(swri_string_util::ToDouble("+1.0e0", value));
00253 EXPECT_FLOAT_EQ(1, value);
00254
00255 value = 0;
00256 EXPECT_TRUE(swri_string_util::ToDouble("+1.0e-0", value));
00257 EXPECT_FLOAT_EQ(1, value);
00258
00259 value = 0;
00260 EXPECT_TRUE(swri_string_util::ToDouble("+1.0e+0", value));
00261 EXPECT_FLOAT_EQ(1, value);
00262
00263 value = 0;
00264 EXPECT_TRUE(swri_string_util::ToDouble("-1", value));
00265 EXPECT_FLOAT_EQ(-1, value);
00266
00267 value = 0;
00268 EXPECT_TRUE(swri_string_util::ToDouble("-1.", value));
00269 EXPECT_FLOAT_EQ(-1, value);
00270
00271 value = 0;
00272 EXPECT_TRUE(swri_string_util::ToDouble("-1.0", value));
00273 EXPECT_FLOAT_EQ(-1, value);
00274
00275 value = 0;
00276 EXPECT_TRUE(swri_string_util::ToDouble("-1.00", value));
00277 EXPECT_FLOAT_EQ(-1, value);
00278
00279 value = 0;
00280 EXPECT_TRUE(swri_string_util::ToDouble("-1.0e0", value));
00281 EXPECT_FLOAT_EQ(-1, value);
00282
00283 value = 0;
00284 EXPECT_TRUE(swri_string_util::ToDouble("-1.0e-0", value));
00285 EXPECT_FLOAT_EQ(-1, value);
00286
00287 value = 0;
00288 EXPECT_TRUE(swri_string_util::ToDouble("-1.0e+0", value));
00289 EXPECT_FLOAT_EQ(-1, value);
00290
00291 value = 0;
00292 EXPECT_TRUE(swri_string_util::ToDouble(" 1", value));
00293 EXPECT_FLOAT_EQ(1, value);
00294
00295 value = 0;
00296 EXPECT_TRUE(swri_string_util::ToDouble(" 1.", value));
00297 EXPECT_FLOAT_EQ(1, value);
00298
00299 value = 0;
00300 EXPECT_TRUE(swri_string_util::ToDouble(" 1.0", value));
00301 EXPECT_FLOAT_EQ(1, value);
00302
00303 value = 0;
00304 EXPECT_TRUE(swri_string_util::ToDouble(" 1.00", value));
00305 EXPECT_FLOAT_EQ(1, value);
00306
00307 value = 0;
00308 EXPECT_TRUE(swri_string_util::ToDouble(" 1.0e0", value));
00309 EXPECT_FLOAT_EQ(1, value);
00310
00311 value = 0;
00312 EXPECT_TRUE(swri_string_util::ToDouble(" 1.0e-0", value));
00313 EXPECT_FLOAT_EQ(1, value);
00314
00315 value = 0;
00316 EXPECT_TRUE(swri_string_util::ToDouble(" 1.0e+0", value));
00317 EXPECT_FLOAT_EQ(1, value);
00318
00319 value = 0;
00320 EXPECT_TRUE(swri_string_util::ToDouble(" +1", value));
00321 EXPECT_FLOAT_EQ(1, value);
00322
00323 value = 0;
00324 EXPECT_TRUE(swri_string_util::ToDouble(" +1.", value));
00325 EXPECT_FLOAT_EQ(1, value);
00326
00327 value = 0;
00328 EXPECT_TRUE(swri_string_util::ToDouble(" +1.0", value));
00329 EXPECT_FLOAT_EQ(1, value);
00330
00331 value = 0;
00332 EXPECT_TRUE(swri_string_util::ToDouble(" +1.00", value));
00333 EXPECT_FLOAT_EQ(1, value);
00334
00335 value = 0;
00336 EXPECT_TRUE(swri_string_util::ToDouble(" +1.0e0", value));
00337 EXPECT_FLOAT_EQ(1, value);
00338
00339 value = 0;
00340 EXPECT_TRUE(swri_string_util::ToDouble(" +1.0e-0", value));
00341 EXPECT_FLOAT_EQ(1, value);
00342
00343 value = 0;
00344 EXPECT_TRUE(swri_string_util::ToDouble(" +1.0e+0", value));
00345 EXPECT_FLOAT_EQ(1, value);
00346
00347 value = 0;
00348 EXPECT_TRUE(swri_string_util::ToDouble(" -1", value));
00349 EXPECT_FLOAT_EQ(-1, value);
00350
00351 value = 0;
00352 EXPECT_TRUE(swri_string_util::ToDouble(" -1.", value));
00353 EXPECT_FLOAT_EQ(-1, value);
00354
00355 value = 0;
00356 EXPECT_TRUE(swri_string_util::ToDouble(" -1.0", value));
00357 EXPECT_FLOAT_EQ(-1, value);
00358
00359 value = 0;
00360 EXPECT_TRUE(swri_string_util::ToDouble(" -1.00", value));
00361 EXPECT_FLOAT_EQ(-1, value);
00362
00363 value = 0;
00364 EXPECT_TRUE(swri_string_util::ToDouble(" -1.0e0", value));
00365 EXPECT_FLOAT_EQ(-1, value);
00366
00367 value = 0;
00368 EXPECT_TRUE(swri_string_util::ToDouble(" -1.0e-0", value));
00369 EXPECT_FLOAT_EQ(-1, value);
00370
00371 value = 0;
00372 EXPECT_TRUE(swri_string_util::ToDouble(" -1.0e+0", value));
00373 EXPECT_FLOAT_EQ(-1, value);
00374
00375 value = 0;
00376 EXPECT_TRUE(swri_string_util::ToDouble(" 10.0e-1", value));
00377 EXPECT_FLOAT_EQ(1, value);
00378
00379 value = 0;
00380 EXPECT_TRUE(swri_string_util::ToDouble(" 100.0e-2", value));
00381 EXPECT_FLOAT_EQ(1, value);
00382
00383 value = 0;
00384 EXPECT_TRUE(swri_string_util::ToDouble(" 0.1e1", value));
00385 EXPECT_FLOAT_EQ(1, value);
00386
00387 value = 0;
00388 EXPECT_TRUE(swri_string_util::ToDouble(" 0.1e+1", value));
00389 EXPECT_FLOAT_EQ(1, value);
00390
00391 value = 0;
00392 EXPECT_TRUE(swri_string_util::ToDouble(" 0.01e+2", value));
00393 EXPECT_FLOAT_EQ(1, value);
00394 }
00395
00396 TEST(StringUtilTests, ToDouble)
00397 {
00398 double value = 0;
00399 EXPECT_TRUE(swri_string_util::ToDouble("0.123456789", value));
00400 EXPECT_FLOAT_EQ(0.123456789, value);
00401
00402 value = 0;
00403 EXPECT_TRUE(swri_string_util::ToDouble("123456789.", value));
00404 EXPECT_FLOAT_EQ(123456789, value);
00405
00406 value = 0;
00407 EXPECT_TRUE(swri_string_util::ToDouble("12345678.9", value));
00408 EXPECT_FLOAT_EQ(12345678.9, value);
00409
00410 value = 0;
00411 EXPECT_TRUE(swri_string_util::ToDouble("123456789.00", value));
00412 EXPECT_FLOAT_EQ(123456789, value);
00413
00414 value = 0;
00415 EXPECT_TRUE(swri_string_util::ToDouble("12345.6789", value));
00416 EXPECT_FLOAT_EQ(12345.6789, value);
00417
00418 value = 0;
00419 EXPECT_TRUE(swri_string_util::ToDouble("1e308", value));
00420 EXPECT_FLOAT_EQ(1e308, value);
00421
00422 value = 0;
00423 EXPECT_TRUE(swri_string_util::ToDouble("1e-307", value));
00424 EXPECT_FLOAT_EQ(1e-307, value);
00425 }
00426
00427 TEST(StringUtilTests, ToDoubleInvalid)
00428 {
00429 double value = 0;
00430
00431 EXPECT_FALSE(swri_string_util::ToDouble("a", value));
00432 EXPECT_FALSE(swri_string_util::ToDouble("a0", value));
00433 EXPECT_FALSE(swri_string_util::ToDouble("0a", value));
00434 EXPECT_FALSE(swri_string_util::ToDouble("0 ", value));
00435 EXPECT_FALSE(swri_string_util::ToDouble("1e309", value));
00436 EXPECT_FALSE(swri_string_util::ToDouble("1e-308", value));
00437 }
00438
00439 TEST(StringUtilTests, ToFloat_0)
00440 {
00441 float value = -1;
00442 EXPECT_TRUE(swri_string_util::ToFloat("0", value));
00443 EXPECT_FLOAT_EQ(0, value);
00444
00445 value = -1;
00446 EXPECT_TRUE(swri_string_util::ToFloat(".0", value));
00447 EXPECT_FLOAT_EQ(0, value);
00448
00449 value = -1;
00450 EXPECT_TRUE(swri_string_util::ToFloat("0.0", value));
00451 EXPECT_FLOAT_EQ(0, value);
00452
00453 value = -1;
00454 EXPECT_TRUE(swri_string_util::ToFloat("0.00", value));
00455 EXPECT_FLOAT_EQ(0, value);
00456
00457 value = -1;
00458 EXPECT_TRUE(swri_string_util::ToFloat("0.0e0", value));
00459 EXPECT_FLOAT_EQ(0, value);
00460
00461 value = -1;
00462 EXPECT_TRUE(swri_string_util::ToFloat("0.0e-0", value));
00463 EXPECT_FLOAT_EQ(0, value);
00464
00465 value = -1;
00466 EXPECT_TRUE(swri_string_util::ToFloat("0.0e+0", value));
00467 EXPECT_FLOAT_EQ(0, value);
00468
00469 value = -1;
00470 EXPECT_TRUE(swri_string_util::ToFloat("+0", value));
00471 EXPECT_FLOAT_EQ(0, value);
00472
00473 value = -1;
00474 EXPECT_TRUE(swri_string_util::ToFloat("+.0", value));
00475 EXPECT_FLOAT_EQ(0, value);
00476
00477 value = -1;
00478 EXPECT_TRUE(swri_string_util::ToFloat("+0.0", value));
00479 EXPECT_FLOAT_EQ(0, value);
00480
00481 value = -1;
00482 EXPECT_TRUE(swri_string_util::ToFloat("+0.00", value));
00483 EXPECT_FLOAT_EQ(0, value);
00484
00485 value = -1;
00486 EXPECT_TRUE(swri_string_util::ToFloat("+0.0e0", value));
00487 EXPECT_FLOAT_EQ(0, value);
00488
00489 value = -1;
00490 EXPECT_TRUE(swri_string_util::ToFloat("+0.0e-0", value));
00491 EXPECT_FLOAT_EQ(0, value);
00492
00493 value = -1;
00494 EXPECT_TRUE(swri_string_util::ToFloat("+0.0e+0", value));
00495 EXPECT_FLOAT_EQ(0, value);
00496
00497 value = -1;
00498 EXPECT_TRUE(swri_string_util::ToFloat("-0", value));
00499 EXPECT_FLOAT_EQ(0, value);
00500
00501 value = -1;
00502 EXPECT_TRUE(swri_string_util::ToFloat("-.0", value));
00503 EXPECT_FLOAT_EQ(0, value);
00504
00505 value = -1;
00506 EXPECT_TRUE(swri_string_util::ToFloat("-0.0", value));
00507 EXPECT_FLOAT_EQ(0, value);
00508
00509 value = -1;
00510 EXPECT_TRUE(swri_string_util::ToFloat("-0.00", value));
00511 EXPECT_FLOAT_EQ(0, value);
00512
00513 value = -1;
00514 EXPECT_TRUE(swri_string_util::ToFloat("-0.0e0", value));
00515 EXPECT_FLOAT_EQ(0, value);
00516
00517 value = -1;
00518 EXPECT_TRUE(swri_string_util::ToFloat("-0.0e-0", value));
00519 EXPECT_FLOAT_EQ(0, value);
00520
00521 value = -1;
00522 EXPECT_TRUE(swri_string_util::ToFloat("-0.0e+0", value));
00523 EXPECT_FLOAT_EQ(0, value);
00524
00525 value = -1;
00526 EXPECT_TRUE(swri_string_util::ToFloat(" 0", value));
00527 EXPECT_FLOAT_EQ(0, value);
00528
00529 value = -1;
00530 EXPECT_TRUE(swri_string_util::ToFloat(" .0", value));
00531 EXPECT_FLOAT_EQ(0, value);
00532
00533 value = -1;
00534 EXPECT_TRUE(swri_string_util::ToFloat(" 0.0", value));
00535 EXPECT_FLOAT_EQ(0, value);
00536
00537 value = -1;
00538 EXPECT_TRUE(swri_string_util::ToFloat(" 0.00", value));
00539 EXPECT_FLOAT_EQ(0, value);
00540
00541 value = -1;
00542 EXPECT_TRUE(swri_string_util::ToFloat(" 0.0e0", value));
00543 EXPECT_FLOAT_EQ(0, value);
00544
00545 value = -1;
00546 EXPECT_TRUE(swri_string_util::ToFloat(" 0.0e-0", value));
00547 EXPECT_FLOAT_EQ(0, value);
00548
00549 value = -1;
00550 EXPECT_TRUE(swri_string_util::ToFloat(" 0.0e+0", value));
00551 EXPECT_FLOAT_EQ(0, value);
00552
00553 value = -1;
00554 EXPECT_TRUE(swri_string_util::ToFloat(" +0", value));
00555 EXPECT_FLOAT_EQ(0, value);
00556
00557 value = -1;
00558 EXPECT_TRUE(swri_string_util::ToFloat(" +.0", value));
00559 EXPECT_FLOAT_EQ(0, value);
00560
00561 value = -1;
00562 EXPECT_TRUE(swri_string_util::ToFloat(" +0.0", value));
00563 EXPECT_FLOAT_EQ(0, value);
00564
00565 value = -1;
00566 EXPECT_TRUE(swri_string_util::ToFloat(" +0.00", value));
00567 EXPECT_FLOAT_EQ(0, value);
00568
00569 value = -1;
00570 EXPECT_TRUE(swri_string_util::ToFloat(" +0.0e0", value));
00571 EXPECT_FLOAT_EQ(0, value);
00572
00573 value = -1;
00574 EXPECT_TRUE(swri_string_util::ToFloat(" +0.0e-0", value));
00575 EXPECT_FLOAT_EQ(0, value);
00576
00577 value = -1;
00578 EXPECT_TRUE(swri_string_util::ToFloat(" +0.0e+0", value));
00579 EXPECT_FLOAT_EQ(0, value);
00580
00581 value = -1;
00582 EXPECT_TRUE(swri_string_util::ToFloat(" -0", value));
00583 EXPECT_FLOAT_EQ(0, value);
00584
00585 value = -1;
00586 EXPECT_TRUE(swri_string_util::ToFloat(" -.0", value));
00587 EXPECT_FLOAT_EQ(0, value);
00588
00589 value = -1;
00590 EXPECT_TRUE(swri_string_util::ToFloat(" -0.0", value));
00591 EXPECT_FLOAT_EQ(0, value);
00592
00593 value = -1;
00594 EXPECT_TRUE(swri_string_util::ToFloat(" -0.00", value));
00595 EXPECT_FLOAT_EQ(0, value);
00596
00597 value = -1;
00598 EXPECT_TRUE(swri_string_util::ToFloat(" -0.0e0", value));
00599 EXPECT_FLOAT_EQ(0, value);
00600
00601 value = -1;
00602 EXPECT_TRUE(swri_string_util::ToFloat(" -0.0e-0", value));
00603 EXPECT_FLOAT_EQ(0, value);
00604
00605 value = -1;
00606 EXPECT_TRUE(swri_string_util::ToFloat(" -0.0e+0", value));
00607 EXPECT_FLOAT_EQ(0, value);
00608 }
00609
00610 TEST(StringUtilTests, ToFloat_1)
00611 {
00612 float value = 0;
00613 EXPECT_TRUE(swri_string_util::ToFloat("1", value));
00614 EXPECT_FLOAT_EQ(1, value);
00615
00616 value = 0;
00617 EXPECT_TRUE(swri_string_util::ToFloat("1.", value));
00618 EXPECT_FLOAT_EQ(1, value);
00619
00620 value = 0;
00621 EXPECT_TRUE(swri_string_util::ToFloat("1.0", value));
00622 EXPECT_FLOAT_EQ(1, value);
00623
00624 value = 0;
00625 EXPECT_TRUE(swri_string_util::ToFloat("1.00", value));
00626 EXPECT_FLOAT_EQ(1, value);
00627
00628 value = 0;
00629 EXPECT_TRUE(swri_string_util::ToFloat("1.0e0", value));
00630 EXPECT_FLOAT_EQ(1, value);
00631
00632 value = 0;
00633 EXPECT_TRUE(swri_string_util::ToFloat("1.0e-0", value));
00634 EXPECT_FLOAT_EQ(1, value);
00635
00636 value = 0;
00637 EXPECT_TRUE(swri_string_util::ToFloat("1.0e+0", value));
00638 EXPECT_FLOAT_EQ(1, value);
00639
00640 value = 0;
00641 EXPECT_TRUE(swri_string_util::ToFloat("+1", value));
00642 EXPECT_FLOAT_EQ(1, value);
00643
00644 value = 0;
00645 EXPECT_TRUE(swri_string_util::ToFloat("+1.", value));
00646 EXPECT_FLOAT_EQ(1, value);
00647
00648 value = 0;
00649 EXPECT_TRUE(swri_string_util::ToFloat("+1.0", value));
00650 EXPECT_FLOAT_EQ(1, value);
00651
00652 value = 0;
00653 EXPECT_TRUE(swri_string_util::ToFloat("+1.00", value));
00654 EXPECT_FLOAT_EQ(1, value);
00655
00656 value = 0;
00657 EXPECT_TRUE(swri_string_util::ToFloat("+1.0e0", value));
00658 EXPECT_FLOAT_EQ(1, value);
00659
00660 value = 0;
00661 EXPECT_TRUE(swri_string_util::ToFloat("+1.0e-0", value));
00662 EXPECT_FLOAT_EQ(1, value);
00663
00664 value = 0;
00665 EXPECT_TRUE(swri_string_util::ToFloat("+1.0e+0", value));
00666 EXPECT_FLOAT_EQ(1, value);
00667
00668 value = 0;
00669 EXPECT_TRUE(swri_string_util::ToFloat("-1", value));
00670 EXPECT_FLOAT_EQ(-1, value);
00671
00672 value = 0;
00673 EXPECT_TRUE(swri_string_util::ToFloat("-1.", value));
00674 EXPECT_FLOAT_EQ(-1, value);
00675
00676 value = 0;
00677 EXPECT_TRUE(swri_string_util::ToFloat("-1.0", value));
00678 EXPECT_FLOAT_EQ(-1, value);
00679
00680 value = 0;
00681 EXPECT_TRUE(swri_string_util::ToFloat("-1.00", value));
00682 EXPECT_FLOAT_EQ(-1, value);
00683
00684 value = 0;
00685 EXPECT_TRUE(swri_string_util::ToFloat("-1.0e0", value));
00686 EXPECT_FLOAT_EQ(-1, value);
00687
00688 value = 0;
00689 EXPECT_TRUE(swri_string_util::ToFloat("-1.0e-0", value));
00690 EXPECT_FLOAT_EQ(-1, value);
00691
00692 value = 0;
00693 EXPECT_TRUE(swri_string_util::ToFloat("-1.0e+0", value));
00694 EXPECT_FLOAT_EQ(-1, value);
00695
00696 value = 0;
00697 EXPECT_TRUE(swri_string_util::ToFloat(" 1", value));
00698 EXPECT_FLOAT_EQ(1, value);
00699
00700 value = 0;
00701 EXPECT_TRUE(swri_string_util::ToFloat(" 1.", value));
00702 EXPECT_FLOAT_EQ(1, value);
00703
00704 value = 0;
00705 EXPECT_TRUE(swri_string_util::ToFloat(" 1.0", value));
00706 EXPECT_FLOAT_EQ(1, value);
00707
00708 value = 0;
00709 EXPECT_TRUE(swri_string_util::ToFloat(" 1.00", value));
00710 EXPECT_FLOAT_EQ(1, value);
00711
00712 value = 0;
00713 EXPECT_TRUE(swri_string_util::ToFloat(" 1.0e0", value));
00714 EXPECT_FLOAT_EQ(1, value);
00715
00716 value = 0;
00717 EXPECT_TRUE(swri_string_util::ToFloat(" 1.0e-0", value));
00718 EXPECT_FLOAT_EQ(1, value);
00719
00720 value = 0;
00721 EXPECT_TRUE(swri_string_util::ToFloat(" 1.0e+0", value));
00722 EXPECT_FLOAT_EQ(1, value);
00723
00724 value = 0;
00725 EXPECT_TRUE(swri_string_util::ToFloat(" +1", value));
00726 EXPECT_FLOAT_EQ(1, value);
00727
00728 value = 0;
00729 EXPECT_TRUE(swri_string_util::ToFloat(" +1.", value));
00730 EXPECT_FLOAT_EQ(1, value);
00731
00732 value = 0;
00733 EXPECT_TRUE(swri_string_util::ToFloat(" +1.0", value));
00734 EXPECT_FLOAT_EQ(1, value);
00735
00736 value = 0;
00737 EXPECT_TRUE(swri_string_util::ToFloat(" +1.00", value));
00738 EXPECT_FLOAT_EQ(1, value);
00739
00740 value = 0;
00741 EXPECT_TRUE(swri_string_util::ToFloat(" +1.0e0", value));
00742 EXPECT_FLOAT_EQ(1, value);
00743
00744 value = 0;
00745 EXPECT_TRUE(swri_string_util::ToFloat(" +1.0e-0", value));
00746 EXPECT_FLOAT_EQ(1, value);
00747
00748 value = 0;
00749 EXPECT_TRUE(swri_string_util::ToFloat(" +1.0e+0", value));
00750 EXPECT_FLOAT_EQ(1, value);
00751
00752 value = 0;
00753 EXPECT_TRUE(swri_string_util::ToFloat(" -1", value));
00754 EXPECT_FLOAT_EQ(-1, value);
00755
00756 value = 0;
00757 EXPECT_TRUE(swri_string_util::ToFloat(" -1.", value));
00758 EXPECT_FLOAT_EQ(-1, value);
00759
00760 value = 0;
00761 EXPECT_TRUE(swri_string_util::ToFloat(" -1.0", value));
00762 EXPECT_FLOAT_EQ(-1, value);
00763
00764 value = 0;
00765 EXPECT_TRUE(swri_string_util::ToFloat(" -1.00", value));
00766 EXPECT_FLOAT_EQ(-1, value);
00767
00768 value = 0;
00769 EXPECT_TRUE(swri_string_util::ToFloat(" -1.0e0", value));
00770 EXPECT_FLOAT_EQ(-1, value);
00771
00772 value = 0;
00773 EXPECT_TRUE(swri_string_util::ToFloat(" -1.0e-0", value));
00774 EXPECT_FLOAT_EQ(-1, value);
00775
00776 value = 0;
00777 EXPECT_TRUE(swri_string_util::ToFloat(" -1.0e+0", value));
00778 EXPECT_FLOAT_EQ(-1, value);
00779
00780 value = 0;
00781 EXPECT_TRUE(swri_string_util::ToFloat(" 10.0e-1", value));
00782 EXPECT_FLOAT_EQ(1, value);
00783
00784 value = 0;
00785 EXPECT_TRUE(swri_string_util::ToFloat(" 100.0e-2", value));
00786 EXPECT_FLOAT_EQ(1, value);
00787
00788 value = 0;
00789 EXPECT_TRUE(swri_string_util::ToFloat(" 0.1e1", value));
00790 EXPECT_FLOAT_EQ(1, value);
00791
00792 value = 0;
00793 EXPECT_TRUE(swri_string_util::ToFloat(" 0.1e+1", value));
00794 EXPECT_FLOAT_EQ(1, value);
00795
00796 value = 0;
00797 EXPECT_TRUE(swri_string_util::ToFloat(" 0.01e+2", value));
00798 EXPECT_FLOAT_EQ(1, value);
00799 }
00800
00801 TEST(StringUtilTests, ToFloat)
00802 {
00803 float value = 0;
00804 EXPECT_TRUE(swri_string_util::ToFloat("0.123456789", value));
00805 EXPECT_FLOAT_EQ(0.123456789, value);
00806
00807 value = 0;
00808 EXPECT_TRUE(swri_string_util::ToFloat("123456789.", value));
00809 EXPECT_FLOAT_EQ(123456789, value);
00810
00811 value = 0;
00812 EXPECT_TRUE(swri_string_util::ToFloat("12345678.9", value));
00813 EXPECT_FLOAT_EQ(12345678.9, value);
00814
00815 value = 0;
00816 EXPECT_TRUE(swri_string_util::ToFloat("123456789.00", value));
00817 EXPECT_FLOAT_EQ(123456789, value);
00818
00819 value = 0;
00820 EXPECT_TRUE(swri_string_util::ToFloat("12345.6789", value));
00821 EXPECT_FLOAT_EQ(12345.6789, value);
00822
00823 value = 0;
00824 EXPECT_TRUE(swri_string_util::ToFloat("1e38", value));
00825 EXPECT_FLOAT_EQ(1e38, value);
00826
00827 value = 0;
00828 EXPECT_TRUE(swri_string_util::ToFloat("1e-37", value));
00829 EXPECT_FLOAT_EQ(1e-37, value);
00830 }
00831
00832 TEST(StringUtilTests, ToFloatInvalid)
00833 {
00834 float value = 0;
00835
00836 EXPECT_FALSE(swri_string_util::ToFloat("", value));
00837 EXPECT_FALSE(swri_string_util::ToFloat(" ", value));
00838 EXPECT_FALSE(swri_string_util::ToFloat("a", value));
00839 EXPECT_FALSE(swri_string_util::ToFloat("a0", value));
00840 EXPECT_FALSE(swri_string_util::ToFloat("0a", value));
00841 EXPECT_FALSE(swri_string_util::ToFloat("0 ", value));
00842 EXPECT_FALSE(swri_string_util::ToFloat("1e39", value));
00843 EXPECT_FALSE(swri_string_util::ToFloat("1e-38", value));
00844 }
00845
00846 TEST(StringUtilTests, ToInt32Base10)
00847 {
00848 int32_t value = 1;
00849 EXPECT_TRUE(swri_string_util::ToInt32("0", value));
00850 EXPECT_EQ(0, value);
00851
00852 EXPECT_TRUE(swri_string_util::ToInt32("00", value));
00853 EXPECT_EQ(0, value);
00854
00855 value = 1;
00856 EXPECT_TRUE(swri_string_util::ToInt32("-0", value));
00857 EXPECT_EQ(0, value);
00858
00859 value = 1;
00860 EXPECT_TRUE(swri_string_util::ToInt32("+0", value));
00861 EXPECT_EQ(0, value);
00862
00863 value = 0;
00864 EXPECT_TRUE(swri_string_util::ToInt32("1", value));
00865 EXPECT_EQ(1, value);
00866
00867 value = 0;
00868 EXPECT_TRUE(swri_string_util::ToInt32("+1", value));
00869 EXPECT_EQ(1, value);
00870
00871 value = 0;
00872 EXPECT_TRUE(swri_string_util::ToInt32("-1", value));
00873 EXPECT_EQ(-1, value);
00874
00875 value = 0;
00876 EXPECT_TRUE(swri_string_util::ToInt32("12345678", value));
00877 EXPECT_EQ(12345678, value);
00878
00879 value = 0;
00880 EXPECT_TRUE(swri_string_util::ToInt32("012345678", value));
00881 EXPECT_EQ(12345678, value);
00882
00883 value = 0;
00884 EXPECT_TRUE(swri_string_util::ToInt32("-123456789", value));
00885 EXPECT_EQ(-123456789, value);
00886
00887 value = 0;
00888 EXPECT_TRUE(swri_string_util::ToInt32("2147483647", value));
00889 EXPECT_EQ(2147483647, value);
00890 }
00891
00892 TEST(StringUtilTests, ToInt32Base10Invalid)
00893 {
00894 int32_t value = 0;
00895
00896 EXPECT_FALSE(swri_string_util::ToInt32("", value));
00897 EXPECT_FALSE(swri_string_util::ToInt32(" ", value));
00898 EXPECT_FALSE(swri_string_util::ToInt32("a", value));
00899 EXPECT_FALSE(swri_string_util::ToInt32("a0", value));
00900 EXPECT_FALSE(swri_string_util::ToInt32("0a", value));
00901 EXPECT_FALSE(swri_string_util::ToInt32("0 ", value));
00902 EXPECT_FALSE(swri_string_util::ToInt32("1e39", value));
00903 EXPECT_FALSE(swri_string_util::ToInt32("1e-38", value));
00904 EXPECT_FALSE(swri_string_util::ToInt32("1e1", value));
00905 EXPECT_FALSE(swri_string_util::ToInt32("1e0", value));
00906 EXPECT_FALSE(swri_string_util::ToInt32(".", value));
00907 EXPECT_FALSE(swri_string_util::ToInt32("0.0", value));
00908 EXPECT_FALSE(swri_string_util::ToInt32("0.", value));
00909 EXPECT_FALSE(swri_string_util::ToInt32("2147483648", value));
00910 }
00911
00912 TEST(StringUtilTests, ToInt32Base16)
00913 {
00914 int32_t value = 1;
00915 EXPECT_TRUE(swri_string_util::ToInt32("0", value, 16));
00916 EXPECT_EQ(0, value);
00917
00918 EXPECT_TRUE(swri_string_util::ToInt32("00", value, 16));
00919 EXPECT_EQ(0, value);
00920
00921 value = 1;
00922 EXPECT_TRUE(swri_string_util::ToInt32("-0", value, 16));
00923 EXPECT_EQ(0, value);
00924
00925 value = 1;
00926 EXPECT_TRUE(swri_string_util::ToInt32("+0", value, 16));
00927 EXPECT_EQ(0, value);
00928
00929 value = 0;
00930 EXPECT_TRUE(swri_string_util::ToInt32("1", value, 16));
00931 EXPECT_EQ(1, value);
00932
00933 value = 0;
00934 EXPECT_TRUE(swri_string_util::ToInt32("+1", value, 16));
00935 EXPECT_EQ(1, value);
00936
00937 value = 0;
00938 EXPECT_TRUE(swri_string_util::ToInt32("-1", value, 16));
00939 EXPECT_EQ(-1, value);
00940
00941 value = 0;
00942 EXPECT_TRUE(swri_string_util::ToInt32("12345678", value, 16));
00943 EXPECT_EQ(0x12345678, value);
00944
00945 value = 0;
00946 EXPECT_TRUE(swri_string_util::ToInt32("012345678", value, 16));
00947 EXPECT_EQ(0x12345678, value);
00948
00949 value = 0;
00950 EXPECT_TRUE(swri_string_util::ToInt32("-12345678", value, 16));
00951 EXPECT_EQ(-0x12345678, value);
00952
00953 value = 0;
00954 EXPECT_TRUE(swri_string_util::ToInt32("aff", value, 16));
00955 EXPECT_EQ(0xaff, value);
00956 }
00957
00958 TEST(StringUtilTests, ToInt32Base16Invalid)
00959 {
00960 int32_t value = 0;
00961
00962 EXPECT_FALSE(swri_string_util::ToInt32("", value, 16));
00963 EXPECT_FALSE(swri_string_util::ToInt32(" ", value, 16));
00964 EXPECT_FALSE(swri_string_util::ToInt32("g", value, 16));
00965 EXPECT_FALSE(swri_string_util::ToInt32("g0", value, 16));
00966 EXPECT_FALSE(swri_string_util::ToInt32("0g", value, 16));
00967 EXPECT_FALSE(swri_string_util::ToInt32("0 ", value, 16));
00968 EXPECT_FALSE(swri_string_util::ToInt32(".", value, 16));
00969 EXPECT_FALSE(swri_string_util::ToInt32("0.0", value, 16));
00970 EXPECT_FALSE(swri_string_util::ToInt32("0.", value, 16));
00971 }
00972
00973 TEST(StringUtilTests, ToUInt32Base10)
00974 {
00975 uint32_t value = 1;
00976 EXPECT_TRUE(swri_string_util::ToUInt32("0", value));
00977 EXPECT_EQ(0, value);
00978
00979 EXPECT_TRUE(swri_string_util::ToUInt32("00", value));
00980 EXPECT_EQ(0, value);
00981
00982 value = 1;
00983 EXPECT_TRUE(swri_string_util::ToUInt32("-0", value));
00984 EXPECT_EQ(0, value);
00985
00986 value = 1;
00987 EXPECT_TRUE(swri_string_util::ToUInt32("+0", value));
00988 EXPECT_EQ(0, value);
00989
00990 value = 0;
00991 EXPECT_TRUE(swri_string_util::ToUInt32("1", value));
00992 EXPECT_EQ(1, value);
00993
00994 value = 0;
00995 EXPECT_TRUE(swri_string_util::ToUInt32("+1", value));
00996 EXPECT_EQ(1, value);
00997
00998 value = 0;
00999 EXPECT_TRUE(swri_string_util::ToUInt32("12345678", value));
01000 EXPECT_EQ(12345678, value);
01001
01002 value = 0;
01003 EXPECT_TRUE(swri_string_util::ToUInt32("012345678", value));
01004 EXPECT_EQ(12345678, value);
01005
01006 value = 0;
01007 EXPECT_TRUE(swri_string_util::ToUInt32("4294967295", value));
01008 EXPECT_EQ(4294967295, value);
01009 }
01010
01011 TEST(StringUtilTests, ToUInt32Base10Invalid)
01012 {
01013 uint32_t value = 0;
01014
01015 EXPECT_FALSE(swri_string_util::ToUInt32("", value));
01016 EXPECT_FALSE(swri_string_util::ToUInt32(" ", value));
01017 EXPECT_FALSE(swri_string_util::ToUInt32("a", value));
01018 EXPECT_FALSE(swri_string_util::ToUInt32("a0", value));
01019 EXPECT_FALSE(swri_string_util::ToUInt32("0a", value));
01020 EXPECT_FALSE(swri_string_util::ToUInt32("0 ", value));
01021 EXPECT_FALSE(swri_string_util::ToUInt32("1e39", value));
01022 EXPECT_FALSE(swri_string_util::ToUInt32("1e-38", value));
01023 EXPECT_FALSE(swri_string_util::ToUInt32("1e1", value));
01024 EXPECT_FALSE(swri_string_util::ToUInt32("1e0", value));
01025 EXPECT_FALSE(swri_string_util::ToUInt32(".", value));
01026 EXPECT_FALSE(swri_string_util::ToUInt32("0.0", value));
01027 EXPECT_FALSE(swri_string_util::ToUInt32("0.", value));
01028 EXPECT_FALSE(swri_string_util::ToUInt32("4294967296", value));
01029 EXPECT_FALSE(swri_string_util::ToUInt32("-1", value));
01030 EXPECT_FALSE(swri_string_util::ToUInt32("-123456789", value));
01031 }
01032
01033
01034 int main(int argc, char **argv)
01035 {
01036 testing::InitGoogleTest(&argc, argv);
01037
01038 return RUN_ALL_TESTS();
01039 }