@@ -322,16 +322,81 @@ BOOST_AUTO_TEST_CASE(test_ParseInt32)
322
322
BOOST_CHECK (ParseInt32 (" -2147483648" , &n) && n == -2147483648 );
323
323
BOOST_CHECK (ParseInt32 (" -1234" , &n) && n == -1234 );
324
324
// Invalid values
325
+ BOOST_CHECK (!ParseInt32 (" " , &n));
326
+ BOOST_CHECK (!ParseInt32 (" 1" , &n)); // no padding inside
327
+ BOOST_CHECK (!ParseInt32 (" 1 " , &n));
325
328
BOOST_CHECK (!ParseInt32 (" 1a" , &n));
326
329
BOOST_CHECK (!ParseInt32 (" aap" , &n));
327
330
BOOST_CHECK (!ParseInt32 (" 0x1" , &n)); // no hex
331
+ BOOST_CHECK (!ParseInt32 (" 0x1" , &n)); // no hex
332
+ const char test_bytes[] = {' 1' , 0 , ' 1' };
333
+ std::string teststr (test_bytes, sizeof (test_bytes));
334
+ BOOST_CHECK (!ParseInt32 (teststr, &n)); // no embedded NULs
328
335
// Overflow and underflow
329
336
BOOST_CHECK (!ParseInt32 (" -2147483649" , NULL ));
330
337
BOOST_CHECK (!ParseInt32 (" 2147483648" , NULL ));
331
338
BOOST_CHECK (!ParseInt32 (" -32482348723847471234" , NULL ));
332
339
BOOST_CHECK (!ParseInt32 (" 32482348723847471234" , NULL ));
333
340
}
334
341
342
+ BOOST_AUTO_TEST_CASE (test_ParseInt64)
343
+ {
344
+ int64_t n;
345
+ // Valid values
346
+ BOOST_CHECK (ParseInt64 (" 1234" , NULL ));
347
+ BOOST_CHECK (ParseInt64 (" 0" , &n) && n == 0LL );
348
+ BOOST_CHECK (ParseInt64 (" 1234" , &n) && n == 1234LL );
349
+ BOOST_CHECK (ParseInt64 (" 01234" , &n) && n == 1234LL ); // no octal
350
+ BOOST_CHECK (ParseInt64 (" 2147483647" , &n) && n == 2147483647LL );
351
+ BOOST_CHECK (ParseInt64 (" -2147483648" , &n) && n == -2147483648LL );
352
+ BOOST_CHECK (ParseInt64 (" 9223372036854775807" , &n) && n == 9223372036854775807LL );
353
+ BOOST_CHECK (ParseInt64 (" -9223372036854775808" , &n) && n == 9223372036854775808LL );
354
+ BOOST_CHECK (ParseInt64 (" -1234" , &n) && n == -1234LL );
355
+ // Invalid values
356
+ BOOST_CHECK (!ParseInt64 (" " , &n));
357
+ BOOST_CHECK (!ParseInt64 (" 1" , &n)); // no padding inside
358
+ BOOST_CHECK (!ParseInt64 (" 1 " , &n));
359
+ BOOST_CHECK (!ParseInt64 (" 1a" , &n));
360
+ BOOST_CHECK (!ParseInt64 (" aap" , &n));
361
+ BOOST_CHECK (!ParseInt64 (" 0x1" , &n)); // no hex
362
+ const char test_bytes[] = {' 1' , 0 , ' 1' };
363
+ std::string teststr (test_bytes, sizeof (test_bytes));
364
+ BOOST_CHECK (!ParseInt64 (teststr, &n)); // no embedded NULs
365
+ // Overflow and underflow
366
+ BOOST_CHECK (!ParseInt64 (" -9223372036854775809" , NULL ));
367
+ BOOST_CHECK (!ParseInt64 (" 9223372036854775808" , NULL ));
368
+ BOOST_CHECK (!ParseInt64 (" -32482348723847471234" , NULL ));
369
+ BOOST_CHECK (!ParseInt64 (" 32482348723847471234" , NULL ));
370
+ }
371
+
372
+ BOOST_AUTO_TEST_CASE (test_ParseDouble)
373
+ {
374
+ double n;
375
+ // Valid values
376
+ BOOST_CHECK (ParseDouble (" 1234" , NULL ));
377
+ BOOST_CHECK (ParseDouble (" 0" , &n) && n == 0.0 );
378
+ BOOST_CHECK (ParseDouble (" 1234" , &n) && n == 1234.0 );
379
+ BOOST_CHECK (ParseDouble (" 01234" , &n) && n == 1234.0 ); // no octal
380
+ BOOST_CHECK (ParseDouble (" 2147483647" , &n) && n == 2147483647.0 );
381
+ BOOST_CHECK (ParseDouble (" -2147483648" , &n) && n == -2147483648.0 );
382
+ BOOST_CHECK (ParseDouble (" -1234" , &n) && n == -1234.0 );
383
+ BOOST_CHECK (ParseDouble (" 1e6" , &n) && n == 1e6 );
384
+ BOOST_CHECK (ParseDouble (" -1e6" , &n) && n == -1e6 );
385
+ // Invalid values
386
+ BOOST_CHECK (!ParseDouble (" " , &n));
387
+ BOOST_CHECK (!ParseDouble (" 1" , &n)); // no padding inside
388
+ BOOST_CHECK (!ParseDouble (" 1 " , &n));
389
+ BOOST_CHECK (!ParseDouble (" 1a" , &n));
390
+ BOOST_CHECK (!ParseDouble (" aap" , &n));
391
+ BOOST_CHECK (!ParseDouble (" 0x1" , &n)); // no hex
392
+ const char test_bytes[] = {' 1' , 0 , ' 1' };
393
+ std::string teststr (test_bytes, sizeof (test_bytes));
394
+ BOOST_CHECK (!ParseDouble (teststr, &n)); // no embedded NULs
395
+ // Overflow and underflow
396
+ BOOST_CHECK (!ParseDouble (" -1e10000" , NULL ));
397
+ BOOST_CHECK (!ParseDouble (" 1e10000" , NULL ));
398
+ }
399
+
335
400
BOOST_AUTO_TEST_CASE (test_FormatParagraph)
336
401
{
337
402
BOOST_CHECK_EQUAL (FormatParagraph (" " , 79 , 0 ), " " );
0 commit comments