diff --git a/Sconstruct b/Sconstruct index 620fbe44..82539f91 100644 --- a/Sconstruct +++ b/Sconstruct @@ -18,6 +18,7 @@ class OEnvironment(Environment): self.Append(CXXCOMSTR = "C++ $TARGET") self.Append(CCCOMSTR = "CC $TARGET") self.Append(LINKCOMSTR = "Linking $TARGET") + self.Append(ENV = { "DISPLAY" : os.environ["DISPLAY"] }) self.Debug = CONFIG_DEBUG self.Version = CONFIG_VERSION diff --git a/gui/builder.c b/gui/builder.c new file mode 100644 index 00000000..9dc44652 --- /dev/null +++ b/gui/builder.c @@ -0,0 +1,24 @@ +/* + * Copyright 2016 (c) Anna Schumaker. + */ +#include + +static GtkBuilder *gui_builder = NULL; + +void gui_builder_init(const char *file) +{ + gui_builder = gtk_builder_new_from_file(file); +} + +void gui_builder_deinit() +{ + g_object_unref(G_OBJECT(gui_builder)); + gui_builder = NULL; +} + +#ifdef CONFIG_TESTING +GtkBuilder *test_get_gui_builder() +{ + return gui_builder; +} +#endif /* CONFIG_TESTING */ diff --git a/include/gui/builder.h b/include/gui/builder.h new file mode 100644 index 00000000..e32eda76 --- /dev/null +++ b/include/gui/builder.h @@ -0,0 +1,17 @@ +/* + * Copyright 2016 (c) Anna Schumaker. + */ +#ifndef OCARINA_GUI_BUILDER_H +#define OCARINA_GUI_BUILDER_H +#include + +/* Called to initialize the GTK builder. */ +void gui_builder_init(const char *); + +/* Called to deinitialize the GTK builder. */ +void gui_builder_deinit(); + +#ifdef CONFIG_TESTING +GtkBuilder *test_get_gui_builder(); +#endif /* CONFIG_TESTING */ +#endif /* OCARINA_GUI_BUILDER_H */ diff --git a/tests/Sconscript b/tests/Sconscript index d3cce3ea..f7e1fbd2 100644 --- a/tests/Sconscript +++ b/tests/Sconscript @@ -26,7 +26,7 @@ test_o = env.Object("test", "test.c") def UnitTest(test, sources): name = os.path.basename(test) make = env.Program(name, sources + [ test_o ]) - run = Command("%s.fake" % name, [], "tests/%s" % test) + run = Command("%s.fake" % name, [], "tests/%s" % test, ENV = os.environ) Depends(run, make) Alias("tests/%s" % test, run) return run diff --git a/tests/gui/.gitignore b/tests/gui/.gitignore index a01c11a4..f46d2890 100644 --- a/tests/gui/.gitignore +++ b/tests/gui/.gitignore @@ -1 +1,2 @@ settings +builder diff --git a/tests/gui/Sconscript b/tests/gui/Sconscript index 33714512..2c47f080 100644 --- a/tests/gui/Sconscript +++ b/tests/gui/Sconscript @@ -24,6 +24,7 @@ def GuiTest(name): res += [ GuiTest("settings") ] +res += [ GuiTest("builder") ] ignore.close() Return("res") diff --git a/tests/gui/builder.c b/tests/gui/builder.c new file mode 100644 index 00000000..80fca11b --- /dev/null +++ b/tests/gui/builder.c @@ -0,0 +1,23 @@ +/* + * Copyright 2016 (c) Anna Schumaker. + */ +#include +#include + +static void test_builder() +{ + int argc = 0; + + test_equal((void *)test_get_gui_builder(), NULL); + + gtk_init(&argc, NULL); + gui_builder_init("share/ocarina/ocarina6.glade"); + test_not_equal((void *)test_get_gui_builder(), NULL); + + gui_builder_deinit(); + test_equal((void *)test_get_gui_builder(), NULL); +} + +DECLARE_UNIT_TESTS( + UNIT_TEST("GTK Builder", test_builder), +);