Add GTest test program for GncRational.

Starting off with the constructors.
This commit is contained in:
John Ralls
2017-01-14 14:34:30 -08:00
parent 848f77dacf
commit 43fbb338af
3 changed files with 79 additions and 0 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -0,0 +1,60 @@
/********************************************************************
* Gtest-gnc-rational.cpp -- unit tests for the GncInt128 class *
* Copyright (C) 2017 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-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);
}