GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
test-lots.c
Go to the documentation of this file.
1 /***************************************************************************
2  * test-lots.c
3  *
4  * Copyright (C) 2003 Linas Vepstas <[email protected]>
5  ****************************************************************************/
6 /*
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20  * 02110-1301, USA.
21  */
28 #include "config.h"
29 #include <ctype.h>
30 #include <glib.h>
31 #include "qof.h"
32 #include "Account.h"
33 #include "Scrub3.h"
34 #include "cashobjects.h"
35 #include "test-stuff.h"
36 #include "test-engine-stuff.h"
37 #include "Transaction.h"
38 
39 static gint transaction_num = 320;
40 static gint max_iterate = 10;
41 
42 static void
43 run_test (void)
44 {
45  QofSession *sess;
46  QofBook *book;
47  Account *root;
48 
49  /* --------------------------------------------------------- */
50  /* In the first test, we will merely try to see if we can run
51  * without crashing. We don't check to see if data is good. */
52  sess = get_random_session ();
53  book = qof_session_get_book (sess);
54  do_test ((NULL != book), "create random data");
55 
56  add_random_transactions_to_book (book, transaction_num);
57 
58  root = gnc_book_get_root_account (book);
59  xaccAccountTreeScrubLots (root);
60 
61  /* --------------------------------------------------------- */
62  /* In the second test, we create an account with unrealized gains,
63  * and see if that gets fixed correctly, with the correct balances,
64  * and etc.
65  * XXX not implemented
66  */
67  success ("automatic lot scrubbing lightly tested and seem to work");
68  qof_session_end (sess);
69 
70 }
71 
72 int
73 main (int argc, char **argv)
74 {
75  gint i;
76 
77  qof_init();
78  if (!cashobjects_register())
79  exit(1);
80 
81  /* Any tests that cause an error or warning to be printed
82  * automatically fail! */
83  g_log_set_always_fatal( G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING );
84  /* Set up a reproducible test-case */
85  srand(0);
86  /* Iterate the test a number of times */
87  for (i = 0; i < max_iterate; i++)
88  {
89  fprintf(stdout, " Lots: %d of %d paired tests . . . \r",
90  (i + 1) * 2, max_iterate * 2);
91  fflush(stdout);
92  run_test ();
93  }
94  /* 'erase' the recurring tag line with dummy spaces. */
95  fprintf(stdout, "Lots: Test series complete. \n");
96  fflush(stdout);
97  print_test_results();
98 
99  qof_close();
100  return get_rv();
101 }
High-Level API for imposing Lot constraints.
QofBook * qof_session_get_book(const QofSession *session)
Account handling public routines.
void qof_close(void)
Safely close down the Query Object Framework.
void qof_session_end(QofSession *session)
void qof_init(void)
Initialise the Query Object Framework.
API for Transactions and Splits (journal entries)