[gnome-builder] tests: add snippet-parsing test program



commit 65542995e87ba8cb4551bcaa916137591f88b362
Author: Christian Hergert <chergert redhat com>
Date:   Fri Mar 11 16:42:35 2016 -0800

    tests: add snippet-parsing test program
    
    This can be used to verify a snippets file, as well as serve as a base
    for fuzzing if you'd like to work on that (Use AFL or something similar).

 tests/Makefile.am           |    6 +++++
 tests/test-snippet-parser.c |   52 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+), 0 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 743209c..19097ad 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -154,6 +154,12 @@ test_egg_slider_CFLAGS = $(egg_cflags)
 test_egg_slider_LDADD = $(egg_libs)
 
 
+misc_programs += test-snippet-parser
+test_snippet_parser_SOURCES = test-snippet-parser.c
+test_snippet_parser_CFLAGS = $(tests_cflags)
+test_snippet_parser_LDADD = $(tests_libs)
+
+
 #TESTS += test-ide-ctags
 #test_ide_ctags_SOURCES = test-ide-ctags.c
 #test_ide_ctags_CFLAGS = $(tests_cflags)
diff --git a/tests/test-snippet-parser.c b/tests/test-snippet-parser.c
new file mode 100644
index 0000000..400aa60
--- /dev/null
+++ b/tests/test-snippet-parser.c
@@ -0,0 +1,52 @@
+#include <ide.h>
+#include <stdlib.h>
+
+#include "ide-source-snippet-parser.h"
+
+gint
+main (gint   argc,
+      gchar *argv[])
+{
+  GOptionContext *context;
+  GOptionEntry entries[] = {
+    NULL
+  };
+  GError *error = NULL;
+  gint i;
+
+  context = g_option_context_new ("[FILES...] - test snippet parsing");
+  g_option_context_add_main_entries (context, entries, NULL);
+
+  if (!g_option_context_parse (context, &argc, &argv, &error))
+    {
+      g_printerr ("%s\n", error->message);
+      return EXIT_FAILURE;
+    }
+
+  for (i = 1; i < argc; i++)
+    {
+      const gchar *filename = argv [i];
+      g_autoptr(IdeSourceSnippetParser) parser = NULL;
+      g_autoptr(GFile) file = NULL;
+
+      if (!g_file_test (filename, G_FILE_TEST_IS_REGULAR))
+        {
+          g_printerr ("Failed to open %s\n", filename);
+          return EXIT_FAILURE;
+        }
+
+      file = g_file_new_for_commandline_arg (filename);
+
+      parser = ide_source_snippet_parser_new ();
+
+      if (!ide_source_snippet_parser_load_from_file (parser, file, &error))
+        {
+          g_printerr ("%s\n", error->message);
+          return EXIT_FAILURE;
+        }
+    }
+
+  g_option_context_free (context);
+
+  return EXIT_SUCCESS;
+}


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