summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Withnall <philip.withnall@collabora.co.uk>2014-05-05 10:19:41 +0100
committerPhilip Withnall <philip.withnall@collabora.co.uk>2014-05-05 11:44:03 +0100
commit989ecb0db66685ec86243f1ef201d336339dbae6 (patch)
tree1156faa0a00466d5cbf8c6db2a67401eb9af2d1b
parent4c4ce269c5932525ab12ccddf9cd5ae4b06aca1a (diff)
clang-plugin: Enable GVariant checks for other methods
This enables GVariant format string checking for: • g_variant_get_child() • g_variant_lookup() • g_variant_iter_next() • g_variant_iter_loop() • g_variant_builder_add() and adds basic unit tests for all of them. GVariant support is now complete!
-rw-r--r--.be/8443e173-30ee-4e83-9228-9e11414e3432/bugs/85d225cc-52a3-4a5a-bb7c-5e0700c220a4/values2
-rw-r--r--clang-plugin/gvariant-checker.cpp3
-rw-r--r--tests/Makefile.am6
-rw-r--r--tests/gvariant-builder.c41
-rw-r--r--tests/gvariant-get-child.c40
-rw-r--r--tests/gvariant-iter.c69
-rw-r--r--tests/gvariant-lookup.c52
-rwxr-xr-xtests/wrapper-compiler-errors4
8 files changed, 211 insertions, 6 deletions
diff --git a/.be/8443e173-30ee-4e83-9228-9e11414e3432/bugs/85d225cc-52a3-4a5a-bb7c-5e0700c220a4/values b/.be/8443e173-30ee-4e83-9228-9e11414e3432/bugs/85d225cc-52a3-4a5a-bb7c-5e0700c220a4/values
index 4bdfb22..7279b57 100644
--- a/.be/8443e173-30ee-4e83-9228-9e11414e3432/bugs/85d225cc-52a3-4a5a-bb7c-5e0700c220a4/values
+++ b/.be/8443e173-30ee-4e83-9228-9e11414e3432/bugs/85d225cc-52a3-4a5a-bb7c-5e0700c220a4/values
@@ -26,7 +26,7 @@
- "status": "open",
+ "status": "fixed",
diff --git a/clang-plugin/gvariant-checker.cpp b/clang-plugin/gvariant-checker.cpp
index 802bf65..ba23f00 100644
--- a/clang-plugin/gvariant-checker.cpp
+++ b/clang-plugin/gvariant-checker.cpp
@@ -98,14 +98,11 @@ static const VariantFuncInfo gvariant_format_funcs[] = {
{ "g_variant_new_va", 0, 2, true, true },
{ "g_variant_get", 1, 2, false, false },
{ "g_variant_get_va", 1, 3, true, false },
-/*
{ "g_variant_get_child", 2, 3, false, false },
{ "g_variant_lookup", 2, 3, false, false },
{ "g_variant_iter_next", 1, 2, false, false },
{ "g_variant_iter_loop", 1, 2, false, false },
{ "g_variant_builder_add", 1, 2, false, true },
- { "g_variant_builder_add_parsed", 1, 2, false, true },
-*/
};
/**
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 131bf19..ab04f2c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -6,8 +6,12 @@ TEST_EXTENSIONS = .c
C_LOG_COMPILER = ./wrapper-compiler-errors
TESTS = \
- gvariant-new.c \
+ gvariant-builder.c \
gvariant-get.c \
+ gvariant-get-child.c \
+ gvariant-iter.c \
+ gvariant-lookup.c \
+ gvariant-new.c \
$(NULL)
-include $(top_srcdir)/git.mk
diff --git a/tests/gvariant-builder.c b/tests/gvariant-builder.c
new file mode 100644
index 0000000..6cebb70
--- /dev/null
+++ b/tests/gvariant-builder.c
@@ -0,0 +1,41 @@
+/*
+ * No error
+ */
+{
+ GVariantBuilder *builder;
+ int i;
+
+ builder = g_variant_builder_new (G_VARIANT_TYPE_ARRAY);
+ for (i = 0; i < 16; i++) {
+ gchar buf[3];
+
+ sprintf (buf, "%d", i);
+ g_variant_builder_add (builder, "{is}", i, buf);
+ }
+
+ g_variant_builder_end (builder);
+}
+
+/*
+ * Expected a GVariant variadic argument of type ‘char *’ but saw one of type ‘int’.
+ * g_variant_builder_add (builder, "{ss}", "hi", 15);
+ * ^
+ */
+{
+ GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE_ARRAY);
+ g_variant_builder_add (builder, "{ss}", "hi", 15);
+ g_variant_builder_end (builder);
+}
+
+/*
+ * Expected a GVariant variadic argument of type ‘char *’ but saw NULL instead.
+ * g_variant_builder_add (builder, "s", FALSE);
+ * ^
+ */
+{
+ GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE_TUPLE);
+ g_variant_builder_add (builder, "s", "hi");
+ g_variant_builder_add (builder, "s", "hi");
+ g_variant_builder_add (builder, "s", FALSE);
+ g_variant_builder_end (builder);
+}
diff --git a/tests/gvariant-get-child.c b/tests/gvariant-get-child.c
new file mode 100644
index 0000000..08c2bce
--- /dev/null
+++ b/tests/gvariant-get-child.c
@@ -0,0 +1,40 @@
+/*
+ * No error
+ */
+{
+ gchar *str1 = NULL, *str2 = NULL;
+ g_variant_get_child (existing_variant, 0, "(ss)", &str1, &str2);
+}
+
+/*
+ * No error
+ */
+{
+ gchar *str1 = NULL, *str2 = NULL;
+ g_variant_get_child (existing_variant, 0, "(ss)", NULL, NULL);
+}
+
+/*
+ * No error
+ */
+{
+ const gchar *str1 = NULL, *str2 = NULL;
+ g_variant_get_child (existing_variant, 0, "(&s&s)", &str1, &str2);
+}
+
+/*
+ * No error
+ */
+{
+ g_variant_get_child (existing_variant, 0, "()");
+}
+
+/*
+ * Expected a GVariant variadic argument of type ‘const char **’ but saw one of type ‘guint *’.
+ * g_variant_get_child (existing_variant, 0, "&s", &not_a_string);
+ * ^
+ */
+{
+ guint not_a_string;
+ g_variant_get_child (existing_variant, 0, "&s", &not_a_string);
+}
diff --git a/tests/gvariant-iter.c b/tests/gvariant-iter.c
new file mode 100644
index 0000000..03e0117
--- /dev/null
+++ b/tests/gvariant-iter.c
@@ -0,0 +1,69 @@
+/*
+ * No error
+ */
+{
+ GVariant *dictionary;
+ GVariantIter iter;
+ GVariant *value;
+ gchar *key;
+
+ g_variant_iter_init (&iter, dictionary);
+ while (g_variant_iter_loop (&iter, "{sv}", &key, &value)) {
+ /* Something */
+ }
+}
+
+/*
+ * Expected a GVariant variadic argument of type ‘GVariant **’ but saw one of type ‘gchar **’.
+ * while (g_variant_iter_loop (&iter, "{sv}", &key, &not_a_value)) {
+ * ^
+ */
+{
+ GVariant *dictionary;
+ GVariantIter iter;
+ gchar *not_a_value;
+ gchar *key;
+
+ g_variant_iter_init (&iter, dictionary);
+ while (g_variant_iter_loop (&iter, "{sv}", &key, &not_a_value)) {
+ /* Something */
+ }
+}
+
+/*
+ * No error
+ */
+{
+ GVariant *dictionary;
+ GVariantIter iter;
+ GVariant *value;
+ gchar *key;
+
+ g_variant_iter_init (&iter, dictionary);
+ while (g_variant_iter_next (&iter, "{sv}", &key, &value)) {
+ /* Something */
+
+ g_variant_unref (value);
+ g_free (key);
+ }
+}
+
+/*
+ * Expected a GVariant variadic argument of type ‘GVariant **’ but saw one of type ‘gchar **’.
+ * while (g_variant_iter_next (&iter, "{sv}", &key, &not_a_value)) {
+ * ^
+ */
+{
+ GVariant *dictionary;
+ GVariantIter iter;
+ gchar *not_a_value;
+ gchar *key;
+
+ g_variant_iter_init (&iter, dictionary);
+ while (g_variant_iter_next (&iter, "{sv}", &key, &not_a_value)) {
+ /* Something */
+
+ g_free (not_a_value);
+ g_free (key);
+ }
+}
diff --git a/tests/gvariant-lookup.c b/tests/gvariant-lookup.c
new file mode 100644
index 0000000..e6d91af
--- /dev/null
+++ b/tests/gvariant-lookup.c
@@ -0,0 +1,52 @@
+/*
+ * No error
+ */
+{
+ // FIXME: Dynamically check that @existing_variant is a dictionary.
+ gchar *str1 = NULL, *str2 = NULL;
+ g_variant_lookup (existing_variant, "key", "(ss)", &str1, &str2);
+}
+
+/*
+ * No error
+ */
+{
+ gchar *str1 = NULL, *str2 = NULL;
+ g_variant_lookup (existing_variant, "key", "(ss)", NULL, NULL);
+}
+
+/*
+ * No error
+ */
+{
+ const gchar *str1 = NULL, *str2 = NULL;
+ g_variant_lookup (existing_variant, "key", "(&s&s)", &str1, &str2);
+}
+
+/*
+ * No error
+ */
+{
+ // The standard a{?*} example.
+ GVariant *value;
+ g_variant_lookup (existing_variant, "key", "*", &value);
+}
+
+/*
+ * No error
+ */
+{
+ // The standard a{sv} example.
+ GVariant *value;
+ g_variant_lookup (existing_variant, "key", "v", &value);
+}
+
+/*
+ * Expected a GVariant variadic argument of type ‘char **’ but saw one of type ‘guint *’.
+ * g_variant_lookup (existing_variant, "key", "s", &not_a_string);
+ * ^
+ */
+{
+ guint not_a_string;
+ g_variant_lookup (existing_variant, "key", "s", &not_a_string);
+}
diff --git a/tests/wrapper-compiler-errors b/tests/wrapper-compiler-errors
index d6459bc..c705038 100755
--- a/tests/wrapper-compiler-errors
+++ b/tests/wrapper-compiler-errors
@@ -35,7 +35,7 @@ system_includes=`echo | cpp -Wp,-v 2>&1 | grep '^[[:space:]]' | \
csplit --keep-files --elide-empty-files --silent \
--prefix="${temp_dir}/${input_filename}_" \
--suffix-format='%02d.c' \
- "${input_filename}" '/\/\*/' '{*}'
+ "${input_filename}" '/^\/\*/' '{*}'
num=0
while [[ -f `printf "${temp_dir}/${input_filename}_%02d.c" ${num}` ]]; do
@@ -51,6 +51,8 @@ while [[ -f `printf "${temp_dir}/${input_filename}_%02d.c" ${num}` ]]; do
# Wrap the section’s code with a prefix and suffix.
(cat << EOF
+#include <stdio.h>
+
#include <glib.h>
int