From 43fbb338af1cc56f2ab9588282d8f3271dbe8e28 Mon Sep 17 00:00:00 2001 From: John Ralls Date: Sat, 14 Jan 2017 14:34:30 -0800 Subject: [PATCH] Add GTest test program for GncRational. Starting off with the constructors. --- src/libqof/qof/test/CMakeLists.txt | 7 +++ src/libqof/qof/test/Makefile.am | 12 +++++ src/libqof/qof/test/gtest-gnc-rational.cpp | 60 ++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 src/libqof/qof/test/gtest-gnc-rational.cpp diff --git a/src/libqof/qof/test/CMakeLists.txt b/src/libqof/qof/test/CMakeLists.txt index 47834e47d5..672fdebe1a 100644 --- a/src/libqof/qof/test/CMakeLists.txt +++ b/src/libqof/qof/test/CMakeLists.txt @@ -61,6 +61,13 @@ IF (NOT WIN32) GNC_ADD_TEST(test-gnc-int128 "${test_gnc_int128_SOURCES}" gtest_qof_INCLUDES gtest_qof_LIBS) + SET(test_gnc_rational_SOURCES + ${MODULEPATH}/gnc-rational.cpp + gtest-gnc-rational.cpp + ${GTEST_SRC}) + GNC_ADD_TEST(test-gnc-rational "${test_gnc_rational_SOURCES}" + gtest_qof_INCLUDES gtest_qof_LIBS) + SET(test_gnc_timezone_SOURCES ${MODULEPATH}/gnc-timezone.cpp gtest-gnc-timezone.cpp diff --git a/src/libqof/qof/test/Makefile.am b/src/libqof/qof/test/Makefile.am index 5e2a70e4fa..2d6b36fee0 100644 --- a/src/libqof/qof/test/Makefile.am +++ b/src/libqof/qof/test/Makefile.am @@ -108,6 +108,18 @@ nodist_test_gnc_int128_SOURCES = \ endif check_PROGRAMS += test-gnc-int128 +test_gnc_rational_SOURCES = \ + $(top_srcdir)/${MODULEPATH}/gnc-rational.cpp \ + gtest-gnc-rational.cpp +test_gnc_rational_CPPFLAGS = -I${GTEST_HEADERS} + +test_gnc_rational_LDADD = ${GTEST_LIBS} +if !GOOGLE_TEST_LIBS +nodist_test_gnc_rational_SOURCES = \ + ${GTEST_SRC}/src/gtest_main.cc +endif +check_PROGRAMS += test-gnc-rational + test_gnc_timezone_SOURCES = \ $(top_srcdir)/${MODULEPATH}/gnc-timezone.cpp \ gtest-gnc-timezone.cpp diff --git a/src/libqof/qof/test/gtest-gnc-rational.cpp b/src/libqof/qof/test/gtest-gnc-rational.cpp new file mode 100644 index 0000000000..7a749cf9e0 --- /dev/null +++ b/src/libqof/qof/test/gtest-gnc-rational.cpp @@ -0,0 +1,60 @@ +/******************************************************************** + * Gtest-gnc-rational.cpp -- unit tests for the GncInt128 class * + * Copyright (C) 2017 John Ralls * + * * + * 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 +#include "../gnc-rational.hpp" + +TEST(gncrational_constructors, test_default_constructor) +{ + GncRational value; + EXPECT_EQ(value.m_num, 0); + EXPECT_EQ(value.m_den, 1); + EXPECT_EQ(value.m_error, GNC_ERROR_OK); +} + +TEST(gncrational_constructors, test_gnc_numeric_constructor) +{ + gnc_numeric input = gnc_numeric_create(123, 456); + GncRational value(input); + EXPECT_EQ(input.num, value.m_num); + EXPECT_EQ(input.denom, value.m_den); + EXPECT_EQ(value.m_error, GNC_ERROR_OK); +} + +TEST(gncrational_constructors, test_gnc_int128_constructor) +{ + GncInt128 num(123), denom(456); + GncRational value(num, denom); + EXPECT_EQ(value.m_num, 123); + EXPECT_EQ(value.m_den, 456); + EXPECT_EQ(value.m_error, GNC_ERROR_OK); +} + +TEST(gncrational_constructors, test_implicit_int_constructor) +{ + int num(123), denom(456); + GncRational value(num, denom); + EXPECT_EQ(value.m_num, 123); + EXPECT_EQ(value.m_den, 456); + EXPECT_EQ(value.m_error, GNC_ERROR_OK); +}