THRIFT-5772: UUID support for c++ #2952
Client: cpp
Patch: CJCombrink

This closes #2952
diff --git a/lib/cpp/test/Benchmark.cpp b/lib/cpp/test/Benchmark.cpp
index 56adac0..97a5317 100644
--- a/lib/cpp/test/Benchmark.cpp
+++ b/lib/cpp/test/Benchmark.cpp
@@ -66,6 +66,7 @@
   ooe.some_characters = "JSON THIS! \"\1";
   ooe.zomg_unicode = "\xd7\n\a\t";
   ooe.base64 = "\1\2\3\255";
+  ooe.rfc4122_uuid = "{5e2ab188-1726-4e75-a04f-1ed9a6a89c4c}";
 
   int num = 100000;
   std::shared_ptr<TMemoryBuffer> buf(new TMemoryBuffer(num*1000));
diff --git a/lib/cpp/test/CMakeLists.txt b/lib/cpp/test/CMakeLists.txt
index 1117cd9..87ed109 100644
--- a/lib/cpp/test/CMakeLists.txt
+++ b/lib/cpp/test/CMakeLists.txt
@@ -360,7 +360,7 @@
 )
 
 add_custom_command(OUTPUT gen-cpp/DebugProtoTest_types.cpp gen-cpp/DebugProtoTest_types.h gen-cpp/EmptyService.cpp gen-cpp/EmptyService.h
-    COMMAND ${THRIFT_COMPILER} --gen cpp ${PROJECT_SOURCE_DIR}/test/v0.16/DebugProtoTest.thrift
+    COMMAND ${THRIFT_COMPILER} --gen cpp ${PROJECT_SOURCE_DIR}/test/DebugProtoTest.thrift
 )
 
 add_custom_command(OUTPUT gen-cpp/EnumTest_types.cpp gen-cpp/EnumTest_types.h
@@ -384,7 +384,7 @@
 )
 
 add_custom_command(OUTPUT gen-cpp/SecondService.cpp gen-cpp/ThriftTest_constants.cpp gen-cpp/ThriftTest.cpp gen-cpp/ThriftTest_types.cpp gen-cpp/ThriftTest_types.h
-    COMMAND ${THRIFT_COMPILER} --gen cpp ${PROJECT_SOURCE_DIR}/test/v0.16/ThriftTest.thrift
+    COMMAND ${THRIFT_COMPILER} --gen cpp ${PROJECT_SOURCE_DIR}/test/ThriftTest.thrift
 )
 
 add_custom_command(OUTPUT gen-cpp/OneWayService.cpp gen-cpp/OneWayTest_types.h gen-cpp/OneWayService.h
diff --git a/lib/cpp/test/DebugProtoTest.cpp b/lib/cpp/test/DebugProtoTest.cpp
index 060f354..cc4e5ff 100644
--- a/lib/cpp/test/DebugProtoTest.cpp
+++ b/lib/cpp/test/DebugProtoTest.cpp
@@ -74,6 +74,11 @@
     "    [1] = 2,\n"
     "    [2] = 3,\n"
     "  },\n"
+    "  15: rfc4122_uuid (uuid) = {\n"
+    "    [in ] = \"\",\n"
+    "    [raw] = \"\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\",\n"
+    "    [enc] = \"00000000-0000-0000-0000-000000000000\"\n"
+    "  }\n"
     "}");
   const std::string result(apache::thrift::ThriftDebugString(*ooe));
 
@@ -98,6 +103,7 @@
                                "\xb0\xcf\x81\xe2\x84\x8e\x20\xce\x91\x74\x74"
                                "\xce\xb1\xe2\x85\xbd\xce\xba\xc7\x83\xe2\x80"
                                "\xbc";
+  n->my_ooe.rfc4122_uuid = "{5e2ab188-1726-4e75-a04f-1ed9a6a89c4c}";
   n->my_bonk.type = 31337;
   n->my_bonk.message = "I am a bonk... xor!";
 }
@@ -141,6 +147,11 @@
     "      [1] = 2,\n"
     "      [2] = 3,\n"
     "    },\n"
+    "    15: rfc4122_uuid (uuid) = {\n"
+    "      [in ] = \"{5e2ab188-1726-4e75-a04f-1ed9a6a89c4c}\",\n"
+    "      [raw] = \"^*\\xb1\\x88\\x17&Nu\\xa0O\\x1e\\xd9\\xa6\\xa8\\x9cL\",\n"
+    "      [enc] = \"5e2ab188-1726-4e75-a04f-1ed9a6a89c4c\"\n"
+    "    }\n"
     "  },\n"
     "}");
   const std::string result(apache::thrift::ThriftDebugString(*n));
@@ -228,6 +239,11 @@
     "        [1] = 2,\n"
     "        [2] = 3,\n"
     "      },\n"
