aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2012-04-26 22:15:10 -0500
committerCharles Kerr <charles.kerr@canonical.com>2012-04-26 22:15:10 -0500
commit2a3f56b5168e9745547d2289c0710ae606920cde (patch)
treed61e3982c09c776a7519be6a028feb4e1cf80af2
parentceb09d1a5aa9f8659765a11f37c2778058d218ab (diff)
parent4636768621434e40918be355637ab6e1920ef2ba (diff)
downloadayatana-ido-2a3f56b5168e9745547d2289c0710ae606920cde.tar.gz
ayatana-ido-2a3f56b5168e9745547d2289c0710ae606920cde.tar.bz2
ayatana-ido-2a3f56b5168e9745547d2289c0710ae606920cde.zip
merge lp:~ted/ido/gtest to add the gtest framework and a few tests to make sure our menu items can be created and realized.
-rw-r--r--.bzrignore4
-rw-r--r--Makefile.am2
-rw-r--r--configure.ac8
-rw-r--r--m4/gtest.m463
-rw-r--r--src/idorange.h2
-rw-r--r--tests/Makefile.am52
-rw-r--r--tests/gtest-menuitems.cpp102
7 files changed, 232 insertions, 1 deletions
diff --git a/.bzrignore b/.bzrignore
index a59b116..95c37a1 100644
--- a/.bzrignore
+++ b/.bzrignore
@@ -28,3 +28,7 @@ src/idotypebuiltins.lo
src/libido3-0.1.la
src/stamp-idotypebuiltins.h
m4
+m4/gtk-doc.m4
+.deps
+.libs
+gtest-menuitems
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 c7b4864..6e350b9 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,12 @@ AC_SUBST(COVERAGE_CFLAGS)
AC_SUBST(COVERAGE_CXXFLAGS)
AC_SUBST(COVERAGE_LDFLAGS)
+dnl = Google Test Framework ===================================================
+
+m4_include([m4/gtest.m4])
+CHECK_GTEST
+CHECK_XORG_GTEST
+
dnl = GTK Doc Check ===========================================================
GTK_DOC_CHECK([1.8])
@@ -138,6 +145,7 @@ AC_CONFIG_FILES([
Makefile
src/Makefile
example/Makefile
+ tests/Makefile
libido.pc
libido3.pc
])
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
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 <gtk/gtk.h>
+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))
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644
index 0000000..04e6cde
--- /dev/null
+++ b/tests/Makefile.am
@@ -0,0 +1,52 @@
+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 =
+TESTS =
+
+AM_CPPFLAGS = \
+ $(GTEST_CPPFLAGS) \
+ -I${top_srcdir}/src
+
+#############################
+# Google Test base library
+#############################
+
+nodist_libgtest_a_SOURCES = \
+ $(XORG_GTEST_SOURCE)/src/xorg-gtest-all.cpp \
+ $(GTEST_SOURCE)/src/gtest-all.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)
+
+#############################
+# 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) \
+ $(IDOLIB) \
+ libgtest.a
+
diff --git a/tests/gtest-menuitems.cpp b/tests/gtest-menuitems.cpp
new file mode 100644
index 0000000..269d360
--- /dev/null
+++ b/tests/gtest-menuitems.cpp
@@ -0,0 +1,102 @@
+
+#include <gtk/gtk.h>
+#include <gtest/gtest.h>
+#include "idocalendarmenuitem.h"
+#include "idoentrymenuitem.h"
+#include "idoscalemenuitem.h"
+
+class TestMenuitems : public ::testing::Test
+{
+public:
+ TestMenuitems()
+ {
+ gint argc = 0;
+ gchar * argv[] = {NULL};
+ gtk_init(&argc, (gchar ***)&argv);
+ 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));
+
+ 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(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;
+}
+
+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;
+}