[glib/gvariant: 110/116] <struct> -> <tuple> in markup parser. Fix tests.



commit 7c0ace0acde2031bd5acd53a2b91c3a3a974b923
Author: Ryan Lortie <desrt desrt ca>
Date:   Wed Jan 13 12:36:06 2010 -0500

    <struct> -> <tuple> in markup parser.  Fix tests.
    
    This was the last instance of "struct" appearing anywhere in GVariant
    teminology.
    
    Add proper copyright headers to the tests and highlevel documentation to
    the non-obvious ones.  Update the tests to deal with the <struct> to
    <tuple> change.

 glib/gvariant-markup.c                |    6 +++---
 glib/tests/gvariant-big.c             |   19 +++++++++++++++++++
 glib/tests/gvariant-constructors.c    |    9 +++++----
 glib/tests/gvariant-endian.c          |   13 ++++++++++++-
 glib/tests/gvariant-fuzz.c            |   33 +++++++++++++++++++++++++++++++--
 glib/tests/gvariant-handle.c          |    9 +++++----
 glib/tests/gvariant-markup.c          |   23 +++++++++++++++++------
 glib/tests/gvariant-printer-parser.c  |   11 +++++++++++
 glib/tests/gvariant-random.c          |   22 +++++++++++++++++++---
 glib/tests/gvariant-serialiser.c      |   27 +++++++++++++++++++--------
 glib/tests/gvariant-varargs-strings.c |   11 +++++++++++
 glib/tests/gvariant-varargs.c         |   11 +++++++++++
 12 files changed, 163 insertions(+), 31 deletions(-)
---
diff --git a/glib/gvariant-markup.c b/glib/gvariant-markup.c
index 0d8090a..25b2315 100644
--- a/glib/gvariant-markup.c
+++ b/glib/gvariant-markup.c
@@ -199,7 +199,7 @@ g_variant_markup_print_string (GVariant *value,
           {
             GVariant *element;
 
-            g_string_append (string, "<struct>");
+            g_string_append (string, "<tuple>");
             g_variant_markup_newline (string, newlines);
 
             while ((element = g_variant_iter_next_value (&iter)))
@@ -207,7 +207,7 @@ g_variant_markup_print_string (GVariant *value,
                                              newlines, indentation, tabstop);
 
             g_variant_markup_indent (string, indentation - tabstop);
-            g_string_append (string, "</struct>");
+            g_string_append (string, "</tuple>");
           }
         else
           g_string_append (string, "<triv/>");
@@ -428,7 +428,7 @@ type_class_from_keyword (const char *keyword)
     { G_VARIANT_TYPE_CLASS_MAYBE,            "maybe" },
     { G_VARIANT_TYPE_CLASS_MAYBE,            "nothing" },
     { G_VARIANT_TYPE_CLASS_ARRAY,            "array" },
-    { G_VARIANT_TYPE_CLASS_TUPLE,           "struct" },
+    { G_VARIANT_TYPE_CLASS_TUPLE,            "tuple" },
     { G_VARIANT_TYPE_CLASS_DICT_ENTRY,       "dictionary-entry" }
   };
   gint i;
diff --git a/glib/tests/gvariant-big.c b/glib/tests/gvariant-big.c
index be334e9..d186a7c 100644
--- a/glib/tests/gvariant-big.c
+++ b/glib/tests/gvariant-big.c
@@ -1,3 +1,22 @@
+/*
+ * Copyright © 2008, Ryan Lortie
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * See the COPYING file for more information.
+ */
+
+/* This test creates two random number generators with the same seed and
+ * uses one of them to construct a large GVariant instance with random
+ * content.  The second generator is then used to verify that that
+ * GVariant is equal to a randomly selected value.  Since both
+ * generators are seeded to the same number, the verification should
+ * always succeed unless GVariant is corrupting data.
+ */
+
 #include <glib.h>
 
 gdouble
diff --git a/glib/tests/gvariant-constructors.c b/glib/tests/gvariant-constructors.c
index 5c44d2f..bdcab4a 100644
--- a/glib/tests/gvariant-constructors.c
+++ b/glib/tests/gvariant-constructors.c
@@ -1,11 +1,12 @@
 /*
  * Copyright © 2008 Philip Van Hoof, Ryan Lortie
  *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of version 3 of the GNU General Public License as
- * published by the Free Software Foundation.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
  *
- * See the included COPYING file for more information.
+ * See the COPYING file for more information.
  */
 
 #include <glib.h>
diff --git a/glib/tests/gvariant-endian.c b/glib/tests/gvariant-endian.c
index 3200852..f95b832 100644
--- a/glib/tests/gvariant-endian.c
+++ b/glib/tests/gvariant-endian.c
@@ -1,3 +1,14 @@
+/*
+ * Copyright © 2008 Ryan Lortie
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * See the COPYING file for more information.
+ */
+
 #include <glib.h>
 
 static void
