diff options
author | Jacek Antonelli | 2008-08-15 23:45:34 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:45:34 -0500 |
commit | cd17687f01420952712a500107e0f93e7ab8d5f8 (patch) | |
tree | ce48c2b706f2c1176290e39fb555fbdf6648ce01 /linden/indra/test/llsdserialize_tut.cpp | |
parent | Second Life viewer sources 1.19.0.5 (diff) | |
download | meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.zip meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.gz meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.bz2 meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.xz |
Second Life viewer sources 1.19.1.0
Diffstat (limited to '')
-rw-r--r-- | linden/indra/test/llsdserialize_tut.cpp | 927 |
1 files changed, 885 insertions, 42 deletions
diff --git a/linden/indra/test/llsdserialize_tut.cpp b/linden/indra/test/llsdserialize_tut.cpp index 0246b16..fe732cd 100644 --- a/linden/indra/test/llsdserialize_tut.cpp +++ b/linden/indra/test/llsdserialize_tut.cpp | |||
@@ -1,6 +1,6 @@ | |||
1 | /** | 1 | /** |
2 | * @file llsdserialize_tut.cpp | 2 | * @file llsdserialize_tut.cpp |
3 | * @date April 2006 | 3 | * @date 2006-04 |
4 | * @brief LLSDSerialize unit tests | 4 | * @brief LLSDSerialize unit tests |
5 | * | 5 | * |
6 | * $LicenseInfo:firstyear=2006&license=viewergpl$ | 6 | * $LicenseInfo:firstyear=2006&license=viewergpl$ |
@@ -32,6 +32,10 @@ | |||
32 | 32 | ||
33 | #include <tut/tut.h> | 33 | #include <tut/tut.h> |
34 | 34 | ||
35 | #if !LL_WINDOWS | ||
36 | #include <netinet/in.h> | ||
37 | #endif | ||
38 | |||
35 | #include "linden_common.h" | 39 | #include "linden_common.h" |
36 | #include "llsd.h" | 40 | #include "llsd.h" |
37 | #include "llsdserialize.h" | 41 | #include "llsdserialize.h" |
@@ -39,6 +43,7 @@ | |||
39 | #include "llformat.h" | 43 | #include "llformat.h" |
40 | 44 | ||
41 | // These tests take too long to run on Windows. JC | 45 | // These tests take too long to run on Windows. JC |
46 | // Yeah, who cares if windows works or not, right? Phoenix | ||
42 | #if !LL_WINDOWS | 47 | #if !LL_WINDOWS |
43 | 48 | ||
44 | namespace tut | 49 | namespace tut |
@@ -220,7 +225,7 @@ namespace tut | |||
220 | mFormatter->format(v, stream); | 225 | mFormatter->format(v, stream); |
221 | //llinfos << "checkRoundTrip: length " << stream.str().length() << llendl; | 226 | //llinfos << "checkRoundTrip: length " << stream.str().length() << llendl; |
222 | LLSD w; | 227 | LLSD w; |
223 | mParser->parse(stream, w); | 228 | mParser->parse(stream, w, stream.str().size()); |
224 | 229 | ||
225 | try | 230 | try |
226 | { | 231 | { |
@@ -446,34 +451,55 @@ namespace tut | |||
446 | doRoundTripTests("binary serialization"); | 451 | doRoundTripTests("binary serialization"); |
447 | } | 452 | } |
448 | 453 | ||
449 | 454 | ||
450 | 455 | /** | |
451 | 456 | * @class TestLLSDParsing | |
452 | class TestLLSDXMLParsing | 457 | * @brief Base class for of a parse tester. |
458 | */ | ||
459 | template <class parser_t> | ||
460 | class TestLLSDParsing | ||
453 | { | 461 | { |
454 | public: | 462 | public: |
455 | TestLLSDXMLParsing() | 463 | TestLLSDParsing() |
456 | { | 464 | { |
457 | mParser = new LLSDXMLParser; | 465 | mParser = new parser_t; |
458 | } | 466 | } |
459 | void ensureParse(const std::string& msg, const char* xml, const LLSD& expected); | 467 | |
460 | 468 | void ensureParse( | |
461 | LLPointer<LLSDXMLParser> mParser; | 469 | const std::string& msg, |
470 | const std::string& in, | ||
471 | const LLSD& expected_value, | ||
472 | S32 expected_count) | ||
473 | { | ||
474 | std::stringstream input; | ||
475 | input.str(in); | ||
476 | |||
477 | LLSD parsed_result; | ||
478 | S32 parsed_count = mParser->parse(input, parsed_result, in.size()); | ||
479 | ensure_equals(msg, parsed_result, expected_value); | ||
480 | |||
481 | // This count check is really only useful for expected | ||
482 | // parse failures, since the ensures equal will already | ||
483 | // require eqality. | ||
484 | std::string count_msg(msg); | ||
485 | count_msg += " (count)"; | ||
486 | ensure_equals(count_msg, parsed_count, expected_count); | ||
487 | } | ||
488 | |||
489 | LLPointer<parser_t> mParser; | ||
462 | }; | 490 | }; |
463 | 491 | ||
464 | void TestLLSDXMLParsing::ensureParse( | 492 | |
465 | const std::string& msg, const char* xmlstring, const LLSD& expected) | 493 | /** |
494 | * @class TestLLSDXMLParsing | ||
495 | * @brief Concrete instance of a parse tester. | ||
496 | */ | ||
497 | class TestLLSDXMLParsing : public TestLLSDParsing<LLSDXMLParser> | ||
466 | { | 498 | { |
467 | std::stringstream input; | 499 | public: |
468 | input.str(xmlstring); | 500 | TestLLSDXMLParsing() {} |
469 | 501 | }; | |
470 | LLSD parsedResult; | ||
471 | mParser->parse(input, parsedResult); | ||
472 | |||
473 | ensure_equals(msg, parsedResult, expected); | ||
474 | } | ||
475 | 502 | ||
476 | |||
477 | typedef tut::test_group<TestLLSDXMLParsing> TestLLSDXMLParsingGroup; | 503 | typedef tut::test_group<TestLLSDXMLParsing> TestLLSDXMLParsingGroup; |
478 | typedef TestLLSDXMLParsingGroup::object TestLLSDXMLParsingObject; | 504 | typedef TestLLSDXMLParsingGroup::object TestLLSDXMLParsingObject; |
479 | TestLLSDXMLParsingGroup gTestLLSDXMLParsingGroup("llsd XML parsing"); | 505 | TestLLSDXMLParsingGroup gTestLLSDXMLParsingGroup("llsd XML parsing"); |
@@ -481,12 +507,28 @@ namespace tut | |||
481 | template<> template<> | 507 | template<> template<> |
482 | void TestLLSDXMLParsingObject::test<1>() | 508 | void TestLLSDXMLParsingObject::test<1>() |
483 | { | 509 | { |
484 | // test handling of xml not recognized as llsd results in an LLSD Undefined" | 510 | // test handling of xml not recognized as llsd results in an |
485 | 511 | // LLSD Undefined | |
486 | ensureParse("malformed xml", "<llsd><string>ha ha</string>", LLSD()); | 512 | ensureParse( |
487 | ensureParse("not llsd", "<html><body><p>ha ha</p></body></html>", LLSD()); | 513 | "malformed xml", |
488 | ensureParse("value without llsd", "<string>ha ha</string>", LLSD()); | 514 | "<llsd><string>ha ha</string>", |
489 | ensureParse("key without llsd", "<key>ha ha</key>", LLSD()); | 515 | LLSD(), |
516 | LLSDParser::PARSE_FAILURE); | ||
517 | ensureParse( | ||
518 | "not llsd", | ||
519 | "<html><body><p>ha ha</p></body></html>", | ||
520 | LLSD(), | ||
521 | LLSDParser::PARSE_FAILURE); | ||
522 | ensureParse( | ||
523 | "value without llsd", | ||
524 | "<string>ha ha</string>", | ||
525 | LLSD(), | ||
526 | LLSDParser::PARSE_FAILURE); | ||
527 | ensureParse( | ||
528 | "key without llsd", | ||
529 | "<key>ha ha</key>", | ||
530 | LLSD(), | ||
531 | LLSDParser::PARSE_FAILURE); | ||
490 | } | 532 | } |
491 | 533 | ||
492 | 534 | ||
@@ -494,18 +536,20 @@ namespace tut | |||
494 | void TestLLSDXMLParsingObject::test<2>() | 536 | void TestLLSDXMLParsingObject::test<2>() |
495 | { | 537 | { |
496 | // test handling of unrecognized or unparseable llsd values | 538 | // test handling of unrecognized or unparseable llsd values |
497 | |||
498 | LLSD v; | 539 | LLSD v; |
499 | v["amy"] = 23; | 540 | v["amy"] = 23; |
500 | v["bob"] = LLSD(); | 541 | v["bob"] = LLSD(); |
501 | v["cam"] = 1.23; | 542 | v["cam"] = 1.23; |
502 | 543 | ||
503 | ensureParse("unknown data type", | 544 | ensureParse( |
545 | "unknown data type", | ||
504 | "<llsd><map>" | 546 | "<llsd><map>" |
505 | "<key>amy</key><integer>23</integer>" | 547 | "<key>amy</key><integer>23</integer>" |
506 | "<key>bob</key><bigint>99999999999999999</bigint>" | 548 | "<key>bob</key><bigint>99999999999999999</bigint>" |
507 | "<key>cam</key><real>1.23</real>" | 549 | "<key>cam</key><real>1.23</real>" |
508 | "</map></llsd>", v); | 550 | "</map></llsd>", |
551 | v, | ||
552 | v.size() + 1); | ||
509 | } | 553 | } |
510 | 554 | ||
511 | template<> template<> | 555 | template<> template<> |
@@ -517,28 +561,35 @@ namespace tut | |||
517 | v["amy"] = 23; | 561 | v["amy"] = 23; |
518 | v["cam"] = 1.23; | 562 | v["cam"] = 1.23; |
519 | 563 | ||
520 | ensureParse("map with html", | 564 | ensureParse( |
565 | "map with html", | ||
521 | "<llsd><map>" | 566 | "<llsd><map>" |
522 | "<key>amy</key><integer>23</integer>" | 567 | "<key>amy</key><integer>23</integer>" |
523 | "<html><body>ha ha</body></html>" | 568 | "<html><body>ha ha</body></html>" |
524 | "<key>cam</key><real>1.23</real>" | 569 | "<key>cam</key><real>1.23</real>" |
525 | "</map></llsd>", v); | 570 | "</map></llsd>", |
571 | v, | ||
572 | v.size() + 1); | ||
526 | 573 | ||
527 | v.clear(); | 574 | v.clear(); |
528 | v["amy"] = 23; | 575 | v["amy"] = 23; |
529 | v["cam"] = 1.23; | 576 | v["cam"] = 1.23; |
530 | ensureParse("map with value for key", | 577 | ensureParse( |
578 | "map with value for key", | ||
531 | "<llsd><map>" | 579 | "<llsd><map>" |
532 | "<key>amy</key><integer>23</integer>" | 580 | "<key>amy</key><integer>23</integer>" |
533 | "<string>ha ha</string>" | 581 | "<string>ha ha</string>" |
534 | "<key>cam</key><real>1.23</real>" | 582 | "<key>cam</key><real>1.23</real>" |
535 | "</map></llsd>", v); | 583 | "</map></llsd>", |
584 | v, | ||
585 | v.size() + 1); | ||
536 | 586 | ||
537 | v.clear(); | 587 | v.clear(); |
538 | v["amy"] = 23; | 588 | v["amy"] = 23; |
539 | v["bob"] = LLSD::emptyMap(); | 589 | v["bob"] = LLSD::emptyMap(); |
540 | v["cam"] = 1.23; | 590 | v["cam"] = 1.23; |
541 | ensureParse("map with map of html", | 591 | ensureParse( |
592 | "map with map of html", | ||
542 | "<llsd><map>" | 593 | "<llsd><map>" |
543 | "<key>amy</key><integer>23</integer>" | 594 | "<key>amy</key><integer>23</integer>" |
544 | "<key>bob</key>" | 595 | "<key>bob</key>" |
@@ -546,32 +597,40 @@ namespace tut | |||
546 | "<html><body>ha ha</body></html>" | 597 | "<html><body>ha ha</body></html>" |
547 | "</map>" | 598 | "</map>" |
548 | "<key>cam</key><real>1.23</real>" | 599 | "<key>cam</key><real>1.23</real>" |
549 | "</map></llsd>", v); | 600 | "</map></llsd>", |
601 | v, | ||
602 | v.size() + 1); | ||
550 | 603 | ||
551 | v.clear(); | 604 | v.clear(); |
552 | v[0] = 23; | 605 | v[0] = 23; |
553 | v[1] = LLSD(); | 606 | v[1] = LLSD(); |
554 | v[2] = 1.23; | 607 | v[2] = 1.23; |
555 | 608 | ||
556 | ensureParse("array value of html", | 609 | ensureParse( |
610 | "array value of html", | ||
557 | "<llsd><array>" | 611 | "<llsd><array>" |
558 | "<integer>23</integer>" | 612 | "<integer>23</integer>" |
559 | "<html><body>ha ha</body></html>" | 613 | "<html><body>ha ha</body></html>" |
560 | "<real>1.23</real>" | 614 | "<real>1.23</real>" |
561 | "</array></llsd>", v); | 615 | "</array></llsd>", |
616 | v, | ||
617 | v.size() + 1); | ||
562 | 618 | ||
563 | v.clear(); | 619 | v.clear(); |
564 | v[0] = 23; | 620 | v[0] = 23; |
565 | v[1] = LLSD::emptyMap(); | 621 | v[1] = LLSD::emptyMap(); |
566 | v[2] = 1.23; | 622 | v[2] = 1.23; |
567 | ensureParse("array with map of html", | 623 | ensureParse( |
624 | "array with map of html", | ||
568 | "<llsd><array>" | 625 | "<llsd><array>" |
569 | "<integer>23</integer>" | 626 | "<integer>23</integer>" |
570 | "<map>" | 627 | "<map>" |
571 | "<html><body>ha ha</body></html>" | 628 | "<html><body>ha ha</body></html>" |
572 | "</map>" | 629 | "</map>" |
573 | "<real>1.23</real>" | 630 | "<real>1.23</real>" |
574 | "</array></llsd>", v); | 631 | "</array></llsd>", |
632 | v, | ||
633 | v.size() + 1); | ||
575 | } | 634 | } |
576 | 635 | ||
577 | /* | 636 | /* |
@@ -581,6 +640,790 @@ namespace tut | |||
581 | nested LLSD tags | 640 | nested LLSD tags |
582 | multiple values inside an LLSD | 641 | multiple values inside an LLSD |
583 | */ | 642 | */ |
643 | |||
644 | |||
645 | /** | ||
646 | * @class TestLLSDNotationParsing | ||
647 | * @brief Concrete instance of a parse tester. | ||
648 | */ | ||
649 | class TestLLSDNotationParsing : public TestLLSDParsing<LLSDNotationParser> | ||
650 | { | ||
651 | public: | ||
652 | TestLLSDNotationParsing() {} | ||
653 | }; | ||
654 | |||
655 | typedef tut::test_group<TestLLSDNotationParsing> TestLLSDNotationParsingGroup; | ||
656 | typedef TestLLSDNotationParsingGroup::object TestLLSDNotationParsingObject; | ||
657 | TestLLSDNotationParsingGroup gTestLLSDNotationParsingGroup( | ||
658 | "llsd notation parsing"); | ||
659 | |||
660 | template<> template<> | ||
661 | void TestLLSDNotationParsingObject::test<1>() | ||
662 | { | ||
663 | // test handling of xml not recognized as llsd results in an | ||
664 | // LLSD Undefined | ||
665 | ensureParse( | ||
666 | "malformed notation map", | ||
667 | "{'ha ha'", | ||
668 | LLSD(), | ||
669 | LLSDParser::PARSE_FAILURE); | ||
670 | ensureParse( | ||
671 | "malformed notation array", | ||
672 | "['ha ha'", | ||
673 | LLSD(), | ||
674 | LLSDParser::PARSE_FAILURE); | ||
675 | ensureParse( | ||
676 | "malformed notation string", | ||
677 | "'ha ha", | ||
678 | LLSD(), | ||
679 | LLSDParser::PARSE_FAILURE); | ||
680 | ensureParse( | ||
681 | "bad notation noise", | ||
682 | "g48ejlnfr", | ||
683 | LLSD(), | ||
684 | LLSDParser::PARSE_FAILURE); | ||
685 | } | ||
686 | |||
687 | template<> template<> | ||
688 | void TestLLSDNotationParsingObject::test<2>() | ||
689 | { | ||
690 | ensureParse("valid undef", "!", LLSD(), 1); | ||
691 | } | ||
692 | |||
693 | template<> template<> | ||
694 | void TestLLSDNotationParsingObject::test<3>() | ||
695 | { | ||
696 | LLSD val = false; | ||
697 | ensureParse("valid boolean false 0", "false", val, 1); | ||
698 | ensureParse("valid boolean false 1", "f", val, 1); | ||
699 | ensureParse("valid boolean false 2", "0", val, 1); | ||
700 | ensureParse("valid boolean false 3", "F", val, 1); | ||
701 | ensureParse("valid boolean false 4", "FALSE", val, 1); | ||
702 | val = true; | ||
703 | ensureParse("valid boolean true 0", "true", val, 1); | ||
704 | ensureParse("valid boolean true 1", "t", val, 1); | ||
705 | ensureParse("valid boolean true 2", "1", val, 1); | ||
706 | ensureParse("valid boolean true 3", "T", val, 1); | ||
707 | ensureParse("valid boolean true 4", "TRUE", val, 1); | ||
708 | |||
709 | val.clear(); | ||
710 | ensureParse("invalid true", "TR", val, LLSDParser::PARSE_FAILURE); | ||
711 | ensureParse("invalid false", "FAL", val, LLSDParser::PARSE_FAILURE); | ||
712 | } | ||
713 | |||
714 | template<> template<> | ||
715 | void TestLLSDNotationParsingObject::test<4>() | ||
716 | { | ||
717 | LLSD val = 123; | ||
718 | ensureParse("valid integer", "i123", val, 1); | ||
719 | val.clear(); | ||
720 | ensureParse("invalid integer", "421", val, LLSDParser::PARSE_FAILURE); | ||
721 | } | ||
722 | |||
723 | template<> template<> | ||
724 | void TestLLSDNotationParsingObject::test<5>() | ||
725 | { | ||
726 | LLSD val = 456.7; | ||
727 | ensureParse("valid real", "r456.7", val, 1); | ||
728 | val.clear(); | ||
729 | ensureParse("invalid real", "456.7", val, LLSDParser::PARSE_FAILURE); | ||
730 | } | ||
731 | |||
732 | template<> template<> | ||
733 | void TestLLSDNotationParsingObject::test<6>() | ||
734 | { | ||
735 | LLUUID id; | ||
736 | LLSD val = id; | ||
737 | ensureParse( | ||
738 | "unparseable uuid", | ||
739 | "u123", | ||
740 | LLSD(), | ||
741 | LLSDParser::PARSE_FAILURE); | ||
742 | id.generate(); | ||
743 | val = id; | ||
744 | std::string uuid_str("u"); | ||
745 | uuid_str += id.asString(); | ||
746 | ensureParse("valid uuid", uuid_str.c_str(), val, 1); | ||
747 | } | ||
748 | |||
749 | template<> template<> | ||
750 | void TestLLSDNotationParsingObject::test<7>() | ||
751 | { | ||
752 | LLSD val = std::string("foolish"); | ||
753 | ensureParse("valid string 1", "\"foolish\"", val, 1); | ||
754 | val = std::string("g'day"); | ||
755 | ensureParse("valid string 2", "\"g'day\"", val, 1); | ||
756 | val = std::string("have a \"nice\" day"); | ||
757 | ensureParse("valid string 3", "'have a \"nice\" day'", val, 1); | ||
758 | val = std::string("whatever"); | ||
759 | ensureParse("valid string 4", "s(8)\"whatever\"", val, 1); | ||
760 | } | ||
761 | |||
762 | template<> template<> | ||
763 | void TestLLSDNotationParsingObject::test<8>() | ||
764 | { | ||
765 | ensureParse( | ||
766 | "invalid string 1", | ||
767 | "s(7)\"whatever\"", | ||
768 | LLSD(), | ||
769 | LLSDParser::PARSE_FAILURE); | ||
770 | ensureParse( | ||
771 | "invalid string 2", | ||
772 | "s(9)\"whatever\"", | ||
773 | LLSD(), | ||
774 | LLSDParser::PARSE_FAILURE); | ||
775 | } | ||
776 | |||
777 | template<> template<> | ||
778 | void TestLLSDNotationParsingObject::test<9>() | ||
779 | { | ||
780 | LLSD val = LLURI("http://www.google.com"); | ||
781 | ensureParse("valid uri", "l\"http://www.google.com\"", val, 1); | ||
782 | } | ||
783 | |||
784 | template<> template<> | ||
785 | void TestLLSDNotationParsingObject::test<10>() | ||
786 | { | ||
787 | LLSD val = LLDate("2007-12-28T09:22:53.10Z"); | ||
788 | ensureParse("valid date", "d\"2007-12-28T09:22:53.10Z\"", val, 1); | ||
789 | } | ||
790 | |||
791 | template<> template<> | ||
792 | void TestLLSDNotationParsingObject::test<11>() | ||
793 | { | ||
794 | std::vector<U8> vec; | ||
795 | vec.push_back((U8)'a'); vec.push_back((U8)'b'); vec.push_back((U8)'c'); | ||
796 | vec.push_back((U8)'3'); vec.push_back((U8)'2'); vec.push_back((U8)'1'); | ||
797 | LLSD val = vec; | ||
798 | ensureParse("valid binary b64", "b64\"YWJjMzIx\"", val, 1); | ||
799 | ensureParse("valid bainry b16", "b16\"616263333231\"", val, 1); | ||
800 | ensureParse("valid bainry raw", "b(6)\"abc321\"", val, 1); | ||
801 | } | ||
802 | |||
803 | template<> template<> | ||
804 | void TestLLSDNotationParsingObject::test<12>() | ||
805 | { | ||
806 | ensureParse( | ||
807 | "invalid -- binary length specified too long", | ||
808 | "b(7)\"abc321\"", | ||
809 | LLSD(), | ||
810 | LLSDParser::PARSE_FAILURE); | ||
811 | ensureParse( | ||
812 | "invalid -- binary length specified way too long", | ||
813 | "b(1000000)\"abc321\"", | ||
814 | LLSD(), | ||
815 | LLSDParser::PARSE_FAILURE); | ||
816 | } | ||
817 | |||
818 | template<> template<> | ||
819 | void TestLLSDNotationParsingObject::test<13>() | ||
820 | { | ||
821 | LLSD val; | ||
822 | val["amy"] = 23; | ||
823 | val["bob"] = LLSD(); | ||
824 | val["cam"] = 1.23; | ||
825 | ensureParse("simple map", "{'amy':i23,'bob':!,'cam':r1.23}", val, 4); | ||
826 | |||
827 | val["bob"] = LLSD::emptyMap(); | ||
828 | val["bob"]["vehicle"] = std::string("bicycle"); | ||
829 | ensureParse( | ||
830 | "nested map", | ||
831 | "{'amy':i23,'bob':{'vehicle':'bicycle'},'cam':r1.23}", | ||
832 | val, | ||
833 | 5); | ||
834 | } | ||
835 | |||
836 | template<> template<> | ||
837 | void TestLLSDNotationParsingObject::test<14>() | ||
838 | { | ||
839 | LLSD val; | ||
840 | val.append(23); | ||
841 | val.append(LLSD()); | ||
842 | val.append(1.23); | ||
843 | ensureParse("simple array", "[i23,!,r1.23]", val, 4); | ||
844 | val[1] = LLSD::emptyArray(); | ||
845 | val[1].append("bicycle"); | ||
846 | ensureParse("nested array", "[i23,['bicycle'],r1.23]", val, 5); | ||
847 | } | ||
848 | |||
849 | template<> template<> | ||
850 | void TestLLSDNotationParsingObject::test<15>() | ||
851 | { | ||
852 | LLSD val; | ||
853 | val["amy"] = 23; | ||
854 | val["bob"]["dogs"] = LLSD::emptyArray(); | ||
855 | val["bob"]["dogs"].append(LLSD::emptyMap()); | ||
856 | val["bob"]["dogs"][0]["name"] = std::string("groove"); | ||
857 | val["bob"]["dogs"][0]["breed"] = std::string("samoyed"); | ||
858 | val["bob"]["dogs"].append(LLSD::emptyMap()); | ||
859 | val["bob"]["dogs"][1]["name"] = std::string("greyley"); | ||
860 | val["bob"]["dogs"][1]["breed"] = std::string("chow/husky"); | ||
861 | val["cam"] = 1.23; | ||
862 | ensureParse( | ||
863 | "nested notation", | ||
864 | "{'amy':i23," | ||
865 | " 'bob':{'dogs':[" | ||
866 | "{'name':'groove', 'breed':'samoyed'}," | ||
867 | "{'name':'greyley', 'breed':'chow/husky'}]}," | ||
868 | " 'cam':r1.23}", | ||
869 | val, | ||
870 | 11); | ||
871 | } | ||
872 | |||
873 | template<> template<> | ||
874 | void TestLLSDNotationParsingObject::test<16>() | ||
875 | { | ||
876 | // text to make sure that incorrect sizes bail because | ||
877 | std::string bad_str("s(5)\"hi\""); | ||
878 | ensureParse( | ||
879 | "size longer than bytes left", | ||
880 | bad_str, | ||
881 | LLSD(), | ||
882 | LLSDParser::PARSE_FAILURE); | ||
883 | } | ||
884 | |||
885 | template<> template<> | ||
886 | void TestLLSDNotationParsingObject::test<17>() | ||
887 | { | ||
888 | // text to make sure that incorrect sizes bail because | ||
889 | std::string bad_bin("b(5)\"hi\""); | ||
890 | ensureParse( | ||
891 | "size longer than bytes left", | ||
892 | bad_bin, | ||
893 | LLSD(), | ||
894 | LLSDParser::PARSE_FAILURE); | ||
895 | } | ||
896 | |||
897 | /** | ||
898 | * @class TestLLSDBinaryParsing | ||
899 | * @brief Concrete instance of a parse tester. | ||
900 | */ | ||
901 | class TestLLSDBinaryParsing : public TestLLSDParsing<LLSDBinaryParser> | ||
902 | { | ||
903 | public: | ||
904 | TestLLSDBinaryParsing() {} | ||
905 | }; | ||
906 | |||
907 | typedef tut::test_group<TestLLSDBinaryParsing> TestLLSDBinaryParsingGroup; | ||
908 | typedef TestLLSDBinaryParsingGroup::object TestLLSDBinaryParsingObject; | ||
909 | TestLLSDBinaryParsingGroup gTestLLSDBinaryParsingGroup( | ||
910 | "llsd binary parsing"); | ||
911 | |||
912 | template<> template<> | ||
913 | void TestLLSDBinaryParsingObject::test<1>() | ||
914 | { | ||
915 | std::vector<U8> vec; | ||
916 | vec.resize(6); | ||
917 | vec[0] = 'a'; vec[1] = 'b'; vec[2] = 'c'; | ||
918 | vec[3] = '3'; vec[4] = '2'; vec[5] = '1'; | ||
919 | std::string string_expected((char*)&vec[0], vec.size()); | ||
920 | LLSD value = string_expected; | ||
921 | |||
922 | vec.resize(11); | ||
923 | vec[0] = 's'; // for string | ||
924 | vec[5] = 'a'; vec[6] = 'b'; vec[7] = 'c'; | ||
925 | vec[8] = '3'; vec[9] = '2'; vec[10] = '1'; | ||
926 | |||
927 | uint32_t size = htonl(6); | ||
928 | memcpy(&vec[1], &size, sizeof(uint32_t)); | ||
929 | std::string str_good((char*)&vec[0], vec.size()); | ||
930 | ensureParse("correct string parse", str_good, value, 1); | ||
931 | |||
932 | size = htonl(7); | ||
933 | memcpy(&vec[1], &size, sizeof(uint32_t)); | ||
934 | std::string str_bad_1((char*)&vec[0], vec.size()); | ||
935 | ensureParse( | ||
936 | "incorrect size string parse", | ||
937 | str_bad_1, | ||
938 | LLSD(), | ||
939 | LLSDParser::PARSE_FAILURE); | ||
940 | |||
941 | size = htonl(100000); | ||
942 | memcpy(&vec[1], &size, sizeof(uint32_t)); | ||
943 | std::string str_bad_2((char*)&vec[0], vec.size()); | ||
944 | ensureParse( | ||
945 | "incorrect size string parse", | ||
946 | str_bad_2, | ||
947 | LLSD(), | ||
948 | LLSDParser::PARSE_FAILURE); | ||
949 | } | ||
950 | |||
951 | template<> template<> | ||
952 | void TestLLSDBinaryParsingObject::test<2>() | ||
953 | { | ||
954 | std::vector<U8> vec; | ||
955 | vec.resize(6); | ||
956 | vec[0] = 'a'; vec[1] = 'b'; vec[2] = 'c'; | ||
957 | vec[3] = '3'; vec[4] = '2'; vec[5] = '1'; | ||
958 | LLSD value = vec; | ||
959 | |||
960 | vec.resize(11); | ||
961 | vec[0] = 'b'; // for binary | ||
962 | vec[5] = 'a'; vec[6] = 'b'; vec[7] = 'c'; | ||
963 | vec[8] = '3'; vec[9] = '2'; vec[10] = '1'; | ||
964 | |||
965 | uint32_t size = htonl(6); | ||
966 | memcpy(&vec[1], &size, sizeof(uint32_t)); | ||
967 | std::string str_good((char*)&vec[0], vec.size()); | ||
968 | ensureParse("correct binary parse", str_good, value, 1); | ||
969 | |||
970 | size = htonl(7); | ||
971 | memcpy(&vec[1], &size, sizeof(uint32_t)); | ||
972 | std::string str_bad_1((char*)&vec[0], vec.size()); | ||
973 | ensureParse( | ||
974 | "incorrect size binary parse 1", | ||
975 | str_bad_1, | ||
976 | LLSD(), | ||
977 | LLSDParser::PARSE_FAILURE); | ||
978 | |||
979 | size = htonl(100000); | ||
980 | memcpy(&vec[1], &size, sizeof(uint32_t)); | ||
981 | std::string str_bad_2((char*)&vec[0], vec.size()); | ||
982 | ensureParse( | ||
983 | "incorrect size binary parse 2", | ||
984 | str_bad_2, | ||
985 | LLSD(), | ||
986 | LLSDParser::PARSE_FAILURE); | ||
987 | } | ||
988 | |||
989 | template<> template<> | ||
990 | void TestLLSDBinaryParsingObject::test<3>() | ||
991 | { | ||
992 | // test handling of xml not recognized as llsd results in an | ||
993 | // LLSD Undefined | ||
994 | ensureParse( | ||
995 | "malformed binary map", | ||
996 | "{'ha ha'", | ||
997 | LLSD(), | ||
998 | LLSDParser::PARSE_FAILURE); | ||
999 | ensureParse( | ||
1000 | "malformed binary array", | ||
1001 | "['ha ha'", | ||
1002 | LLSD(), | ||
1003 | LLSDParser::PARSE_FAILURE); | ||
1004 | ensureParse( | ||
1005 | "malformed binary string", | ||
1006 | "'ha ha", | ||
1007 | LLSD(), | ||
1008 | LLSDParser::PARSE_FAILURE); | ||
1009 | ensureParse( | ||
1010 | "bad noise", | ||
1011 | "g48ejlnfr", | ||
1012 | LLSD(), | ||
1013 | LLSDParser::PARSE_FAILURE); | ||
1014 | } | ||
1015 | template<> template<> | ||
1016 | void TestLLSDBinaryParsingObject::test<4>() | ||
1017 | { | ||
1018 | ensureParse("valid undef", "!", LLSD(), 1); | ||
1019 | } | ||
1020 | |||
1021 | template<> template<> | ||
1022 | void TestLLSDBinaryParsingObject::test<5>() | ||
1023 | { | ||
1024 | LLSD val = false; | ||
1025 | ensureParse("valid boolean false 2", "0", val, 1); | ||
1026 | val = true; | ||
1027 | ensureParse("valid boolean true 2", "1", val, 1); | ||
1028 | |||
1029 | val.clear(); | ||
1030 | ensureParse("invalid true", "t", val, LLSDParser::PARSE_FAILURE); | ||
1031 | ensureParse("invalid false", "f", val, LLSDParser::PARSE_FAILURE); | ||
1032 | } | ||
1033 | |||
1034 | template<> template<> | ||
1035 | void TestLLSDBinaryParsingObject::test<6>() | ||
1036 | { | ||
1037 | std::vector<U8> vec; | ||
1038 | vec.push_back('{'); | ||
1039 | vec.resize(vec.size() + 4); | ||
1040 | uint32_t size = htonl(1); | ||
1041 | memcpy(&vec[1], &size, sizeof(uint32_t)); | ||
1042 | vec.push_back('k'); | ||
1043 | int key_size_loc = vec.size(); | ||
1044 | size = htonl(1); // 1 too short | ||
1045 | vec.resize(vec.size() + 4); | ||
1046 | memcpy(&vec[key_size_loc], &size, sizeof(uint32_t)); | ||
1047 | vec.push_back('a'); vec.push_back('m'); vec.push_back('y'); | ||
1048 | vec.push_back('i'); | ||
1049 | int integer_loc = vec.size(); | ||
1050 | vec.resize(vec.size() + 4); | ||
1051 | uint32_t val_int = htonl(23); | ||
1052 | memcpy(&vec[integer_loc], &val_int, sizeof(uint32_t)); | ||
1053 | std::string str_bad_1((char*)&vec[0], vec.size()); | ||
1054 | ensureParse( | ||
1055 | "invalid key size", | ||
1056 | str_bad_1, | ||
1057 | LLSD(), | ||
1058 | LLSDParser::PARSE_FAILURE); | ||
1059 | |||
1060 | // check with correct size, but unterminated map (missing '}') | ||
1061 | size = htonl(3); // correct size | ||
1062 | memcpy(&vec[key_size_loc], &size, sizeof(uint32_t)); | ||
1063 | std::string str_bad_2((char*)&vec[0], vec.size()); | ||
1064 | ensureParse( | ||
1065 | "valid key size, unterminated map", | ||
1066 | str_bad_2, | ||
1067 | LLSD(), | ||
1068 | LLSDParser::PARSE_FAILURE); | ||
1069 | |||
1070 | // check w/ correct size and correct map termination | ||
1071 | LLSD val; | ||
1072 | val["amy"] = 23; | ||
1073 | vec.push_back('}'); | ||
1074 | std::string str_good((char*)&vec[0], vec.size()); | ||
1075 | ensureParse( | ||
1076 | "valid map", | ||
1077 | str_good, | ||
1078 | val, | ||
1079 | 2); | ||
1080 | |||
1081 | // check w/ incorrect sizes and correct map termination | ||
1082 | size = htonl(0); // 1 too few (for the map entry) | ||
1083 | memcpy(&vec[1], &size, sizeof(uint32_t)); | ||
1084 | std::string str_bad_3((char*)&vec[0], vec.size()); | ||
1085 | ensureParse( | ||
1086 | "invalid map too long", | ||
1087 | str_bad_3, | ||
1088 | LLSD(), | ||
1089 | LLSDParser::PARSE_FAILURE); | ||
1090 | |||
1091 | size = htonl(2); // 1 too many | ||
1092 | memcpy(&vec[1], &size, sizeof(uint32_t)); | ||
1093 | std::string str_bad_4((char*)&vec[0], vec.size()); | ||
1094 | ensureParse( | ||
1095 | "invalid map too short", | ||
1096 | str_bad_4, | ||
1097 | LLSD(), | ||
1098 | LLSDParser::PARSE_FAILURE); | ||
1099 | } | ||
1100 | |||
1101 | template<> template<> | ||
1102 | void TestLLSDBinaryParsingObject::test<7>() | ||
1103 | { | ||
1104 | std::vector<U8> vec; | ||
1105 | vec.push_back('['); | ||
1106 | vec.resize(vec.size() + 4); | ||
1107 | uint32_t size = htonl(1); // 1 too short | ||
1108 | memcpy(&vec[1], &size, sizeof(uint32_t)); | ||
1109 | vec.push_back('"'); vec.push_back('a'); vec.push_back('m'); | ||
1110 | vec.push_back('y'); vec.push_back('"'); vec.push_back('i'); | ||
1111 | int integer_loc = vec.size(); | ||
1112 | vec.resize(vec.size() + 4); | ||
1113 | uint32_t val_int = htonl(23); | ||
1114 | memcpy(&vec[integer_loc], &val_int, sizeof(uint32_t)); | ||
1115 | |||
1116 | std::string str_bad_1((char*)&vec[0], vec.size()); | ||
1117 | ensureParse( | ||
1118 | "invalid array size", | ||
1119 | str_bad_1, | ||
1120 | LLSD(), | ||
1121 | LLSDParser::PARSE_FAILURE); | ||
1122 | |||
1123 | // check with correct size, but unterminated map (missing ']') | ||
1124 | size = htonl(2); // correct size | ||
1125 | memcpy(&vec[1], &size, sizeof(uint32_t)); | ||
1126 | std::string str_bad_2((char*)&vec[0], vec.size()); | ||
1127 | ensureParse( | ||
1128 | "unterminated array", | ||
1129 | str_bad_2, | ||
1130 | LLSD(), | ||
1131 | LLSDParser::PARSE_FAILURE); | ||
1132 | |||
1133 | // check w/ correct size and correct map termination | ||
1134 | LLSD val; | ||
1135 | val.append("amy"); | ||
1136 | val.append(23); | ||
1137 | vec.push_back(']'); | ||
1138 | std::string str_good((char*)&vec[0], vec.size()); | ||
1139 | ensureParse( | ||
1140 | "valid array", | ||
1141 | str_good, | ||
1142 | val, | ||
1143 | 3); | ||
1144 | |||
1145 | // check with too many elements | ||
1146 | size = htonl(3); // 1 too long | ||
1147 | memcpy(&vec[1], &size, sizeof(uint32_t)); | ||
1148 | std::string str_bad_3((char*)&vec[0], vec.size()); | ||
1149 | ensureParse( | ||
1150 | "array too short", | ||
1151 | str_bad_3, | ||
1152 | LLSD(), | ||
1153 | LLSDParser::PARSE_FAILURE); | ||
1154 | } | ||
1155 | |||
1156 | template<> template<> | ||
1157 | void TestLLSDBinaryParsingObject::test<8>() | ||
1158 | { | ||
1159 | std::vector<U8> vec; | ||
1160 | vec.push_back('{'); | ||
1161 | vec.resize(vec.size() + 4); | ||
1162 | memset(&vec[1], 0, 4); | ||
1163 | vec.push_back('}'); | ||
1164 | std::string str_good((char*)&vec[0], vec.size()); | ||
1165 | LLSD val = LLSD::emptyMap(); | ||
1166 | ensureParse( | ||
1167 | "empty map", | ||
1168 | str_good, | ||
1169 | val, | ||
1170 | 1); | ||
1171 | } | ||
1172 | |||
1173 | template<> template<> | ||
1174 | void TestLLSDBinaryParsingObject::test<9>() | ||
1175 | { | ||
1176 | std::vector<U8> vec; | ||
1177 | vec.push_back('['); | ||
1178 | vec.resize(vec.size() + 4); | ||
1179 | memset(&vec[1], 0, 4); | ||
1180 | vec.push_back(']'); | ||
1181 | std::string str_good((char*)&vec[0], vec.size()); | ||
1182 | LLSD val = LLSD::emptyArray(); | ||
1183 | ensureParse( | ||
1184 | "empty array", | ||
1185 | str_good, | ||
1186 | val, | ||
1187 | 1); | ||
1188 | } | ||
1189 | |||
1190 | template<> template<> | ||
1191 | void TestLLSDBinaryParsingObject::test<10>() | ||
1192 | { | ||
1193 | std::vector<U8> vec; | ||
1194 | vec.push_back('l'); | ||
1195 | vec.resize(vec.size() + 4); | ||
1196 | uint32_t size = htonl(14); // 1 too long | ||
1197 | memcpy(&vec[1], &size, sizeof(uint32_t)); | ||
1198 | vec.push_back('h'); vec.push_back('t'); vec.push_back('t'); | ||
1199 | vec.push_back('p'); vec.push_back(':'); vec.push_back('/'); | ||
1200 | vec.push_back('/'); vec.push_back('s'); vec.push_back('l'); | ||
1201 | vec.push_back('.'); vec.push_back('c'); vec.push_back('o'); | ||
1202 | vec.push_back('m'); | ||
1203 | std::string str_bad((char*)&vec[0], vec.size()); | ||
1204 | ensureParse( | ||
1205 | "invalid uri length size", | ||
1206 | str_bad, | ||
1207 | LLSD(), | ||
1208 | LLSDParser::PARSE_FAILURE); | ||
1209 | |||
1210 | LLSD val; | ||
1211 | val = LLURI("http://sl.com"); | ||
1212 | size = htonl(13); // correct length | ||
1213 | memcpy(&vec[1], &size, sizeof(uint32_t)); | ||
1214 | std::string str_good((char*)&vec[0], vec.size()); | ||
1215 | ensureParse( | ||
1216 | "valid key size", | ||
1217 | str_good, | ||
1218 | val, | ||
1219 | 1); | ||
1220 | } | ||
1221 | |||
1222 | /* | ||
1223 | template<> template<> | ||
1224 | void TestLLSDBinaryParsingObject::test<11>() | ||
1225 | { | ||
1226 | } | ||
1227 | */ | ||
1228 | |||
1229 | /** | ||
1230 | * @class TestLLSDCrossCompatible | ||
1231 | * @brief Miscellaneous serialization and parsing tests | ||
1232 | */ | ||
1233 | class TestLLSDCrossCompatible | ||
1234 | { | ||
1235 | public: | ||
1236 | TestLLSDCrossCompatible() {} | ||
1237 | |||
1238 | void ensureBinaryAndNotation( | ||
1239 | const std::string& msg, | ||
1240 | const LLSD& input) | ||
1241 | { | ||
1242 | // to binary, and back again | ||
1243 | std::stringstream str1; | ||
1244 | S32 count1 = LLSDSerialize::toBinary(input, str1); | ||
1245 | LLSD actual_value_bin; | ||
1246 | S32 count2 = LLSDSerialize::fromBinary( | ||
1247 | actual_value_bin, | ||
1248 | str1, | ||
1249 | LLSDSerialize::SIZE_UNLIMITED); | ||
1250 | ensure_equals( | ||
1251 | "ensureBinaryAndNotation binary count", | ||
1252 | count2, | ||
1253 | count1); | ||
1254 | |||
1255 | // to notation and back again | ||
1256 | std::stringstream str2; | ||
1257 | S32 count3 = LLSDSerialize::toNotation(actual_value_bin, str2); | ||
1258 | ensure_equals( | ||
1259 | "ensureBinaryAndNotation notation count1", | ||
1260 | count3, | ||
1261 | count2); | ||
1262 | LLSD actual_value_notation; | ||
1263 | S32 count4 = LLSDSerialize::fromNotation( | ||
1264 | actual_value_notation, | ||
1265 | str2, | ||
1266 | LLSDSerialize::SIZE_UNLIMITED); | ||
1267 | ensure_equals( | ||
1268 | "ensureBinaryAndNotation notation count2", | ||
1269 | count4, | ||
1270 | count3); | ||
1271 | ensure_equals( | ||
1272 | msg + " (binaryandnotation)", | ||
1273 | actual_value_notation, | ||
1274 | input); | ||
1275 | } | ||
1276 | |||
1277 | void ensureBinaryAndXML( | ||
1278 | const std::string& msg, | ||
1279 | const LLSD& input) | ||
1280 | { | ||
1281 | // to binary, and back again | ||
1282 | std::stringstream str1; | ||
1283 | S32 count1 = LLSDSerialize::toBinary(input, str1); | ||
1284 | LLSD actual_value_bin; | ||
1285 | S32 count2 = LLSDSerialize::fromBinary( | ||
1286 | actual_value_bin, | ||
1287 | str1, | ||
1288 | LLSDSerialize::SIZE_UNLIMITED); | ||
1289 | ensure_equals( | ||
1290 | "ensureBinaryAndXML binary count", | ||
1291 | count2, | ||
1292 | count1); | ||
1293 | |||
1294 | // to xml and back again | ||
1295 | std::stringstream str2; | ||
1296 | S32 count3 = LLSDSerialize::toXML(actual_value_bin, str2); | ||
1297 | ensure_equals( | ||
1298 | "ensureBinaryAndXML xml count1", | ||
1299 | count3, | ||
1300 | count2); | ||
1301 | LLSD actual_value_xml; | ||
1302 | S32 count4 = LLSDSerialize::fromXML(actual_value_xml, str2); | ||
1303 | ensure_equals( | ||
1304 | "ensureBinaryAndXML xml count2", | ||
1305 | count4, | ||
1306 | count3); | ||
1307 | ensure_equals(msg + " (binaryandxml)", actual_value_xml, input); | ||
1308 | } | ||
1309 | }; | ||
1310 | |||
1311 | typedef tut::test_group<TestLLSDCrossCompatible> TestLLSDCompatibleGroup; | ||
1312 | typedef TestLLSDCompatibleGroup::object TestLLSDCompatibleObject; | ||
1313 | TestLLSDCompatibleGroup gTestLLSDCompatibleGroup( | ||
1314 | "llsd serialize compatible"); | ||
1315 | |||
1316 | template<> template<> | ||
1317 | void TestLLSDCompatibleObject::test<1>() | ||
1318 | { | ||
1319 | LLSD test; | ||
1320 | ensureBinaryAndNotation("undef", test); | ||
1321 | ensureBinaryAndXML("undef", test); | ||
1322 | test = true; | ||
1323 | ensureBinaryAndNotation("boolean true", test); | ||
1324 | ensureBinaryAndXML("boolean true", test); | ||
1325 | test = false; | ||
1326 | ensureBinaryAndNotation("boolean false", test); | ||
1327 | ensureBinaryAndXML("boolean false", test); | ||
1328 | test = 0; | ||
1329 | ensureBinaryAndNotation("integer zero", test); | ||
1330 | ensureBinaryAndXML("integer zero", test); | ||
1331 | test = 1; | ||
1332 | ensureBinaryAndNotation("integer positive", test); | ||
1333 | ensureBinaryAndXML("integer positive", test); | ||
1334 | test = -234567; | ||
1335 | ensureBinaryAndNotation("integer negative", test); | ||
1336 | ensureBinaryAndXML("integer negative", test); | ||
1337 | test = 0.0; | ||
1338 | ensureBinaryAndNotation("real zero", test); | ||
1339 | ensureBinaryAndXML("real zero", test); | ||
1340 | test = 1.0; | ||
1341 | ensureBinaryAndNotation("real positive", test); | ||
1342 | ensureBinaryAndXML("real positive", test); | ||
1343 | test = -1.0; | ||
1344 | ensureBinaryAndNotation("real negative", test); | ||
1345 | ensureBinaryAndXML("real negative", test); | ||
1346 | } | ||
1347 | |||
1348 | template<> template<> | ||
1349 | void TestLLSDCompatibleObject::test<2>() | ||
1350 | { | ||
1351 | LLSD test; | ||
1352 | test = "foobar"; | ||
1353 | ensureBinaryAndNotation("string", test); | ||
1354 | ensureBinaryAndXML("string", test); | ||
1355 | } | ||
1356 | |||
1357 | template<> template<> | ||
1358 | void TestLLSDCompatibleObject::test<3>() | ||
1359 | { | ||
1360 | LLSD test; | ||
1361 | LLUUID id; | ||
1362 | id.generate(); | ||
1363 | test = id; | ||
1364 | ensureBinaryAndNotation("uuid", test); | ||
1365 | ensureBinaryAndXML("uuid", test); | ||
1366 | } | ||
1367 | |||
1368 | template<> template<> | ||
1369 | void TestLLSDCompatibleObject::test<4>() | ||
1370 | { | ||
1371 | LLSD test; | ||
1372 | test = LLDate(12345.0); | ||
1373 | ensureBinaryAndNotation("date", test); | ||
1374 | ensureBinaryAndXML("date", test); | ||
1375 | } | ||
1376 | |||
1377 | template<> template<> | ||
1378 | void TestLLSDCompatibleObject::test<5>() | ||
1379 | { | ||
1380 | LLSD test; | ||
1381 | test = LLURI("http://www.secondlife.com/"); | ||
1382 | ensureBinaryAndNotation("uri", test); | ||
1383 | ensureBinaryAndXML("uri", test); | ||
1384 | } | ||
1385 | |||
1386 | template<> template<> | ||
1387 | void TestLLSDCompatibleObject::test<6>() | ||
1388 | { | ||
1389 | LLSD test; | ||
1390 | typedef std::vector<U8> buf_t; | ||
1391 | buf_t val; | ||
1392 | for(int ii = 0; ii < 100; ++ii) | ||
1393 | { | ||
1394 | srand(ii); /* Flawfinder: ignore */ | ||
1395 | S32 size = rand() % 100 + 10; | ||
1396 | std::generate_n( | ||
1397 | std::back_insert_iterator<buf_t>(val), | ||
1398 | size, | ||
1399 | rand); | ||
1400 | } | ||
1401 | test = val; | ||
1402 | ensureBinaryAndNotation("binary", test); | ||
1403 | ensureBinaryAndXML("binary", test); | ||
1404 | } | ||
1405 | |||
1406 | template<> template<> | ||
1407 | void TestLLSDCompatibleObject::test<7>() | ||
1408 | { | ||
1409 | LLSD test; | ||
1410 | test = LLSD::emptyArray(); | ||
1411 | test.append(1); | ||
1412 | test.append("hello"); | ||
1413 | ensureBinaryAndNotation("array", test); | ||
1414 | ensureBinaryAndXML("array", test); | ||
1415 | } | ||
1416 | |||
1417 | template<> template<> | ||
1418 | void TestLLSDCompatibleObject::test<8>() | ||
1419 | { | ||
1420 | LLSD test; | ||
1421 | test = LLSD::emptyArray(); | ||
1422 | test["foo"] = "bar"; | ||
1423 | test["baz"] = 100; | ||
1424 | ensureBinaryAndNotation("map", test); | ||
1425 | ensureBinaryAndXML("map", test); | ||
1426 | } | ||
584 | } | 1427 | } |
585 | 1428 | ||
586 | #endif | 1429 | #endif |