gnucash maint: Multiple changes pushed
John Ralls
jralls at code.gnucash.org
Sun Nov 8 16:47:43 EST 2020
Updated via https://github.com/Gnucash/gnucash/commit/26fa239f (commit)
via https://github.com/Gnucash/gnucash/commit/69789b2b (commit)
via https://github.com/Gnucash/gnucash/commit/f26215fe (commit)
via https://github.com/Gnucash/gnucash/commit/fa16a299 (commit)
via https://github.com/Gnucash/gnucash/commit/e5378b20 (commit)
via https://github.com/Gnucash/gnucash/commit/982cf86d (commit)
via https://github.com/Gnucash/gnucash/commit/9d4c0b05 (commit)
via https://github.com/Gnucash/gnucash/commit/1cf7defe (commit)
via https://github.com/Gnucash/gnucash/commit/9bf550d3 (commit)
via https://github.com/Gnucash/gnucash/commit/5cd777b6 (commit)
via https://github.com/Gnucash/gnucash/commit/2faecb20 (commit)
via https://github.com/Gnucash/gnucash/commit/a1806a2f (commit)
via https://github.com/Gnucash/gnucash/commit/51715e45 (commit)
from https://github.com/Gnucash/gnucash/commit/bbc6887b (commit)
commit 26fa239f89aaebf6446de14f12fbe384a4d95968
Merge: bbc6887b0 69789b2b9
Author: John Ralls <jralls at ceridwen.us>
Date: Sun Nov 8 13:44:41 2020 -0800
Merge Christian Klein's 'auto-clear-tests' into maint.
commit 69789b2b93253b1e41c10aab6a22dcc5c84043cd
Author: Cristian Klein <cristian.klein at elastisys.com>
Date: Sun Nov 8 09:58:57 2020 +0100
[auto-tests] Stick to CodingStandard for member variables
diff --git a/libgnucash/app-utils/test/test-autoclear.cpp b/libgnucash/app-utils/test/test-autoclear.cpp
index 4157458de..abb84e1c5 100644
--- a/libgnucash/app-utils/test/test-autoclear.cpp
+++ b/libgnucash/app-utils/test/test-autoclear.cpp
@@ -109,37 +109,37 @@ TestCase ambiguousTestCase = {
class AutoClearTest : public ::testing::TestWithParam<TestCase *> {
protected:
- std::shared_ptr<QofBook> book_;
- Account *account_; // owned by book_
- TestCase &testCase_;
+ std::shared_ptr<QofBook> m_book;
+ Account *m_account; // owned by m_book
+ TestCase &m_testCase;
public:
AutoClearTest() :
- book_(qof_book_new(), qof_book_destroy),
- account_(xaccMallocAccount(book_.get())),
- testCase_(*GetParam())
+ m_book(qof_book_new(), qof_book_destroy),
+ m_account(xaccMallocAccount(m_book.get())),
+ m_testCase(*GetParam())
{
- xaccAccountSetName(account_, "Test Account");
- xaccAccountBeginEdit(account_);
- for (auto &d : testCase_.splits) {
- Split *split = xaccMallocSplit(book_.get());
+ xaccAccountSetName(m_account, "Test Account");
+ xaccAccountBeginEdit(m_account);
+ for (auto &d : m_testCase.splits) {
+ Split *split = xaccMallocSplit(m_book.get());
xaccSplitSetMemo(split, d.memo);
xaccSplitSetAmount(split, gnc_numeric_create(d.amount, DENOM));
xaccSplitSetReconcile(split, d.cleared ? CREC : NREC);
- xaccSplitSetAccount(split, account_);
+ xaccSplitSetAccount(split, m_account);
- gnc_account_insert_split(account_, split);
+ gnc_account_insert_split(m_account, split);
}
- xaccAccountCommitEdit(account_);
+ xaccAccountCommitEdit(m_account);
}
};
TEST_P(AutoClearTest, DoesAutoClear) {
- for (auto &t : testCase_.tests) {
+ for (auto &t : m_testCase.tests) {
gnc_numeric amount_to_clear = gnc_numeric_create(t.amount, DENOM);
char *err;
- GList *splits_to_clear = gnc_account_get_autoclear_splits(account_, amount_to_clear, &err);
+ GList *splits_to_clear = gnc_account_get_autoclear_splits(m_account, amount_to_clear, &err);
// Actually clear splits
for (GList *node = splits_to_clear; node; node = node->next) {
@@ -149,7 +149,7 @@ TEST_P(AutoClearTest, DoesAutoClear) {
ASSERT_STREQ(err, t.expectedErr);
if (t.expectedErr == NULL) {
- gnc_numeric c = xaccAccountGetClearedBalance(account_);
+ gnc_numeric c = xaccAccountGetClearedBalance(m_account);
ASSERT_EQ(c.num, t.amount);
ASSERT_EQ(c.denom, DENOM);
}
commit f26215feae0516f04670566dfe247018c0c3bcea
Author: Cristian Klein <cristian.klein at elastisys.com>
Date: Sun Nov 8 09:58:17 2020 +0100
[auto-tests] Fix misspelling
diff --git a/libgnucash/app-utils/test/test-autoclear.cpp b/libgnucash/app-utils/test/test-autoclear.cpp
index b99b5d655..4157458de 100644
--- a/libgnucash/app-utils/test/test-autoclear.cpp
+++ b/libgnucash/app-utils/test/test-autoclear.cpp
@@ -31,7 +31,7 @@ extern "C" {
#include <Split.h>
#include <gtest/gtest.h>
-static const int64_t DENOM = 100; //< Denomerator is always 100 for simplicity.
+static const int64_t DENOM = 100; //< Denominator is always 100 for simplicity.
struct SplitDatum {
const char *memo;
commit fa16a299480c583f6e8f8b37bb2f447e7311430d
Author: Cristian Klein <cristian.klein at elastisys.com>
Date: Wed Oct 28 22:36:11 2020 +0100
Add auto-clear to register page
diff --git a/gnucash/ui/gnc-plugin-page-register-ui.xml b/gnucash/ui/gnc-plugin-page-register-ui.xml
index a32b3bd5a..5a240a5b2 100644
--- a/gnucash/ui/gnc-plugin-page-register-ui.xml
+++ b/gnucash/ui/gnc-plugin-page-register-ui.xml
@@ -44,6 +44,7 @@
<separator name="ActionsSep1"/>
<menuitem name="ActionsTransfer" action="ActionsTransferAction"/>
<menuitem name="ActionsReconcile" action="ActionsReconcileAction"/>
+ <menuitem name="ActionsAutoClear" action="ActionsAutoClearAction"/>
<menuitem name="ActionsStockSplit" action="ActionsStockSplitAction"/>
<menuitem name="ActionLots" action="ActionsLotsAction"/>
<separator name="ActionsSep4"/>
diff --git a/gnucash/ui/gnc-plugin-page-register2-ui.xml b/gnucash/ui/gnc-plugin-page-register2-ui.xml
index 3d903d9ac..8c4c4afab 100644
--- a/gnucash/ui/gnc-plugin-page-register2-ui.xml
+++ b/gnucash/ui/gnc-plugin-page-register2-ui.xml
@@ -43,6 +43,7 @@
<separator name="ActionsSep1"/>
<menuitem name="ActionsTransfer" action="ActionsTransferAction"/>
<menuitem name="ActionsReconcile" action="ActionsReconcileAction"/>
+ <menuitem name="ActionsAutoClear" action="ActionsAutoClearAction"/>
<menuitem name="ActionsStockSplit" action="ActionsStockSplitAction"/>
<menuitem name="ActionLots" action="ActionsLotsAction"/>
<separator name="ActionsSep4"/>
commit e5378b204849dcdaca429e3ac2a57bedfd681877
Author: Cristian Klein <cristian.klein at elastisys.com>
Date: Wed Oct 28 22:25:56 2020 +0100
[auto-clear] Make test more future-proof with GoogleTest
diff --git a/libgnucash/app-utils/test/test-autoclear.cpp b/libgnucash/app-utils/test/test-autoclear.cpp
index f00b80976..b99b5d655 100644
--- a/libgnucash/app-utils/test/test-autoclear.cpp
+++ b/libgnucash/app-utils/test/test-autoclear.cpp
@@ -156,11 +156,15 @@ TEST_P(AutoClearTest, DoesAutoClear) {
}
}
+#ifndef INSTANTIATE_TEST_SUITE_P
// Silence "no previous declaration for" which is treated as error, due to -Werror
testing::internal::ParamGenerator<TestCase*> gtest_InstantiationAutoClearTestAutoClearTest_EvalGenerator_();
std::string gtest_InstantiationAutoClearTestAutoClearTest_EvalGenerateName_(const testing::TestParamInfo<TestCase*>&);
INSTANTIATE_TEST_CASE_P(
+#else // INSTANTIATE_TEST_SUITE_P
+INSTANTIATE_TEST_SUITE_P(
+#endif // INSTANTIATE_TEST_SUITE_P
InstantiationAutoClearTest,
AutoClearTest,
::testing::Values(
commit 982cf86deb20f0b0c549e9f0efa9e0a24195ae2f
Author: Cristian Klein <cristian.klein at elastisys.com>
Date: Mon Oct 26 14:48:20 2020 +0100
[auto-clear] Fix test with googletest 1.8
diff --git a/libgnucash/app-utils/test/test-autoclear.cpp b/libgnucash/app-utils/test/test-autoclear.cpp
index 2696c2a9f..f00b80976 100644
--- a/libgnucash/app-utils/test/test-autoclear.cpp
+++ b/libgnucash/app-utils/test/test-autoclear.cpp
@@ -27,6 +27,7 @@
extern "C" {
#include "../gnc-ui-balances.h"
}
+#include <memory>
#include <Split.h>
#include <gtest/gtest.h>
@@ -106,19 +107,18 @@ TestCase ambiguousTestCase = {
},
};
-class AutoClearTest : public testing::TestWithParam<TestCase> {
+class AutoClearTest : public ::testing::TestWithParam<TestCase *> {
protected:
std::shared_ptr<QofBook> book_;
Account *account_; // owned by book_
- TestCase testCase_;
+ TestCase &testCase_;
public:
AutoClearTest() :
book_(qof_book_new(), qof_book_destroy),
- account_(xaccMallocAccount(book_.get()))
+ account_(xaccMallocAccount(book_.get())),
+ testCase_(*GetParam())
{
- testCase_ = GetParam();
-
xaccAccountSetName(account_, "Test Account");
xaccAccountBeginEdit(account_);
for (auto &d : testCase_.splits) {
@@ -156,11 +156,15 @@ TEST_P(AutoClearTest, DoesAutoClear) {
}
}
-INSTANTIATE_TEST_SUITE_P(
+// Silence "no previous declaration for" which is treated as error, due to -Werror
+testing::internal::ParamGenerator<TestCase*> gtest_InstantiationAutoClearTestAutoClearTest_EvalGenerator_();
+std::string gtest_InstantiationAutoClearTestAutoClearTest_EvalGenerateName_(const testing::TestParamInfo<TestCase*>&);
+
+INSTANTIATE_TEST_CASE_P(
InstantiationAutoClearTest,
AutoClearTest,
- testing::Values(
- easyTestCase,
- ambiguousTestCase
+ ::testing::Values(
+ &easyTestCase,
+ &ambiguousTestCase
)
);
commit 9d4c0b05dbd181734c687012573f1c51b11512fa
Author: Cristian Klein <cristian.klein at elastisys.com>
Date: Mon Oct 26 12:35:09 2020 +0100
[auto-clear] Improve #include style
diff --git a/libgnucash/app-utils/test/test-autoclear.cpp b/libgnucash/app-utils/test/test-autoclear.cpp
index 780e67bb0..2696c2a9f 100644
--- a/libgnucash/app-utils/test/test-autoclear.cpp
+++ b/libgnucash/app-utils/test/test-autoclear.cpp
@@ -27,9 +27,8 @@
extern "C" {
#include "../gnc-ui-balances.h"
}
-#include "Split.h"
-
-#include "gtest/gtest.h"
+#include <Split.h>
+#include <gtest/gtest.h>
static const int64_t DENOM = 100; //< Denomerator is always 100 for simplicity.
commit 1cf7defee88db324e937a0e7c9d247c80a03603b
Author: Cristian Klein <cristian.klein at elastisys.com>
Date: Mon Oct 26 12:33:13 2020 +0100
[auto-clear] Address feedback
diff --git a/libgnucash/app-utils/test/test-autoclear.cpp b/libgnucash/app-utils/test/test-autoclear.cpp
index 73d9ae173..780e67bb0 100644
--- a/libgnucash/app-utils/test/test-autoclear.cpp
+++ b/libgnucash/app-utils/test/test-autoclear.cpp
@@ -31,7 +31,7 @@ extern "C" {
#include "gtest/gtest.h"
-const gint64 DENOM = 100; //< Denomerator is always 100 for simplicity.
+static const int64_t DENOM = 100; //< Denomerator is always 100 for simplicity.
struct SplitDatum {
const char *memo;
@@ -39,100 +39,108 @@ struct SplitDatum {
bool cleared;
};
-struct TestCase {
+struct Tests {
gint64 amount;
const char *expectedErr;
};
-std::vector<SplitDatum> easySplitData = {
- { "Memo 01", - 8234, true },
- { "Memo 02", -156326, true },
- { "Memo 03", - 4500, true },
- { "Memo 04", -694056, true },
- { "Memo 05", - 7358, true },
- { "Memo 06", - 11700, true },
- { "Memo 07", - 20497, true },
- { "Memo 08", - 11900, true },
- { "Memo 09", - 8275, true },
- { "Memo 10", - 58700, true },
- { "Memo 11", +100000, true },
- { "Memo 12", - 13881, true },
- { "Memo 13", - 5000, true },
- { "Memo 14", +200000, true },
- { "Memo 15", - 16800, true },
- { "Memo 16", -152000, true },
- { "Memo 17", +160000, false },
- { "Memo 18", - 63610, false },
- { "Memo 19", - 2702, false },
- { "Memo 20", - 15400, false },
- { "Memo 21", - 3900, false },
- { "Memo 22", - 22042, false },
- { "Memo 23", - 2900, false },
- { "Memo 24", - 10900, false },
- { "Memo 25", - 44400, false },
- { "Memo 26", - 9200, false },
- { "Memo 27", - 7900, false },
- { "Memo 28", - 1990, false },
- { "Memo 29", - 7901, false },
- { "Memo 30", - 61200, false },
-};
-
-std::vector<TestCase> easyTestCases = {
- { 0, "The selected amount cannot be cleared.", },
- { -869227, "Account is already at Auto-Clear Balance." }, // No splits need to be cleared.
- { -869300, "The selected amount cannot be cleared." },
- { -869230, NULL },
- { -963272, NULL }, // All splits need to be cleared.
+struct TestCase {
+ std::vector<SplitDatum> splits;
+ std::vector<Tests> tests;
};
-std::vector<SplitDatum> ambiguousSplitData = {
- { "Memo 01", -10, false },
- { "Memo 02", -10, false },
- { "Memo 03", -10, false },
+TestCase easyTestCase = {
+ .splits = {
+ { "Memo 01", - 8234, true },
+ { "Memo 02", -156326, true },
+ { "Memo 03", - 4500, true },
+ { "Memo 04", -694056, true },
+ { "Memo 05", - 7358, true },
+ { "Memo 06", - 11700, true },
+ { "Memo 07", - 20497, true },
+ { "Memo 08", - 11900, true },
+ { "Memo 09", - 8275, true },
+ { "Memo 10", - 58700, true },
+ { "Memo 11", +100000, true },
+ { "Memo 12", - 13881, true },
+ { "Memo 13", - 5000, true },
+ { "Memo 14", +200000, true },
+ { "Memo 15", - 16800, true },
+ { "Memo 16", -152000, true },
+ { "Memo 17", +160000, false },
+ { "Memo 18", - 63610, false },
+ { "Memo 19", - 2702, false },
+ { "Memo 20", - 15400, false },
+ { "Memo 21", - 3900, false },
+ { "Memo 22", - 22042, false },
+ { "Memo 23", - 2900, false },
+ { "Memo 24", - 10900, false },
+ { "Memo 25", - 44400, false },
+ { "Memo 26", - 9200, false },
+ { "Memo 27", - 7900, false },
+ { "Memo 28", - 1990, false },
+ { "Memo 29", - 7901, false },
+ { "Memo 30", - 61200, false },
+ },
+ .tests = {
+ { 0, "The selected amount cannot be cleared.", },
+ { -869227, "Account is already at Auto-Clear Balance." }, // No splits need to be cleared.
+ { -869300, "The selected amount cannot be cleared." },
+ { -869230, NULL },
+ { -963272, NULL }, // All splits need to be cleared.
+ },
};
-std::vector<TestCase> ambiguousTestCases = {
- { -10, "Cannot uniquely clear splits. Found multiple possibilities." },
- { -20, "Cannot uniquely clear splits. Found multiple possibilities." },
-
- // Commented out, auto-clear algorithm is not smart enough yet.
- //{ -30, NULL },
+TestCase ambiguousTestCase = {
+ .splits = {
+ { "Memo 01", -10, false },
+ { "Memo 02", -10, false },
+ { "Memo 03", -10, false },
+ },
+ .tests = {
+ { -10, "Cannot uniquely clear splits. Found multiple possibilities." },
+ { -20, "Cannot uniquely clear splits. Found multiple possibilities." },
+
+ // Forbid auto-clear to be too smart. We expect the user to manually deal
+ // with such situations.
+ { -30, "Cannot uniquely clear splits. Found multiple possibilities." },
+ },
};
-class AutoClearTest
- : public testing::TestWithParam<
- std::pair<
- std::vector<SplitDatum>,
- std::vector<TestCase>
- >
- > {
+class AutoClearTest : public testing::TestWithParam<TestCase> {
+protected:
+ std::shared_ptr<QofBook> book_;
+ Account *account_; // owned by book_
+ TestCase testCase_;
+
+public:
+ AutoClearTest() :
+ book_(qof_book_new(), qof_book_destroy),
+ account_(xaccMallocAccount(book_.get()))
+ {
+ testCase_ = GetParam();
+
+ xaccAccountSetName(account_, "Test Account");
+ xaccAccountBeginEdit(account_);
+ for (auto &d : testCase_.splits) {
+ Split *split = xaccMallocSplit(book_.get());
+ xaccSplitSetMemo(split, d.memo);
+ xaccSplitSetAmount(split, gnc_numeric_create(d.amount, DENOM));
+ xaccSplitSetReconcile(split, d.cleared ? CREC : NREC);
+ xaccSplitSetAccount(split, account_);
+
+ gnc_account_insert_split(account_, split);
+ }
+ xaccAccountCommitEdit(account_);
+ }
};
TEST_P(AutoClearTest, DoesAutoClear) {
- auto splitData = GetParam().first;
- auto testCase = GetParam().second;
-
- QofBook *book = qof_book_new ();
- Account *account = xaccMallocAccount(book);
- xaccAccountSetName(account, "Test Account");
-
- xaccAccountBeginEdit(account);
- for (auto &d : splitData) {
- Split *split = xaccMallocSplit(book);
- xaccSplitSetMemo(split, d.memo);
- xaccSplitSetAmount(split, gnc_numeric_create(d.amount, DENOM));
- xaccSplitSetReconcile(split, d.cleared ? CREC : NREC);
- xaccSplitSetAccount(split, account);
-
- gnc_account_insert_split(account, split);
- }
- xaccAccountCommitEdit(account);
-
- for (auto &t : testCase) {
+ for (auto &t : testCase_.tests) {
gnc_numeric amount_to_clear = gnc_numeric_create(t.amount, DENOM);
char *err;
- GList *splits_to_clear = gnc_account_get_autoclear_splits(account, amount_to_clear, &err);
+ GList *splits_to_clear = gnc_account_get_autoclear_splits(account_, amount_to_clear, &err);
// Actually clear splits
for (GList *node = splits_to_clear; node; node = node->next) {
@@ -142,20 +150,18 @@ TEST_P(AutoClearTest, DoesAutoClear) {
ASSERT_STREQ(err, t.expectedErr);
if (t.expectedErr == NULL) {
- gnc_numeric c = xaccAccountGetClearedBalance(account);
+ gnc_numeric c = xaccAccountGetClearedBalance(account_);
ASSERT_EQ(c.num, t.amount);
ASSERT_EQ(c.denom, DENOM);
}
}
-
- qof_book_destroy(book);
}
INSTANTIATE_TEST_SUITE_P(
InstantiationAutoClearTest,
AutoClearTest,
testing::Values(
- std::pair{ easySplitData, easyTestCases },
- std::pair{ ambiguousSplitData, ambiguousTestCases }
+ easyTestCase,
+ ambiguousTestCase
)
);
commit 9bf550d38f19498f78562d2c4c8ed08ec784056a
Author: Cristian Klein <cristian.klein at elastisys.com>
Date: Fri Oct 23 16:34:46 2020 +0200
[auto-clear] Include test for ambiguous cases
diff --git a/libgnucash/app-utils/test/test-autoclear.cpp b/libgnucash/app-utils/test/test-autoclear.cpp
index b6ba6ba19..73d9ae173 100644
--- a/libgnucash/app-utils/test/test-autoclear.cpp
+++ b/libgnucash/app-utils/test/test-autoclear.cpp
@@ -39,7 +39,12 @@ struct SplitDatum {
bool cleared;
};
-SplitDatum splitData[] = {
+struct TestCase {
+ gint64 amount;
+ const char *expectedErr;
+};
+
+std::vector<SplitDatum> easySplitData = {
{ "Memo 01", - 8234, true },
{ "Memo 02", -156326, true },
{ "Memo 03", - 4500, true },
@@ -72,12 +77,7 @@ SplitDatum splitData[] = {
{ "Memo 30", - 61200, false },
};
-struct TestCase {
- gint64 amount;
- const char *expectedErr;
-};
-
-TestCase testCases[] = {
+std::vector<TestCase> easyTestCases = {
{ 0, "The selected amount cannot be cleared.", },
{ -869227, "Account is already at Auto-Clear Balance." }, // No splits need to be cleared.
{ -869300, "The selected amount cannot be cleared." },
@@ -85,7 +85,33 @@ TestCase testCases[] = {
{ -963272, NULL }, // All splits need to be cleared.
};
-TEST(AutoClear, AutoClearAll) {
+std::vector<SplitDatum> ambiguousSplitData = {
+ { "Memo 01", -10, false },
+ { "Memo 02", -10, false },
+ { "Memo 03", -10, false },
+};
+
+std::vector<TestCase> ambiguousTestCases = {
+ { -10, "Cannot uniquely clear splits. Found multiple possibilities." },
+ { -20, "Cannot uniquely clear splits. Found multiple possibilities." },
+
+ // Commented out, auto-clear algorithm is not smart enough yet.
+ //{ -30, NULL },
+};
+
+class AutoClearTest
+ : public testing::TestWithParam<
+ std::pair<
+ std::vector<SplitDatum>,
+ std::vector<TestCase>
+ >
+ > {
+};
+
+TEST_P(AutoClearTest, DoesAutoClear) {
+ auto splitData = GetParam().first;
+ auto testCase = GetParam().second;
+
QofBook *book = qof_book_new ();
Account *account = xaccMallocAccount(book);
xaccAccountSetName(account, "Test Account");
@@ -102,7 +128,7 @@ TEST(AutoClear, AutoClearAll) {
}
xaccAccountCommitEdit(account);
- for (auto &t : testCases) {
+ for (auto &t : testCase) {
gnc_numeric amount_to_clear = gnc_numeric_create(t.amount, DENOM);
char *err;
@@ -124,3 +150,12 @@ TEST(AutoClear, AutoClearAll) {
qof_book_destroy(book);
}
+
+INSTANTIATE_TEST_SUITE_P(
+ InstantiationAutoClearTest,
+ AutoClearTest,
+ testing::Values(
+ std::pair{ easySplitData, easyTestCases },
+ std::pair{ ambiguousSplitData, ambiguousTestCases }
+ )
+);
commit 5cd777b6739c14ccefa3f88996b63b4f1b1eff95
Author: Cristian Klein <cristian.klein at elastisys.com>
Date: Fri Oct 23 15:30:35 2020 +0200
[auto-clear] Fix test: Add xaccAccountBeginEdit / xaccAccountCommitEdit
diff --git a/libgnucash/app-utils/test/test-autoclear.cpp b/libgnucash/app-utils/test/test-autoclear.cpp
index cd193790b..b6ba6ba19 100644
--- a/libgnucash/app-utils/test/test-autoclear.cpp
+++ b/libgnucash/app-utils/test/test-autoclear.cpp
@@ -90,6 +90,7 @@ TEST(AutoClear, AutoClearAll) {
Account *account = xaccMallocAccount(book);
xaccAccountSetName(account, "Test Account");
+ xaccAccountBeginEdit(account);
for (auto &d : splitData) {
Split *split = xaccMallocSplit(book);
xaccSplitSetMemo(split, d.memo);
@@ -99,7 +100,7 @@ TEST(AutoClear, AutoClearAll) {
gnc_account_insert_split(account, split);
}
- xaccAccountRecomputeBalance(account);
+ xaccAccountCommitEdit(account);
for (auto &t : testCases) {
gnc_numeric amount_to_clear = gnc_numeric_create(t.amount, DENOM);
commit 2faecb207432027ebd9efd6c92b53c35bec44fa7
Author: Cristian Klein <cristian.klein at elastisys.com>
Date: Fri Oct 23 15:26:58 2020 +0200
[auto-clear] Avoid testing ambigous auto-clear
diff --git a/libgnucash/app-utils/test/test-autoclear.cpp b/libgnucash/app-utils/test/test-autoclear.cpp
index 62fb18890..cd193790b 100644
--- a/libgnucash/app-utils/test/test-autoclear.cpp
+++ b/libgnucash/app-utils/test/test-autoclear.cpp
@@ -58,7 +58,7 @@ SplitDatum splitData[] = {
{ "Memo 16", -152000, true },
{ "Memo 17", +160000, false },
{ "Memo 18", - 63610, false },
- { "Memo 19", - 2700, false },
+ { "Memo 19", - 2702, false },
{ "Memo 20", - 15400, false },
{ "Memo 21", - 3900, false },
{ "Memo 22", - 22042, false },
@@ -68,7 +68,7 @@ SplitDatum splitData[] = {
{ "Memo 26", - 9200, false },
{ "Memo 27", - 7900, false },
{ "Memo 28", - 1990, false },
- { "Memo 29", - 7900, false },
+ { "Memo 29", - 7901, false },
{ "Memo 30", - 61200, false },
};
@@ -80,9 +80,9 @@ struct TestCase {
TestCase testCases[] = {
{ 0, "The selected amount cannot be cleared.", },
{ -869227, "Account is already at Auto-Clear Balance." }, // No splits need to be cleared.
- { -877127, "Cannot uniquely clear splits. Found multiple possibilities." }, // Two splits need to be cleared.
- { -891269, NULL }, // One split need to be cleared.
- { -963269, NULL }, // All splits need to be cleared.
+ { -869300, "The selected amount cannot be cleared." },
+ { -869230, NULL },
+ { -963272, NULL }, // All splits need to be cleared.
};
TEST(AutoClear, AutoClearAll) {
commit a1806a2f9429b5f69403b812cd77fcae32371688
Author: Cristian Klein <cristian.klein at elastisys.com>
Date: Fri Oct 23 15:26:23 2020 +0200
[auto-clear] Fix model
diff --git a/libgnucash/app-utils/test/test-autoclear.cpp b/libgnucash/app-utils/test/test-autoclear.cpp
index 834c77e91..62fb18890 100644
--- a/libgnucash/app-utils/test/test-autoclear.cpp
+++ b/libgnucash/app-utils/test/test-autoclear.cpp
@@ -31,11 +31,11 @@ extern "C" {
#include "gtest/gtest.h"
-const int DENOM = 100; //< Denomerator is always 100 for simplicity.
+const gint64 DENOM = 100; //< Denomerator is always 100 for simplicity.
struct SplitDatum {
const char *memo;
- int amount; //< Numerator of amount.
+ gint64 amount; //< Numerator of amount.
bool cleared;
};
@@ -73,7 +73,7 @@ SplitDatum splitData[] = {
};
struct TestCase {
- int amount;
+ gint64 amount;
const char *expectedErr;
};
@@ -88,14 +88,15 @@ TestCase testCases[] = {
TEST(AutoClear, AutoClearAll) {
QofBook *book = qof_book_new ();
Account *account = xaccMallocAccount(book);
+ xaccAccountSetName(account, "Test Account");
for (auto &d : splitData) {
Split *split = xaccMallocSplit(book);
xaccSplitSetMemo(split, d.memo);
xaccSplitSetAmount(split, gnc_numeric_create(d.amount, DENOM));
xaccSplitSetReconcile(split, d.cleared ? CREC : NREC);
+ xaccSplitSetAccount(split, account);
- // This way of inserting a split, seems to actualy work best. :D
gnc_account_insert_split(account, split);
}
xaccAccountRecomputeBalance(account);
commit 51715e454c022413c141e3fb5a2aa570d33dc16e
Author: Cristian Klein <cristian.klein at elastisys.com>
Date: Fri Oct 23 14:04:16 2020 +0200
[auto-clear] Add tests
diff --git a/libgnucash/app-utils/test/CMakeLists.txt b/libgnucash/app-utils/test/CMakeLists.txt
index b738202fd..85b85679e 100644
--- a/libgnucash/app-utils/test/CMakeLists.txt
+++ b/libgnucash/app-utils/test/CMakeLists.txt
@@ -85,3 +85,21 @@ set_dist_list(test_app_utils_DIST
${test_app_utils_scheme_SOURCES}
${test_app_utils_SOURCES}
)
+
+
+set(test_autoclear_SOURCES
+ test-autoclear.cpp
+)
+set(test_autoclear_INCLUDE_DIRS
+ ${APP_UTILS_TEST_INCLUDE_DIRS}
+ ${GTEST_INCLUDE_DIR}
+)
+set(test_autoclear_LIBS
+ ${APP_UTILS_TEST_LIBS}
+ gtest
+)
+
+gnc_add_test(test-autoclear "${test_autoclear_SOURCES}"
+ test_autoclear_INCLUDE_DIRS
+ test_autoclear_LIBS
+)
diff --git a/libgnucash/app-utils/test/test-autoclear.cpp b/libgnucash/app-utils/test/test-autoclear.cpp
new file mode 100644
index 000000000..834c77e91
--- /dev/null
+++ b/libgnucash/app-utils/test/test-autoclear.cpp
@@ -0,0 +1,124 @@
+/********************************************************************
+ * test-autoclear.c: test suite for Auto-Clear *
+ * Copyright 2020 Cristian Klein <cristian at kleinlabs.eu> *
+ * *
+ * 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 *
+ * https://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 "config.h"
+
+// GoogleTest is written in C++, however, the function we test in C.
+extern "C" {
+#include "../gnc-ui-balances.h"
+}
+#include "Split.h"
+
+#include "gtest/gtest.h"
+
+const int DENOM = 100; //< Denomerator is always 100 for simplicity.
+
+struct SplitDatum {
+ const char *memo;
+ int amount; //< Numerator of amount.
+ bool cleared;
+};
+
+SplitDatum splitData[] = {
+ { "Memo 01", - 8234, true },
+ { "Memo 02", -156326, true },
+ { "Memo 03", - 4500, true },
+ { "Memo 04", -694056, true },
+ { "Memo 05", - 7358, true },
+ { "Memo 06", - 11700, true },
+ { "Memo 07", - 20497, true },
+ { "Memo 08", - 11900, true },
+ { "Memo 09", - 8275, true },
+ { "Memo 10", - 58700, true },
+ { "Memo 11", +100000, true },
+ { "Memo 12", - 13881, true },
+ { "Memo 13", - 5000, true },
+ { "Memo 14", +200000, true },
+ { "Memo 15", - 16800, true },
+ { "Memo 16", -152000, true },
+ { "Memo 17", +160000, false },
+ { "Memo 18", - 63610, false },
+ { "Memo 19", - 2700, false },
+ { "Memo 20", - 15400, false },
+ { "Memo 21", - 3900, false },
+ { "Memo 22", - 22042, false },
+ { "Memo 23", - 2900, false },
+ { "Memo 24", - 10900, false },
+ { "Memo 25", - 44400, false },
+ { "Memo 26", - 9200, false },
+ { "Memo 27", - 7900, false },
+ { "Memo 28", - 1990, false },
+ { "Memo 29", - 7900, false },
+ { "Memo 30", - 61200, false },
+};
+
+struct TestCase {
+ int amount;
+ const char *expectedErr;
+};
+
+TestCase testCases[] = {
+ { 0, "The selected amount cannot be cleared.", },
+ { -869227, "Account is already at Auto-Clear Balance." }, // No splits need to be cleared.
+ { -877127, "Cannot uniquely clear splits. Found multiple possibilities." }, // Two splits need to be cleared.
+ { -891269, NULL }, // One split need to be cleared.
+ { -963269, NULL }, // All splits need to be cleared.
+};
+
+TEST(AutoClear, AutoClearAll) {
+ QofBook *book = qof_book_new ();
+ Account *account = xaccMallocAccount(book);
+
+ for (auto &d : splitData) {
+ Split *split = xaccMallocSplit(book);
+ xaccSplitSetMemo(split, d.memo);
+ xaccSplitSetAmount(split, gnc_numeric_create(d.amount, DENOM));
+ xaccSplitSetReconcile(split, d.cleared ? CREC : NREC);
+
+ // This way of inserting a split, seems to actualy work best. :D
+ gnc_account_insert_split(account, split);
+ }
+ xaccAccountRecomputeBalance(account);
+
+ for (auto &t : testCases) {
+ gnc_numeric amount_to_clear = gnc_numeric_create(t.amount, DENOM);
+ char *err;
+
+ GList *splits_to_clear = gnc_account_get_autoclear_splits(account, amount_to_clear, &err);
+
+ // Actually clear splits
+ for (GList *node = splits_to_clear; node; node = node->next) {
+ Split *split = (Split *)node->data;
+ xaccSplitSetReconcile(split, CREC);
+ }
+
+ ASSERT_STREQ(err, t.expectedErr);
+ if (t.expectedErr == NULL) {
+ gnc_numeric c = xaccAccountGetClearedBalance(account);
+ ASSERT_EQ(c.num, t.amount);
+ ASSERT_EQ(c.denom, DENOM);
+ }
+ }
+
+ qof_book_destroy(book);
+}
Summary of changes:
libgnucash/app-utils/test/CMakeLists.txt | 18 +++
libgnucash/app-utils/test/test-autoclear.cpp | 174 +++++++++++++++++++++++++++
2 files changed, 192 insertions(+)
create mode 100644 libgnucash/app-utils/test/test-autoclear.cpp
More information about the gnucash-changes
mailing list