+    "      15: rfc4122_uuid (uuid) = {\n"
+    "        [in ] = \"\",\n"
+    "        [raw] = \"\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\",\n"
+    "        [enc] = \"00000000-0000-0000-0000-000000000000\"\n"
+    "      }\n"
     "    },\n"
     "    [1] = OneOfEach {\n"
     "      01: im_true (bool) = true,\n"
@@ -259,6 +275,11 @@
     "        [1] = 2,\n"
     "        [2] = 3,\n"
     "      },\n"
+    "      15: rfc4122_uuid (uuid) = {\n"
+    "        [in ] = \"{5e2ab188-1726-4e75-a04f-1ed9a6a89c4c}\",\n"
+    "        [raw] = \"^*\\xb1\\x88\\x17&Nu\\xa0O\\x1e\\xd9\\xa6\\xa8\\x9cL\",\n"
+    "        [enc] = \"5e2ab188-1726-4e75-a04f-1ed9a6a89c4c\"\n"
+    "      }\n"
     "    },\n"
     "  },\n"
     "  02: contain (set) = set<list>[3] {\n"
diff --git a/lib/cpp/test/JSONProtoTest.cpp b/lib/cpp/test/JSONProtoTest.cpp
index 082c8a2..fedf99e 100644
--- a/lib/cpp/test/JSONProtoTest.cpp
+++ b/lib/cpp/test/JSONProtoTest.cpp
@@ -48,6 +48,7 @@
   ooe->some_characters = "JSON THIS! \"\1";
   ooe->zomg_unicode = "\xd7\n\a\t";
   ooe->base64 = "\1\2\3\255";
+  ooe->rfc4122_uuid = "00000000-0000-0000-0000-000000000000";
 }
 
 BOOST_AUTO_TEST_CASE(test_json_proto_1) {
@@ -59,7 +60,7 @@
   "535897931},\"8\":{\"str\":\"JSON THIS! \\\"\\u0001\"},\"9\":{\"str\":\"\xd7\\"
   "n\\u0007\\t\"},\"10\":{\"tf\":0},\"11\":{\"str\":\"AQIDrQ\"},\"12\":{\"lst\""
   ":[\"i8\",3,1,2,3]},\"13\":{\"lst\":[\"i16\",3,1,2,3]},\"14\":{\"lst\":[\"i64"
-  "\",3,1,2,3]}}");
+  "\",3,1,2,3]},\"15\":{\"uid\":\"00000000-0000-0000-0000-000000000000\"}}");
 
   const std::string result(apache::thrift::ThriftJSONString(*ooe));
 
@@ -84,6 +85,7 @@
                                "\xb0\xcf\x81\xe2\x84\x8e\x20\xce\x91\x74\x74"
                                "\xce\xb1\xe2\x85\xbd\xce\xba\xc7\x83\xe2\x80"
                                "\xbc";
+  n->my_ooe.rfc4122_uuid = "5e2ab188-1726-4e75-a04f-1ed9a6a89c4c";
   n->my_bonk.type = 31337;
   n->my_bonk.message = "I am a bonk... xor!";
 }
@@ -98,7 +100,8 @@
     "1.6180339887498949},\"8\":{\"str\":\":R (me going \\\"rrrr\\\")\"},\"9\":{"
     "\"str\":\"ӀⅮΝ Нοⅿоɡгаρℎ Αttαⅽκǃ‼\"},\"10\":{\"tf\":0},\"11\":{\"str\":\""
     "AQIDrQ\"},\"12\":{\"lst\":[\"i8\",3,1,2,3]},\"13\":{\"lst\":[\"i16\",3,1,2"
-    ",3]},\"14\":{\"lst\":[\"i64\",3,1,2,3]}}}}"
+    ",3]},\"14\":{\"lst\":[\"i64\",3,1,2,3]},\"15\":{\"uid\":\"5e2ab188-1726-"
+    "4e75-a04f-1ed9a6a89c4c\"}}}}"
   );
 
   const std::string result(apache::thrift::ThriftJSONString(*n));
@@ -162,12 +165,14 @@
   "},\"7\":{\"dbl\":3.1415926535897931},\"8\":{\"str\":\"JSON THIS! \\\"\\u0001"
   "\"},\"9\":{\"str\":\"\xd7\\n\\u0007\\t\"},\"10\":{\"tf\":0},\"11\":{\"str\":"
   "\"AQIDrQ\"},\"12\":{\"lst\":[\"i8\",3,1,2,3]},\"13\":{\"lst\":[\"i16\",3,1,2"
