-- cgit v1.2.3 From 8bba0b8f3b67abd6670f208ac7d54127aed725b9 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 25 Apr 2012 11:06:56 -0500 Subject: Adding in Google test build utilities --- configure.ac | 6 ++++++ m4/gtest.m4 | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 m4/gtest.m4 diff --git a/configure.ac b/configure.ac index c7b4864..06cfc63 100644 --- a/configure.ac +++ b/configure.ac @@ -57,6 +57,7 @@ dnl =========================================================================== # Checks for programs AC_PROG_CC AM_PROG_CC_C_O +AC_PROG_CXX # Initialize libtool LT_PREREQ([2.2]) @@ -128,6 +129,11 @@ AC_SUBST(COVERAGE_CFLAGS) AC_SUBST(COVERAGE_CXXFLAGS) AC_SUBST(COVERAGE_LDFLAGS) +dnl = Google Test Framework =================================================== + +m4_include([m4/gtest.m4]) +CHECK_GTEST + dnl = GTK Doc Check =========================================================== GTK_DOC_CHECK([1.8]) diff --git a/m4/gtest.m4 b/m4/gtest.m4 new file mode 100644 index 0000000..2de334c --- /dev/null +++ b/m4/gtest.m4 @@ -0,0 +1,63 @@ +# Copyright (C) 2012 Canonical, Ltd. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice (including the next +# paragraph) shall be included in all copies or substantial portions of the +# Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +# Checks whether the gtest source is available on the system. Allows for +# adjusting the include and source path. Sets have_gtest=yes if the source is +# present. Sets GTEST_CPPFLAGS and GTEST_SOURCE to the preprocessor flags and +# source location respectively. +AC_DEFUN([CHECK_GTEST], +[ + AC_ARG_WITH([gtest-include-path], + [AS_HELP_STRING([--with-gtest-include-path], + [location of the Google test headers])], + [GTEST_CPPFLAGS="-I$withval"]) + + AC_ARG_WITH([gtest-source-path], + [AS_HELP_STRING([--with-gtest-source-path], + [location of the Google test sources, defaults to /usr/src/gtest])], + [GTEST_SOURCE="$withval"], + [GTEST_SOURCE="/usr/src/gtest"]) + + GTEST_CPPFLAGS="$GTEST_CPPFLAGS -I$GTEST_SOURCE" + + AC_LANG_PUSH([C++]) + + tmp_CPPFLAGS="$CPPFLAGS" + CPPFLAGS="$CPPFLAGS $GTEST_CPPFLAGS" + + AC_CHECK_HEADER([gtest/gtest.h]) + + CPPFLAGS="$tmp_CPPFLAGS" + + AC_LANG_POP + + AC_CHECK_FILES([$GTEST_SOURCE/src/gtest-all.cc] + [$GTEST_SOURCE/src/gtest_main.cc], + [have_gtest_source=yes], + [have_gtest_source=no]) + + AS_IF([test "x$ac_cv_header_gtest_gtest_h" = xyes -a \ + "x$have_gtest_source" = xyes], + [have_gtest=yes] + [AC_SUBST(GTEST_CPPFLAGS)] + [AC_SUBST(GTEST_SOURCE)], + [have_gtest=no]) +]) # CHECK_GTEST -- cgit v1.2.3 From 4f9a30d2aaca583d992df6dd8046e563004e13be Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 25 Apr 2012 11:09:24 -0500 Subject: We've now got a test directory! --- Makefile.am | 2 +- configure.ac | 1 + tests/Makefile.am | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 tests/Makefile.am diff --git a/Makefile.am b/Makefile.am index 530ded5..6cad78b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -10,7 +10,7 @@ V = @ Q = $(V:1=) QUIET_GEN = $(Q:@=@echo ' GEN '$@;) -SUBDIRS = src example +SUBDIRS = src example tests %-0.1.pc: %.pc $(QUIET_GEN) cp -f $< $@ diff --git a/configure.ac b/configure.ac index 06cfc63..648c056 100644 --- a/configure.ac +++ b/configure.ac @@ -144,6 +144,7 @@ AC_CONFIG_FILES([ Makefile src/Makefile example/Makefile + tests/Makefile libido.pc libido3.pc ]) diff --git a/tests/Makefile.am b/tests/Makefile.am new file mode 100644 index 0000000..e0b73f5 --- /dev/null +++ b/tests/Makefile.am @@ -0,0 +1 @@ +# Testing, one, two, three -- cgit v1.2.3 From 68dedd8bd6eb262c10955a8ab27732e52a8114d7 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 25 Apr 2012 11:09:47 -0500 Subject: No gtk-doc.m4 needed --- .bzrignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.bzrignore b/.bzrignore index a59b116..13b4905 100644 --- a/.bzrignore +++ b/.bzrignore @@ -28,3 +28,4 @@ src/idotypebuiltins.lo src/libido3-0.1.la src/stamp-idotypebuiltins.h m4 +m4/gtk-doc.m4 -- cgit v1.2.3 From 274e47788ea7e1d7cd453598715233eb99a75292 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 25 Apr 2012 11:39:52 -0500 Subject: Adding in a dummy test and the dependencies to build it --- .bzrignore | 3 +++ tests/Makefile.am | 44 +++++++++++++++++++++++++++++++++++++++++++- tests/gtest-menuitems.cpp | 8 ++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 tests/gtest-menuitems.cpp diff --git a/.bzrignore b/.bzrignore index 13b4905..95c37a1 100644 --- a/.bzrignore +++ b/.bzrignore @@ -29,3 +29,6 @@ src/libido3-0.1.la src/stamp-idotypebuiltins.h m4 m4/gtk-doc.m4 +.deps +.libs +gtest-menuitems diff --git a/tests/Makefile.am b/tests/Makefile.am index e0b73f5..8fded37 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1 +1,43 @@ -# Testing, one, two, three + +check_LIBRARIES = libgtest.a +check_PROGRAMS = +TESTS = + +AM_CPPFLAGS = \ + $(GTEST_CPPFLAGS) \ + -I${top_srcdir}/src + +############################# +# Google Test base library +############################# + +nodist_libgtest_a_SOURCES = \ + $(GTEST_SOURCE)/src/gtest-all.cc \ + $(GTEST_SOURCE)/src/gtest_main.cc +libgtest_a_CPPFLAGS = \ + $(GTEST_CPPFLAGS) -w +libgtest_a_CXXFLAGS = \ + $(AM_CXXFLAGS) +libgtest_a_CPPFLAGS = \ + $(AM_CPPFLAGS) + +############################# +# Menuitem tests +############################# + +TESTS += gtest-menuitems +check_PROGRAMS += gtest-menuitems + +gtest_menuitems_SOURCES = \ + gtest-menuitems.cpp +gtest_menuitems_CPPFLAGS = \ + $(GCC_CFLAGS) \ + $(GTK_CFLAGS) \ + $(MAINTAINER_CFLAGS) \ + $(AM_CPPFLAGS) +gtest_menuitems_LDFLAGS = \ + -pthread +gtest_menuitems_LDADD = \ + $(GTK_LIBS) \ + libgtest.a + diff --git a/tests/gtest-menuitems.cpp b/tests/gtest-menuitems.cpp new file mode 100644 index 0000000..cac28c4 --- /dev/null +++ b/tests/gtest-menuitems.cpp @@ -0,0 +1,8 @@ + +#include +#include + +TEST(StartTesting, DummyTest) { + g_type_init(); + EXPECT_TRUE(true); +} -- cgit v1.2.3 From 7db7f0e734e5c4d7dbc46fb415b8c60c3c570f8e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 25 Apr 2012 14:12:59 -0500 Subject: Now we're allocating a calendar --- tests/Makefile.am | 8 ++++++++ tests/gtest-menuitems.cpp | 26 ++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/tests/Makefile.am b/tests/Makefile.am index 8fded37..03429c7 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,3 +1,10 @@ +if USE_GTK3 +VER=3 +IDOLIB = $(top_builddir)/src/libido3-0.1.la +else +VER= +IDOLIB = $(top_builddir)/src/libido-0.1.la +endif check_LIBRARIES = libgtest.a check_PROGRAMS = @@ -39,5 +46,6 @@ gtest_menuitems_LDFLAGS = \ -pthread gtest_menuitems_LDADD = \ $(GTK_LIBS) \ + $(IDOLIB) \ libgtest.a diff --git a/tests/gtest-menuitems.cpp b/tests/gtest-menuitems.cpp index cac28c4..17356fb 100644 --- a/tests/gtest-menuitems.cpp +++ b/tests/gtest-menuitems.cpp @@ -1,8 +1,26 @@ -#include +#include #include +#include "idocalendarmenuitem.h" -TEST(StartTesting, DummyTest) { - g_type_init(); - EXPECT_TRUE(true); +class TestMenuitems : public ::testing::Test +{ +public: + TestMenuitems() + { + g_type_init(); + return; + } +}; + +TEST_F(TestMenuitems, BuildCalendar) { + GtkWidget * cal = ido_calendar_menu_item_new(); + + EXPECT_TRUE(cal != NULL); + EXPECT_TRUE(IDO_IS_CALENDAR_MENU_ITEM(cal)); + EXPECT_TRUE(GTK_IS_MENU_ITEM(cal)); + + g_object_ref_sink(cal); + g_object_unref(cal); + return; } -- cgit v1.2.3 From 072a5ab6d97eda7911de3c8ec843f9368af44c61 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 25 Apr 2012 14:22:27 -0500 Subject: Now we can realize the menu item to make sure it doesn't mess that up --- tests/gtest-menuitems.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/gtest-menuitems.cpp b/tests/gtest-menuitems.cpp index 17356fb..1f3b866 100644 --- a/tests/gtest-menuitems.cpp +++ b/tests/gtest-menuitems.cpp @@ -8,7 +8,9 @@ class TestMenuitems : public ::testing::Test public: TestMenuitems() { - g_type_init(); + gint argc = 0; + gchar * argv[] = {NULL}; + gtk_init(&argc, (gchar ***)&argv); return; } }; @@ -20,6 +22,15 @@ TEST_F(TestMenuitems, BuildCalendar) { EXPECT_TRUE(IDO_IS_CALENDAR_MENU_ITEM(cal)); EXPECT_TRUE(GTK_IS_MENU_ITEM(cal)); + GtkWidget * menu = gtk_menu_new(); + gtk_widget_show(menu); + gtk_menu_shell_append(GTK_MENU_SHELL(menu), cal); + + gtk_widget_show(cal); + gtk_widget_realize(cal); + + EXPECT_TRUE(gtk_widget_get_realized(cal)); + g_object_ref_sink(cal); g_object_unref(cal); return; -- cgit v1.2.3 From e112516ee13759235fd8056a30f886b7dcae2fda Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 25 Apr 2012 14:31:55 -0500 Subject: Putting in the BEGIN_DECLS for the C++ folks --- src/idorange.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/idorange.h b/src/idorange.h index 0dd6952..7c2e79b 100644 --- a/src/idorange.h +++ b/src/idorange.h @@ -28,6 +28,8 @@ #include +G_BEGIN_DECLS + #define IDO_TYPE_RANGE (ido_range_get_type ()) #define IDO_RANGE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), IDO_TYPE_RANGE, IdoRange)) #define IDO_RANGE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), IDO_TYPE_RANGE, IdoRangeClass)) -- cgit v1.2.3 From d02dfec2a8f5bb873107345b002595b7f43a010e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 25 Apr 2012 14:32:14 -0500 Subject: Adding in the entry menuitem as well. --- tests/gtest-menuitems.cpp | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/tests/gtest-menuitems.cpp b/tests/gtest-menuitems.cpp index 1f3b866..4e99cc7 100644 --- a/tests/gtest-menuitems.cpp +++ b/tests/gtest-menuitems.cpp @@ -2,6 +2,8 @@ #include #include #include "idocalendarmenuitem.h" +#include "idoentrymenuitem.h" +#include "idoscalemenuitem.h" class TestMenuitems : public ::testing::Test { @@ -31,7 +33,29 @@ TEST_F(TestMenuitems, BuildCalendar) { EXPECT_TRUE(gtk_widget_get_realized(cal)); - g_object_ref_sink(cal); - g_object_unref(cal); + g_object_ref_sink(menu); + g_object_unref(menu); return; } + +TEST_F(TestMenuitems, BuildEntry) { + GtkWidget * entry = ido_entry_menu_item_new(); + + EXPECT_TRUE(entry != NULL); + EXPECT_TRUE(IDO_IS_ENTRY_MENU_ITEM(entry)); + EXPECT_TRUE(GTK_IS_MENU_ITEM(entry)); + + GtkWidget * menu = gtk_menu_new(); + gtk_widget_show(menu); + gtk_menu_shell_append(GTK_MENU_SHELL(menu), entry); + + gtk_widget_show(entry); + gtk_widget_realize(entry); + + EXPECT_TRUE(gtk_widget_get_realized(entry)); + + g_object_ref_sink(menu); + g_object_unref(menu); + return; +} + -- cgit v1.2.3 From 62a010afdc5c7c30db3484df181ba84de7f8912d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 25 Apr 2012 14:41:21 -0500 Subject: Build a scale menu item as well --- tests/gtest-menuitems.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/gtest-menuitems.cpp b/tests/gtest-menuitems.cpp index 4e99cc7..269d360 100644 --- a/tests/gtest-menuitems.cpp +++ b/tests/gtest-menuitems.cpp @@ -59,3 +59,44 @@ TEST_F(TestMenuitems, BuildEntry) { return; } +TEST_F(TestMenuitems, BuildScaleDefault) { + GtkWidget * scale = ido_scale_menu_item_new("Label", IDO_RANGE_STYLE_DEFAULT, gtk_adjustment_new(0.5, 0.0, 1.0, 0.01, 0.1, 0.1)); + + EXPECT_TRUE(scale != NULL); + EXPECT_TRUE(IDO_IS_SCALE_MENU_ITEM(scale)); + EXPECT_TRUE(GTK_IS_MENU_ITEM(scale)); + + GtkWidget * menu = gtk_menu_new(); + gtk_widget_show(menu); + gtk_menu_shell_append(GTK_MENU_SHELL(menu), scale); + + gtk_widget_show(scale); + gtk_widget_realize(scale); + + EXPECT_TRUE(gtk_widget_get_realized(scale)); + + g_object_ref_sink(menu); + g_object_unref(menu); + return; +} + +TEST_F(TestMenuitems, BuildScaleSmall) { + GtkWidget * scale = ido_scale_menu_item_new("Label", IDO_RANGE_STYLE_SMALL, gtk_adjustment_new(0.5, 0.0, 1.0, 0.01, 0.1, 0.1)); + + EXPECT_TRUE(scale != NULL); + EXPECT_TRUE(IDO_IS_SCALE_MENU_ITEM(scale)); + EXPECT_TRUE(GTK_IS_MENU_ITEM(scale)); + + GtkWidget * menu = gtk_menu_new(); + gtk_widget_show(menu); + gtk_menu_shell_append(GTK_MENU_SHELL(menu), scale); + + gtk_widget_show(scale); + gtk_widget_realize(scale); + + EXPECT_TRUE(gtk_widget_get_realized(scale)); + + g_object_ref_sink(menu); + g_object_unref(menu); + return; +} -- cgit v1.2.3 From 4636768621434e40918be355637ab6e1920ef2ba Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 25 Apr 2012 15:24:26 -0500 Subject: Bring in xorg-gtest to get an X11 wrapper --- configure.ac | 1 + tests/Makefile.am | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 648c056..6e350b9 100644 --- a/configure.ac +++ b/configure.ac @@ -133,6 +133,7 @@ dnl = Google Test Framework =================================================== m4_include([m4/gtest.m4]) CHECK_GTEST +CHECK_XORG_GTEST dnl = GTK Doc Check =========================================================== diff --git a/tests/Makefile.am b/tests/Makefile.am index 03429c7..04e6cde 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -19,14 +19,15 @@ AM_CPPFLAGS = \ ############################# nodist_libgtest_a_SOURCES = \ + $(XORG_GTEST_SOURCE)/src/xorg-gtest-all.cpp \ $(GTEST_SOURCE)/src/gtest-all.cc \ - $(GTEST_SOURCE)/src/gtest_main.cc + $(XORG_GTEST_SOURCE)/src/xorg-gtest_main.cpp libgtest_a_CPPFLAGS = \ + $(XORG_GTEST_CPPFLAGS) \ + $(AM_CPPFLAGS) \ $(GTEST_CPPFLAGS) -w libgtest_a_CXXFLAGS = \ $(AM_CXXFLAGS) -libgtest_a_CPPFLAGS = \ - $(AM_CPPFLAGS) ############################# # Menuitem tests -- cgit v1.2.3