Commit cfb919f1 authored by Andrei Nigmatulin's avatar Andrei Nigmatulin Committed by Robert Edmonds

added unit test for required_fields_bitmap hashing issue

parent 613b3675
......@@ -1595,6 +1595,23 @@ test_alloc_fail (void)
free (packed);
}
/* This test checks that protobuf decoder is capable of detecting special
cases of incomplete messages. The message should have at least two required
fields field1 and field129 with positions pos1 and pos2 (no matter what the
field numbers are), such as (pos1 % 128) == (pos2 % 128). The decoder must
return NULL instead of incomplete message with field129 missing. */
static void test_required_fields_bitmap_hashing(void)
{
const uint8_t source[] = {
(1 << 3) | PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED,
sizeof("hello") - 1,
'h', 'e', 'l', 'l', 'o'
};
Foo__TestRequiredFieldsHashing128 *msg;
msg = foo__test_required_fields_hashing128__unpack(NULL, sizeof(source), source);
assert (msg == NULL);
}
/* === simple testing framework === */
typedef void (*TestFunc) (void);
......@@ -1699,6 +1716,8 @@ static Test tests[] =
{ "test free unpacked", test_alloc_free_all },
{ "test alloc failure", test_alloc_fail },
{ "test required_fields_bitmap 128-bit hashing", test_required_fields_bitmap_hashing },
};
#define n_tests (sizeof(tests)/sizeof(Test))
......
......@@ -221,3 +221,135 @@ message AllocValues {
required bytes a_bytes = 4;
required DefaultRequiredValues a_mess = 5;
}
message TestRequiredFieldsHashing128 {
required string field1 = 1;
optional string field2 = 2;
optional string field3 = 3;
optional string field4 = 4;
optional string field5 = 5;
optional string field6 = 6;
optional string field7 = 7;
optional string field8 = 8;
optional string field9 = 9;
optional string field10 = 10;
optional string field11 = 11;
optional string field12 = 12;
optional string field13 = 13;
optional string field14 = 14;
optional string field15 = 15;
optional string field16 = 16;
optional string field17 = 17;
optional string field18 = 18;
optional string field19 = 19;
optional string field20 = 20;
optional string field21 = 21;
optional string field22 = 22;
optional string field23 = 23;
optional string field24 = 24;
optional string field25 = 25;
optional string field26 = 26;
optional string field27 = 27;
optional string field28 = 28;
optional string field29 = 29;
optional string field30 = 30;
optional string field31 = 31;
optional string field32 = 32;
optional string field33 = 33;
optional string field34 = 34;
optional string field35 = 35;
optional string field36 = 36;
optional string field37 = 37;
optional string field38 = 38;
optional string field39 = 39;
optional string field40 = 40;
optional string field41 = 41;
optional string field42 = 42;
optional string field43 = 43;
optional string field44 = 44;
optional string field45 = 45;
optional string field46 = 46;
optional string field47 = 47;
optional string field48 = 48;
optional string field49 = 49;
optional string field50 = 50;
optional string field51 = 51;
optional string field52 = 52;
optional string field53 = 53;
optional string field54 = 54;
optional string field55 = 55;
optional string field56 = 56;
optional string field57 = 57;
optional string field58 = 58;
optional string field59 = 59;
optional string field60 = 60;
optional string field61 = 61;
optional string field62 = 62;
optional string field63 = 63;
optional string field64 = 64;
optional string field65 = 65;
optional string field66 = 66;
optional string field67 = 67;
optional string field68 = 68;
optional string field69 = 69;
optional string field70 = 70;
optional string field71 = 71;
optional string field72 = 72;
optional string field73 = 73;
optional string field74 = 74;
optional string field75 = 75;
optional string field76 = 76;
optional string field77 = 77;
optional string field78 = 78;
optional string field79 = 79;
optional string field80 = 80;
optional string field81 = 81;
optional string field82 = 82;
optional string field83 = 83;
optional string field84 = 84;
optional string field85 = 85;
optional string field86 = 86;
optional string field87 = 87;
optional string field88 = 88;
optional string field89 = 89;
optional string field90 = 90;
optional string field91 = 91;
optional string field92 = 92;
optional string field93 = 93;
optional string field94 = 94;
optional string field95 = 95;
optional string field96 = 96;
optional string field97 = 97;
optional string field98 = 98;
optional string field99 = 99;
optional string field100 = 100;
optional string field101 = 101;
optional string field102 = 102;
optional string field103 = 103;
optional string field104 = 104;
optional string field105 = 105;
optional string field106 = 106;
optional string field107 = 107;
optional string field108 = 108;
optional string field109 = 109;
optional string field110 = 110;
optional string field111 = 111;
optional string field112 = 112;
optional string field113 = 113;
optional string field114 = 114;
optional string field115 = 115;
optional string field116 = 116;
optional string field117 = 117;
optional string field118 = 118;
optional string field119 = 119;
optional string field120 = 120;
optional string field121 = 121;
optional string field122 = 122;
optional string field123 = 123;
optional string field124 = 124;
optional string field125 = 125;
optional string field126 = 126;
optional string field127 = 127;
optional string field128 = 128;
required string field129 = 129;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment