Basic tests for TimeZoneProvider.

This commit is contained in:
John Ralls 2015-01-04 16:30:02 -08:00
parent 15a0d5d25f
commit 45170bb5eb
3 changed files with 79 additions and 10 deletions

View File

@ -372,12 +372,15 @@ update to latest darwin])
darwin*)
platform=darwin
AC_DEFINE(PLATFORM_OSX,1,[Running on OSX, either X11 or Quartz])
AC_DEFINE(GNC_PLATFORM_POSIX, 1, [POSIX-compliant OS])
AC_DEFINE(GNC_PLATFORM_DARWIN, 1, [Darwin-based OS])
AC_MSG_RESULT($platform)
AC_MSG_CHECKING(For GDK-Quartz)
platform=osx
_gdk_tgt=`$PKG_CONFIG --variable=target gdk-2.0`
if test "x$_gdk_tgt" = xquartz; then
platform=darwin/quartz
AC_DEFINE(GNC_PLATFORM_COCOA, 1, [Cocoa/Nexstep/GnuStep framework])
AC_MSG_RESULT(yes)
AC_DEFINE(GDK_QUARTZ,,[Using GDK Quartz (not X11)])
PKG_CHECK_MODULES([GTK_MAC], gtk-mac-integration-gtk2,
@ -402,6 +405,7 @@ update to latest darwin])
mingw*|cygwin*)
platform=win32
AC_MSG_RESULT($platform)
AC_DEFINE(GNC_PLATFORM_WINDOWS, 1, [Microsoft Windows OS])
LT_PROG_RC
AC_MSG_CHECKING(for native win32)
@ -443,6 +447,7 @@ update to latest darwin])
*)
platform=linux/other
AC_DEFINE(GNC_PLATFORM_POSIX, 1, [POSIX-compliant OS])
AC_MSG_RESULT($platform)
;;
esac

View File

@ -41,8 +41,8 @@ test_kvp_value_SOURCES = \
test_kvp_value_LDADD = \
$(top_builddir)/$(MODULEPATH)/libgnc-qof.la \
$(GLIB_LIBS) \
$(GTEST_LIBS) \
$(BOOST_LDFLAGS)
if !GOOGLE_TEST_LIBS
nodist_test_kvp_value_SOURCES = \
${GTEST_SRC}/src/gtest_main.cc
@ -52,28 +52,39 @@ endif
test_kvp_value_CPPFLAGS = \
-I$(GTEST_HEADERS) \
-I$(top_srcdir)/$(MODULEPATH) \
$(BOOST_CPPFLAGS) \
$(GLIB_CFLAGS)
$(BOOST_CPPFLAGS)
check_PROGRAMS += test-kvp-value
test_gnc_int128_SOURCES = \
$(top_srcdir)/${MODULEPATH}/gnc-int128.cpp \
gtest-gnc-int128.cpp
test_gnc_int128_CPPFLAGS = \
-I${GTEST_HEADERS} \
${GLIB_CFLAGS}
test_gnc_int128_CPPFLAGS = -I${GTEST_HEADERS}
test_gnc_int128_LDADD = \
${GLIB_LIBS} \
$(GTEST_LIBS)
test_gnc_int128_LDADD = $(GTEST_LIBS)
if !GOOGLE_TEST_LIBS
nodist_test_gnc_int128_SOURCES = \
${GTEST_SRC}/src/gtest_main.cc
test_gnc_int128_LDADD += $(top_builddir)/src/test-core/libgtest.a
endif
check_PROGRAMS += test-gnc-int128
test_gnc_timezone_SOURCES = \
$(top_srcdir)/${MODULEPATH}/gnc-timezone.cpp \
gtest-gnc-timezone.cpp
test_gnc_timezone_CPPFLAGS = \
-I${GTEST_HEADERS} \
-I${top_srcdir}/src \
$(BOOST_CPPFLAGS)
test_gnc_timezone_LDADD = $(GTEST_LIBS)
if !GOOGLE_TEST_LIBS
nodist_test_gnc_timezone_SOURCES = \
${GTEST_SRC}/src/gtest_main.cc
test_gnc_timezone_LDADD += $(top_builddir)/src/test-core/libgtest.a
endif
check_PROGRAMS += test-gnc-timezone
endif
test_qofdir = ${GNC_LIBEXECDIR}/${MODULEPATH}/test

View File

@ -0,0 +1,53 @@
/********************************************************************
* Gtest-gnc-int128.cpp -- unit tests for the GncInt128 class *
* Copyright (C) 2014 John Ralls <jralls@ceridwen.us> *
* *
* This program 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 2 of *
* the License, or (at your option) any later version. *
* *
* This program 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 more details. *
* *
* You should have received a copy of the GNU General Public License*
* along with this program; if not, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
* *
*******************************************************************/
#include <gtest/gtest.h>
#include "../gnc-timezone.hpp"
TEST(gnc_timezone_constructors, test_default_constructor)
{
TimeZoneProvider tzp {};
EXPECT_NO_THROW (tzp.get(2014));
TZ_Ptr tz = tzp.get (2014);
//Can't really test anything explicit, we don't know what to expect
//from the default TZ.
EXPECT_FALSE(tz->std_zone_abbrev().empty());
}
TEST(gnc_timezone_constructors, test_pacific_time_constructor)
{
TimeZoneProvider tzp ("Pacific Standard Time");
EXPECT_NO_THROW (tzp.get(2006));
TZ_Ptr tz = tzp.get (2006);
EXPECT_FALSE(tz->std_zone_abbrev().empty());
EXPECT_TRUE(tz->std_zone_abbrev() == "Pacific Standard Time");
EXPECT_TRUE(tz->base_utc_offset().hours() == -8);
}
TEST(gnc_timezone_constructors, test_bogus_time_constructor)
{
EXPECT_THROW (TimeZoneProvider tzp ("New York Standard Time"),
std::invalid_argument);
}