38 namespace objectivec {
41 TEST(ObjCHelper, TextFormatDecodeData_DecodeDataForString_RawStrings) {
42 string input_for_decode(
"abcdefghIJ");
43 string desired_output_for_decode;
49 desired_output_for_decode =
"zbcdefghIJ";
50 expected =
string(
"\0zbcdefghIJ\0", 12);
52 desired_output_for_decode);
55 desired_output_for_decode =
"abcdezghIJ";
56 expected =
string(
"\0abcdezghIJ\0", 12);
58 desired_output_for_decode);
63 desired_output_for_decode =
"abcdefghI";
64 expected =
string(
"\0abcdefghI\0", 11);
66 desired_output_for_decode);
71 desired_output_for_decode =
"abcdefghIJz";
72 expected =
string(
"\0abcdefghIJz\0", 13);
74 desired_output_for_decode);
78 TEST(ObjCHelper, TextFormatDecodeData_DecodeDataForString_ByteCodes) {
79 string input_for_decode(
"abcdefghIJ");
80 string desired_output_for_decode;
84 desired_output_for_decode =
"abcdefghIJ";
85 expected =
string(
"\x0A\x0", 2);
87 desired_output_for_decode);
90 desired_output_for_decode =
"_AbcdefghIJ";
91 expected =
string(
"\xCA\x0", 2);
93 desired_output_for_decode);
96 desired_output_for_decode =
"ABCD__EfghI_j";
97 expected =
string(
"\x64\x80\xC5\xA1\x0", 5);
99 desired_output_for_decode);
105 "longFieldNameIsLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong1000";
106 desired_output_for_decode =
107 "long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_1000";
108 expected =
string(
"\x04\xA5\xA4\xA2\xBF\x1F\x0E\x84\x0", 9);
110 desired_output_for_decode);
115 #ifdef PROTOBUF_HAS_DEATH_TEST
116 TEST(ObjCHelperDeathTest, TextFormatDecodeData_DecodeDataForString_Failures) {
120 ::testing::KilledBySignal(SIGABRT),
121 "error: got empty string for making TextFormat data, input:");
123 ::testing::KilledBySignal(SIGABRT),
124 "error: got empty string for making TextFormat data, input:");
126 ::testing::KilledBySignal(SIGABRT),
127 "error: got empty string for making TextFormat data, input:");
131 string str_with_null_char(
"ab\0c", 4);
134 ::testing::KilledBySignal(SIGABRT),
135 "error: got a null char in a string for making TextFormat data, input:");
138 ::testing::KilledBySignal(SIGABRT),
139 "error: got a null char in a string for making TextFormat data, input:");
141 #endif // PROTOBUF_HAS_DEATH_TEST
143 TEST(ObjCHelper, TextFormatDecodeData_RawStrings) {
144 TextFormatDecodeData decode_data;
147 decode_data.AddString(1,
"abcdefghIJ",
"zbcdefghIJ");
148 decode_data.AddString(3,
"abcdefghIJ",
"abcdezghIJ");
150 decode_data.AddString(2,
"abcdefghIJ",
"abcdefghI");
152 decode_data.AddString(4,
"abcdefghIJ",
"abcdefghIJz");
156 uint8 expected_data[] = {
158 0x1, 0x0,
'z',
'b',
'c',
'd',
'e',
'f',
'g',
'h',
'I',
'J', 0x0,
159 0x3, 0x0,
'a',
'b',
'c',
'd',
'e',
'z',
'g',
'h',
'I',
'J', 0x0,
160 0x2, 0x0,
'a',
'b',
'c',
'd',
'e',
'f',
'g',
'h',
'I', 0x0,
161 0x4, 0x0,
'a',
'b',
'c',
'd',
'e',
'f',
'g',
'h',
'I',
'J',
'z', 0x0,
163 string expected((
const char*)expected_data,
sizeof(expected_data));
168 TEST(ObjCHelper, TextFormatDecodeData_ByteCodes) {
169 TextFormatDecodeData decode_data;
171 decode_data.AddString(1,
"abcdefghIJ",
"abcdefghIJ");
172 decode_data.AddString(3,
"abcdefghIJ",
"_AbcdefghIJ");
173 decode_data.AddString(2,
"abcdefghIJ",
"Abcd_EfghIJ");
174 decode_data.AddString(4,
"abcdefghIJ",
"ABCD__EfghI_j");
175 decode_data.AddString(1000,
176 "longFieldNameIsLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong1000",
177 "long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_1000");
181 uint8 expected_data[] = {
188 0x2, 0x44, 0xC6, 0x0,
191 0x4, 0x64, 0x80, 0xC5, 0xA1, 0x0,
197 0xE8, 0x07, 0x04, 0xA5, 0xA4, 0xA2, 0xBF, 0x1F, 0x0E, 0x84, 0x0,
199 string expected((
const char*)expected_data,
sizeof(expected_data));
206 #ifdef PROTOBUF_HAS_DEATH_TEST
207 TEST(ObjCHelperDeathTest, TextFormatDecodeData_Failures) {
208 TextFormatDecodeData decode_data;
212 EXPECT_EXIT(decode_data.AddString(1,
"",
""),
213 ::testing::KilledBySignal(SIGABRT),
214 "error: got empty string for making TextFormat data, input:");
215 EXPECT_EXIT(decode_data.AddString(1,
"a",
""),
216 ::testing::KilledBySignal(SIGABRT),
217 "error: got empty string for making TextFormat data, input:");
218 EXPECT_EXIT(decode_data.AddString(1,
"",
"a"),
219 ::testing::KilledBySignal(SIGABRT),
220 "error: got empty string for making TextFormat data, input:");
224 string str_with_null_char(
"ab\0c", 4);
226 decode_data.AddString(1, str_with_null_char,
"def"),
227 ::testing::KilledBySignal(SIGABRT),
228 "error: got a null char in a string for making TextFormat data, input:");
230 decode_data.AddString(1,
"def", str_with_null_char),
231 ::testing::KilledBySignal(SIGABRT),
232 "error: got a null char in a string for making TextFormat data, input:");
236 decode_data.AddString(1,
"abcdefghIJ",
"abcdefghIJ");
237 decode_data.AddString(3,
"abcdefghIJ",
"_AbcdefghIJ");
238 decode_data.AddString(2,
"abcdefghIJ",
"Abcd_EfghIJ");
239 EXPECT_EXIT(decode_data.AddString(2,
"xyz",
"x_yz"),
240 ::testing::KilledBySignal(SIGABRT),
241 "error: duplicate key \\(2\\) making TextFormat data, input:");
243 #endif // PROTOBUF_HAS_DEATH_TEST