@@ -19,7 +30,7 @@ test_byteswap (void)
   string = g_variant_markup_print (value, FALSE, 0, 0);
   g_variant_unref (value);
 
-  g_assert_cmpstr (string, ==, "<struct><uint64>8</uint64><uint32>1</uint32><uint16>2</uint16><byte>0x01</byte><false/></struct>");
+  g_assert_cmpstr (string, ==, "<tuple><uint64>8</uint64><uint32>1</uint32><uint16>2</uint16><byte>0x01</byte><false/></tuple>");
   g_free (string);
 }
 
diff --git a/glib/tests/gvariant-fuzz.c b/glib/tests/gvariant-fuzz.c
index fa00b8d..045fd79 100644
--- a/glib/tests/gvariant-fuzz.c
+++ b/glib/tests/gvariant-fuzz.c
@@ -1,3 +1,32 @@
+/*
+ * Copyright © 2008 William Hua, Ryan Lortie
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * See the COPYING file for more information.
+ */
+
+/* This test generates a random GVariant value and serialises it.  It
+ * then changes the serialised data by making a non-zero number of
+ * random corruptions.  This ensures that GVariant won't crash when
+ * presented with bad data.
+ *
+ * Different levels of corruption (ie: more or less changes) are tested.
+ *
+ * As an additional check, now that the data has been changed, at least
+ * one of two things must be true:
+ *
+ *  - GVariant realises that the serialised data is not in normal form
+ *    (ie: has been corrupted)
+ *  - GVariant recognises the serialised data as being valid, but
+ *    representing a value that is not equal to the original value.
+ *
+ * This extra check is also performed.
+ */
+
 #include <glib.h>
 #include <glib/gstdio.h>
 #include <string.h>
