|
GnuCash 2.4.99
|
00001 /*************************************************************************** 00002 * test-query.c 00003 * 00004 * Tue Sep 27 19:12:41 2005 00005 * Copyright 2005 GnuCash team 00006 ****************************************************************************/ 00007 /* 00008 * This program is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU General Public License as published by 00010 * the Free Software Foundation; either version 2 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * This program is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with this program; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00021 * 02110-1301, USA. 00022 */ 00023 00024 #include "config.h" 00025 #include <glib.h> 00026 #include "qof.h" 00027 #include "cashobjects.h" 00028 #include "Transaction.h" 00029 #include "TransLog.h" 00030 #include "gnc-engine.h" 00031 #include "test-engine-stuff.h" 00032 #include "test-stuff.h" 00033 00034 static int 00035 test_trans_query (Transaction *trans, gpointer data) 00036 { 00037 QofBook *book = data; 00038 GList *list; 00039 QofQuery *q; 00040 00041 q = make_trans_query (trans, ALL_QT); 00042 qof_query_set_book (q, book); 00043 00044 list = xaccQueryGetTransactions (q, QUERY_TXN_MATCH_ANY); 00045 if (g_list_length (list) != 1) 00046 { 00047 failure_args ("test number returned", __FILE__, __LINE__, 00048 "number of matching transactions %d not 1", 00049 g_list_length (list)); 00050 g_list_free (list); 00051 return 13; 00052 } 00053 00054 if (list->data != trans) 00055 { 00056 failure ("matching transaction is wrong"); 00057 g_list_free (list); 00058 return 13; 00059 } 00060 00061 success ("found right transaction"); 00062 qof_query_destroy (q); 00063 g_list_free (list); 00064 00065 return 0; 00066 } 00067 00068 static void 00069 run_test (void) 00070 { 00071 QofSession *session; 00072 Account *root; 00073 QofBook *book; 00074 00075 session = get_random_session (); 00076 book = qof_session_get_book (session); 00077 root = gnc_book_get_root_account (book); 00078 00079 add_random_transactions_to_book (book, 20); 00080 00081 xaccAccountTreeForEachTransaction (root, test_trans_query, book); 00082 00083 qof_session_end (session); 00084 } 00085 00086 int 00087 main (int argc, char **argv) 00088 { 00089 int i; 00090 00091 qof_init(); 00092 g_log_set_always_fatal( G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING ); 00093 00094 xaccLogDisable (); 00095 00096 /* Always start from the same random seed so we fail consistently */ 00097 srand(0); 00098 if (!cashobjects_register()) 00099 { 00100 failure("can't register cashbojects"); 00101 goto cleanup; 00102 } 00103 00104 /* Loop the test. */ 00105 for (i = 0; i < 10; i++) 00106 { 00107 run_test (); 00108 } 00109 success("queries seem to work"); 00110 00111 cleanup: 00112 qof_close(); 00113 return get_rv(); 00114 }
1.7.4