1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169
|
/* generate byte arrays that match the constructs in test-generated-code2.c.
* these are tested against eachother to make sure the c and c++ agree. */
#define __STDC_LIMIT_MACROS
#include "t/test-full.pb.h"
#include <limits.h>
# if defined(_MSC_VER)
/* On windows, in ms visual studio, define the types ourselves */
# define int32_t signed __int32
# define INT32_MIN _I32_MIN
# define INT32_MAX _I32_MAX
# define uint32_t unsigned __int32
# define UINT32_MIN _UI32_MIN
# define UINT32_MAX _UI32_MAX
# define int64_t signed __int64
# define INT64_MIN _I64_MIN
# define INT64_MAX _I64_MAX
# define uint64_t unsigned __int64
# define UINT64_MIN _UI64_MIN
# define UINT64_MAX _UI64_MAX
# define uint8_t unsigned char
# else
/* Use the system inttypes.h */
# include <inttypes.h>
# endif
#include <stdio.h>
using namespace foo;
#define protobuf_c_boolean bool
#define TEST_ENUM_SMALL_TYPE_NAME TestEnumSmall
#define TEST_ENUM_SMALL(NAME) foo::NAME
#define TEST_ENUM_TYPE_NAME TestEnum
#define TEST_ENUM(NAME) foo::NAME
#include "common-test-arrays.h"
#define N_ELEMENTS(arr) (sizeof(arr)/sizeof((arr)[0]))
static void
dump_messages_bytes(size_t n_msgs,
google::protobuf::Message **messages,
const char *label)
{
printf ("static const uint8_t %s[] = { ", label);
for (unsigned m = 0; m < n_msgs; m++) {
std::string rv;
google::protobuf::Message *message = messages[m];
if (m)
printf (", ");
if (!message->SerializeToString(&rv))
assert(0);
unsigned char *bytes = (unsigned char *) rv.data();
for (unsigned i = 0; i < rv.size(); i++) {
if (i)
printf (", ");
printf ("0x%02x", bytes[i]);
}
}
printf (" };\n");
}
static void
dump_message_bytes(google::protobuf::Message *message,
const char *label)
{
dump_messages_bytes (1, &message, label);
}
static void
dump_test_enum_small (void)
{
TestMessRequiredEnumSmall es;
es.set_test(NEG_VALUE);
dump_message_bytes(&es, "test_enum_small_NEG_VALUE");
es.set_test(VALUE);
dump_message_bytes(&es, "test_enum_small_VALUE");
es.set_test(OTHER_VALUE);
dump_message_bytes(&es, "test_enum_small_OTHER_VALUE");
}
static void
dump_test_enum_big (void)
{
TestMessRequiredEnum eb;
eb.set_test(VALUENEG123456); dump_message_bytes(&eb, "test_enum_big_VALUENEG123456");
eb.set_test(VALUENEG1); dump_message_bytes(&eb, "test_enum_big_VALUENEG1");
eb.set_test(VALUE0); dump_message_bytes(&eb, "test_enum_big_VALUE0");
eb.set_test(VALUE127); dump_message_bytes(&eb, "test_enum_big_VALUE127");
eb.set_test(VALUE128); dump_message_bytes(&eb, "test_enum_big_VALUE128");
eb.set_test(VALUE16383); dump_message_bytes(&eb, "test_enum_big_VALUE16383");
eb.set_test(VALUE16384); dump_message_bytes(&eb, "test_enum_big_VALUE16384");
eb.set_test(VALUE2097151); dump_message_bytes(&eb, "test_enum_big_VALUE2097151");
eb.set_test(VALUE2097152); dump_message_bytes(&eb, "test_enum_big_VALUE2097152");
eb.set_test(VALUE268435455); dump_message_bytes(&eb, "test_enum_big_VALUE268435455");
eb.set_test(VALUE268435456); dump_message_bytes(&eb, "test_enum_big_VALUE268435456");
}
static void
dump_test_field_numbers (void)
{
#define DUMP_ONE(num) \
{ TestFieldNo##num f; \
f.set_test("tst"); \
dump_message_bytes(&f, "test_field_number_" #num); }
DUMP_ONE (15)
DUMP_ONE (16)
DUMP_ONE (2047)
DUMP_ONE (2048)
DUMP_ONE (262143)
DUMP_ONE (262144)
DUMP_ONE (33554431)
DUMP_ONE (33554432)
#undef DUMP_ONE
}
static void dump_test_required_int32 (void)
{
TestMessRequiredInt32 mess;
mess.set_test (INT32_MIN);
dump_message_bytes (&mess, "test_required_int32_min");
mess.set_test (-1000);
dump_message_bytes (&mess, "test_required_int32_m1000");
mess.set_test (0);
dump_message_bytes (&mess, "test_required_int32_0");
mess.set_test (INT32_MAX);
dump_message_bytes (&mess, "test_required_int32_max");
}
static void dump_test_required_sint32 (void)
{
TestMessRequiredSInt32 mess;
mess.set_test (INT32_MIN);
dump_message_bytes (&mess, "test_required_sint32_min");
mess.set_test (-1000);
dump_message_bytes (&mess, "test_required_sint32_m1000");
mess.set_test (0);
dump_message_bytes (&mess, "test_required_sint32_0");
mess.set_test (INT32_MAX);
dump_message_bytes (&mess, "test_required_sint32_max");
}
static void dump_test_required_sfixed32 (void)
{
TestMessRequiredSFixed32 mess;
mess.set_test (INT32_MIN);
dump_message_bytes (&mess, "test_required_sfixed32_min");
mess.set_test (-1000);
dump_message_bytes (&mess, "test_required_sfixed32_m1000");
mess.set_test (0);
dump_message_bytes (&mess, "test_required_sfixed32_0");
mess.set_test (INT32_MAX);
dump_message_bytes (&mess, "test_required_sfixed32_max");
}
static void dump_test_required_uint32 (void)
{
TestMessRequiredUInt32 mess;
mess.set_test (0);
dump_message_bytes (&mess, "test_required_uint32_0");
mess.set_test (MILLION);
dump_message_bytes (&mess, "test_required_uint32_million");
mess.set_test (UINT32_MAX);
dump_message_bytes (&mess, "test_required_uint32_max");
}
static void dump_test_required_fixed32 (void)
{
TestMessRequiredFixed32 mess;
mess.set_test (0);
dump_message_bytes (&mess, "test_required_fixed32_0");
mess.set_test (MILLION);
dump_message_bytes (&mess, "test_required_fixed32_million");
mess.set_test (UINT32_MAX);
dump_message_bytes (&mess, "test_required_fixed32_max");
}
static void dump_test_required_int64 (void)
{
TestMessRequiredInt64 mess;
mess.set_test (INT64_MIN);
dump_message_bytes (&mess, "test_required_int64_min");
mess.set_test (-TRILLION);
dump_message_bytes (&mess, "test_required_int64_mtril");
mess.set_test (0);
dump_message_bytes (&mess, "test_required_int64_0");
mess.set_test (QUADRILLION);
dump_message_bytes (&mess, "test_required_int64_quad");
mess.set_test (INT64_MAX);
dump_message_bytes (&mess, "test_required_int64_max");
}
static void dump_test_required_sint64 (void)
{
TestMessRequiredSInt64 mess;
mess.set_test (INT64_MIN);
dump_message_bytes (&mess, "test_required_sint64_min");
mess.set_test (-TRILLION);
dump_message_bytes (&mess, "test_required_sint64_mtril");
mess.set_test (0);
dump_message_bytes (&mess, "test_required_sint64_0");
mess.set_test (QUADRILLION);
dump_message_bytes (&mess, "test_required_sint64_quad");
mess.set_test (INT64_MAX);
dump_message_bytes (&mess, "test_required_sint64_max");
}
static void dump_test_required_sfixed64 (void)
{
TestMessRequiredSFixed64 mess;
mess.set_test (INT64_MIN);
dump_message_bytes (&mess, "test_required_sfixed64_min");
mess.set_test (-TRILLION);
dump_message_bytes (&mess, "test_required_sfixed64_mtril");
mess.set_test (0);
dump_message_bytes (&mess, "test_required_sfixed64_0");
mess.set_test (QUADRILLION);
dump_message_bytes (&mess, "test_required_sfixed64_quad");
mess.set_test (INT64_MAX);
dump_message_bytes (&mess, "test_required_sfixed64_max");
}
static void dump_test_required_uint64 (void)
{
TestMessRequiredUInt64 mess;
mess.set_test (0);
dump_message_bytes (&mess, "test_required_uint64_0");
mess.set_test (THOUSAND);
dump_message_bytes (&mess, "test_required_uint64_thou");
mess.set_test (MILLION);
dump_message_bytes (&mess, "test_required_uint64_mill");
mess.set_test (BILLION);
dump_message_bytes (&mess, "test_required_uint64_bill");
mess.set_test (BILLION*20);
dump_message_bytes (&mess, "test_required_uint64_20_bill");
mess.set_test (TRILLION);
dump_message_bytes (&mess, "test_required_uint64_tril");
mess.set_test (TRILLION*20);
dump_message_bytes (&mess, "test_required_uint64_20_tril");
mess.set_test (QUADRILLION);
dump_message_bytes (&mess, "test_required_uint64_quad");
mess.set_test (QUINTILLION);
dump_message_bytes (&mess, "test_required_uint64_quint");
mess.set_test (UINT64_MAX);
dump_message_bytes (&mess, "test_required_uint64_max");
}
static void dump_test_required_fixed64 (void)
{
TestMessRequiredFixed64 mess;
mess.set_test (0);
dump_message_bytes (&mess, "test_required_fixed64_0");
mess.set_test (THOUSAND);
dump_message_bytes (&mess, "test_required_fixed64_thou");
mess.set_test (MILLION);
dump_message_bytes (&mess, "test_required_fixed64_mill");
mess.set_test (BILLION);
dump_message_bytes (&mess, "test_required_fixed64_bill");
mess.set_test (TRILLION);
dump_message_bytes (&mess, "test_required_fixed64_tril");
mess.set_test (QUADRILLION);
dump_message_bytes (&mess, "test_required_fixed64_quad");
mess.set_test (QUINTILLION);
dump_message_bytes (&mess, "test_required_fixed64_quint");
mess.set_test (UINT64_MAX);
dump_message_bytes (&mess, "test_required_fixed64_max");
}
static void dump_test_required_float (void)
{
TestMessRequiredFloat mess;
mess.set_test(-THOUSAND);
dump_message_bytes (&mess, "test_required_float_mthou");
mess.set_test(0);
dump_message_bytes (&mess, "test_required_float_0");
mess.set_test(420);
dump_message_bytes (&mess, "test_required_float_420");
}
static void dump_test_required_double (void)
{
TestMessRequiredDouble mess;
mess.set_test(-THOUSAND);
dump_message_bytes (&mess, "test_required_double_mthou");
mess.set_test(0);
dump_message_bytes (&mess, "test_required_double_0");
mess.set_test(420);
dump_message_bytes (&mess, "test_required_double_420");
}
static void dump_test_required_bool (void)
{
TestMessRequiredBool mess;
mess.set_test(false);
dump_message_bytes (&mess, "test_required_bool_0");
mess.set_test(true);
dump_message_bytes (&mess, "test_required_bool_1");
}
static void dump_test_required_enum_small (void)
{
TestMessRequiredEnumSmall mess;
mess.set_test(VALUE);
dump_message_bytes (&mess, "test_required_enum_small_VALUE");
mess.set_test(OTHER_VALUE);
dump_message_bytes (&mess, "test_required_enum_small_OTHER_VALUE");
}
static void dump_test_required_enum (void)
{
TestMessRequiredEnum mess;
mess.set_test (VALUENEG1);
dump_message_bytes (&mess, "test_required_enum_neg1");
mess.set_test (VALUE0);
dump_message_bytes (&mess, "test_required_enum_0");
mess.set_test (VALUE1);
dump_message_bytes (&mess, "test_required_enum_1");
mess.set_test (VALUE127);
dump_message_bytes (&mess, "test_required_enum_127");
mess.set_test (VALUE128);
dump_message_bytes (&mess, "test_required_enum_128");
mess.set_test (VALUE16383);
dump_message_bytes (&mess, "test_required_enum_16383");
mess.set_test (VALUE16384);
dump_message_bytes (&mess, "test_required_enum_16384");
mess.set_test (VALUE2097151);
dump_message_bytes (&mess, "test_required_enum_2097151");
mess.set_test (VALUE2097152);
dump_message_bytes (&mess, "test_required_enum_2097152");
mess.set_test (VALUE268435455);
dump_message_bytes (&mess, "test_required_enum_268435455");
mess.set_test (VALUE268435456);
dump_message_bytes (&mess, "test_required_enum_268435456");
}
static void dump_test_required_string (void)
{
TestMessRequiredString mess;
mess.set_test ("");
dump_message_bytes(&mess, "test_required_string_empty");
mess.set_test ("hello");
dump_message_bytes(&mess, "test_required_string_hello");
mess.set_test ("two hundred xs follow: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
dump_message_bytes(&mess, "test_required_string_long");
}
static void dump_test_required_bytes (void)
{
TestMessRequiredBytes mess;
mess.set_test ("");
dump_message_bytes (&mess, "test_required_bytes_empty");
mess.set_test ("hello");
dump_message_bytes (&mess, "test_required_bytes_hello");
mess.set_test (std::string("\1") + '\0' + "\375\2\4");
dump_message_bytes (&mess, "test_required_bytes_random");
}
static void dump_test_required_message (void)
{
TestMessRequiredMessage mess;
mess.mutable_test()->set_test(0);
dump_message_bytes (&mess, "test_required_submess_0");
mess.mutable_test()->set_test(42);
dump_message_bytes (&mess, "test_required_submess_42");
}
static void dump_test_optional_int32 (void)
{
TestMessOptional opt;
opt.set_test_int32 (INT32_MIN);
dump_message_bytes (&opt, "test_optional_int32_min");
opt.set_test_int32 (-1);
dump_message_bytes (&opt, "test_optional_int32_m1");
opt.set_test_int32 (0);
dump_message_bytes (&opt, "test_optional_int32_0");
opt.set_test_int32 (666);
dump_message_bytes (&opt, "test_optional_int32_666");
opt.set_test_int32 (INT32_MAX);
dump_message_bytes (&opt, "test_optional_int32_max");
}
static void dump_test_optional_sint32 (void)
{
TestMessOptional opt;
opt.set_test_sint32 (INT32_MIN);
dump_message_bytes (&opt, "test_optional_sint32_min");
opt.set_test_sint32 (-1);
dump_message_bytes (&opt, "test_optional_sint32_m1");
opt.set_test_sint32 (0);
dump_message_bytes (&opt, "test_optional_sint32_0");
opt.set_test_sint32 (666);
dump_message_bytes (&opt, "test_optional_sint32_666");
opt.set_test_sint32 (INT32_MAX);
dump_message_bytes (&opt, "test_optional_sint32_max");
}
static void dump_test_optional_sfixed32 (void)
{
TestMessOptional opt;
opt.set_test_sfixed32 (INT32_MIN);
dump_message_bytes (&opt, "test_optional_sfixed32_min");
opt.set_test_sfixed32 (-1);
dump_message_bytes (&opt, "test_optional_sfixed32_m1");
opt.set_test_sfixed32 (0);
dump_message_bytes (&opt, "test_optional_sfixed32_0");
opt.set_test_sfixed32 (666);
dump_message_bytes (&opt, "test_optional_sfixed32_666");
opt.set_test_sfixed32 (INT32_MAX);
dump_message_bytes (&opt, "test_optional_sfixed32_max");
}
static void dump_test_optional_int64 (void)
{
TestMessOptional opt;
opt.set_test_int64 (INT64_MIN);
dump_message_bytes (&opt, "test_optional_int64_min");
opt.set_test_int64 (-1111111111LL);
dump_message_bytes (&opt, "test_optional_int64_m1111111111LL");
opt.set_test_int64 (0);
dump_message_bytes (&opt, "test_optional_int64_0");
opt.set_test_int64 (QUINTILLION);
dump_message_bytes (&opt, "test_optional_int64_quintillion");
opt.set_test_int64 (INT64_MAX);
dump_message_bytes (&opt, "test_optional_int64_max");
}
static void dump_test_optional_sint64 (void)
{
TestMessOptional opt;
opt.set_test_sint64 (INT64_MIN);
dump_message_bytes (&opt, "test_optional_sint64_min");
opt.set_test_sint64 (-1111111111LL);
dump_message_bytes (&opt, "test_optional_sint64_m1111111111LL");
opt.set_test_sint64 (0);
dump_message_bytes (&opt, "test_optional_sint64_0");
opt.set_test_sint64 (QUINTILLION);
dump_message_bytes (&opt, "test_optional_sint64_quintillion");
opt.set_test_sint64 (INT64_MAX);
dump_message_bytes (&opt, "test_optional_sint64_max");
}
static void dump_test_optional_sfixed64 (void)
{
TestMessOptional opt;
opt.set_test_sfixed64 (INT64_MIN);
dump_message_bytes (&opt, "test_optional_sfixed64_min");
opt.set_test_sfixed64 (-1111111111LL);
dump_message_bytes (&opt, "test_optional_sfixed64_m1111111111LL");
opt.set_test_sfixed64 (0);
dump_message_bytes (&opt, "test_optional_sfixed64_0");
opt.set_test_sfixed64 (QUINTILLION);
dump_message_bytes (&opt, "test_optional_sfixed64_quintillion");
opt.set_test_sfixed64 (INT64_MAX);
dump_message_bytes (&opt, "test_optional_sfixed64_max");
}
static void dump_test_optional_uint32 (void)
{
TestMessOptional opt;
opt.set_test_uint32(0);
dump_message_bytes (&opt, "test_optional_uint32_0");
opt.set_test_uint32(669);
dump_message_bytes (&opt, "test_optional_uint32_669");
opt.set_test_uint32(UINT32_MAX);
dump_message_bytes (&opt, "test_optional_uint32_max");
}
static void dump_test_optional_fixed32 (void)
{
TestMessOptional opt;
opt.set_test_fixed32(0);
dump_message_bytes (&opt, "test_optional_fixed32_0");
opt.set_test_fixed32(669);
dump_message_bytes (&opt, "test_optional_fixed32_669");
opt.set_test_fixed32(UINT32_MAX);
dump_message_bytes (&opt, "test_optional_fixed32_max");
}
static void dump_test_optional_uint64 (void)
{
TestMessOptional opt;
opt.set_test_uint64(0);
dump_message_bytes (&opt, "test_optional_uint64_0");
opt.set_test_uint64(669669669669669ULL);
dump_message_bytes (&opt, "test_optional_uint64_669669669669669");
opt.set_test_uint64(UINT64_MAX);
dump_message_bytes (&opt, "test_optional_uint64_max");
}
static void dump_test_optional_fixed64 (void)
{
TestMessOptional opt;
opt.set_test_fixed64(0);
dump_message_bytes (&opt, "test_optional_fixed64_0");
opt.set_test_fixed64(669669669669669ULL);
dump_message_bytes (&opt, "test_optional_fixed64_669669669669669");
opt.set_test_fixed64(UINT64_MAX);
dump_message_bytes (&opt, "test_optional_fixed64_max");
}
static void dump_test_optional_float (void)
{
TestMessOptional opt;
opt.set_test_float (-100);
dump_message_bytes (&opt, "test_optional_float_m100");
opt.set_test_float (0);
dump_message_bytes (&opt, "test_optional_float_0");
opt.set_test_float (141243);
dump_message_bytes (&opt, "test_optional_float_141243");
}
static void dump_test_optional_double (void)
{
TestMessOptional opt;
opt.set_test_double (-100);
dump_message_bytes (&opt, "test_optional_double_m100");
opt.set_test_double (0);
dump_message_bytes (&opt, "test_optional_double_0");
opt.set_test_double (141243);
dump_message_bytes (&opt, "test_optional_double_141243");
}
static void dump_test_optional_bool (void)
{
TestMessOptional opt;
opt.set_test_boolean (false);
dump_message_bytes (&opt, "test_optional_bool_0");
opt.set_test_boolean (true);
dump_message_bytes (&opt, "test_optional_bool_1");
}
static void dump_test_optional_enum_small (void)
{
TestMessOptional opt;
opt.set_test_enum_small (NEG_VALUE);
dump_message_bytes (&opt, "test_optional_enum_small_neg1");
opt.set_test_enum_small (VALUE);
dump_message_bytes (&opt, "test_optional_enum_small_0");
opt.set_test_enum_small (OTHER_VALUE);
dump_message_bytes (&opt, "test_optional_enum_small_1");
}
static void dump_test_optional_enum (void)
{
TestMessOptional opt;
//for a in 0 1 127 128 16383 16384 2097151 2097152 268435455 268435456 ; do
//echo ' opt.set_test_enum (VALUE'$a');
//dump_message_bytes (&opt, "test_optional_enum_'$a'");'
//done
opt.set_test_enum (VALUENEG1);
dump_message_bytes (&opt, "test_optional_enum_neg1");
opt.set_test_enum (VALUE0);
dump_message_bytes (&opt, "test_optional_enum_0");
opt.set_test_enum (VALUE1);
dump_message_bytes (&opt, "test_optional_enum_1");
opt.set_test_enum (VALUE127);
dump_message_bytes (&opt, "test_optional_enum_127");
opt.set_test_enum (VALUE128);
dump_message_bytes (&opt, "test_optional_enum_128");
opt.set_test_enum (VALUE16383);
dump_message_bytes (&opt, "test_optional_enum_16383");
opt.set_test_enum (VALUE16384);
dump_message_bytes (&opt, "test_optional_enum_16384");
opt.set_test_enum (VALUE2097151);
dump_message_bytes (&opt, "test_optional_enum_2097151");
opt.set_test_enum (VALUE2097152);
dump_message_bytes (&opt, "test_optional_enum_2097152");
opt.set_test_enum (VALUE268435455);
dump_message_bytes (&opt, "test_optional_enum_268435455");
opt.set_test_enum (VALUE268435456);
dump_message_bytes (&opt, "test_optional_enum_268435456");
}
static void dump_test_optional_string (void)
{
TestMessOptional opt;
opt.set_test_string ("");
dump_message_bytes (&opt, "test_optional_string_empty");
opt.set_test_string ("hello");
dump_message_bytes (&opt, "test_optional_string_hello");
}
static void dump_test_optional_bytes (void)
{
TestMessOptional opt;
opt.set_test_bytes ("");
dump_message_bytes (&opt, "test_optional_bytes_empty");
opt.set_test_bytes ("hello");
dump_message_bytes (&opt, "test_optional_bytes_hello");
opt.set_test_bytes (std::string("\1") + '\0' + "\375\2\4");
dump_message_bytes (&opt, "test_optional_bytes_random");
}
static void dump_test_optional_message (void)
{
TestMessOptional opt;
opt.mutable_test_message()->set_test(0);
dump_message_bytes (&opt, "test_optional_submess_0");
opt.mutable_test_message()->set_test(42);
dump_message_bytes (&opt, "test_optional_submess_42");
}
static void dump_test_oneof_merge (void)
{
#define SWAP(a, b) temp = a, a = b, b = temp
google::protobuf::Message *temp;
TestMessOptional opt[6];
google::protobuf::Message *msgs[6] = { &opt[0], &opt[1], &opt[2], &opt[3],
&opt[4], &opt[5] };
opt[0].set_test_bytes ("hello");
opt[1].mutable_test_message()->set_test (42);
opt[2].set_test_string ("");
opt[3].set_test_int32 (666);
opt[4].set_test_float (333);
opt[5].set_test_double (444455555);
dump_messages_bytes (6, msgs, "test_oneof_merge_double");
SWAP (msgs[5], msgs[4]);
dump_messages_bytes (6, msgs, "test_oneof_merge_float");
SWAP (msgs[5], msgs[3]);
dump_messages_bytes (6, msgs, "test_oneof_merge_int32");
SWAP (msgs[5], msgs[2]);
dump_messages_bytes (6, msgs, "test_oneof_merge_string");
SWAP (msgs[5], msgs[1]);
dump_messages_bytes (6, msgs, "test_oneof_merge_submess");
SWAP (msgs[5], msgs[0]);
dump_messages_bytes (6, msgs, "test_oneof_merge_bytes");
#undef SWAP
}
#define DUMP_STATIC_ARRAY_GENERIC(member, static_array, output_array_name) \
do{ \
TestMess mess; \
for (unsigned i = 0; i < N_ELEMENTS (static_array); i++) \
mess.add_##member(static_array[i]); \
dump_message_bytes(&mess, output_array_name); \
}while(0)
static void dump_test_repeated_int32 (void)
{
#define DUMP_STATIC_ARRAY(static_array, output_array_name) \
DUMP_STATIC_ARRAY_GENERIC(test_int32, static_array, output_array_name)
DUMP_STATIC_ARRAY (int32_arr0, "test_repeated_int32_arr0");
DUMP_STATIC_ARRAY (int32_arr1, "test_repeated_int32_arr1");
DUMP_STATIC_ARRAY (int32_arr_min_max, "test_repeated_int32_arr_min_max");
#undef DUMP_STATIC_ARRAY
}
static void dump_test_repeated_sint32 (void)
{
#define DUMP_STATIC_ARRAY(static_array, output_array_name) \
DUMP_STATIC_ARRAY_GENERIC(test_sint32, static_array, output_array_name)
DUMP_STATIC_ARRAY (int32_arr0, "test_repeated_sint32_arr0");
DUMP_STATIC_ARRAY (int32_arr1, "test_repeated_sint32_arr1");
DUMP_STATIC_ARRAY (int32_arr_min_max, "test_repeated_sint32_arr_min_max");
#undef DUMP_STATIC_ARRAY
}
static void dump_test_repeated_uint32 (void)
{
#define DUMP_STATIC_ARRAY(static_array, output_array_name) \
DUMP_STATIC_ARRAY_GENERIC(test_uint32, static_array, output_array_name)
DUMP_STATIC_ARRAY (uint32_roundnumbers, "test_repeated_uint32_roundnumbers");
DUMP_STATIC_ARRAY (uint32_0_max, "test_repeated_uint32_0_max");
#undef DUMP_STATIC_ARRAY
}
static void dump_test_repeated_sfixed32 (void)
{
#define DUMP_STATIC_ARRAY(static_array, output_array_name) \
DUMP_STATIC_ARRAY_GENERIC(test_sfixed32, static_array, output_array_name)
DUMP_STATIC_ARRAY (int32_arr0, "test_repeated_sfixed32_arr0");
DUMP_STATIC_ARRAY (int32_arr1, "test_repeated_sfixed32_arr1");
DUMP_STATIC_ARRAY (int32_arr_min_max, "test_repeated_sfixed32_arr_min_max");
#undef DUMP_STATIC_ARRAY
}
static void dump_test_repeated_fixed32 (void)
{
#define DUMP_STATIC_ARRAY(static_array, output_array_name) \
DUMP_STATIC_ARRAY_GENERIC(test_fixed32, static_array, output_array_name)
DUMP_STATIC_ARRAY (uint32_roundnumbers, "test_repeated_fixed32_roundnumbers");
DUMP_STATIC_ARRAY (uint32_0_max, "test_repeated_fixed32_0_max");
#undef DUMP_STATIC_ARRAY
}
static void dump_test_repeated_int64 (void)
{
#define DUMP_STATIC_ARRAY(static_array, output_array_name) \
DUMP_STATIC_ARRAY_GENERIC(test_int64, static_array, output_array_name)
DUMP_STATIC_ARRAY (int64_roundnumbers, "test_repeated_int64_roundnumbers");
DUMP_STATIC_ARRAY (int64_min_max, "test_repeated_int64_min_max");
#undef DUMP_STATIC_ARRAY
}
static void dump_test_repeated_sint64 (void)
{
#define DUMP_STATIC_ARRAY(static_array, output_array_name) \
DUMP_STATIC_ARRAY_GENERIC(test_sint64, static_array, output_array_name)
DUMP_STATIC_ARRAY (int64_roundnumbers, "test_repeated_sint64_roundnumbers");
DUMP_STATIC_ARRAY (int64_min_max, "test_repeated_sint64_min_max");
#undef DUMP_STATIC_ARRAY
}
static void dump_test_repeated_sfixed64 (void)
{
#define DUMP_STATIC_ARRAY(static_array, output_array_name) \
DUMP_STATIC_ARRAY_GENERIC(test_sfixed64, static_array, output_array_name)
DUMP_STATIC_ARRAY (int64_roundnumbers, "test_repeated_sfixed64_roundnumbers");
DUMP_STATIC_ARRAY (int64_min_max, "test_repeated_sfixed64_min_max");
#undef DUMP_STATIC_ARRAY
}
static void dump_test_repeated_uint64 (void)
{
#define DUMP_STATIC_ARRAY(static_array, output_array_name) \
DUMP_STATIC_ARRAY_GENERIC (test_uint64, static_array, output_array_name)
DUMP_STATIC_ARRAY(uint64_roundnumbers, "test_repeated_uint64_roundnumbers");
DUMP_STATIC_ARRAY(uint64_0_1_max, "test_repeated_uint64_0_1_max");
DUMP_STATIC_ARRAY(uint64_random, "test_repeated_uint64_random");
#undef DUMP_STATIC_ARRAY
}
static void dump_test_repeated_fixed64 (void)
{
#define DUMP_STATIC_ARRAY(static_array, output_array_name) \
DUMP_STATIC_ARRAY_GENERIC(test_fixed64, static_array, output_array_name)
DUMP_STATIC_ARRAY(uint64_roundnumbers, "test_repeated_fixed64_roundnumbers");
DUMP_STATIC_ARRAY(uint64_0_1_max, "test_repeated_fixed64_0_1_max");
DUMP_STATIC_ARRAY(uint64_random, "test_repeated_fixed64_random");
#undef DUMP_STATIC_ARRAY
}
static void dump_test_repeated_float (void)
{
#define DUMP_STATIC_ARRAY(static_array, output_array_name) \
DUMP_STATIC_ARRAY_GENERIC(test_float, static_array, output_array_name)
DUMP_STATIC_ARRAY(float_random, "test_repeated_float_random");
#undef DUMP_STATIC_ARRAY
}
static void dump_test_repeated_double (void)
{
#define DUMP_STATIC_ARRAY(static_array, output_array_name) \
DUMP_STATIC_ARRAY_GENERIC(test_double, static_array, output_array_name)
DUMP_STATIC_ARRAY(double_random, "test_repeated_double_random");
#undef DUMP_STATIC_ARRAY
}
static void dump_test_repeated_boolean (void)
{
#define DUMP_STATIC_ARRAY(static_array, output_array_name) \
DUMP_STATIC_ARRAY_GENERIC(test_boolean, static_array, output_array_name)
DUMP_STATIC_ARRAY(boolean_0, "test_repeated_boolean_0");
DUMP_STATIC_ARRAY(boolean_1, "test_repeated_boolean_1");
DUMP_STATIC_ARRAY(boolean_random, "test_repeated_boolean_random");
#undef DUMP_STATIC_ARRAY
}
static void dump_test_repeated_enum_small (void)
{
#define DUMP_STATIC_ARRAY(static_array, output_array_name) \
DUMP_STATIC_ARRAY_GENERIC (test_enum_small, static_array, output_array_name)
DUMP_STATIC_ARRAY (enum_small_0, "test_repeated_enum_small_0");
DUMP_STATIC_ARRAY (enum_small_1, "test_repeated_enum_small_1");
DUMP_STATIC_ARRAY (enum_small_random, "test_repeated_enum_small_random");
#undef DUMP_STATIC_ARRAY
}
static void dump_test_repeated_enum (void)
{
#define DUMP_STATIC_ARRAY(static_array, output_array_name) \
DUMP_STATIC_ARRAY_GENERIC (test_enum, static_array, output_array_name)
DUMP_STATIC_ARRAY (enum_0, "test_repeated_enum_0");
DUMP_STATIC_ARRAY (enum_1, "test_repeated_enum_1");
DUMP_STATIC_ARRAY (enum_random, "test_repeated_enum_random");
#undef DUMP_STATIC_ARRAY
}
static void dump_test_repeated_string (void)
{
#define DUMP_STATIC_ARRAY(static_array, output_array_name) \
DUMP_STATIC_ARRAY_GENERIC (test_string, static_array, output_array_name)
DUMP_STATIC_ARRAY (repeated_strings_0, "test_repeated_strings_0");
DUMP_STATIC_ARRAY (repeated_strings_1, "test_repeated_strings_1");
DUMP_STATIC_ARRAY (repeated_strings_2, "test_repeated_strings_2");
DUMP_STATIC_ARRAY (repeated_strings_3, "test_repeated_strings_3");
#undef DUMP_STATIC_ARRAY
}
static void dump_test_repeated_bytes (void)
{
TestMess mess;
mess.add_test_bytes(std::string("text"));
mess.add_test_bytes(std::string("str\1\2\3\4\5") + '\0');
mess.add_test_bytes(std::string("gobble") + '\0' + "foo");
dump_message_bytes(&mess, "test_repeated_bytes_0");
}
static void dump_test_repeated_SubMess (void)
{
TestMess mess;
mess.add_test_message()->set_test(0);
mess.add_test_message()->set_test(0);
mess.add_test_message()->set_test(0);
dump_message_bytes(&mess, "test_repeated_submess_0");
mess.clear_test_message();
mess.add_test_message()->set_test(42);
mess.add_test_message()->set_test(-10000);
mess.add_test_message()->set_test(667);
dump_message_bytes(&mess, "test_repeated_submess_1");
}
#undef DUMP_STATIC_ARRAY_GENERIC
#define DUMP_STATIC_ARRAY_GENERIC(member, static_array, output_array_name) \
do{ \
TestMessPacked mess; \
for (unsigned i = 0; i < N_ELEMENTS (static_array); i++) \
mess.add_##member(static_array[i]); \
dump_message_bytes(&mess, output_array_name); \
}while(0)
static void dump_test_packed_repeated_int32 (void)
{
#define DUMP_STATIC_ARRAY(static_array, output_array_name) \
DUMP_STATIC_ARRAY_GENERIC(test_int32, static_array, output_array_name)
DUMP_STATIC_ARRAY (int32_arr0, "test_packed_repeated_int32_arr0");
DUMP_STATIC_ARRAY (int32_arr1, "test_packed_repeated_int32_arr1");
DUMP_STATIC_ARRAY (int32_arr_min_max, "test_packed_repeated_int32_arr_min_max");
#undef DUMP_STATIC_ARRAY
}
static void dump_test_packed_repeated_sint32 (void)
{
#define DUMP_STATIC_ARRAY(static_array, output_array_name) \
DUMP_STATIC_ARRAY_GENERIC(test_sint32, static_array, output_array_name)
DUMP_STATIC_ARRAY (int32_arr0, "test_packed_repeated_sint32_arr0");
DUMP_STATIC_ARRAY (int32_arr1, "test_packed_repeated_sint32_arr1");
DUMP_STATIC_ARRAY (int32_arr_min_max, "test_packed_repeated_sint32_arr_min_max");
#undef DUMP_STATIC_ARRAY
}
static void dump_test_packed_repeated_uint32 (void)
{
#define DUMP_STATIC_ARRAY(static_array, output_array_name) \
DUMP_STATIC_ARRAY_GENERIC(test_uint32, static_array, output_array_name)
DUMP_STATIC_ARRAY (uint32_roundnumbers, "test_packed_repeated_uint32_roundnumbers");
DUMP_STATIC_ARRAY (uint32_0_max, "test_packed_repeated_uint32_0_max");
#undef DUMP_STATIC_ARRAY
}
static void dump_test_packed_repeated_sfixed32 (void)
{
#define DUMP_STATIC_ARRAY(static_array, output_array_name) \
DUMP_STATIC_ARRAY_GENERIC(test_sfixed32, static_array, output_array_name)
DUMP_STATIC_ARRAY (int32_arr0, "test_packed_repeated_sfixed32_arr0");
DUMP_STATIC_ARRAY (int32_arr1, "test_packed_repeated_sfixed32_arr1");
DUMP_STATIC_ARRAY (int32_arr_min_max, "test_packed_repeated_sfixed32_arr_min_max");
#undef DUMP_STATIC_ARRAY
}
static void dump_test_packed_repeated_fixed32 (void)
{
#define DUMP_STATIC_ARRAY(static_array, output_array_name) \
DUMP_STATIC_ARRAY_GENERIC(test_fixed32, static_array, output_array_name)
DUMP_STATIC_ARRAY (uint32_roundnumbers, "test_packed_repeated_fixed32_roundnumbers");
DUMP_STATIC_ARRAY (uint32_0_max, "test_packed_repeated_fixed32_0_max");
#undef DUMP_STATIC_ARRAY
}
static void dump_test_packed_repeated_int64 (void)
{
#define DUMP_STATIC_ARRAY(static_array, output_array_name) \
DUMP_STATIC_ARRAY_GENERIC(test_int64, static_array, output_array_name)
DUMP_STATIC_ARRAY (int64_roundnumbers, "test_packed_repeated_int64_roundnumbers");
DUMP_STATIC_ARRAY (int64_min_max, "test_packed_repeated_int64_min_max");
#undef DUMP_STATIC_ARRAY
}
static void dump_test_packed_repeated_sint64 (void)
{
#define DUMP_STATIC_ARRAY(static_array, output_array_name) \
DUMP_STATIC_ARRAY_GENERIC(test_sint64, static_array, output_array_name)
DUMP_STATIC_ARRAY (int64_roundnumbers, "test_packed_repeated_sint64_roundnumbers");
DUMP_STATIC_ARRAY (int64_min_max, "test_packed_repeated_sint64_min_max");
#undef DUMP_STATIC_ARRAY
}
static void dump_test_packed_repeated_sfixed64 (void)
{
#define DUMP_STATIC_ARRAY(static_array, output_array_name) \
DUMP_STATIC_ARRAY_GENERIC(test_sfixed64, static_array, output_array_name)
DUMP_STATIC_ARRAY (int64_roundnumbers, "test_packed_repeated_sfixed64_roundnumbers");
DUMP_STATIC_ARRAY (int64_min_max, "test_packed_repeated_sfixed64_min_max");
#undef DUMP_STATIC_ARRAY
}
static void dump_test_packed_repeated_uint64 (void)
{
#define DUMP_STATIC_ARRAY(static_array, output_array_name) \
DUMP_STATIC_ARRAY_GENERIC (test_uint64, static_array, output_array_name)
DUMP_STATIC_ARRAY(uint64_roundnumbers, "test_packed_repeated_uint64_roundnumbers");
DUMP_STATIC_ARRAY(uint64_0_1_max, "test_packed_repeated_uint64_0_1_max");
DUMP_STATIC_ARRAY(uint64_random, "test_packed_repeated_uint64_random");
#undef DUMP_STATIC_ARRAY
}
static void dump_test_packed_repeated_fixed64 (void)
{
#define DUMP_STATIC_ARRAY(static_array, output_array_name) \
DUMP_STATIC_ARRAY_GENERIC(test_fixed64, static_array, output_array_name)
DUMP_STATIC_ARRAY(uint64_roundnumbers, "test_packed_repeated_fixed64_roundnumbers");
DUMP_STATIC_ARRAY(uint64_0_1_max, "test_packed_repeated_fixed64_0_1_max");
DUMP_STATIC_ARRAY(uint64_random, "test_packed_repeated_fixed64_random");
#undef DUMP_STATIC_ARRAY
}
static void dump_test_packed_repeated_float (void)
{
#define DUMP_STATIC_ARRAY(static_array, output_array_name) \
DUMP_STATIC_ARRAY_GENERIC(test_float, static_array, output_array_name)
DUMP_STATIC_ARRAY(float_random, "test_packed_repeated_float_random");
#undef DUMP_STATIC_ARRAY
}
static void dump_test_packed_repeated_double (void)
{
#define DUMP_STATIC_ARRAY(static_array, output_array_name) \
DUMP_STATIC_ARRAY_GENERIC(test_double, static_array, output_array_name)
DUMP_STATIC_ARRAY(double_random, "test_packed_repeated_double_random");
#undef DUMP_STATIC_ARRAY
}
static void dump_test_packed_repeated_boolean (void)
{
#define DUMP_STATIC_ARRAY(static_array, output_array_name) \
DUMP_STATIC_ARRAY_GENERIC(test_boolean, static_array, output_array_name)
DUMP_STATIC_ARRAY(boolean_0, "test_packed_repeated_boolean_0");
DUMP_STATIC_ARRAY(boolean_1, "test_packed_repeated_boolean_1");
DUMP_STATIC_ARRAY(boolean_random, "test_packed_repeated_boolean_random");
#undef DUMP_STATIC_ARRAY
}
static void dump_test_packed_repeated_enum_small (void)
{
#define DUMP_STATIC_ARRAY(static_array, output_array_name) \
DUMP_STATIC_ARRAY_GENERIC (test_enum_small, static_array, output_array_name)
DUMP_STATIC_ARRAY (enum_small_0, "test_packed_repeated_enum_small_0");
DUMP_STATIC_ARRAY (enum_small_1, "test_packed_repeated_enum_small_1");
DUMP_STATIC_ARRAY (enum_small_random, "test_packed_repeated_enum_small_random");
#undef DUMP_STATIC_ARRAY
}
static void dump_test_packed_repeated_enum (void)
{
#define DUMP_STATIC_ARRAY(static_array, output_array_name) \
DUMP_STATIC_ARRAY_GENERIC (test_enum, static_array, output_array_name)
DUMP_STATIC_ARRAY (enum_0, "test_packed_repeated_enum_0");
DUMP_STATIC_ARRAY (enum_1, "test_packed_repeated_enum_1");
DUMP_STATIC_ARRAY (enum_random, "test_packed_repeated_enum_random");
#undef DUMP_STATIC_ARRAY
}
static void dump_test_unknown_fields (void)
{
EmptyMess mess;
const google::protobuf::Message::Reflection *reflection = mess.GetReflection();
google::protobuf::UnknownFieldSet *fs = reflection->MutableUnknownFields(&mess);
#if GOOGLE_PROTOBUF_VERSION >= 2001000
fs->AddVarint(5454, 255);
fs->AddFixed32(5555, 260);
#else
google::protobuf::UnknownField *f;
f = fs->AddField(5454);
f->add_varint(255);
f = fs->AddField(5555);
f->add_fixed32(260);
#endif
dump_message_bytes (&mess, "test_unknown_fields_0");
fs->Clear();
#if GOOGLE_PROTOBUF_VERSION >= 2001000
fs->AddLengthDelimited(6666, "xxxxxxxx");
fs->AddFixed64(7777, 0x10101);
#else
f = fs->AddField(6666);
f->add_length_delimited("xxxxxxxx");
f = fs->AddField(7777);
f->add_fixed64(0x10101);
#endif
dump_message_bytes (&mess, "test_unknown_fields_1");
}
static void dump_test_submess_merge (void)
{
TestMessSubMess mess1, mess2, merged1, merged2;
/* Repeated merge */
mess1.mutable_rep_mess()->add_test_int32(1);
mess1.mutable_rep_mess()->add_test_int32(2);
mess2.mutable_rep_mess()->add_test_int32(3);
mess2.mutable_rep_mess()->add_test_int32(4);
mess1.mutable_rep_mess()->add_test_string("hello ");
mess2.mutable_rep_mess()->add_test_string("world");
mess1.mutable_rep_mess()->add_test_bytes("\001\002\003");
mess2.mutable_rep_mess()->add_test_bytes("\004\005\006");
mess1.mutable_rep_mess()->add_test_message()->set_test(111);
mess2.mutable_rep_mess()->add_test_message()->set_test(222);
/* Optional merge */
mess1.mutable_opt_mess()->set_test_sint32(-1);
mess2.mutable_opt_mess()->set_test_sint32(-2);
mess1.mutable_opt_mess()->set_test_float(333);
mess2.mutable_opt_mess()->set_test_double(444);
mess1.mutable_opt_mess()->set_test_bytes("\001\002\003");
mess1.mutable_opt_mess()->mutable_test_message()->set_test(111);
mess2.mutable_opt_mess()->set_test_string("hello");
/* Oneof merge */
mess1.mutable_oneof_mess()->set_opt_int (1);
mess2.mutable_oneof_mess()->mutable_test_message()->set_test(111);
/* Required merge */
mess1.mutable_req_mess()->set_test(1);
mess2.mutable_req_mess()->set_test(2);
/* Default value merge */
mess1.mutable_def_mess()->set_v_int32(111);
mess1.mutable_def_mess()->set_v_string("hello");
mess2.mutable_def_mess()->set_v_bytes("\001\002\003");
mess2.mutable_def_mess()->set_v_double(444);
/* Merge both ways and encode the merged and unmerged messages */
merged1.CopyFrom(mess1);
merged1.MergeFrom(mess2);
merged2.CopyFrom(mess2);
merged2.MergeFrom(mess1);
google::protobuf::Message *msgs[] = { &mess1, &mess2 };
dump_messages_bytes (2, msgs, "test_submess_unmerged1");
msgs[0] = &mess2;
msgs[1] = &mess1;
dump_messages_bytes (2, msgs, "test_submess_unmerged2");
dump_message_bytes(&merged1, "test_submess_merged1");
dump_message_bytes(&merged2, "test_submess_merged2");
}
int main()
{
dump_test_enum_small ();
dump_test_enum_big ();
dump_test_field_numbers ();
dump_test_required_int32 ();
dump_test_required_sint32 ();
dump_test_required_sfixed32 ();
dump_test_required_uint32 ();
dump_test_required_fixed32 ();
dump_test_required_int64 ();
dump_test_required_sint64 ();
dump_test_required_sfixed64 ();
dump_test_required_uint64 ();
dump_test_required_fixed64 ();
dump_test_required_float ();
dump_test_required_double ();
dump_test_required_bool ();
dump_test_required_enum_small ();
dump_test_required_enum ();
dump_test_required_string ();
dump_test_required_bytes ();
dump_test_required_message ();
dump_test_optional_int32 ();
dump_test_optional_sint32 ();
dump_test_optional_sfixed32 ();
dump_test_optional_int64 ();
dump_test_optional_sint64 ();
dump_test_optional_sfixed64 ();
dump_test_optional_uint32 ();
dump_test_optional_fixed32 ();
dump_test_optional_uint64 ();
dump_test_optional_fixed64 ();
dump_test_optional_float ();
dump_test_optional_double ();
dump_test_optional_bool ();
dump_test_optional_enum_small ();
dump_test_optional_enum ();
dump_test_optional_string ();
dump_test_optional_bytes ();
dump_test_optional_message ();
dump_test_oneof_merge ();
dump_test_repeated_int32 ();
dump_test_repeated_sint32 ();
dump_test_repeated_uint32 ();
dump_test_repeated_sfixed32 ();
dump_test_repeated_fixed32 ();
dump_test_repeated_int64 ();
dump_test_repeated_sint64 ();
dump_test_repeated_sfixed64 ();
dump_test_repeated_uint64 ();
dump_test_repeated_fixed64 ();
dump_test_repeated_float ();
dump_test_repeated_double ();
dump_test_repeated_boolean ();
dump_test_repeated_enum_small ();
dump_test_repeated_enum ();
dump_test_repeated_string ();
dump_test_repeated_bytes ();
dump_test_repeated_SubMess ();
dump_test_packed_repeated_int32 ();
dump_test_packed_repeated_sint32 ();
dump_test_packed_repeated_uint32 ();
dump_test_packed_repeated_sfixed32 ();
dump_test_packed_repeated_fixed32 ();
dump_test_packed_repeated_int64 ();
dump_test_packed_repeated_sint64 ();
dump_test_packed_repeated_sfixed64 ();
dump_test_packed_repeated_uint64 ();
dump_test_packed_repeated_fixed64 ();
dump_test_packed_repeated_float ();
dump_test_packed_repeated_double ();
dump_test_packed_repeated_boolean ();
dump_test_packed_repeated_enum_small ();
dump_test_packed_repeated_enum ();
dump_test_unknown_fields ();
dump_test_submess_merge ();
return 0;
}
|