| 1 | // Generator of protobuf delimited messages used in the protobuf IO tests |
| 2 | // dbms/tests/queries/0_stateless/00825_protobuf_format* |
| 3 | |
| 4 | #include <boost/program_options.hpp> |
| 5 | #include <fstream> |
| 6 | #include <iostream> |
| 7 | #include <google/protobuf/util/delimited_message_util.h> |
| 8 | #include "00825_protobuf_format.pb.h" |
| 9 | #include "00825_protobuf_format_syntax2.pb.h" |
| 10 | |
| 11 | |
| 12 | void writeInsertDataQueryForInputTest(std::stringstream & delimited_messages, const std::string & table_name, const std::string & format_schema, std::ostream & out) |
| 13 | { |
| 14 | out << "echo -ne '" ; |
| 15 | std::string bytes = delimited_messages.str(); |
| 16 | delimited_messages.str("" ); |
| 17 | for (const char c : bytes) |
| 18 | { |
| 19 | char buf[5]; |
| 20 | sprintf(buf, "\\x%02x" , static_cast<unsigned char>(c)); |
| 21 | out << buf; |
| 22 | } |
| 23 | out << "' | $CLICKHOUSE_CLIENT --query=\"INSERT INTO " << table_name << " FORMAT Protobuf" |
| 24 | " SETTINGS format_schema = '$CURDIR/" |
| 25 | << format_schema << "'\"" << std::endl; |
| 26 | } |
| 27 | |
| 28 | void writeInsertDataQueriesForInputTest(std::ostream & out) |
| 29 | { |
| 30 | std::stringstream ss; |
| 31 | { |
| 32 | Person person; |
| 33 | person.set_uuid("a7522158-3d41-4b77-ad69-6c598ee55c49" ); |
| 34 | person.set_name("Ivan" ); |
| 35 | person.set_surname("Petrov" ); |
| 36 | person.set_gender(Gender::male); |
| 37 | person.set_birthdate(4015); // 1980-12-29 |
| 38 | person.set_photo("png" ); |
| 39 | person.set_phonenumber("+74951234567" ); |
| 40 | person.set_isonline(true); |
| 41 | person.set_visittime(1546703100); // 2019-01-05 18:45:00 |
| 42 | person.set_age(38); |
| 43 | person.set_zodiacsign(ZodiacSign::capricorn); |
| 44 | person.add_songs("Yesterday" ); |
| 45 | person.add_songs("Flowers" ); |
| 46 | person.add_color(255); |
| 47 | person.add_color(0); |
| 48 | person.add_color(0); |
| 49 | person.set_hometown("Moscow" ); |
| 50 | person.add_location(55.753215); |
| 51 | person.add_location(37.622504); |
| 52 | person.set_pi(3.14); |
| 53 | person.set_lotterywin(214.10); |
| 54 | person.set_someratio(0.1); |
| 55 | person.set_temperature(5.8); |
| 56 | person.set_randombignumber(17060000000); |
| 57 | auto* mu = person.add_measureunits(); |
| 58 | mu->set_unit("meter" ); |
| 59 | mu->set_coef(1); |
| 60 | mu = person.add_measureunits(); |
| 61 | mu->set_unit("centimeter" ); |
| 62 | mu->set_coef(0.01); |
| 63 | mu = person.add_measureunits(); |
| 64 | mu->set_unit("kilometer" ); |
| 65 | mu->set_coef(1000); |
| 66 | person.mutable_nestiness()->mutable_a()->mutable_b()->mutable_c()->set_d(500); |
| 67 | person.mutable_nestiness()->mutable_a()->mutable_b()->mutable_c()->add_e(501); |
| 68 | person.mutable_nestiness()->mutable_a()->mutable_b()->mutable_c()->add_e(502); |
| 69 | google::protobuf::util::SerializeDelimitedToOstream(person, &ss); |
| 70 | } |
| 71 | |
| 72 | { |
| 73 | Person person; |
| 74 | person.set_uuid("c694ad8a-f714-4ea3-907d-fd54fb25d9b5" ); |
| 75 | person.set_name("Natalia" ); |
| 76 | person.set_surname("Sokolova" ); |
| 77 | person.set_gender(Gender::female); |
| 78 | person.set_birthdate(8102); // 1992-03-08 |
| 79 | person.set_photo("jpg" ); |
| 80 | person.set_isonline(false); |
| 81 | person.set_age(26); |
| 82 | person.set_zodiacsign(ZodiacSign::pisces); |
| 83 | person.add_color(100); |
| 84 | person.add_color(200); |
| 85 | person.add_color(50); |
| 86 | person.set_hometown("Plymouth" ); |
| 87 | person.add_location(50.403724); |
| 88 | person.add_location(-4.142123); |
| 89 | person.set_pi(3.14159); |
| 90 | person.set_someratio(0.007); |
| 91 | person.set_temperature(5.4); |
| 92 | person.set_randombignumber(-20000000000000); |
| 93 | google::protobuf::util::SerializeDelimitedToOstream(person, &ss); |
| 94 | } |
| 95 | |
| 96 | { |
| 97 | Person person; |
| 98 | person.set_uuid("a7da1aa6-f425-4789-8947-b034786ed374" ); |
| 99 | person.set_name("Vasily" ); |
| 100 | person.set_surname("Sidorov" ); |
| 101 | person.set_gender(Gender::male); |
| 102 | person.set_birthdate(9339); // 1995-07-28 |
| 103 | person.set_photo("bmp" ); |
| 104 | person.set_phonenumber("+442012345678" ); |
| 105 | person.set_isonline(true); |
| 106 | person.set_visittime(1546117200); // 2018-12-30 00:00:00 |
| 107 | person.set_age(23); |
| 108 | person.set_zodiacsign(ZodiacSign::leo); |
| 109 | person.add_songs("Sunny" ); |
| 110 | person.add_color(250); |
| 111 | person.add_color(244); |
| 112 | person.add_color(10); |
| 113 | person.set_hometown("Murmansk" ); |
| 114 | person.add_location(68.970682); |
| 115 | person.add_location(33.074981); |
| 116 | person.set_pi(3.14159265358979); |
| 117 | person.set_lotterywin(100000000000); |
| 118 | person.set_someratio(800); |
| 119 | person.set_temperature(-3.2); |
| 120 | person.set_randombignumber(154400000); |
| 121 | auto* mu = person.add_measureunits(); |
| 122 | mu->set_unit("pound" ); |
| 123 | mu->set_coef(16); |
| 124 | person.mutable_nestiness()->mutable_a()->mutable_b()->mutable_c()->set_d(503); |
| 125 | google::protobuf::util::SerializeDelimitedToOstream(person, &ss); |
| 126 | } |
| 127 | |
| 128 | writeInsertDataQueryForInputTest(ss, "in_persons_00825" , "00825_protobuf_format:Person" , out); |
| 129 | |
| 130 | { |
| 131 | AltPerson person; |
| 132 | person.add_location(42); |
| 133 | person.add_location(-88); |
| 134 | person.set_pi(3.141); |
| 135 | person.set_uuid("20fcd95a-332d-41db-a9ec-161f644d059c" ); |
| 136 | person.set_name("Frida" ); |
| 137 | person.set_gender(AltPerson::female); |
| 138 | person.set_zodiacsign(1122); // sagittarius |
| 139 | person.set_birthdate(3267); // 1978-12-12 |
| 140 | person.set_age("40" ); |
| 141 | person.set_isonline(OnlineStatus::offline); |
| 142 | person.set_someratio(0.5); |
| 143 | person.set_visittime(1363005000); // 2013-03-11 16:30:00 |
| 144 | person.set_randombignumber(8010000009); |
| 145 | person.add_color(110); |
| 146 | person.add_color(210); |
| 147 | person.add_color(74); |
| 148 | person.set_lotterywin(311); |
| 149 | person.set_surname("Ermakova" ); |
| 150 | person.set_phonenumber(3124555929); |
| 151 | person.set_temperature(10); |
| 152 | person.add_measureunits_unit("KB" ); |
| 153 | person.add_measureunits_coef(1024); |
| 154 | person.add_measureunits_unit("MB" ); |
| 155 | person.add_measureunits_coef(1048576); |
| 156 | person.set_nestiness_a_b_c_d(700); |
| 157 | person.add_nestiness_a_b_c_e(701); |
| 158 | google::protobuf::util::SerializeDelimitedToOstream(person, &ss); |
| 159 | } |
| 160 | |
| 161 | { |
| 162 | AltPerson person; |
| 163 | person.add_location(26); |
| 164 | person.add_location(-80); |
| 165 | person.set_pi(3.1416); |
| 166 | person.set_uuid("7cfa6856-a54a-4786-b8e5-745159d52278" ); |
| 167 | person.set_name("Isolde" ); |
| 168 | person.set_gender(AltPerson::female); |
| 169 | person.set_zodiacsign(120); // aquarius |
| 170 | person.set_birthdate(6248); // 1987-02-09 |
| 171 | person.set_age("32" ); |
| 172 | person.set_isonline(OnlineStatus::online); |
| 173 | person.set_someratio(4.5); |
| 174 | person.set_randombignumber(-11111111111111); |
| 175 | person.add_color(255); |
| 176 | person.add_color(0); |
| 177 | person.add_color(255); |
| 178 | person.set_surname("Lavrova" ); |
| 179 | person.set_temperature(25); |
| 180 | person.set_newfieldstr("abc" ); |
| 181 | person.set_newfieldbool(true); |
| 182 | person.add_newfieldint(44); |
| 183 | person.add_measureunits_unit("Byte" ); |
| 184 | person.add_measureunits_coef(8); |
| 185 | person.add_measureunits_unit("Bit" ); |
| 186 | person.add_measureunits_coef(1); |
| 187 | person.mutable_newmessage()->set_z(91); |
| 188 | person.set_nestiness_a_b_c_d(702); |
| 189 | google::protobuf::util::SerializeDelimitedToOstream(person, &ss); |
| 190 | } |
| 191 | |
| 192 | writeInsertDataQueryForInputTest(ss, "in_persons_00825" , "00825_protobuf_format:AltPerson" , out); |
| 193 | |
| 194 | { |
| 195 | StrPerson person; |
| 196 | person.set_uuid("aa0e5a06-cab2-4034-a6a2-48e82b91664e" ); |
| 197 | person.set_name("Leonid" ); |
| 198 | person.set_surname("Kirillov" ); |
| 199 | person.set_gender("male" ); |
| 200 | person.set_birthdate("1983-06-24" ); |
| 201 | person.set_phonenumber("+74950275864" ); |
| 202 | person.set_isonline("1" ); |
| 203 | person.set_visittime("2019-02-04 09:45:00" ); |
| 204 | person.set_age("35" ); |
| 205 | person.set_zodiacsign("cancer" ); |
| 206 | person.add_songs("7 rings" ); |
| 207 | person.add_songs("Eastside" ); |
| 208 | person.add_songs("Last Hurrah" ); |
| 209 | person.add_color("0" ); |
| 210 | person.add_color("0" ); |
| 211 | person.add_color("255" ); |
| 212 | person.set_hometown("San Diego" ); |
| 213 | person.add_location("32.823943" ); |
| 214 | person.add_location("-117.081327" ); |
| 215 | person.set_pi("3.1415927" ); |
| 216 | person.set_lotterywin("15000000" ); |
| 217 | person.set_someratio("186.75" ); |
| 218 | person.set_temperature("-2.1" ); |
| 219 | person.set_randombignumber("20659829331" ); |
| 220 | person.mutable_measureunits()->add_unit("minute" ); |
| 221 | person.mutable_measureunits()->add_coef("60" ); |
| 222 | person.mutable_measureunits()->add_unit("hour" ); |
| 223 | person.mutable_measureunits()->add_coef("3600" ); |
| 224 | person.mutable_nestiness_a()->mutable_b_c()->add_e("1800" ); |
| 225 | google::protobuf::util::SerializeDelimitedToOstream(person, &ss); |
| 226 | } |
| 227 | |
| 228 | writeInsertDataQueryForInputTest(ss, "in_persons_00825" , "00825_protobuf_format:StrPerson" , out); |
| 229 | |
| 230 | { |
| 231 | Syntax2Person person; |
| 232 | person.set_uuid("3faee064-c4f7-4d34-b6f3-8d81c2b6a15d" ); |
| 233 | person.set_name("Nick" ); |
| 234 | person.set_surname("Kolesnikov" ); |
| 235 | person.set_gender(Syntax2Person::male); |
| 236 | person.set_birthdate(10586); // 1998-12-26 |
| 237 | person.set_photo("bmp" ); |
| 238 | person.set_phonenumber("412-687-5007" ); |
| 239 | person.set_isonline(true); |
| 240 | person.set_visittime(1542596399); // 2018-11-19 05:59:59 |
| 241 | person.set_age(20); |
| 242 | person.set_zodiacsign(Syntax2Person::capricorn); |
| 243 | person.add_songs("Havana" ); |
| 244 | person.add_color(128); |
| 245 | person.add_color(0); |
| 246 | person.add_color(128); |
| 247 | person.set_hometown("Pittsburgh" ); |
| 248 | person.add_location(40.517193); |
| 249 | person.add_location(-79.949452); |
| 250 | person.set_pi(3.1415926535898); |
| 251 | person.set_lotterywin(50000000000); |
| 252 | person.set_someratio(780); |
| 253 | person.set_temperature(18.3); |
| 254 | person.set_randombignumber(195500007); |
| 255 | person.mutable_measureunits()->add_unit("ounce" ); |
| 256 | person.mutable_measureunits()->add_coef(28.35); |
| 257 | person.mutable_measureunits()->add_unit("carat" ); |
| 258 | person.mutable_measureunits()->add_coef(0.2); |
| 259 | person.mutable_measureunits()->add_unit("gram" ); |
| 260 | person.mutable_measureunits()->add_coef(1); |
| 261 | person.mutable_nestiness()->mutable_a()->mutable_b()->mutable_c()->set_d(9494); |
| 262 | google::protobuf::util::SerializeDelimitedToOstream(person, &ss); |
| 263 | } |
| 264 | |
| 265 | writeInsertDataQueryForInputTest(ss, "in_persons_00825" , "00825_protobuf_format_syntax2:Syntax2Person" , out); |
| 266 | |
| 267 | { |
| 268 | NumberAndSquare ns; |
| 269 | ns.set_number(2); |
| 270 | ns.set_square(4); |
| 271 | google::protobuf::util::SerializeDelimitedToOstream(ns, &ss); |
| 272 | } |
| 273 | |
| 274 | { |
| 275 | NumberAndSquare ns; |
| 276 | ns.set_number(0); |
| 277 | ns.set_square(0); |
| 278 | google::protobuf::util::SerializeDelimitedToOstream(ns, &ss); |
| 279 | } |
| 280 | |
| 281 | { |
| 282 | NumberAndSquare ns; |
| 283 | ns.set_number(3); |
| 284 | ns.set_square(9); |
| 285 | google::protobuf::util::SerializeDelimitedToOstream(ns, &ss); |
| 286 | } |
| 287 | |
| 288 | writeInsertDataQueryForInputTest(ss, "in_squares_00825" , "00825_protobuf_format:NumberAndSquare" , out); |
| 289 | } |
| 290 | |
| 291 | |
| 292 | void writeReferenceForOutputTest(std::ostream & out) |
| 293 | { |
| 294 | { |
| 295 | Person person; |
| 296 | person.set_uuid("a7522158-3d41-4b77-ad69-6c598ee55c49" ); |
| 297 | person.set_name("Ivan" ); |
| 298 | person.set_surname("Petrov" ); |
| 299 | person.set_gender(Gender::male); |
| 300 | person.set_birthdate(4015); // 1980-12-29 |
| 301 | person.set_photo("png" ); |
| 302 | person.set_phonenumber(std::string("+74951234567\0" , 13)); // Converted from FixedString(13) |
| 303 | person.set_isonline(true); |
| 304 | person.set_visittime(1546703100); // 2019-01-05 18:45:00 |
| 305 | person.set_age(38); |
| 306 | person.set_zodiacsign(ZodiacSign::capricorn); |
| 307 | person.add_songs("Yesterday" ); |
| 308 | person.add_songs("Flowers" ); |
| 309 | person.add_color(255); |
| 310 | person.add_color(0); |
| 311 | person.add_color(0); |
| 312 | person.set_hometown("Moscow" ); |
| 313 | person.add_location(55.753215); |
| 314 | person.add_location(37.622504); |
| 315 | person.set_pi(3.14); |
| 316 | person.set_lotterywin(214.10); |
| 317 | person.set_someratio(0.1); |
| 318 | person.set_temperature(5.8); |
| 319 | person.set_randombignumber(17060000000); |
| 320 | auto* mu = person.add_measureunits(); |
| 321 | mu->set_unit("meter" ); |
| 322 | mu->set_coef(1); |
| 323 | mu = person.add_measureunits(); |
| 324 | mu->set_unit("centimeter" ); |
| 325 | mu->set_coef(0.01); |
| 326 | mu = person.add_measureunits(); |
| 327 | mu->set_unit("kilometer" ); |
| 328 | mu->set_coef(1000); |
| 329 | person.mutable_nestiness()->mutable_a()->mutable_b()->mutable_c()->set_d(500); |
| 330 | person.mutable_nestiness()->mutable_a()->mutable_b()->mutable_c()->add_e(501); |
| 331 | person.mutable_nestiness()->mutable_a()->mutable_b()->mutable_c()->add_e(502); |
| 332 | google::protobuf::util::SerializeDelimitedToOstream(person, &out); |
| 333 | } |
| 334 | |
| 335 | { |
| 336 | Person person; |
| 337 | person.set_uuid("c694ad8a-f714-4ea3-907d-fd54fb25d9b5" ); |
| 338 | person.set_name("Natalia" ); |
| 339 | person.set_surname("Sokolova" ); |
| 340 | person.set_gender(Gender::female); |
| 341 | person.set_birthdate(8102); // 1992-03-08 |
| 342 | person.set_photo("jpg" ); |
| 343 | person.set_isonline(false); |
| 344 | person.set_age(26); |
| 345 | person.set_zodiacsign(ZodiacSign::pisces); |
| 346 | person.add_color(100); |
| 347 | person.add_color(200); |
| 348 | person.add_color(50); |
| 349 | person.set_hometown("Plymouth" ); |
| 350 | person.add_location(50.403724); |
| 351 | person.add_location(-4.142123); |
| 352 | person.set_pi(3.14159); |
| 353 | person.set_someratio(0.007); |
| 354 | person.set_temperature(5.4); |
| 355 | person.set_randombignumber(-20000000000000); |
| 356 | google::protobuf::util::SerializeDelimitedToOstream(person, &out); |
| 357 | } |
| 358 | |
| 359 | { |
| 360 | Person person; |
| 361 | person.set_uuid("a7da1aa6-f425-4789-8947-b034786ed374" ); |
| 362 | person.set_name("Vasily" ); |
| 363 | person.set_surname("Sidorov" ); |
| 364 | person.set_gender(Gender::male); |
| 365 | person.set_birthdate(9339); // 1995-07-28 |
| 366 | person.set_photo("bmp" ); |
| 367 | person.set_phonenumber("+442012345678" ); |
| 368 | person.set_isonline(true); |
| 369 | person.set_visittime(1546117200); // 2018-12-30 00:00:00 |
| 370 | person.set_age(23); |
| 371 | person.set_zodiacsign(ZodiacSign::leo); |
| 372 | person.add_songs("Sunny" ); |
| 373 | person.add_color(250); |
| 374 | person.add_color(244); |
| 375 | person.add_color(10); |
| 376 | person.set_hometown("Murmansk" ); |
| 377 | person.add_location(68.970682); |
| 378 | person.add_location(33.074981); |
| 379 | person.set_pi(3.14159265358979); |
| 380 | person.set_lotterywin(100000000000); |
| 381 | person.set_someratio(800); |
| 382 | person.set_temperature(-3.2); |
| 383 | person.set_randombignumber(154400000); |
| 384 | auto* mu = person.add_measureunits(); |
| 385 | mu->set_unit("pound" ); |
| 386 | mu->set_coef(16); |
| 387 | person.mutable_nestiness()->mutable_a()->mutable_b()->mutable_c()->set_d(503); |
| 388 | google::protobuf::util::SerializeDelimitedToOstream(person, &out); |
| 389 | } |
| 390 | |
| 391 | out << "ALTERNATIVE->" << std::endl; |
| 392 | |
| 393 | { |
| 394 | AltPerson person; |
| 395 | person.add_location(55); |
| 396 | person.add_location(37); |
| 397 | person.set_pi(3.14); |
| 398 | person.set_uuid("a7522158-3d41-4b77-ad69-6c598ee55c49" ); |
| 399 | person.set_name("Ivan" ); |
| 400 | person.set_gender(AltPerson::male); |
| 401 | person.set_zodiacsign(1222); // capricorn |
| 402 | person.set_birthdate(4015); // 1980-12-29 |
| 403 | person.set_age("38" ); |
| 404 | person.set_isonline(OnlineStatus::online); |
| 405 | person.set_someratio(0.100000001490116119384765625); // 0.1 converted from float to double |
| 406 | person.set_visittime(1546703100); // 2019-01-05 18:45:00 |
| 407 | person.set_randombignumber(17060000000); |
| 408 | person.add_color(255); |
| 409 | person.add_color(0); |
| 410 | person.add_color(0); |
| 411 | person.set_lotterywin(214); |
| 412 | person.set_surname("Petrov" ); |
| 413 | person.set_phonenumber(+74951234567); |
| 414 | person.set_temperature(5); |
| 415 | person.add_measureunits_unit("meter" ); |
| 416 | person.add_measureunits_coef(1); |
| 417 | person.add_measureunits_unit("centimeter" ); |
| 418 | person.add_measureunits_coef(0.01); |
| 419 | person.add_measureunits_unit("kilometer" ); |
| 420 | person.add_measureunits_coef(1000); |
| 421 | person.set_nestiness_a_b_c_d(500); |
| 422 | person.add_nestiness_a_b_c_e(501); |
| 423 | person.add_nestiness_a_b_c_e(502); |
| 424 | google::protobuf::util::SerializeDelimitedToOstream(person, &out); |
| 425 | } |
| 426 | |
| 427 | { |
| 428 | AltPerson person; |
| 429 | person.add_location(50); |
| 430 | person.add_location(-4); |
| 431 | person.set_pi(3.14159); |
| 432 | person.set_uuid("c694ad8a-f714-4ea3-907d-fd54fb25d9b5" ); |
| 433 | person.set_name("Natalia" ); |
| 434 | person.set_gender(AltPerson::female); |
| 435 | person.set_zodiacsign(219); // pisces |
| 436 | person.set_birthdate(8102); // 1992-03-08 |
| 437 | person.set_age("26" ); |
| 438 | person.set_isonline(OnlineStatus::offline); |
| 439 | person.set_someratio(0.007000000216066837310791015625); // 0.007 converted from float to double |
| 440 | person.set_randombignumber(-20000000000000); |
| 441 | person.add_color(100); |
| 442 | person.add_color(200); |
| 443 | person.add_color(50); |
| 444 | person.set_surname("Sokolova" ); |
| 445 | person.set_temperature(5); |
| 446 | google::protobuf::util::SerializeDelimitedToOstream(person, &out); |
| 447 | } |
| 448 | |
| 449 | { |
| 450 | AltPerson person; |
| 451 | person.add_location(68); |
| 452 | person.add_location(33); |
| 453 | person.set_pi(3.1415926535897); |
| 454 | person.set_uuid("a7da1aa6-f425-4789-8947-b034786ed374" ); |
| 455 | person.set_name("Vasily" ); |
| 456 | person.set_gender(AltPerson::male); |
| 457 | person.set_zodiacsign(723); // leo |
| 458 | person.set_birthdate(9339); // 1995-07-28 |
| 459 | person.set_age("23" ); |
| 460 | person.set_isonline(OnlineStatus::online); |
| 461 | person.set_someratio(800); |
| 462 | person.set_visittime(1546117200); // 2018-12-30 00:00:00 |
| 463 | person.set_randombignumber(154400000); |
| 464 | person.add_color(250); |
| 465 | person.add_color(244); |
| 466 | person.add_color(10); |
| 467 | person.set_lotterywin(100000000000); |
| 468 | person.set_surname("Sidorov" ); |
| 469 | person.set_phonenumber(+442012345678); |
| 470 | person.set_temperature(-3); |
| 471 | person.add_measureunits_unit("pound" ); |
| 472 | person.add_measureunits_coef(16); |
| 473 | person.set_nestiness_a_b_c_d(503); |
| 474 | google::protobuf::util::SerializeDelimitedToOstream(person, &out); |
| 475 | } |
| 476 | |
| 477 | out << "STRINGS->" << std::endl; |
| 478 | |
| 479 | { |
| 480 | StrPerson person; |
| 481 | person.set_uuid("a7522158-3d41-4b77-ad69-6c598ee55c49" ); |
| 482 | person.set_name("Ivan" ); |
| 483 | person.set_surname("Petrov" ); |
| 484 | person.set_gender("male" ); |
| 485 | person.set_birthdate("1980-12-29" ); |
| 486 | person.set_phonenumber(std::string("+74951234567\0" , 13)); // Converted from FixedString(13) |
| 487 | person.set_isonline("1" ); |
| 488 | person.set_visittime("2019-01-05 18:45:00" ); |
| 489 | person.set_age("38" ); |
| 490 | person.set_zodiacsign("capricorn" ); |
| 491 | person.add_songs("Yesterday" ); |
| 492 | person.add_songs("Flowers" ); |
| 493 | person.add_color("255" ); |
| 494 | person.add_color("0" ); |
| 495 | person.add_color("0" ); |
| 496 | person.set_hometown("Moscow" ); |
| 497 | person.add_location("55.753215" ); |
| 498 | person.add_location("37.622504" ); |
| 499 | person.set_pi("3.14" ); |
| 500 | person.set_lotterywin("214.10" ); |
| 501 | person.set_someratio("0.1" ); |
| 502 | person.set_temperature("5.8" ); |
| 503 | person.set_randombignumber("17060000000" ); |
| 504 | person.mutable_measureunits()->add_unit("meter" ); |
| 505 | person.mutable_measureunits()->add_coef("1" ); |
| 506 | person.mutable_measureunits()->add_unit("centimeter" ); |
| 507 | person.mutable_measureunits()->add_coef("0.01" ); |
| 508 | person.mutable_measureunits()->add_unit("kilometer" ); |
| 509 | person.mutable_measureunits()->add_coef("1000" ); |
| 510 | person.mutable_nestiness_a()->mutable_b_c()->set_d("500" ); |
| 511 | person.mutable_nestiness_a()->mutable_b_c()->add_e("501" ); |
| 512 | person.mutable_nestiness_a()->mutable_b_c()->add_e("502" ); |
| 513 | google::protobuf::util::SerializeDelimitedToOstream(person, &out); |
| 514 | } |
| 515 | |
| 516 | { |
| 517 | StrPerson person; |
| 518 | person.set_uuid("c694ad8a-f714-4ea3-907d-fd54fb25d9b5" ); |
| 519 | person.set_name("Natalia" ); |
| 520 | person.set_surname("Sokolova" ); |
| 521 | person.set_gender("female" ); |
| 522 | person.set_birthdate("1992-03-08" ); |
| 523 | person.set_isonline("0" ); |
| 524 | person.set_age("26" ); |
| 525 | person.set_zodiacsign("pisces" ); |
| 526 | person.add_color("100" ); |
| 527 | person.add_color("200" ); |
| 528 | person.add_color("50" ); |
| 529 | person.set_hometown("Plymouth" ); |
| 530 | person.add_location("50.403724" ); |
| 531 | person.add_location("-4.142123" ); |
| 532 | person.set_pi("3.14159" ); |
| 533 | person.set_someratio("0.007" ); |
| 534 | person.set_temperature("5.4" ); |
| 535 | person.set_randombignumber("-20000000000000" ); |
| 536 | google::protobuf::util::SerializeDelimitedToOstream(person, &out); |
| 537 | } |
| 538 | |
| 539 | { |
| 540 | StrPerson person; |
| 541 | person.set_uuid("a7da1aa6-f425-4789-8947-b034786ed374" ); |
| 542 | person.set_name("Vasily" ); |
| 543 | person.set_surname("Sidorov" ); |
| 544 | person.set_gender("male" ); |
| 545 | person.set_birthdate("1995-07-28" ); |
| 546 | person.set_phonenumber("+442012345678" ); |
| 547 | person.set_isonline("1" ); |
| 548 | person.set_visittime("2018-12-30 00:00:00" ); |
| 549 | person.set_age("23" ); |
| 550 | person.set_zodiacsign("leo" ); |
| 551 | person.add_songs("Sunny" ); |
| 552 | person.add_color("250" ); |
| 553 | person.add_color("244" ); |
| 554 | person.add_color("10" ); |
| 555 | person.set_hometown("Murmansk" ); |
| 556 | person.add_location("68.970682" ); |
| 557 | person.add_location("33.074981" ); |
| 558 | person.set_pi("3.14159265358979" ); |
| 559 | person.set_lotterywin("100000000000.00" ); |
| 560 | person.set_someratio("800" ); |
| 561 | person.set_temperature("-3.2" ); |
| 562 | person.set_randombignumber("154400000" ); |
| 563 | person.mutable_measureunits()->add_unit("pound" ); |
| 564 | person.mutable_measureunits()->add_coef("16" ); |
| 565 | person.mutable_nestiness_a()->mutable_b_c()->set_d("503" ); |
| 566 | google::protobuf::util::SerializeDelimitedToOstream(person, &out); |
| 567 | } |
| 568 | |
| 569 | out << "SYNTAX2->" << std::endl; |
| 570 | |
| 571 | { |
| 572 | Syntax2Person person; |
| 573 | person.set_uuid("a7522158-3d41-4b77-ad69-6c598ee55c49" ); |
| 574 | person.set_name("Ivan" ); |
| 575 | person.set_surname("Petrov" ); |
| 576 | person.set_gender(Syntax2Person::male); |
| 577 | person.set_birthdate(4015); // 1980-12-29 |
| 578 | person.set_photo("png" ); |
| 579 | person.set_phonenumber(std::string("+74951234567\0" , 13)); // Converted from FixedString(13) |
| 580 | person.set_isonline(true); |
| 581 | person.set_visittime(1546703100); // 2019-01-05 18:45:00 |
| 582 | person.set_age(38); |
| 583 | person.set_zodiacsign(Syntax2Person::capricorn); |
| 584 | person.add_songs("Yesterday" ); |
| 585 | person.add_songs("Flowers" ); |
| 586 | person.add_color(255); |
| 587 | person.add_color(0); |
| 588 | person.add_color(0); |
| 589 | person.set_hometown("Moscow" ); |
| 590 | person.add_location(55.753215); |
| 591 | person.add_location(37.622504); |
| 592 | person.set_pi(3.14); |
| 593 | person.set_lotterywin(214.10); |
| 594 | person.set_someratio(0.1); |
| 595 | person.set_temperature(5.8); |
| 596 | person.set_randombignumber(17060000000); |
| 597 | person.mutable_measureunits()->add_unit("meter" ); |
| 598 | person.mutable_measureunits()->add_coef(1); |
| 599 | person.mutable_measureunits()->add_unit("centimeter" ); |
| 600 | person.mutable_measureunits()->add_coef(0.01); |
| 601 | person.mutable_measureunits()->add_unit("kilometer" ); |
| 602 | person.mutable_measureunits()->add_coef(1000); |
| 603 | person.mutable_nestiness()->mutable_a()->mutable_b()->mutable_c()->set_d(500); |
| 604 | person.mutable_nestiness()->mutable_a()->mutable_b()->mutable_c()->add_e(501); |
| 605 | person.mutable_nestiness()->mutable_a()->mutable_b()->mutable_c()->add_e(502); |
| 606 | google::protobuf::util::SerializeDelimitedToOstream(person, &out); |
| 607 | } |
| 608 | |
| 609 | { |
| 610 | Syntax2Person person; |
| 611 | person.set_uuid("c694ad8a-f714-4ea3-907d-fd54fb25d9b5" ); |
| 612 | person.set_name("Natalia" ); |
| 613 | person.set_surname("Sokolova" ); |
| 614 | person.set_gender(Syntax2Person::female); |
| 615 | person.set_birthdate(8102); // 1992-03-08 |
| 616 | person.set_photo("jpg" ); |
| 617 | person.set_isonline(false); |
| 618 | person.set_age(26); |
| 619 | person.set_zodiacsign(Syntax2Person::pisces); |
| 620 | person.add_color(100); |
| 621 | person.add_color(200); |
| 622 | person.add_color(50); |
| 623 | person.set_hometown("Plymouth" ); |
| 624 | person.add_location(50.403724); |
| 625 | person.add_location(-4.142123); |
| 626 | person.set_pi(3.14159); |
| 627 | person.set_someratio(0.007); |
| 628 | person.set_temperature(5.4); |
| 629 | person.set_randombignumber(-20000000000000); |
| 630 | google::protobuf::util::SerializeDelimitedToOstream(person, &out); |
| 631 | } |
| 632 | |
| 633 | { |
| 634 | Syntax2Person person; |
| 635 | person.set_uuid("a7da1aa6-f425-4789-8947-b034786ed374" ); |
| 636 | person.set_name("Vasily" ); |
| 637 | person.set_surname("Sidorov" ); |
| 638 | person.set_gender(Syntax2Person::male); |
| 639 | person.set_birthdate(9339); // 1995-07-28 |
| 640 | person.set_photo("bmp" ); |
| 641 | person.set_phonenumber("+442012345678" ); |
| 642 | person.set_isonline(true); |
| 643 | person.set_visittime(1546117200); // 2018-12-30 00:00:00 |
| 644 | person.set_age(23); |
| 645 | person.set_zodiacsign(Syntax2Person::leo); |
| 646 | person.add_songs("Sunny" ); |
| 647 | person.add_color(250); |
| 648 | person.add_color(244); |
| 649 | person.add_color(10); |
| 650 | person.set_hometown("Murmansk" ); |
| 651 | person.add_location(68.970682); |
| 652 | person.add_location(33.074981); |
| 653 | person.set_pi(3.14159265358979); |
| 654 | person.set_lotterywin(100000000000); |
| 655 | person.set_someratio(800); |
| 656 | person.set_temperature(-3.2); |
| 657 | person.set_randombignumber(154400000); |
| 658 | person.mutable_measureunits()->add_unit("pound" ); |
| 659 | person.mutable_measureunits()->add_coef(16); |
| 660 | person.mutable_nestiness()->mutable_a()->mutable_b()->mutable_c()->set_d(503); |
| 661 | google::protobuf::util::SerializeDelimitedToOstream(person, &out); |
| 662 | } |
| 663 | |
| 664 | out << "SQUARES->" << std::endl; |
| 665 | |
| 666 | { |
| 667 | NumberAndSquare ns; |
| 668 | ns.set_number(0); |
| 669 | ns.set_square(0); |
| 670 | google::protobuf::util::SerializeDelimitedToOstream(ns, &out); |
| 671 | } |
| 672 | |
| 673 | { |
| 674 | NumberAndSquare ns; |
| 675 | ns.set_number(2); |
| 676 | ns.set_square(4); |
| 677 | google::protobuf::util::SerializeDelimitedToOstream(ns, &out); |
| 678 | } |
| 679 | |
| 680 | { |
| 681 | NumberAndSquare ns; |
| 682 | ns.set_number(3); |
| 683 | ns.set_square(9); |
| 684 | google::protobuf::util::SerializeDelimitedToOstream(ns, &out); |
| 685 | } |
| 686 | } |
| 687 | |
| 688 | |
| 689 | void parseCommandLine(int argc, char ** argv, std::string & output_dir) |
| 690 | { |
| 691 | namespace po = boost::program_options; |
| 692 | po::options_description desc; |
| 693 | output_dir = OUTPUT_DIR; |
| 694 | desc.add_options() |
| 695 | ("help,h" , "Show help" ) |
| 696 | ("directory,d" , po::value<std::string>(&output_dir), |
| 697 | "Set the output directory. By default it's " OUTPUT_DIR); |
| 698 | po::parsed_options parsed = po::command_line_parser(argc, argv).options(desc).run(); |
| 699 | po::variables_map vm; |
| 700 | po::store(parsed, vm); |
| 701 | po::notify(vm); |
| 702 | if (!output_dir.empty()) |
| 703 | return; |
| 704 | |
| 705 | // Show help. |
| 706 | std::cout << "This utility generates delimited messages for tests checking protobuf IO support." << std::endl; |
| 707 | std::cout << desc; |
| 708 | std::cout << "Example:" << std::endl; |
| 709 | std::cout << argv[0] << " -g OUTPUT_REFERENCE" << std::endl; |
| 710 | std::exit(0); |
| 711 | } |
| 712 | |
| 713 | void writeFile(const std::string & filepath, void (*fn)(std::ostream &)) |
| 714 | { |
| 715 | std::cout << "Writing '" << filepath << "' ... " ; |
| 716 | std::fstream out(filepath, std::fstream::out | std::fstream::trunc); |
| 717 | fn(out); |
| 718 | std::cout << "done." << std::endl; |
| 719 | } |
| 720 | |
| 721 | int main(int argc, char ** argv) |
| 722 | { |
| 723 | std::string output_dir; |
| 724 | parseCommandLine(argc, argv, output_dir); |
| 725 | writeFile(output_dir + "/00825_protobuf_format_input.insh" , writeInsertDataQueriesForInputTest); |
| 726 | writeFile(output_dir + "/00825_protobuf_format_output.reference" , writeReferenceForOutputTest); |
| 727 | return 0; |
| 728 | } |
| 729 | |