diff options
author | Jacek Antonelli | 2008-08-15 23:44:54 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:54 -0500 |
commit | b2afb8800bb033a04bb3ecdf0363068d56648ef1 (patch) | |
tree | 3568129b5bbddb47cd39d622b4137a8fbff4abaf /linden/indra/test/common.cpp | |
parent | Second Life viewer sources 1.14.0.1 (diff) | |
download | meta-impy-b2afb8800bb033a04bb3ecdf0363068d56648ef1.zip meta-impy-b2afb8800bb033a04bb3ecdf0363068d56648ef1.tar.gz meta-impy-b2afb8800bb033a04bb3ecdf0363068d56648ef1.tar.bz2 meta-impy-b2afb8800bb033a04bb3ecdf0363068d56648ef1.tar.xz |
Second Life viewer sources 1.15.0.2
Diffstat (limited to 'linden/indra/test/common.cpp')
-rw-r--r-- | linden/indra/test/common.cpp | 173 |
1 files changed, 173 insertions, 0 deletions
diff --git a/linden/indra/test/common.cpp b/linden/indra/test/common.cpp index 97ff21c..2a88ba0 100644 --- a/linden/indra/test/common.cpp +++ b/linden/indra/test/common.cpp | |||
@@ -6,6 +6,7 @@ | |||
6 | * | 6 | * |
7 | * Copyright (c) 2005-2007, Linden Research, Inc. | 7 | * Copyright (c) 2005-2007, Linden Research, Inc. |
8 | * | 8 | * |
9 | * Second Life Viewer Source Code | ||
9 | * The source code in this file ("Source Code") is provided by Linden Lab | 10 | * The source code in this file ("Source Code") is provided by Linden Lab |
10 | * to you under the terms of the GNU General Public License, version 2.0 | 11 | * to you under the terms of the GNU General Public License, version 2.0 |
11 | * ("GPL"), unless you have obtained a separate licensing agreement | 12 | * ("GPL"), unless you have obtained a separate licensing agreement |
@@ -43,6 +44,7 @@ | |||
43 | #include "llmemorystream.h" | 44 | #include "llmemorystream.h" |
44 | #include "llsd.h" | 45 | #include "llsd.h" |
45 | #include "llsdserialize.h" | 46 | #include "llsdserialize.h" |
47 | #include "u64.h" | ||
46 | 48 | ||
47 | namespace tut | 49 | namespace tut |
48 | { | 50 | { |
@@ -445,3 +447,174 @@ namespace tut | |||
445 | } | 447 | } |
446 | } | 448 | } |
447 | 449 | ||
450 | namespace tut | ||
451 | { | ||
452 | struct U64_data | ||
453 | { | ||
454 | }; | ||
455 | typedef test_group<U64_data> U64_test; | ||
456 | typedef U64_test::object U64_object; | ||
457 | tut::U64_test U64_testcase("U64_conversion"); | ||
458 | |||
459 | // U64_to_str | ||
460 | template<> template<> | ||
461 | void U64_object::test<1>() | ||
462 | { | ||
463 | U64 val; | ||
464 | std::string val_str; | ||
465 | char result[256]; | ||
466 | std::string result_str; | ||
467 | |||
468 | val = U64L(18446744073709551610); // slightly less than MAX_U64 | ||
469 | val_str = "18446744073709551610"; | ||
470 | |||
471 | U64_to_str(val, result, sizeof(result)); | ||
472 | result_str = (const char*) result; | ||
473 | ensure_equals("U64_to_str converted 1.1", val_str, result_str); | ||
474 | |||
475 | val = 0; | ||
476 | val_str = "0"; | ||
477 | U64_to_str(val, result, sizeof(result)); | ||
478 | result_str = (const char*) result; | ||
479 | ensure_equals("U64_to_str converted 1.2", val_str, result_str); | ||
480 | |||
481 | val = U64L(18446744073709551615); // 0xFFFFFFFFFFFFFFFF | ||
482 | val_str = "18446744073709551615"; | ||
483 | U64_to_str(val, result, sizeof(result)); | ||
484 | result_str = (const char*) result; | ||
485 | ensure_equals("U64_to_str converted 1.3", val_str, result_str); | ||
486 | |||
487 | // overflow - will result in warning at compile time | ||
488 | val = U64L(18446744073709551615) + 1; // overflow 0xFFFFFFFFFFFFFFFF + 1 == 0 | ||
489 | val_str = "0"; | ||
490 | U64_to_str(val, result, sizeof(result)); | ||
491 | result_str = (const char*) result; | ||
492 | ensure_equals("U64_to_str converted 1.4", val_str, result_str); | ||
493 | |||
494 | val = U64L(-1); // 0xFFFFFFFFFFFFFFFF == 18446744073709551615 | ||
495 | val_str = "18446744073709551615"; | ||
496 | U64_to_str(val, result, sizeof(result)); | ||
497 | result_str = (const char*) result; | ||
498 | ensure_equals("U64_to_str converted 1.5", val_str, result_str); | ||
499 | |||
500 | val = U64L(10000000000000000000); // testing preserving of 0s | ||
501 | val_str = "10000000000000000000"; | ||
502 | U64_to_str(val, result, sizeof(result)); | ||
503 | result_str = (const char*) result; | ||
504 | ensure_equals("U64_to_str converted 1.6", val_str, result_str); | ||
505 | |||
506 | val = 1; // testing no leading 0s | ||
507 | val_str = "1"; | ||
508 | U64_to_str(val, result, sizeof(result)); | ||
509 | result_str = (const char*) result; | ||
510 | ensure_equals("U64_to_str converted 1.7", val_str, result_str); | ||
511 | |||
512 | val = U64L(18446744073709551615); // testing exact sized buffer for result | ||
513 | val_str = "18446744073709551615"; | ||
514 | memset(result, 'A', sizeof(result)); // initialize buffer with all 'A' | ||
515 | U64_to_str(val, result, sizeof("18446744073709551615")); //pass in the exact size | ||
516 | result_str = (const char*) result; | ||
517 | ensure_equals("U64_to_str converted 1.8", val_str, result_str); | ||
518 | |||
519 | val = U64L(18446744073709551615); // testing smaller sized buffer for result | ||
520 | val_str = "1844"; | ||
521 | memset(result, 'A', sizeof(result)); // initialize buffer with all 'A' | ||
522 | U64_to_str(val, result, 5); //pass in a size of 5. should only copy first 4 integers and add a null terminator | ||
523 | result_str = (const char*) result; | ||
524 | ensure_equals("U64_to_str converted 1.9", val_str, result_str); | ||
525 | } | ||
526 | |||
527 | // str_to_U64 | ||
528 | template<> template<> | ||
529 | void U64_object::test<2>() | ||
530 | { | ||
531 | U64 val; | ||
532 | U64 result; | ||
533 | |||
534 | val = U64L(18446744073709551610); // slightly less than MAX_U64 | ||
535 | result = str_to_U64("18446744073709551610"); | ||
536 | ensure_equals("str_to_U64 converted 2.1", val, result); | ||
537 | |||
538 | val = U64L(0); // empty string | ||
539 | result = str_to_U64(""); | ||
540 | ensure_equals("str_to_U64 converted 2.2", val, result); | ||
541 | |||
542 | val = U64L(0); // 0 | ||
543 | result = str_to_U64("0"); | ||
544 | ensure_equals("str_to_U64 converted 2.3", val, result); | ||
545 | |||
546 | val = U64L(18446744073709551615); // 0xFFFFFFFFFFFFFFFF | ||
547 | result = str_to_U64("18446744073709551615"); | ||
548 | ensure_equals("str_to_U64 converted 2.4", val, result); | ||
549 | |||
550 | // overflow - will result in warning at compile time | ||
551 | val = U64L(18446744073709551615) + 1; // overflow 0xFFFFFFFFFFFFFFFF + 1 == 0 | ||
552 | result = str_to_U64("18446744073709551616"); | ||
553 | ensure_equals("str_to_U64 converted 2.5", val, result); | ||
554 | |||
555 | val = U64L(1234); // process till first non-integral character | ||
556 | result = str_to_U64("1234A5678"); | ||
557 | ensure_equals("str_to_U64 converted 2.6", val, result); | ||
558 | |||
559 | val = U64L(5678); // skip all non-integral characters | ||
560 | result = str_to_U64("ABCD5678"); | ||
561 | ensure_equals("str_to_U64 converted 2.7", val, result); | ||
562 | |||
563 | // should it skip negative sign and process | ||
564 | // rest of string or return 0 | ||
565 | val = U64L(1234); // skip initial negative sign | ||
566 | result = str_to_U64("-1234"); | ||
567 | ensure_equals("str_to_U64 converted 2.8", val, result); | ||
568 | |||
569 | val = U64L(5678); // stop at negative sign in the middle | ||
570 | result = str_to_U64("5678-1234"); | ||
571 | ensure_equals("str_to_U64 converted 2.9", val, result); | ||
572 | |||
573 | val = U64L(0); // no integers | ||
574 | result = str_to_U64("AaCD"); | ||
575 | ensure_equals("str_to_U64 converted 2.10", val, result); | ||
576 | } | ||
577 | |||
578 | // U64_to_F64 | ||
579 | template<> template<> | ||
580 | void U64_object::test<3>() | ||
581 | { | ||
582 | F64 val; | ||
583 | F64 result; | ||
584 | |||
585 | result = 18446744073709551610.0; | ||
586 | val = U64_to_F64(U64L(18446744073709551610)); | ||
587 | ensure_equals("U64_to_F64 converted 3.1", val, result); | ||
588 | |||
589 | result = 18446744073709551615.0; // 0xFFFFFFFFFFFFFFFF | ||
590 | val = U64_to_F64(U64L(18446744073709551615)); | ||
591 | ensure_equals("U64_to_F64 converted 3.2", val, result); | ||
592 | |||
593 | result = 0.0; // overflow 0xFFFFFFFFFFFFFFFF + 1 == 0 | ||
594 | // overflow - will result in warning at compile time | ||
595 | val = U64_to_F64(U64L(18446744073709551615)+1); | ||
596 | ensure_equals("U64_to_F64 converted 3.3", val, result); | ||
597 | |||
598 | result = 0.0; // 0 | ||
599 | val = U64_to_F64(U64L(0)); | ||
600 | ensure_equals("U64_to_F64 converted 3.4", val, result); | ||
601 | |||
602 | result = 1.0; // odd | ||
603 | val = U64_to_F64(U64L(1)); | ||
604 | ensure_equals("U64_to_F64 converted 3.5", val, result); | ||
605 | |||
606 | result = 2.0; // even | ||
607 | val = U64_to_F64(U64L(2)); | ||
608 | ensure_equals("U64_to_F64 converted 3.6", val, result); | ||
609 | |||
610 | result = U64L(0x7FFFFFFFFFFFFFFF) * 1.0L; // 0x7FFFFFFFFFFFFFFF | ||
611 | val = U64_to_F64(U64L(0x7FFFFFFFFFFFFFFF)); | ||
612 | ensure_equals("U64_to_F64 converted 3.7", val, result); | ||
613 | } | ||
614 | |||
615 | // llstrtou64 | ||
616 | // seems to be deprecated - could not find it being used | ||
617 | // anywhere in the tarball - skipping unit tests for now | ||
618 | } | ||
619 | |||
620 | |||