You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gnucash/libgnucash/engine/test/test-lots.cpp

131 lines
3.7 KiB

/***************************************************************************
* test-lots.c
*
* Copyright (C) 2003 Linas Vepstas <linas@linas.org>
****************************************************************************/
/*
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
/**
* @file test-lots.c
* @brief Minimal test to see if automatic lot scrubbing works.
* @author Linas Vepstas <linas@linas.org>
*/
#include <glib.h>
#include <gtest/gtest.h>
#include <config.h>
#include <ctype.h>
#include "qof.h"
#include "Account.h"
#include "gnc-lot.h"
#include "Scrub3.h"
#include "cashobjects.h"
#include "test-stuff.h"
#include "test-engine-stuff.h"
#include "Transaction.h"
static gint transaction_num = 32;
static gint max_iterate = 1;
TEST(LotsTest, lot_kvp)
{
QofSession *sess = get_random_session ();
QofBook *book = qof_session_get_book (sess);
GNCLot *lot = gnc_lot_new (book);
// title
EXPECT_EQ(gnc_lot_get_title(lot), nullptr);
gnc_lot_set_title (lot, "");
EXPECT_STREQ(gnc_lot_get_title (lot), "");
gnc_lot_set_title (lot, "doc");
EXPECT_STREQ(gnc_lot_get_title(lot), "doc");
gnc_lot_set_title (lot, "unset");
EXPECT_STREQ(gnc_lot_get_title(lot), "unset");
gnc_lot_set_title (lot, NULL);
EXPECT_EQ(gnc_lot_get_title(lot), nullptr);
// notes
EXPECT_EQ(gnc_lot_get_notes(lot), nullptr);
gnc_lot_set_notes (lot, "");
EXPECT_STREQ(gnc_lot_get_notes(lot), "");
gnc_lot_set_notes (lot, "doc");
EXPECT_STREQ(gnc_lot_get_notes(lot), "doc");
gnc_lot_set_notes (lot, "unset");
EXPECT_STREQ(gnc_lot_get_notes(lot), "unset");
gnc_lot_set_notes (lot, NULL);
EXPECT_EQ(gnc_lot_get_notes(lot), nullptr);
gnc_lot_destroy (lot);
qof_session_destroy (sess);
}
TEST(LotsTest, run_test)
{
/* Iterate the test a number of times */
for (auto i = 0; i < max_iterate; i++)
{
fprintf(stdout, " Lots: %d of %d paired tests . . . \r",
(i + 1) * 2, max_iterate * 2);
fflush(stdout);
/* --------------------------------------------------------- */
/* In the first test, we will merely try to see if we can run
* without crashing. We don't check to see if data is good. */
auto sess = get_random_session ();
auto book = qof_session_get_book (sess);
do_test ((NULL != book), "create random data");
add_random_transactions_to_book (book, transaction_num);
auto root = gnc_book_get_root_account (book);
xaccAccountTreeScrubLots (root);
qof_session_destroy (sess);
}
}
int
main (int argc, char **argv)
{
testing::InitGoogleTest(&argc, argv);
qof_init();
if (!cashobjects_register())
exit(1);
/* Any tests that cause an error or warning to be printed
* automatically fail! */
g_log_set_always_fatal((GLogLevelFlags)(G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING));
/* Set up a reproducible test-case */
srand(0);
auto ret = RUN_ALL_TESTS();
qof_close();
get_rv();
return ret;
}