GnuCash 2.4.99
test-lots.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *            test-lots.c
00003  *
00004  *  Copyright (C) 2003 Linas Vepstas <linas@linas.org>
00005  ****************************************************************************/
00006 /*
00007  *  This program is free software; you can redistribute it and/or modify
00008  *  it under the terms of the GNU General Public License as published by
00009  *  the Free Software Foundation; either version 2 of the License, or
00010  *  (at your option) any later version.
00011  *
00012  *  This program is distributed in the hope that it will be useful,
00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *  GNU General Public License for more details.
00016  *
00017  *  You should have received a copy of the GNU General Public License
00018  *  along with this program; if not, write to the Free Software
00019  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00020  *  02110-1301, USA.
00021  */
00028 #include "config.h"
00029 #include <ctype.h>
00030 #include <glib.h>
00031 #include "qof.h"
00032 #include "Account.h"
00033 #include "Scrub3.h"
00034 #include "cashobjects.h"
00035 #include "test-stuff.h"
00036 #include "test-engine-stuff.h"
00037 #include "Transaction.h"
00038 
00039 static gint transaction_num = 320;
00040 static gint     max_iterate = 10;
00041 
00042 static void
00043 run_test (void)
00044 {
00045     QofSession *sess;
00046     QofBook *book;
00047     Account *root;
00048 
00049     /* --------------------------------------------------------- */
00050     /* In the first test, we will merely try to see if we can run
00051      * without crashing.  We don't check to see if data is good. */
00052     sess = get_random_session ();
00053     book = qof_session_get_book (sess);
00054     do_test ((NULL != book), "create random data");
00055 
00056     add_random_transactions_to_book (book, transaction_num);
00057 
00058     root = gnc_book_get_root_account (book);
00059     xaccAccountTreeScrubLots (root);
00060 
00061     /* --------------------------------------------------------- */
00062     /* In the second test, we create an account with unrealized gains,
00063      * and see if that gets fixed correctly, with the correct balances,
00064      * and etc.
00065      * XXX not implemented
00066      */
00067     success ("automatic lot scrubbing lightly tested and seem to work");
00068     qof_session_end (sess);
00069 
00070 }
00071 
00072 int
00073 main (int argc, char **argv)
00074 {
00075     gint i;
00076 
00077     qof_init();
00078     if (!cashobjects_register())
00079         exit(1);
00080 
00081     /* Any tests that cause an error or warning to be printed
00082      * automatically fail! */
00083     g_log_set_always_fatal( G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING );
00084     /* Set up a reproducible test-case */
00085     srand(0);
00086     /* Iterate the test a number of times */
00087     for (i = 0; i < max_iterate; i++)
00088     {
00089         fprintf(stdout, " Lots: %d of %d paired tests . . . \r",
00090                 (i + 1) * 2, max_iterate * 2);
00091         fflush(stdout);
00092         run_test ();
00093     }
00094     /* 'erase' the recurring tag line with dummy spaces. */
00095     fprintf(stdout, "Lots: Test series complete.         \n");
00096     fflush(stdout);
00097     print_test_results();
00098 
00099     qof_close();
00100     return get_rv();
00101 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines