gnucash master: Kvp-Frame test cases
John Ralls
jralls at code.gnucash.org
Sat Dec 20 13:49:40 EST 2014
Updated via https://github.com/Gnucash/gnucash/commit/7d5f0a66 (commit)
from https://github.com/Gnucash/gnucash/commit/2f0a193b (commit)
commit 7d5f0a66a0aaa91f61038e2645a6ec48ba5418e7
Author: lmat <dartme18 at gmail.com>
Date: Mon Nov 17 16:31:17 2014 -0500
Kvp-Frame test cases
Adding google tests for many of Kvp Frame's member functions. One
function in KvpFrameImpl, for_each_slot, should probably be something
like
template <typename T> void
for_each_slot (T & t, void * data) const
{
std::for_each(......
[&t, data] (... a)
{
t(a, data);
}
}
This way, we could create a functor mock object for testing purposes,
but of course, pointers would still behave correctly.
diff --git a/src/libqof/qof/test/Makefile.am b/src/libqof/qof/test/Makefile.am
index e331b2e..43ebb91 100644
--- a/src/libqof/qof/test/Makefile.am
+++ b/src/libqof/qof/test/Makefile.am
@@ -70,7 +70,9 @@ if WITH_GOOGLE_TEST
test_kvp_value_SOURCES = \
$(top_srcdir)/$(MODULEPATH)/kvp-value.cpp \
$(GTEST_ROOT)/src/gtest_main.cc \
- test-kvp-value.cpp
+ test-kvp-value.cpp \
+ test-kvp-frame.cpp
+
test_kvp_value_LDADD = \
$(top_builddir)/$(MODULEPATH)/libgnc-qof.la \
$(top_builddir)/src/test-core/libgtest.a \
@@ -80,7 +82,7 @@ test_kvp_value_CPPFLAGS = \
-I$(GTEST_HEADERS) \
-I$(top_srcdir)/$(MODULEPATH) \
$(BOOST_CPPFLAGS) \
- $(GLIB_CFLAGS)
+ $(GLIB_CFLAGS)
check_PROGRAMS += test_kvp_value
diff --git a/src/libqof/qof/test/test-kvp-frame.cpp b/src/libqof/qof/test/test-kvp-frame.cpp
new file mode 100644
index 0000000..432c811
--- /dev/null
+++ b/src/libqof/qof/test/test-kvp-frame.cpp
@@ -0,0 +1,90 @@
+/********************************************************************
+ * test-kvp-frame.cpp: A Google Test suite for kvp-frame impl. *
+ * Copyright 2014 Aaron Laws <dartme18 at gmail.com> *
+ * *
+ * 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, you can retrieve it from *
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html *
+ * or 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 at gnu.org *
+ ********************************************************************/
+
+#include "../kvp-value.hpp"
+#include "../kvp_frame.hpp"
+#include <gtest/gtest.h>
+#include <algorithm>
+
+template <typename A, typename B> void
+assert_contains (std::vector<A> vec, B const & b)
+{
+ auto val = std::find (vec.begin (), vec.end (), b);
+ EXPECT_NE (val, vec.end ());
+}
+
+TEST (KvpFrameTest, Replace)
+{
+ auto f1 = new KvpFrameImpl;
+ auto v1 = new KvpValueImpl {15.0};
+ auto v2 = new KvpValueImpl { (int64_t)52};
+ std::string k1 {"first key"};
+
+ EXPECT_EQ (nullptr, f1->replace_nc (k1.c_str (), v1));
+ EXPECT_EQ (v1, f1->replace_nc (k1.c_str (), v2));
+
+ delete f1; //this should also delete v2.
+ delete v1;
+}
+
+TEST (KvpFrameTest, GetKeys)
+{
+ auto k1 = "first key";
+ auto k2 = "second key";
+ auto k3 = "first key/third key";
+ auto f1 = new KvpFrameImpl;
+ auto v1 = new KvpValueImpl {15.2};
+ auto v2 = new KvpValueImpl { (int64_t)12};
+ auto v3 = new KvpValueImpl {strdup ("Never again")};
+
+ f1->replace_nc (k1, v1);
+ f1->replace_nc (k2, v2);
+ f1->replace_nc (k3, v3);
+
+ auto keys = f1->get_keys ();
+ EXPECT_EQ (keys.size (), 3);
+
+ assert_contains (keys, k1);
+ assert_contains (keys, k2);
+ assert_contains (keys, k3);
+
+ delete f1;//This should delete our KvpValueImpls, and our string above, too.
+}
+
+TEST (KvpFrameTest, GetSlot)
+{
+ auto f1 = new KvpFrameImpl;
+ auto v1 = new KvpValueImpl {2.2};
+ auto v2 = new KvpValueImpl { (int64_t)4};
+ auto k1 = "first key";
+ auto k2 = "first key/second key";
+
+ f1->replace_nc (k1, v1);
+ EXPECT_EQ (v1, f1->get_slot(k1));
+ f1->replace_nc (k2, v2);
+ EXPECT_EQ (v2, f1->get_slot(k2));
+ EXPECT_EQ (v1, f1->get_slot(k1));
+
+ delete f1;//which will delete both kvpvalues, too.
+}
Summary of changes:
src/libqof/qof/test/Makefile.am | 6 ++-
src/libqof/qof/test/test-kvp-frame.cpp | 90 ++++++++++++++++++++++++++++++++++
2 files changed, 94 insertions(+), 2 deletions(-)
create mode 100644 src/libqof/qof/test/test-kvp-frame.cpp
More information about the gnucash-changes
mailing list