THRIFT-3968: Deserializing empty string/binary fields
Client: C (GLib)
Patch: Simon South <simonsouth@apache.org>

Deserialize empty strings as they are instead of returning NULL.
Expand test cases to clarify existing behavior when deserializing empty
binary fields.
diff --git a/lib/c_glib/test/testcompactprotocol.c b/lib/c_glib/test/testcompactprotocol.c
index 9b57a8c..03bc226 100755
--- a/lib/c_glib/test/testcompactprotocol.c
+++ b/lib/c_glib/test/testcompactprotocol.c
@@ -189,6 +189,7 @@
                                                  TEST_DOUBLE, NULL) > 0);
     assert (thrift_compact_protocol_write_string (protocol,
                                                  TEST_STRING, NULL) > 0);
+    assert (thrift_compact_protocol_write_string (protocol, "", NULL) > 0);
     assert (thrift_compact_protocol_write_binary (protocol, binary,
                                                  len, NULL) > 0);
     assert (thrift_compact_protocol_write_binary (protocol, NULL, 0, NULL) > 0);
@@ -636,6 +637,8 @@
     assert (thrift_compact_protocol_write_string (protocol,
                                                  TEST_STRING, NULL) > 0);
     thrift_transport_flush (transport, NULL);
+    assert (thrift_compact_protocol_write_string (protocol, "", NULL) > 0);
+    thrift_transport_flush (transport, NULL);
     assert (thrift_compact_protocol_write_binary (protocol, binary,
                                                  len, NULL) > 0);
     thrift_transport_flush (transport, NULL);
@@ -677,6 +680,7 @@
   gint64 value_n64 = 0;
   gdouble value_double = 0;
   gchar *string = NULL;
+  gchar *empty_string = NULL;
   gpointer binary = NULL;
   guint32 len = 0;
   void *comparator = (void *) TEST_STRING;
@@ -710,6 +714,8 @@
   assert (thrift_compact_protocol_read_double (protocol,
                                               &value_double, NULL) > 0);
   assert (thrift_compact_protocol_read_string (protocol, &string, NULL) > 0);
+  assert (thrift_compact_protocol_read_string (protocol, &empty_string,
+                                               NULL) > 0);
   assert (thrift_compact_protocol_read_binary (protocol, &binary,
                                               &len, NULL) > 0);
 
@@ -729,12 +735,17 @@
   assert (zigzag_n64 == 3);
   assert (value_double == TEST_DOUBLE);
   assert (strcmp (TEST_STRING, string) == 0);
+  assert (strcmp ("", empty_string) == 0);
   assert (memcmp (comparator, binary, len) == 0);
 
   g_free (string);
+  g_free (empty_string);
   g_free (binary);
 
-  thrift_compact_protocol_read_binary (protocol, &binary, &len, NULL);
+  assert (thrift_compact_protocol_read_binary (protocol, &binary,
+                                               &len, NULL) > 0);
+  assert (binary == NULL);
+  assert (len == 0);
   g_free (binary);
 
   transport_read_count = 0;
@@ -1181,6 +1192,7 @@
   gint64 value_n64 = 0;
   gdouble value_double = 0;
   gchar *string = NULL;
+  gchar *empty_string = NULL;
   gpointer binary = NULL;
   guint32 len = 0;
   void *comparator = (void *) TEST_STRING;
@@ -1217,6 +1229,8 @@
   assert (thrift_compact_protocol_read_double (protocol,
                                               &value_double, NULL) > 0);
   assert (thrift_compact_protocol_read_string (protocol, &string, NULL) > 0);
+  assert (thrift_compact_protocol_read_string (protocol, &empty_string,
+                                               NULL) > 0);
   assert (thrift_compact_protocol_read_binary (protocol, &binary,
                                               &len, NULL) > 0);
 
@@ -1236,9 +1250,17 @@
   assert (zigzag_n64 == 3);
   assert (value_double == TEST_DOUBLE);
   assert (strcmp (TEST_STRING, string) == 0);
+  assert (strcmp ("", empty_string) == 0);
   assert (memcmp (comparator, binary, len) == 0);
 
   g_free (string);
+  g_free (empty_string);
+  g_free (binary);
+
+  assert (thrift_compact_protocol_read_binary (protocol, &binary,
+                                               &len, NULL) > 0);
+  assert (binary == NULL);
+  assert (len == 0);
   g_free (binary);
 
   thrift_transport_read_end (client, NULL);