[glib] Test inplace decoding



commit f13618623b191c539cc151d19f7f5b54e24b3607
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Jun 20 23:46:01 2010 -0400

    Test inplace decoding

 glib/tests/base64.c |   36 +++++++++++++++++++++++++++++++++++-
 1 files changed, 35 insertions(+), 1 deletions(-)
---
diff --git a/glib/tests/base64.c b/glib/tests/base64.c
index fa7640e..982a3e7 100644
--- a/glib/tests/base64.c
+++ b/glib/tests/base64.c
@@ -265,6 +265,24 @@ decode_and_compare (const gchar            *datap,
 }
 
 static void
+decode_inplace_and_compare (const gchar            *datap,
+                            const struct MyRawData *p)
+{
+  gchar *data;
+  guchar *data2;
+  gsize len;
+  int memcmp_decode;
+
+  data = g_strdup (datap);
+  data2 = g_base64_decode_inplace (data, &len);
+  g_assert_cmpint (len, ==, p->length);
+  /* g_print ("length: got %d, expected %d\n",len, length); */
+  memcmp_decode = memcmp (p->data, data2, p->length);
+  g_assert_cmpint (memcmp_decode, ==, 0);
+  g_free (data2);
+}
+
+static void
 test_base64_decode (void)
 {
   int i;
@@ -280,6 +298,21 @@ test_base64_decode (void)
 }
 
 static void
+test_base64_decode_inplace (void)
+{
+  int i;
+  struct MyRawData myraw;
+
+  generate_databuffer_for_base64 (&myraw);
+
+  for (i = 0; ok_100_encode_strs[i]; i++)
+    {
+      myraw.length = i + 1;
+      decode_inplace_and_compare (ok_100_encode_strs[i], &myraw);
+    }
+}
+
+static void
 test_base64_encode_decode (void)
 {
   int i;
@@ -330,7 +363,8 @@ main (int argc, char *argv[])
 
   g_test_add_func ("/base64/encode", test_base64_encode);
   g_test_add_func ("/base64/decode", test_base64_decode);
-  g_test_add_func ("/base64/encode_decode", test_base64_encode_decode);
+  g_test_add_func ("/base64/decode-inplace", test_base64_decode_inplace);
+  g_test_add_func ("/base64/encode-decode", test_base64_encode_decode);
 
   return g_test_run ();
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]