20 #include "gtest/gtest.h" 24 TEST(MarshallingTest, TestBoolParsing) {
104 TEST(MarshallingTest, TestInt16Parsing) {
114 EXPECT_EQ(value, -1);
116 EXPECT_EQ(value, 123);
118 EXPECT_EQ(value, -18765);
126 EXPECT_EQ(value, -1);
128 EXPECT_EQ(value, 100);
132 EXPECT_EQ(value, 16);
134 EXPECT_EQ(value, 564);
137 EXPECT_NE(value, -3);
139 EXPECT_NE(value, 49);
143 EXPECT_EQ(value, 10);
145 EXPECT_EQ(value, 11);
147 EXPECT_EQ(value, 12);
149 EXPECT_EQ(value, 34);
165 TEST(MarshallingTest, TestUint16Parsing) {
175 EXPECT_EQ(value, 123);
185 EXPECT_EQ(value, 100);
189 EXPECT_EQ(value, 16);
191 EXPECT_EQ(value, 564);
194 EXPECT_NE(value, 49);
198 EXPECT_EQ(value, 10);
200 EXPECT_EQ(value, 11);
202 EXPECT_EQ(value, 12);
204 EXPECT_EQ(value, 34);
221 TEST(MarshallingTest, TestInt32Parsing) {
231 EXPECT_EQ(value, -1);
233 EXPECT_EQ(value, 123);
235 EXPECT_EQ(value, -98765);
243 EXPECT_EQ(value, -1);
245 EXPECT_EQ(value, 100);
249 EXPECT_EQ(value, 16);
251 EXPECT_EQ(value, 564);
254 EXPECT_NE(value, -3);
256 EXPECT_NE(value, 49);
260 EXPECT_EQ(value, 10);
262 EXPECT_EQ(value, 11);
264 EXPECT_EQ(value, 12);
266 EXPECT_EQ(value, 34);
282 TEST(MarshallingTest, TestUint32Parsing) {
292 EXPECT_EQ(value, 123);
300 EXPECT_EQ(value, 100);
304 EXPECT_EQ(value, 16);
306 EXPECT_EQ(value, 564);
308 EXPECT_EQ(value, 4294967293);
311 EXPECT_NE(value, 49);
315 EXPECT_EQ(value, 10);
317 EXPECT_EQ(value, 11);
319 EXPECT_EQ(value, 12);
321 EXPECT_EQ(value, 34);
338 TEST(MarshallingTest, TestInt64Parsing) {
348 EXPECT_EQ(value, -1);
350 EXPECT_EQ(value, 123);
352 EXPECT_EQ(value, -98765);
362 EXPECT_EQ(value, 100);
366 EXPECT_EQ(value, 16);
368 EXPECT_EQ(value, 1152827684197027293);
371 EXPECT_NE(value, -2);
373 EXPECT_NE(value, 49);
377 EXPECT_EQ(value, 10);
379 EXPECT_EQ(value, 11);
381 EXPECT_EQ(value, 12);
383 EXPECT_EQ(value, 127);
399 TEST(MarshallingTest, TestUInt64Parsing) {
409 EXPECT_EQ(value, 123);
411 EXPECT_EQ(value, 13);
419 EXPECT_EQ(value, 300);
423 EXPECT_EQ(value, 16);
425 EXPECT_EQ(value, 65535);
428 EXPECT_NE(value, 49);
432 EXPECT_EQ(value, 10);
434 EXPECT_EQ(value, 11);
436 EXPECT_EQ(value, 12);
453 TEST(MarshallingTest, TestFloatParsing) {
459 EXPECT_FLOAT_EQ(value, 1.3f);
461 EXPECT_DOUBLE_EQ(value, -0.1f);
463 EXPECT_DOUBLE_EQ(value, 0.01f);
467 EXPECT_DOUBLE_EQ(value, 1.2e3f);
469 EXPECT_DOUBLE_EQ(value, 9.8765402e-37f);
471 EXPECT_DOUBLE_EQ(value, 0.11e+3f);
473 EXPECT_DOUBLE_EQ(value, 0.f);
475 EXPECT_TRUE(std::isinf(value));
479 EXPECT_DOUBLE_EQ(value, 1.6f);
481 EXPECT_DOUBLE_EQ(value, 0.0001f);
485 EXPECT_DOUBLE_EQ(value, -5.1f);
489 EXPECT_TRUE(std::isnan(value));
491 EXPECT_TRUE(std::isinf(value));
495 EXPECT_DOUBLE_EQ(value, 66096.f);
497 EXPECT_NEAR(value, -60.4092f, 5e-5f);
499 EXPECT_NEAR(value, 1.01328e-05f, 5e-11f);
501 EXPECT_NEAR(value, 0.0078125f, 5e-8f);
505 EXPECT_DOUBLE_EQ(value, 10.1f);
507 EXPECT_DOUBLE_EQ(value, 2.34f);
509 EXPECT_DOUBLE_EQ(value, 5.7f);
511 EXPECT_NEAR(value, -449.8984375f, 5e-8f);
528 TEST(MarshallingTest, TestDoubleParsing) {
534 EXPECT_DOUBLE_EQ(value, 1.3);
536 EXPECT_DOUBLE_EQ(value, -0.1);
538 EXPECT_DOUBLE_EQ(value, 0.01);
542 EXPECT_DOUBLE_EQ(value, 1.2e3);
544 EXPECT_DOUBLE_EQ(value, 9.00000002e-123);
546 EXPECT_DOUBLE_EQ(value, 0.11e+3);
548 EXPECT_DOUBLE_EQ(value, 0);
550 EXPECT_TRUE(std::isinf(value));
554 EXPECT_DOUBLE_EQ(value, 1.6);
556 EXPECT_DOUBLE_EQ(value, 0.0001);
560 EXPECT_DOUBLE_EQ(value, -5.1);
564 EXPECT_TRUE(std::isnan(value));
566 EXPECT_TRUE(std::isnan(value));
568 EXPECT_TRUE(std::isinf(value));
570 EXPECT_TRUE(std::isinf(value));
574 EXPECT_DOUBLE_EQ(value, 66096);
576 EXPECT_NEAR(value, -60.4092, 5e-5);
578 EXPECT_NEAR(value, 1.01328e-05, 5e-11);
580 EXPECT_NEAR(value, 0.0078125, 5e-8);
584 EXPECT_DOUBLE_EQ(value, 10.1);
586 EXPECT_DOUBLE_EQ(value, 2.34);
588 EXPECT_DOUBLE_EQ(value, 5.7);
590 EXPECT_NEAR(value, -449.8984375, 5e-8);
607 TEST(MarshallingTest, TestStringParsing) {
612 EXPECT_EQ(value,
"");
614 EXPECT_EQ(value,
" ");
616 EXPECT_EQ(value,
" ");
618 EXPECT_EQ(value,
"\n");
620 EXPECT_EQ(value,
"\t");
622 EXPECT_EQ(value,
"asdfg");
624 EXPECT_EQ(value,
"asdf ghjk");
626 EXPECT_EQ(value,
"a\nb\nc");
628 EXPECT_EQ(value,
"asd");
630 EXPECT_EQ(value,
"\\\\");
635 TEST(MarshallingTest, TestVectorOfStringParsing) {
637 std::vector<std::string>
value;
640 EXPECT_EQ(value, std::vector<std::string>{});
642 EXPECT_EQ(value, std::vector<std::string>({
"1"}));
644 EXPECT_EQ(value, std::vector<std::string>({
"a",
"b"}));
646 EXPECT_EQ(value, std::vector<std::string>({
"a",
"b",
"c",
""}));
648 EXPECT_EQ(value, std::vector<std::string>({
"a",
"",
""}));
650 EXPECT_EQ(value, std::vector<std::string>({
"",
""}));
652 EXPECT_EQ(value, std::vector<std::string>({
"a",
" b",
"c "}));
657 TEST(MarshallingTest, TestBoolUnparsing) {
664 TEST(MarshallingTest, TestInt16Unparsing) {
681 TEST(MarshallingTest, TestUint16Unparsing) {
694 TEST(MarshallingTest, TestInt32Unparsing) {
711 TEST(MarshallingTest, TestUint32Unparsing) {
724 TEST(MarshallingTest, TestInt64Unparsing) {
737 value = 0x7FFFFFFFFFFFFFFF;
739 value = 0xFFFFFFFFFFFFFFFF;
745 TEST(MarshallingTest, TestUint64Unparsing) {
754 value = 0xFFFFFFFFFFFFFFFF;
760 TEST(MarshallingTest, TestFloatUnparsing) {
775 TEST(MarshallingTest, TestDoubleUnparsing) {
788 value = std::nan(
"");
790 value = std::numeric_limits<double>::infinity();
796 TEST(MarshallingTest, TestStringUnparsing) {
806 template <
typename T>
807 void TestRoundtrip(T
v) {
814 TEST(MarshallingTest, TestFloatRoundTrip) {
816 TestRoundtrip(0.12f);
817 TestRoundtrip(0.123f);
818 TestRoundtrip(0.1234f);
819 TestRoundtrip(0.12345f);
820 TestRoundtrip(0.123456f);
821 TestRoundtrip(0.1234567f);
822 TestRoundtrip(0.12345678f);
824 TestRoundtrip(0.1e20f);
825 TestRoundtrip(0.12e20f);
826 TestRoundtrip(0.123e20f);
827 TestRoundtrip(0.1234e20f);
828 TestRoundtrip(0.12345e20f);
829 TestRoundtrip(0.123456e20f);
830 TestRoundtrip(0.1234567e20f);
831 TestRoundtrip(0.12345678e20f);
833 TestRoundtrip(0.1e-20f);
834 TestRoundtrip(0.12e-20f);
835 TestRoundtrip(0.123e-20f);
836 TestRoundtrip(0.1234e-20f);
837 TestRoundtrip(0.12345e-20f);
838 TestRoundtrip(0.123456e-20f);
839 TestRoundtrip(0.1234567e-20f);
840 TestRoundtrip(0.12345678e-20f);
843 TEST(MarshallingTest, TestDoubleRoundTrip) {
846 TestRoundtrip(0.123);
847 TestRoundtrip(0.1234);
848 TestRoundtrip(0.12345);
849 TestRoundtrip(0.123456);
850 TestRoundtrip(0.1234567);
851 TestRoundtrip(0.12345678);
852 TestRoundtrip(0.123456789);
853 TestRoundtrip(0.1234567891);
854 TestRoundtrip(0.12345678912);
855 TestRoundtrip(0.123456789123);
856 TestRoundtrip(0.1234567891234);
857 TestRoundtrip(0.12345678912345);
858 TestRoundtrip(0.123456789123456);
859 TestRoundtrip(0.1234567891234567);
860 TestRoundtrip(0.12345678912345678);
862 TestRoundtrip(0.1e50);
863 TestRoundtrip(0.12e50);
864 TestRoundtrip(0.123e50);
865 TestRoundtrip(0.1234e50);
866 TestRoundtrip(0.12345e50);
867 TestRoundtrip(0.123456e50);
868 TestRoundtrip(0.1234567e50);
869 TestRoundtrip(0.12345678e50);
870 TestRoundtrip(0.123456789e50);
871 TestRoundtrip(0.1234567891e50);
872 TestRoundtrip(0.12345678912e50);
873 TestRoundtrip(0.123456789123e50);
874 TestRoundtrip(0.1234567891234e50);
875 TestRoundtrip(0.12345678912345e50);
876 TestRoundtrip(0.123456789123456e50);
877 TestRoundtrip(0.1234567891234567e50);
878 TestRoundtrip(0.12345678912345678e50);
880 TestRoundtrip(0.1e-50);
881 TestRoundtrip(0.12e-50);
882 TestRoundtrip(0.123e-50);
883 TestRoundtrip(0.1234e-50);
884 TestRoundtrip(0.12345e-50);
885 TestRoundtrip(0.123456e-50);
886 TestRoundtrip(0.1234567e-50);
887 TestRoundtrip(0.12345678e-50);
888 TestRoundtrip(0.123456789e-50);
889 TestRoundtrip(0.1234567891e-50);
890 TestRoundtrip(0.12345678912e-50);
891 TestRoundtrip(0.123456789123e-50);
892 TestRoundtrip(0.1234567891234e-50);
893 TestRoundtrip(0.12345678912345e-50);
894 TestRoundtrip(0.123456789123456e-50);
895 TestRoundtrip(0.1234567891234567e-50);
896 TestRoundtrip(0.12345678912345678e-50);
std::string UnparseFlag(const T &v)
bool ParseFlag(absl::string_view input, T *dst, std::string *error)
TEST(Symbolize, Unimplemented)