-  ",3]},\"14\":{\"lst\":[\"i64\",3,1,2,3]}},{\"1\":{\"tf\":1},\"2\":{\"tf\":0},"
+  ",3]},\"14\":{\"lst\":[\"i64\",3,1,2,3]},\"15\":{\"uid\":\"00000000-0000-0000"
+  "-0000-000000000000\"}},{\"1\":{\"tf\":1},\"2\":{\"tf\":0},"
   "\"3\":{\"i8\":51},\"4\":{\"i16\":16},\"5\":{\"i32\":32},\"6\":{\"i64\":64},"
   "\"7\":{\"dbl\":1.6180339887498949},\"8\":{\"str\":\":R (me going \\\"rrrr\\\""
   ")\"},\"9\":{\"str\":\"ӀⅮΝ Нοⅿоɡгаρℎ Αttαⅽκǃ‼\"},\"10\":{\"tf\":0},\"11\":{"
   "\"str\":\"AQIDrQ\"},\"12\":{\"lst\":[\"i8\",3,1,2,3]},\"13\":{\"lst\":[\"i16"
-  "\",3,1,2,3]},\"14\":{\"lst\":[\"i64\",3,1,2,3]}}]},\"2\":{\"set\":[\"lst\",3"
+  "\",3,1,2,3]},\"14\":{\"lst\":[\"i64\",3,1,2,3]},\"15\":{\"uid\":\"5e2ab188-"
+  "1726-4e75-a04f-1ed9a6a89c4c\"}}]},\"2\":{\"set\":[\"lst\",3"
   ",[\"str\",0],[\"str\",2,\"and a one\",\"and a two\"],[\"str\",3,\"then a one"
   ", two\",\"three!\",\"FOUR!!\"]]},\"3\":{\"map\":[\"str\",\"lst\",3,{\"nothin"
   "g\":[\"rec\",0],\"poe\":[\"rec\",3,{\"1\":{\"i32\":3},\"2\":{\"str\":\"quoth"
@@ -192,6 +197,8 @@
   OneOfEach ooe2;
   ooe2.read(proto.get());
 
+  BOOST_TEST_INFO("written: " << *ooe);
+  BOOST_TEST_INFO("read   : " << ooe2);
   BOOST_CHECK(*ooe == ooe2);
 }
 
@@ -205,6 +212,8 @@
   HolyMoley hm2;
   hm2.read(proto.get());
 
+  BOOST_TEST_INFO("written: " << *hm);
+  BOOST_TEST_INFO("read   : " << hm2);
   BOOST_CHECK(*hm == hm2);
 
   hm2.big[0].a_bite = 0x00;
@@ -230,14 +239,14 @@
   );
 
   std::shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer());
-  std::shared_ptr<TJSONProtocol> proto(new TJSONProtocol(buffer)); 
+  std::shared_ptr<TJSONProtocol> proto(new TJSONProtocol(buffer));
   dub.write(proto.get());
   Doubles dub_1;
   dub_1.read(proto.get());
 
   const std::string result(apache::thrift::ThriftJSONString(dub));
   const std::string result_1(apache::thrift::ThriftJSONString(dub_1));
-  
+
   BOOST_CHECK_MESSAGE(!expected_result.compare(result),
     "Expected:\n" << expected_result << "\nGotten:\n" << result);
   BOOST_CHECK_MESSAGE(!expected_result.compare(result_1),
diff --git a/lib/cpp/test/SpecializationTest.cpp b/lib/cpp/test/SpecializationTest.cpp
index 008837d..0976112 100644
--- a/lib/cpp/test/SpecializationTest.cpp
+++ b/lib/cpp/test/SpecializationTest.cpp
@@ -26,6 +26,7 @@
   ooe.some_characters = "JSON THIS! \"\1";
   ooe.zomg_unicode = "\xd7\n\a\t";
   ooe.base64 = "\1\2\3\255";
+  ooe.rfc4122_uuid = "00000000-0000-0000-0000-000000000000";
 
   Nesting n;
   n.my_ooe = ooe;
@@ -89,6 +90,8 @@
   OneOfEach ooe2;
   ooe2.read(proto.get());
 
+  BOOST_TEST_INFO("Write: " << ooe);
+  BOOST_TEST_INFO("Read : " << ooe2);
   BOOST_CHECK(ooe == ooe2);
 
   hm.write(proto.get());
diff --git a/lib/cpp/test/ToStringTest.cpp b/lib/cpp/test/ToStringTest.cpp
index 736b33c..68c82ad 100644
--- a/lib/cpp/test/ToStringTest.cpp
+++ b/lib/cpp/test/ToStringTest.cpp
@@ -160,4 +160,13 @@
                     "ListBonks(bonk=[Bonk(message=a, type=0), Bonk(message=b, type=0)])");
 }
 
+BOOST_AUTO_TEST_CASE(generated_uuid_to_string) {
+  thrift::test::CrazyNesting l;
+  l.uuid_field = "{4b686716-5f20-4deb-8ce0-9eaf379e8a3d}";
+
+  BOOST_CHECK_EQUAL(to_string(l),
+                    "CrazyNesting(string_field=, set_field=<null>, list_field=[], binary_field=, "
+                    "uuid_field={4b686716-5f20-4deb-8ce0-9eaf379e8a3d})");
+}
+
 BOOST_AUTO_TEST_SUITE_END()