@@ -216,7 +245,7 @@ random_markup_from_signature (GString     *markup,
           g_string_append (markup, "<triv/>");
         else
           {
-            g_string_append (markup, "<struct>");
+            g_string_append (markup, "<tuple>");
 
             for (;
                  *signature != ')';
@@ -224,7 +253,7 @@ random_markup_from_signature (GString     *markup,
                                                            signature,
                                                            depth - 1));
 
-            g_string_append (markup, "</struct>");
+            g_string_append (markup, "</tuple>");
           }
 
         return signature + 1;
diff --git a/glib/tests/gvariant-handle.c b/glib/tests/gvariant-handle.c
index 0a2e223..7f9ae69 100644
--- a/glib/tests/gvariant-handle.c
+++ b/glib/tests/gvariant-handle.c
@@ -1,11 +1,12 @@
 /*
  * Copyright © 2009 Codethink Limited
  *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of version 3 of the GNU General Public License as
- * published by the Free Software Foundation.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
  *
- * See the included COPYING file for more information.
+ * See the COPYING file for more information.
  */
 
 #include <glib.h>
diff --git a/glib/tests/gvariant-markup.c b/glib/tests/gvariant-markup.c
index 1fe8aa8..42d34fe 100644
--- a/glib/tests/gvariant-markup.c
+++ b/glib/tests/gvariant-markup.c
@@ -1,3 +1,14 @@
+/*
+ * Copyright © 2008 Ryan Lortie
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * See the COPYING file for more information.
+ */
+
 #include <glib.h>
 
 #define add_tests(func, basename, array) \
@@ -19,7 +30,7 @@
 const char *verbatim_tests[] = {
   "<array type='ai'/>",
 
-  "<struct>"
+  "<tuple>"
     "<array>"
       "<int32>1</int32>"
       "<int32>2</int32>"
@@ -30,7 +41,7 @@ const char *verbatim_tests[] = {
       "<array type='aaai'/>"
       "<array type='aaai'/>"
     "</array>"
-  "</struct>",
+  "</tuple>",
 
   "<array>"
     "<string>hello world</string>"
@@ -48,17 +59,17 @@ const char *verbatim_tests[] = {
   "</array>",
 
   "<maybe>"
-    "<struct>"
+    "<tuple>"
       "<uint32>42</uint32>"
       "<byte>0x42</byte>"
       "<int32>-1</int32>"
       "<double>37.500000</double>"
       "<int64>-35383472451088536</int64>"
       "<uint64>9446744073709551616</uint64>"
-    "</struct>"
+    "</tuple>"
   "</maybe>",
 
-  "<struct>"
+  "<tuple>"
     "<array>"
       "<true/>"
       "<false/>"
@@ -73,7 +84,7 @@ const char *verbatim_tests[] = {
       "<triv/>"
       "<triv/>"
     "</array>"
-  "</struct>"
+  "</tuple>"
 };
 
 static void
diff --git a/glib/tests/gvariant-printer-parser.c b/glib/tests/gvariant-printer-parser.c
index c6179ed..cc76ee5 100644
--- a/glib/tests/gvariant-printer-parser.c
+++ b/glib/tests/gvariant-printer-parser.c
@@ -1,3 +1,14 @@
+/*
+ * Copyright © 2008 Ryan Lortie
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * See the COPYING file for more information.
+ */
+
 #include <glib.h>
 
 #define add_tests(func, basename, array) \
diff --git a/glib/tests/gvariant-random.c b/glib/tests/gvariant-random.c
index 0b6e37a..2a457a6 100644
--- a/glib/tests/gvariant-random.c
+++ b/glib/tests/gvariant-random.c
@@ -1,10 +1,26 @@
+/*
+ * Copyright © 2008 William Hua
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * See the COPYING file for more information.
+ */
+
+/* This test checks the markup parser by generating a large string of
+ * (valid) GVariant markup, parsing it, then running the printer to
+ * ensure that the same string is produced.
+ */
+
 #include <glib.h>
 
 #define TESTS                     100
 #define MAXIMUM_DEPTH             16
 #define MAXIMUM_ARRAY_SIZE        8
 #define MAXIMUM_STRUCT_SIZE       8
-/* the probability of an empty array/struct */
+/* the probability of an empty array/tuple */
 #define PROBABILITY_OF_NOTHING    0.1
 #define PROBABILITY_OF_BASIC_TYPE 0.3
 /* log base 2 of maximum string length */
@@ -215,7 +231,7 @@ random_markup_from_signature (GString     *markup,
           g_string_append (markup, "<triv/>");
         else
           {
-            g_string_append (markup, "<struct>");
+            g_string_append (markup, "<tuple>");
 
             for (;
                  *signature != ')';
@@ -223,7 +239,7 @@ random_markup_from_signature (GString     *markup,
                                                            signature,
                                                            depth - 1));
 
-            g_string_append (markup, "</struct>");
+            g_string_append (markup, "</tuple>");
           }
 
         return signature + 1;
diff --git a/glib/tests/gvariant-serialiser.c b/glib/tests/gvariant-serialiser.c
index 2784622..af0a06e 100644
--- a/glib/tests/gvariant-serialiser.c
+++ b/glib/tests/gvariant-serialiser.c
@@ -1,3 +1,14 @@
+/*
+ * Copyright © 2008 Ryan Lortie
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * See the COPYING file for more information.
+ */
+
 #include <glib.h>
 #include <stdio.h>
 
@@ -36,32 +47,32 @@ struct test_case test_cases[] = {
               "<string>se</string>"
             "</array>"),
   testcase ("(syus)", "str\0\xaa\0\0\0\x1\x1\x1\x1theend\0\x4",
-            "<struct>"
+            "<tuple>"
               "<string>str</string>"
               "<byte>0xaa</byte>"
               "<uint32>16843009</uint32>"
               "<string>theend</string>"
-            "</struct>"),
+            "</tuple>"),
   testcase ("a(sss)", "hello\0world\0gvariant\0\xc\x6" /*         0x17 */
                       "this\0hopefully\0works\0\xf\x5" /* +0x17 = 0x2e */
                       "k\0thx\0bye\0\x6\x2"            /* +0x0c = 0x3a */
                       "\x17\x2e\x3a",
             "<array>"
-              "<struct>"
+              "<tuple>"
                 "<string>hello</string>"
                 "<string>world</string>"
                 "<string>gvariant</string>"
-              "</struct>"
-              "<struct>"
+              "</tuple>"
+              "<tuple>"
                 "<string>this</string>"
                 "<string>hopefully</string>"
                 "<string>works</string>"
-              "</struct>"
-              "<struct>"
+              "</tuple>"
+              "<tuple>"
                 "<string>k</string>"
                 "<string>thx</string>"
                 "<string>bye</string>"
-              "</struct>"
+              "</tuple>"
             "</array>")
 
 };
diff --git a/glib/tests/gvariant-varargs-strings.c b/glib/tests/gvariant-varargs-strings.c
index 31c7c36..7aa5eb9 100644
--- a/glib/tests/gvariant-varargs-strings.c
+++ b/glib/tests/gvariant-varargs-strings.c
@@ -1,3 +1,14 @@
+/*
+ * Copyright © 2009 Codethink Limited
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * See the COPYING file for more information.
+ */
+
 #include <glib.h>
 
 static void
diff --git a/glib/tests/gvariant-varargs.c b/glib/tests/gvariant-varargs.c
index 3ada330..134959e 100644
--- a/glib/tests/gvariant-varargs.c
+++ b/glib/tests/gvariant-varargs.c
@@ -1,3 +1,14 @@
+/*
+ * Copyright 2008 Ryan Lortie
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * See the COPYING file for more information.
+ */
+
 #include <glib.h>
 
 struct structure



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