summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-12-07 02:25:31 +0000
committerDavid Robillard <d@drobilla.net>2011-12-07 02:25:31 +0000
commitab83f198624534342de6805df68dc85794421f9c (patch)
tree9975c94262eecc9527f27585e38c50b67aff9d18
parenta3b80d07bc180dfbf2679930b0137321ff0b477f (diff)
downloadganv-ab83f198624534342de6805df68dc85794421f9c.tar.gz
ganv-ab83f198624534342de6805df68dc85794421f9c.tar.bz2
ganv-ab83f198624534342de6805df68dc85794421f9c.zip
Add C test program.
git-svn-id: http://svn.drobilla.net/lad/trunk/ganv@3824 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r--ganv/canvas.h4
-rw-r--r--ganv/ganv.h31
-rw-r--r--ganv/module.h4
-rw-r--r--ganv/port.h14
-rw-r--r--src/Canvas.cpp16
-rw-r--r--src/ganv_test.c55
-rw-r--r--src/module.c21
-rw-r--r--wscript33
8 files changed, 160 insertions, 18 deletions
diff --git a/ganv/canvas.h b/ganv/canvas.h
index 4e3c687..a5bb441 100644
--- a/ganv/canvas.h
+++ b/ganv/canvas.h
@@ -63,6 +63,10 @@ ganv_canvas_resize(GanvCanvas* canvas, double width, double height);
GnomeCanvasGroup*
ganv_canvas_get_root(const GanvCanvas* canvas);
+void
+ganv_canvas_add_node(GanvCanvas* canvas,
+ GanvNode* node);
+
/** Get the default font size in points. */
double
ganv_canvas_get_default_font_size(const GanvCanvas* canvas);
diff --git a/ganv/ganv.h b/ganv/ganv.h
new file mode 100644
index 0000000..3b84935
--- /dev/null
+++ b/ganv/ganv.h
@@ -0,0 +1,31 @@
+/* This file is part of Ganv.
+ * Copyright 2007-2011 David Robillard <http://drobilla.net>
+ *
+ * Ganv 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 any later version.
+ *
+ * Ganv 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 details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with Ganv. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GANV_GANV_H
+#define GANV_GANV_H
+
+#include "ganv/box.h"
+#include "ganv/canvas.h"
+#include "ganv/circle.h"
+#include "ganv/edge.h"
+#include "ganv/ganv.h"
+#include "ganv/module.h"
+#include "ganv/node.h"
+#include "ganv/port.h"
+#include "ganv/text.h"
+#include "ganv/types.h"
+
+#endif /* GANV_GANV_H */
+
diff --git a/ganv/module.h b/ganv/module.h
index 0aace15..e4b4e79 100644
--- a/ganv/module.h
+++ b/ganv/module.h
@@ -55,6 +55,10 @@ struct _GanvModuleClass {
GType ganv_module_get_type(void);
+GanvModule*
+ganv_module_new(GanvCanvas* canvas,
+ const char* first_prop_name, ...);
+
void
ganv_module_add_port(GanvModule* module,
GanvPort* port);
diff --git a/ganv/port.h b/ganv/port.h
index 6b464c2..a3769f7 100644
--- a/ganv/port.h
+++ b/ganv/port.h
@@ -43,7 +43,7 @@ struct _GanvPort
{
GanvBox box;
GanvPortControl* control;
- gboolean is_input;
+ gboolean is_input;
};
struct _GanvPortClass {
@@ -54,8 +54,8 @@ GType ganv_port_get_type(void);
GanvPort*
ganv_port_new(GanvModule* module,
- gboolean is_input,
- const char* first_prop_name, ...);
+ gboolean is_input,
+ const char* first_prop_name, ...);
void
ganv_port_show_control(GanvPort* port);
@@ -65,19 +65,19 @@ ganv_port_hide_control(GanvPort* port);
void
ganv_port_set_control_is_toggle(GanvPort* port,
- gboolean is_toggle);
+ gboolean is_toggle);
void
ganv_port_set_control_value(GanvPort* port,
- float value);
+ float value);
void
ganv_port_set_control_min(GanvPort* port,
- float min);
+ float min);
void
ganv_port_set_control_max(GanvPort* port,
- float max);
+ float max);
double
ganv_port_get_natural_width(const GanvPort* port);
diff --git a/src/Canvas.cpp b/src/Canvas.cpp
index a410588..2faf2a5 100644
--- a/src/Canvas.cpp
+++ b/src/Canvas.cpp
@@ -125,7 +125,7 @@ struct HeadTailOrder {
struct GanvCanvasImpl {
GanvCanvasImpl(GanvCanvas* gobj)
: _gcanvas(gobj)
- , _layout(Glib::wrap(GTK_LAYOUT(_gcanvas)))
+ , _layout(GTK_LAYOUT(_gcanvas))
, _connect_port(NULL)
, _last_selected_port(NULL)
, _base_rect(gnome_canvas_item_new(
@@ -231,8 +231,8 @@ struct GanvCanvasImpl {
void move_contents_to_internal(double x, double y, double min_x, double min_y);
- GanvCanvas* _gcanvas;
- Gtk::Layout* _layout;
+ GanvCanvas* _gcanvas;
+ GtkLayout* _layout;
Items _items; ///< Items on this canvas
Edges _edges; ///< Edges ordered (src, dst)
@@ -310,7 +310,7 @@ GanvCanvasImpl::selection_move_finished()
{
FOREACH_ITEM(_selected_items, i) {
std::cerr << "FIXME: selection move finished" << std::endl;
- Glib::wrap(*i)->signal_moved.emit();
+ //Glib::wrap(*i)->signal_moved.emit();
}
}
@@ -398,8 +398,7 @@ GanvCanvasImpl::select_item(GanvNode* m)
// Select any connections to or from this node
if (GANV_IS_MODULE(m)) {
- Ganv::Module* module = Glib::wrap(GANV_MODULE(m));
- module->for_each_port(select_edges, this);
+ ganv_module_for_each_port(GANV_MODULE(m), select_edges, this);
} else {
for_each_edge_on(m, ganv_edge_select);
}
@@ -425,8 +424,7 @@ GanvCanvasImpl::unselect_item(GanvNode* m)
{
// Unselect any connections to or from this node
if (GANV_IS_MODULE(m)) {
- Ganv::Module* module = Glib::wrap(GANV_MODULE(m));
- module->for_each_port(unselect_edges, this);
+ ganv_module_for_each_port(GANV_MODULE(m), unselect_edges, this);
} else {
for_each_edge_on(m, ganv_edge_unselect);
}
@@ -1707,7 +1705,7 @@ Canvas::root()
Gtk::Layout&
Canvas::widget()
{
- return *impl()->_layout;
+ return *Glib::wrap(impl()->_layout);
}
void
diff --git a/src/ganv_test.c b/src/ganv_test.c
new file mode 100644
index 0000000..a2df8af
--- /dev/null
+++ b/src/ganv_test.c
@@ -0,0 +1,55 @@
+/* This file is part of Ganv.
+ * Copyright 2007-2011 David Robillard <http://drobilla.net>
+ *
+ * Ganv 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 any later version.
+ *
+ * Ganv 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 details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with Ganv. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <gtk/gtk.h>
+
+#include "ganv/ganv.h"
+
+static void
+on_window_destroy(GtkWidget* widget,
+ gpointer data)
+{
+ gtk_main_quit();
+}
+
+int
+main(int argc, char** argv)
+{
+ gtk_init(&argc, &argv);
+
+ GtkWindow* win = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
+ gtk_window_set_title(win, "Ganv Test");
+ g_signal_connect(win, "destroy",
+ G_CALLBACK(on_window_destroy), NULL);
+
+ GanvCanvas* canvas = ganv_canvas_new(1024, 768);
+ gtk_container_add(GTK_CONTAINER(win), GTK_WIDGET(canvas));
+
+ GanvModule* module = ganv_module_new(canvas,
+ "x", 10.0,
+ "y", 10.0,
+ "draggable", TRUE,
+ "label", "test",
+ NULL);
+
+ gnome_canvas_item_show(GNOME_CANVAS_ITEM(module));
+ gnome_canvas_item_raise_to_top(GNOME_CANVAS_ITEM(module));
+
+ gtk_widget_show_all(GTK_WIDGET(win));
+ gtk_window_present(win);
+ gtk_main();
+
+ return 0;
+}
diff --git a/src/module.c b/src/module.c
index 1a76787..acb0a6d 100644
--- a/src/module.c
+++ b/src/module.c
@@ -57,7 +57,7 @@ ganv_module_init(GanvModule* module)
module->widest_input = 0.0;
module->widest_output = 0.0;
module->show_port_labels = FALSE;
- module->must_resize = FALSE;
+ module->must_resize = TRUE;
module->port_size_changed = FALSE;
}
@@ -550,6 +550,25 @@ ganv_module_class_init(GanvModuleClass* class)
node_class->resize = ganv_module_resize;
}
+GanvModule*
+ganv_module_new(GanvCanvas* canvas,
+ const char* first_prop_name, ...)
+{
+ GanvModule* module = GANV_MODULE(
+ g_object_new(ganv_module_get_type(), NULL));
+
+ GnomeCanvasItem* item = GNOME_CANVAS_ITEM(module);
+ va_list args;
+ va_start(args, first_prop_name);
+ gnome_canvas_item_construct(item,
+ gnome_canvas_root(GNOME_CANVAS(canvas)),
+ first_prop_name, args);
+ va_end(args);
+
+ ganv_canvas_add_node(canvas, GANV_NODE(module));
+ return module;
+}
+
void
ganv_module_add_port(GanvModule* module,
GanvPort* port)
diff --git a/wscript b/wscript
index 81c578e..0e00255 100644
--- a/wscript
+++ b/wscript
@@ -26,6 +26,8 @@ def options(opt):
opt.load('compiler_c')
opt.load('compiler_cxx')
autowaf.set_options(opt)
+ opt.add_option('--test', action='store_true', default=False, dest='build_tests',
+ help="Build unit tests")
opt.add_option('--no-graphviz', action='store_true', default=False,
dest='no_graphviz',
help='Do not compile with graphviz support')
@@ -42,7 +44,10 @@ def configure(conf):
autowaf.display_header('Ganv Configuration')
conf.env.append_unique('CFLAGS', '-std=c99')
+ conf.env['BUILD_TESTS'] = Options.options.build_tests
+ autowaf.check_pkg(conf, 'gtk+-2.0', uselib_store='GTK',
+ atleast_version='2.0.0', mandatory=True)
autowaf.check_pkg(conf, 'gtkmm-2.4', uselib_store='GTKMM',
atleast_version='2.10.0', mandatory=True)
autowaf.check_pkg(conf, 'libgnomecanvas-2.0', uselib_store='GNOMECANVAS',
@@ -66,6 +71,7 @@ def configure(conf):
autowaf.display_msg(conf, "Auto-arrange", conf.is_defined('HAVE_AGRAPH'))
autowaf.display_msg(conf, "Native language support", conf.is_defined('ENABLE_NLS'))
autowaf.display_msg(conf, "GObject introspection", conf.is_defined('HAVE_GIR'))
+ autowaf.display_msg(conf, "Unit tests", str(conf.env['BUILD_TESTS']))
print('')
ganv_source = [
@@ -101,7 +107,7 @@ def build(bld):
obj.vnum = GANV_LIB_VERSION
obj.install_path = '${LIBDIR}'
- # Benchmark program
+ # Benchmark program (C++)
obj = bld(features = 'cxx cxxprogram',
source = 'src/ganv_bench.cpp',
includes = ['.', './src'],
@@ -109,6 +115,26 @@ def build(bld):
use_lib = 'GTKMM',
target = 'src/ganv_bench')
+ if bld.env['BUILD_TESTS']:
+ # Static library for test program
+ obj = bld(features = 'c cstlib',
+ source = ganv_source,
+ includes = ['.', './src'],
+ name = 'libganv_profiled',
+ target = 'ganv_profiled',
+ uselib = 'GTKMM GNOMECANVAS AGRAPH',
+ install_path = '',
+ cflags = [ '-fprofile-arcs', '-ftest-coverage' ])
+
+ # Test program (C)
+ obj = bld(features = 'c cprogram',
+ source = 'src/ganv_test.c',
+ includes = ['.', './src'],
+ use = 'libganv_profiled',
+ lib = ['gcov'],
+ use_lib = 'GTK',
+ target = 'src/ganv_test')
+
# Documentation
autowaf.build_dox(bld, 'GANV', GANV_VERSION, top, out)
@@ -143,6 +169,11 @@ def build(bld):
bld.add_post_fun(autowaf.run_ldconfig)
+def test(ctx):
+ autowaf.pre_test(ctx, APPNAME)
+ autowaf.run_tests(ctx, APPNAME, ['src/ganv_test'], dirs=['./src'])
+ autowaf.post_test(ctx, APPNAME)
+
def i18n(bld):
autowaf.build_i18n(bld, '..', 'ganv', APPNAME, ganv_source,
'David Robillard')