[gnome-builder] tests: add simple test case for IdeContext



commit 942d0d76ef12615ca3294010cf2fff7efdf36034
Author: Christian Hergert <christian hergert me>
Date:   Sat Feb 7 12:42:45 2015 -0800

    tests: add simple test case for IdeContext
    
    This just tries to load a simple autotools based project and checks that
    a few items are there.
    
    We are currently bundling all of the test data, since the tests are
    published with the sources. I'm not sure how I feel about that long term,
    but for now it will do.

 .gitignore                       |    9 +---
 tests/test-ide-context.c         |   84 ++++++++++++++++++++++++++++++++++++++
 tests/tests.mk                   |   14 ++++++
 3 files changed, 101 insertions(+), 6 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index db57b86..d5300a5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,8 +2,10 @@
 *.gz
 *.libs
 *.lo
+*.log
 *.o
 *.swp
+*.trs
 *.xz
 *~
 .dirstamp
@@ -27,10 +29,5 @@ libide.la
 libtool
 stamp-h1
 test-c-parse-helper
-test-c-parse-helper
-test-c-parse-helper.log
-test-c-parse-helper.trs
+test-ide-context
 test-navigation-list
-test-navigation-list.log
-test-navigation-list.trs
-test-suite.log
diff --git a/tests/data/project1/configure.ac b/tests/data/project1/configure.ac
new file mode 100644
index 0000000..e69de29
diff --git a/tests/test-ide-context.c b/tests/test-ide-context.c
new file mode 100644
index 0000000..476797c
--- /dev/null
+++ b/tests/test-ide-context.c
@@ -0,0 +1,84 @@
+/* test-context.c
+ *
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <ide.h>
+
+typedef struct
+{
+  GMainLoop    *main_loop;
+  IdeContext   *context;
+  GCancellable *cancellable;
+  GError       *error;
+} test_new_async_state;
+
+static void
+test_new_async_cb1 (GObject      *object,
+                    GAsyncResult *result,
+                    gpointer      user_data)
+{
+  test_new_async_state *state = user_data;
+  state->context = ide_context_new_finish (result, &state->error);
+  g_main_loop_quit (state->main_loop);
+}
+
+static void
+test_new_async (void)
+{
+  test_new_async_state state = { 0 };
+  IdeBuildSystem *bs;
+  IdeVcs *vcs;
+  GFile *project_file;
+  const gchar *root_build_dir;
+
+  project_file = g_file_new_for_path (TEST_DATA_DIR"/project1/configure.ac");
+
+  state.main_loop = g_main_loop_new (NULL, FALSE);
+  state.cancellable = g_cancellable_new ();
+
+  ide_context_new_async (project_file, state.cancellable,
+                         test_new_async_cb1, &state);
+
+  g_main_loop_run (state.main_loop);
+
+  g_assert_no_error (state.error);
+  g_assert (state.context);
+
+  bs = ide_context_get_build_system (state.context);
+  g_assert (IDE_IS_AUTOTOOLS_BUILD_SYSTEM (bs));
+
+  vcs = ide_context_get_vcs (state.context);
+  g_assert (IDE_IS_GIT_VCS (vcs));
+
+  root_build_dir = ide_context_get_root_build_dir (state.context);
+  g_assert (g_str_has_suffix (root_build_dir, "/libide/builds"));
+
+  g_clear_object (&state.cancellable);
+  g_clear_object (&state.context);
+  g_clear_error (&state.error);
+  g_main_loop_unref (state.main_loop);
+  g_clear_object (&project_file);
+}
+
+gint
+main (gint   argc,
+      gchar *argv[])
+{
+  g_test_init (&argc, &argv, NULL);
+  g_test_add_func ("/Ide/Context/new_async", test_new_async);
+  return g_test_run ();
+}
diff --git a/tests/tests.mk b/tests/tests.mk
index ec7438b..d74ef13 100644
--- a/tests/tests.mk
+++ b/tests/tests.mk
@@ -10,3 +10,17 @@ TESTS += test-navigation-list
 test_navigation_list_SOURCES = tests/test-navigation-list.c
 test_navigation_list_CFLAGS = $(libgnome_builder_la_CFLAGS)
 test_navigation_list_LDADD = libgnome-builder.la
+
+
+noinst_PROGRAMS += test-ide-context
+TESTS += test-ide-context
+test_ide_context_SOURCES = tests/test-ide-context.c
+test_ide_context_CFLAGS = \
+       $(libide_la_CFLAGS) \
+       -DTEST_DATA_DIR="\"$(top_srcdir)/tests/data\""
+test_ide_context_LDADD = libide.la
+
+
+EXTRA_DIST += \
+       tests/data/project1/configure.ac \
+       $(NULL)


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