From 0c51533d5bf112e71bb1efb77962acfa795ff34b Mon Sep 17 00:00:00 2001 From: Jesse van den Kieboom Date: Thu, 12 Jul 2012 10:52:22 +0200 Subject: [PATCH] Added diff-view test application --- tests/Makefile.am | 15 ++++- tests/diff-view.vala | 134 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+), 2 deletions(-) create mode 100644 tests/diff-view.vala diff --git a/tests/Makefile.am b/tests/Makefile.am index 580d018a..b87dffba 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,8 +1,19 @@ INCLUDES = -g -I$(top_srcdir) -I$(top_srcdir)/gitg -I$(top_srcdir)/libgitg $(GITG_DEBUG_FLAGS) $(GITG_CFLAGS) -noinst_PROGRAMS = $(TEST_PROGS) -progs_ldadd = $(top_builddir)/libgitg/libgitg-1.0.la $(PACKAGE_LIBS) $(GITG_LIBS) +noinst_PROGRAMS = $(TEST_PROGS) $(DEMO_PROGS) + +VALAFLAGS = $(GITG_PLUGIN_VALAFLAGS) + +DEMO_PROGS = diff-view + +diff_view_SOURCES = diff-view.vala +diff_view_LDADD = $(GITG_PLUGIN_LIBS) +diff_view_CFLAGS = $(GITG_PLUGIN_CFLAGS) -w TESTS = $(TEST_PROGS) +BUILT_SOURCES = \ + diff_view_vala.stamp \ + $(diff_view_SOURCES:.vala=.c) + -include $(top_srcdir)/git.mk diff --git a/tests/diff-view.vala b/tests/diff-view.vala new file mode 100644 index 00000000..3c1bd8f0 --- /dev/null +++ b/tests/diff-view.vala @@ -0,0 +1,134 @@ +class TestDiffView +{ + public static int main(string[] args) + { + Gtk.init(ref args); + + if (Environment.get_variable("GITG_GTK_DIFF_VIEW_DEBUG") != "local" && args.length > 1 && args[1] == "--local") + { + // Launch in local mode + var path = File.new_for_path(args[0]); + var gtk = path.get_parent().get_parent().get_parent().get_child("libgitg-gtk"); + + var rargs = args; + + rargs[0] = "../tests/diff-view"; + + for (var i = 1; i < rargs.length - 1; ++i) + { + rargs[i] = rargs[i + 2]; + } + + int status; + + var sliced = rargs[0:(rargs.length - 1)]; + + var env = Environ.get(); + env += "GITG_GTK_DIFF_VIEW_DEBUG=local"; + + try + { + Process.spawn_sync(gtk.get_path(), + sliced, + env, + 0, + null, + null, + null, + out status); + } + catch (Error err) + { + stderr.printf("Error while spawning local version: %s\n", err.message); + return 1; + } + + return status; + } + + var inipath = "."; + + if (args.length > 1) + { + inipath = args[1]; + } + + File repopath; + Ggit.Repository repo; + + try + { + repopath = Ggit.Repository.discover(File.new_for_commandline_arg(inipath)); + repo = Ggit.Repository.open(repopath); + } + catch + { + stderr.printf("The specified path is not a git repository: %s\n", inipath); + return 1; + } + + Ggit.Ref head; + Ggit.Commit commit; + + try + { + head = repo.get_head(); + commit = head.lookup() as Ggit.Commit; + } + catch + { + stderr.printf("The repository does not have a current HEAD\n"); + return 1; + } + + var wnd = new Gtk.Window(); + wnd.set_default_size(800, 600); + var sw = new Gtk.ScrolledWindow(null, null); + + var v = new GitgGtk.DiffView(null); + sw.add(v); + + v.options = new Ggit.DiffOptions(Ggit.DiffFlags.NORMAL, + 3, + 0, + null, + null, + null); + + v.commit = commit; + + v.key_press_event.connect((vv, ev) => { + var state = ev.state & Gtk.accelerator_get_default_mod_mask(); + + if (ev.keyval == Gdk.Key.r && state == Gdk.ModifierType.CONTROL_MASK) + { + v.reload_bypass_cache(); + return true; + } + else + { + return false; + } + }); + + wnd.delete_event.connect((w, ev) => { + Gtk.main_quit(); + return true; + }); + + wnd.add(sw); + wnd.show_all(); + + if (Environment.get_variable("GITG_GTK_DIFF_VIEW_DEBUG") != "local") + { + stdout.printf("Use `diff-view --local' to use local resources.\n"); + } + + stdout.printf("Press Ctrl+R to refresh...\n"); + + Gtk.main(); + return 0; + } +} + +// vi:ts=4