20 #include <sys/types.h>
31 #include <qofinstance-p.h>
36 #include "gnc-session.h"
38 #include "TransactionP.h"
39 #include "Recurrence.h"
44 #include "test-stuff.h"
45 #include "test-engine-strings.h"
47 static gboolean glist_strings_only = FALSE;
49 static GHashTable *exclude_kvp_types = NULL;
50 static gint kvp_max_depth = 5;
51 static gint kvp_frame_max_elements = 10;
53 static gint max_tree_depth = 1;
54 static gint max_level_accounts = 3;
55 static gint max_total_accounts = 10;
56 static gint max_trans_num = 1000;
57 static gint total_num_accounts = 0;
59 static gint max_scu = 100;
60 static gint min_scu = 100;
61 static const int64_t num_limit = INT64_MAX;
62 static const int64_t max_denom_mult = 1000000LL;
71 static gint borked = 80;
73 gboolean gnc_engine_debug_random = FALSE;
79 set_max_account_tree_depth (gint max_tree_depth_in)
81 max_tree_depth = MAX (max_tree_depth_in, 1);
85 set_max_accounts_per_level (gint max_level_accounts_in)
87 max_level_accounts = MAX (max_level_accounts_in, 1);
91 set_max_kvp_depth (gint max_kvp_depth)
93 kvp_max_depth = MAX (max_kvp_depth, 1);
97 set_max_kvp_frame_elements (gint max_kvp_frame_elements)
99 kvp_frame_max_elements = MAX (max_kvp_frame_elements, 1);
107 if (!exclude_kvp_types)
108 exclude_kvp_types = g_hash_table_new (g_int_hash, g_int_equal);
110 key = g_new (gint, 1);
113 g_hash_table_insert (exclude_kvp_types, key, exclude_kvp_types);
121 if (!exclude_kvp_types)
124 if (g_hash_table_lookup (exclude_kvp_types, &key))
131 random_glist_strings_only (gboolean strings_only)
133 glist_strings_only = strings_only;
136 static gboolean zero_nsec = FALSE;
139 random_timespec_zero_nsec (gboolean zero_nsec_in)
141 zero_nsec = zero_nsec_in;
144 static gboolean usec_resolution = FALSE;
147 random_timespec_usec_resolution (gboolean usec_resolution_in)
149 usec_resolution = usec_resolution_in;
154 static inline gboolean
157 if (1 == get_random_int_in_range (0, borked))
168 get_random_list_element (GList *list)
170 g_return_val_if_fail (list, NULL);
172 return g_list_nth_data (list,
173 get_random_int_in_range (0,
174 g_list_length (list) - 1));
177 static KvpValue* get_random_kvp_value_depth (
int type, gint depth);
180 get_random_glist_depth (gint depth)
183 int count = get_random_int_in_range(1, 5);
186 if (depth >= kvp_max_depth)
189 for (i = 0; i < count; i++)
198 value = get_random_kvp_value_depth (kvpt, depth + 1);
202 ret = g_list_prepend(ret, value);
209 get_random_glist(
void)
211 return get_random_glist_depth (0);
218 get_random_timespec(
void)
224 while (ret->tv_sec <= 0)
225 ret->tv_sec = rand();
231 ret->tv_nsec = rand();
235 ret->tv_nsec = MIN (ret->tv_nsec, 999999999);
236 ret->tv_nsec /= 1000;
237 ret->tv_nsec *= 1000;
245 get_random_guid(
void)
258 static KvpFrame* get_random_kvp_frame_depth (gint depth);
261 get_random_kvp_value_depth (
int type, gint depth)
282 if (kvp_type_excluded (datype))
288 ret = kvp_value_new_gint64(get_random_gint64());
302 tmp_str = get_random_string();
306 ret = kvp_value_new_string(tmp_str);
314 tmp_guid = get_random_guid();
315 ret = kvp_value_new_guid(tmp_guid);
322 Timespec *ts = get_random_timespec();
323 ret = kvp_value_new_timespec (*ts);
335 tmp_frame = get_random_kvp_frame_depth(depth + 1);
336 ret = kvp_value_new_frame(tmp_frame);
349 get_random_kvp_frame_depth (gint depth)
355 if (depth >= kvp_max_depth)
360 vals_to_add = get_random_int_in_range(1, kvp_frame_max_elements);
363 for (; vals_to_add > 0; vals_to_add--)
371 key = get_random_string_without(
"/");
379 val = get_random_kvp_value_depth (-1, depth + 1);
399 get_random_kvp_frame (
void)
401 return get_random_kvp_frame_depth (0);
405 get_random_kvp_value(
int type)
407 return get_random_kvp_value_depth (type, 0);
413 #define RAND_IN_RANGE(X) (((X)*((gint64) (rand()+1)))/RAND_MAX)
416 get_random_gnc_numeric(int64_t deno)
422 if (RAND_MAX / 8 > rand())
425 deno = RAND_IN_RANGE(6000ULL);
429 gint64 norm = RAND_IN_RANGE (11ULL);
441 if (0 == deno) deno = 1;
449 limit = num_limit / (max_denom_mult / deno == 0 ? max_denom_mult : max_denom_mult / deno);
450 numer = get_random_gint64 ();
453 int64_t num = numer % limit;
459 if (0 == numer) numer = 1;
460 g_log(
"test.engine.suff", G_LOG_LEVEL_INFO,
"New GncNumeric %" PRIu64
" / %" PRIu64
" !\n", numer, deno);
461 return gnc_numeric_create(numer, deno);
468 get_random_rate (
void)
472 gint64 numer = get_random_gint64 () % (2ULL << 24);
473 gint64 denom = 100LL;
474 return gnc_numeric_create (numer, denom);
480 const char *types[] =
491 get_random_commodity_namespace(
void)
493 return get_random_string_in_array(types);
502 g_return_val_if_fail (table, NULL);
511 name_space = get_random_list_element (namespaces);
517 com = get_random_list_element (commodities);
519 g_list_free (commodities);
525 g_list_free (namespaces);
531 get_random_commodity (
QofBook *book)
546 get_random_int_in_range (1, 5) < 5)
547 return get_random_commodity_from_table (table);
550 mn = get_random_string_length_in_range(1, 3);
551 space = get_random_commodity_namespace();
555 ret = gnc_commodity_table_lookup (table, space, mn);
564 name = get_random_string();
565 cusip = get_random_string();
567 ran_int = get_random_int_in_range(min_scu, max_scu);
586 g_return_if_fail (com);
588 str = get_random_string ();
592 str = get_random_string ();
596 str = get_random_string ();
600 str = get_random_string ();
613 g_return_if_fail (table);
617 for (node = namespaces; node; node = node->next)
619 const char *ns = node->data;
628 for (com_node = commodities; com_node; com_node = com_node->next)
633 make_random_changes_to_commodity (com);
637 g_list_free (commodities);
640 g_list_free (namespaces);
652 g_return_if_fail (book && p);
654 gnc_price_begin_edit (p);
656 c = get_random_commodity (book);
657 gnc_price_set_commodity (p, c);
659 c = get_random_commodity (book);
660 gnc_price_set_currency (p, c);
662 ts = get_random_timespec ();
663 gnc_price_set_time (p, *ts);
666 string = get_random_string ();
667 gnc_price_set_source (p,
string);
670 string = get_random_string ();
671 gnc_price_set_typestr (p,
string);
676 gnc_price_commit_edit (p);
680 get_random_price(
QofBook *book)
687 failure_args(
"engine-stuff", __FILE__, __LINE__,
688 "get_random_price failed");
692 make_random_changes_to_price (book, p);
695 failure_args(
"engine-stuff", __FILE__, __LINE__,
696 "make_random_changes_to_price failed");
709 num_prices = get_random_int_in_range (1, 41);
712 failure_args(
"engine-stuff", __FILE__, __LINE__,
713 "get_random_int_in_range failed");
717 while (num_prices-- > 0)
721 p = get_random_price (book);
724 failure_args(
"engine-stuff", __FILE__, __LINE__,
725 "get_random_price failed");
741 get_random_pricedb(
QofBook *book)
748 failure_args(
"engine-stuff", __FILE__, __LINE__,
749 "gnc_pricedb_get_db failed");
752 if (!make_random_pricedb (book, db))
761 price_accumulator (
GNCPrice *p, gpointer data)
765 *list = g_list_prepend (*list, p);
776 g_return_if_fail (pdb);
780 for (node = list; node; node = node->next)
784 switch (get_random_int_in_range (0, 5))
792 make_random_changes_to_price (book, p);
804 int i = get_random_int_in_range (1, 5);
808 GNCPrice *p = get_random_price (book);
821 set_account_random_string(
Account* act,
822 void(*func)(
Account *act,
const gchar*str))
824 gchar *tmp_str = get_random_string();
827 (func)(act, tmp_str);
833 set_account_random_string_from_array(
837 const gchar *tmp_str = get_random_string_in_array(list);
839 (func)(act, tmp_str);
844 account_add_subaccounts (
QofBook *book,
Account *account,
int depth)
851 num_accounts = get_random_int_in_range (1, 10);
852 while (num_accounts-- > 0)
854 Account *sub = get_random_account (book);
858 total_num_accounts ++;
859 if (total_num_accounts > max_total_accounts)
return;
861 account_add_subaccounts (book, sub, depth - 1);
870 g_return_if_fail (book);
871 g_return_if_fail (root);
873 total_num_accounts = 0;
874 depth = get_random_int_in_range (1, max_tree_depth);
876 account_add_subaccounts (book, root, depth);
879 if (total_num_accounts <= 1)
880 account_add_subaccounts (book, root, 1);
884 get_random_account_tree (
QofBook *book)
888 g_return_val_if_fail (book, NULL);
890 root = gnc_book_get_root_account (book);
894 gnc_book_set_root_account (book, root);
897 make_random_account_tree (book, root);
919 if (1 >= g_list_length (account_list))
return;
921 acc = get_random_list_element (account_list);
923 s1 = get_random_split(book, acc, trn);
925 bcc = get_random_list_element (account_list);
926 if ((bcc == acc) && (!do_bork()))
934 bcc = get_random_list_element (account_list);
940 s2 = get_random_split(book, bcc, trn);
947 g_log (
"test.engine.suff", G_LOG_LEVEL_DEBUG,
"Borking second %" PRIu64
948 " / %" PRIu64
", scu %d\n", val.num, val.denom, s2_scu);
952 if (val.denom != s2_scu)
954 if (val.denom > s2_scu)
955 val.num /= val.denom / s2_scu;
968 make_random_changes_to_transaction_and_splits (
QofBook *book,
976 g_return_if_fail (book);
977 g_return_if_fail (trans);
978 g_return_if_fail (accounts);
982 make_random_changes_to_transaction (book, trans);
984 switch (get_random_int_in_range (0, 3))
998 add_random_splits (book, trans, accounts);
1007 for (node = splits; node; node = node->next)
1009 Split *split = node->data;
1012 account = get_random_list_element (accounts);
1035 for (node = splits; node; node = node->next)
1037 Split *split = node->data;
1039 if (get_random_boolean ())
1040 make_random_changes_to_split (split);
1043 if (get_random_boolean ())
1050 add_trans_helper (
Transaction *trans, gpointer data)
1053 GList **list = data;
1059 *list = g_list_prepend (*list, ti);
1073 g_return_if_fail (parent && book);
1078 new_account = get_random_account (book);
1080 if (get_random_boolean () || !accounts)
1084 account = get_random_list_element (accounts);
1089 g_list_free (accounts);
1093 add_random_transactions_to_book (book, get_random_int_in_range (1, 6));
1096 for (node = accounts; node; node = node->next)
1098 Account *account = node->data;
1100 if (get_random_boolean ())
1101 make_random_changes_to_account (book, account);
1108 for (node = transes; node; node = node->next)
1116 make_random_changes_to_transaction_and_splits (book, trans, accounts);
1119 for (node = transes; node; node = node->next)
1125 g_list_free (transes);
1129 account = get_random_list_element (accounts);
1132 splits = g_list_copy (splits);
1134 for (node = splits; node; node = node->next)
1136 Split *split = node->data;
1140 new_account = get_random_list_element (accounts);
1142 while (new_account == account);
1150 g_list_free (splits);
1151 g_list_free (accounts);
1156 if (accounts && (g_list_length (accounts) > 1))
1158 int i = get_random_int_in_range (1, 4);
1164 a1 = get_random_list_element (accounts);
1166 if (get_random_boolean ())
1167 a2 = get_random_list_element (accounts);
1189 g_list_free (accounts);
1193 get_random_account(
QofBook *book)
1203 sane_account_names);
1213 qof_instance_set_slots(QOF_INSTANCE(ret), get_random_kvp_frame());
1215 root = gnc_book_get_root_account (book);
1219 gnc_book_set_root_account (book, root);
1232 g_return_if_fail (account);
1246 qof_instance_set_slots(QOF_INSTANCE(account), get_random_kvp_frame());
1252 set_split_random_string(
Split *spl,
1253 void(*func)(
Split *act,
const gchar*str))
1255 gchar *tmp_str = get_random_string();
1258 (func)(spl, tmp_str);
1270 gnc_numeric amt = {0, 1}, val = {0, 1}, rate = {0, 0};
1281 str = get_random_string_in_array(sane_descriptions);
1283 str = get_random_string_in_array(sane_actions);
1288 ts = get_random_timespec();
1295 xaccSplitSetParent(ret, trn);
1296 xaccSplitSetAccount(ret, acct);
1300 val = get_random_gnc_numeric (scu);
1302 fprintf(stderr,
"get_random_split: Created split with zero value: %p\n", ret);
1309 if (val.denom > scu && val.num > num_limit / (max_denom_mult / scu))
1311 int64_t new_num = val.num / (val.denom / scu);
1312 g_log(
"test.engine.suff", G_LOG_LEVEL_DEBUG,
1313 "Adjusting val.denom from %" PRIu64
" to %" PRIu64
"\n",
1321 g_log (
"test.engine.suff", G_LOG_LEVEL_DEBUG,
1322 "Random split value: %" PRIu64
" / %" PRIu64
", scu %d\n",
1323 val.num, val.denom, scu);
1340 rate = get_random_rate ();
1345 g_log (
"test.engine.suff", G_LOG_LEVEL_DEBUG,
"Random split amount: %"
1346 PRIu64
" / %" PRIu64
", rate %" PRIu64
" / %" PRIu64
"\n",
1347 amt.num, amt.denom, rate.num, rate.denom);
1361 qof_instance_set_slots(QOF_INSTANCE (ret), get_random_kvp_frame());
1368 make_random_changes_to_split (
Split *split)
1373 g_return_if_fail (split);
1384 ts = get_random_timespec();
1388 qof_instance_set_slots (QOF_INSTANCE (split), get_random_kvp_frame());
1401 gchar *tmp_str = get_random_string();
1402 if (!trn || !(&trn->inst))
1409 (func)(trn, tmp_str);
1416 set_tran_random_string_from_array(
1418 const gchar *list[])
1420 const gchar *tmp_str = get_random_string_in_array(list);
1422 (func)(trn, tmp_str);
1432 to_set = get_random_timespec();
1439 get_random_transaction_with_currency(
QofBook *book,
1441 GList *account_list)
1454 if (1 >= g_list_length (account_list))
1456 failure_args(
"engine-stuff", __FILE__, __LINE__,
1457 "get_random_transaction_with_currency: account_list too short");
1461 numstr = g_new0(gchar, 10);
1468 currency ? currency :
1469 get_random_commodity (book));
1471 num = get_random_int_in_range (1, max_trans_num);
1472 g_snprintf(numstr, 10,
"%d", num);
1479 f = get_random_kvp_frame();
1480 xaccTransSetSlots_nc(trans, f);
1482 add_random_splits(book, trans, account_list);
1484 if (get_random_int_in_range (1, 10) == 1)
1486 char *reason = get_random_string ();
1494 failure_args(
"engine-stuff", __FILE__, __LINE__,
1495 "get_random_transaction_with_currency failed");
1503 get_random_transaction (
QofBook *book)
1507 g_return_val_if_fail(book, NULL);
1508 ret = get_random_transaction_with_currency (book, NULL, NULL);
1511 failure_args(
"engine-stuff", __FILE__, __LINE__,
1512 "get_random_transaction failed");
1521 g_return_if_fail (trans && book);
1525 if (get_random_int_in_range (1, 2) == 1)
1541 xaccTransSetSlots_nc (trans, get_random_kvp_frame());
1550 get_random_guids(
int max)
1552 GList *guids = NULL;
1555 if (max < 1)
return NULL;
1557 num_guids = get_random_int_in_range (1, max);
1559 while (num_guids-- > 0)
1560 guids = g_list_prepend (guids, get_random_guid ());
1566 free_random_guids(GList *guids)
1570 for (node = guids; node; node = node->next)
1571 g_free (node->data);
1573 g_list_free (guids);
1577 get_random_queryop(
void)
1579 int op_num = get_random_int_in_range(1, 11);
1599 op = QOF_QUERY_NAND;
1608 g_assert_not_reached();
1611 if (gnc_engine_debug_random) printf (
"op = %d (int was %d), ", op, op_num);
1616 get_random_kvp_path (
void)
1622 len = get_random_int_in_range (1, kvp_max_depth);
1625 path = g_slist_prepend (path, get_random_string_without (
"\n\\"));
1627 return g_slist_reverse (path);
1631 free_random_kvp_path (GSList *path)
1635 for (node = path; node; node = node->next)
1636 g_free (node->data);
1638 g_slist_free (path);
1642 get_random_id_type (
void)
1644 switch (get_random_int_in_range (1, 3))
1647 return GNC_ID_SPLIT;
1649 return GNC_ID_TRANS;
1651 return GNC_ID_ACCOUNT;
1653 return get_random_string ();
1671 set_query_sort (
QofQuery *q, sort_type_t sort_code)
1673 GSList *p1 = NULL, *p2 = NULL, *p3 = NULL, *standard;
1683 p1 = g_slist_prepend (p1, TRANS_DATE_POSTED);
1684 p1 = g_slist_prepend (p1, SPLIT_TRANS);
1687 case BY_DATE_ENTERED:
1688 p1 = g_slist_prepend (p1, TRANS_DATE_ENTERED);
1689 p1 = g_slist_prepend (p1, SPLIT_TRANS);
1692 case BY_DATE_RECONCILED:
1693 p1 = g_slist_prepend (p1, SPLIT_RECONCILE);
1694 p2 = g_slist_prepend (p2, SPLIT_DATE_RECONCILED);
1698 p1 = g_slist_prepend (p1, TRANS_NUM);
1699 p1 = g_slist_prepend (p1, SPLIT_TRANS);
1703 p1 = g_slist_prepend (p1, SPLIT_VALUE);
1707 p1 = g_slist_prepend (p1, SPLIT_MEMO);
1711 p1 = g_slist_prepend (p1, TRANS_DESCRIPTION);
1712 p1 = g_slist_prepend (p1, SPLIT_TRANS);
1716 g_slist_free (standard);
1719 g_slist_free (standard);
1720 g_return_if_fail (FALSE);
1728 get_random_query(
void)
1733 num_terms = get_random_int_in_range (1, 3);
1734 if (gnc_engine_debug_random) printf(
"num_terms = %d", num_terms);
1736 q = qof_query_create_for(GNC_ID_SPLIT);
1738 while (num_terms-- > 0)
1749 pr_type = get_random_int_in_range (1, 20);
1750 if (gnc_engine_debug_random) printf(
"\n pr_type = %d ", pr_type);
1755 guids = get_random_guids (10);
1756 xaccQueryAddAccountGUIDMatch
1759 get_random_int_in_range (1, QOF_GUID_MATCH_NONE),
1760 get_random_queryop ());
1761 free_random_guids (guids);
1765 string = get_random_string_without (
"\\");
1766 xaccQueryAddActionMatch (q,
1768 get_random_boolean (),
1769 get_random_boolean (),
1770 get_random_int_in_range (1, QOF_COMPARE_CONTAINS),
1771 get_random_queryop ());
1776 xaccQueryAddBalanceMatch
1778 get_random_boolean (),
1779 get_random_queryop ());
1783 xaccQueryAddClearedMatch
1785 get_random_int_in_range (1,
1788 CLEARED_RECONCILED |
1791 get_random_queryop ());
1795 start = get_random_timespec ();
1796 end = get_random_timespec ();
1797 xaccQueryAddDateMatchTS (q,
1798 get_random_boolean (),
1800 get_random_boolean (),
1802 get_random_queryop ());
1808 string = get_random_string_without (
"\\");
1809 xaccQueryAddDescriptionMatch (q,
1811 get_random_boolean (),
1812 get_random_boolean (),
1813 get_random_int_in_range (1, QOF_COMPARE_CONTAINS),
1814 get_random_queryop ());
1819 guid = get_random_guid ();
1820 xaccQueryAddGUIDMatch (q,
1822 get_random_id_type (),
1823 get_random_queryop ());
1828 path = get_random_kvp_path ();
1831 value = get_random_kvp_value_depth (-2, kvp_max_depth);
1834 xaccQueryAddKVPMatch (q,
1837 get_random_int_in_range (1, QOF_COMPARE_NEQ),
1838 get_random_id_type (),
1839 get_random_queryop ());
1841 free_random_kvp_path (path);
1845 string = get_random_string_without (
"\\");
1846 xaccQueryAddMemoMatch (q,
1848 get_random_boolean (),
1849 get_random_boolean (),
1850 get_random_int_in_range (1, QOF_COMPARE_CONTAINS),
1851 get_random_queryop ());
1856 string = get_random_string_without (
"\\");
1857 xaccQueryAddNumberMatch (q,
1859 get_random_boolean (),
1860 get_random_boolean (),
1861 get_random_int_in_range (1, QOF_COMPARE_CONTAINS),
1862 get_random_queryop ());
1867 xaccQueryAddSharePriceMatch
1870 get_random_int_in_range (1, QOF_COMPARE_NEQ),
1871 get_random_queryop ());
1875 xaccQueryAddSharesMatch
1878 get_random_int_in_range (1, QOF_COMPARE_NEQ),
1879 get_random_queryop ());
1883 xaccQueryAddValueMatch
1886 get_random_int_in_range (1, QOF_NUMERIC_MATCH_ANY),
1887 get_random_int_in_range (1, QOF_COMPARE_NEQ),
1888 get_random_queryop ());
1892 if (gnc_engine_debug_random) printf(
"ignored..");
1898 if (gnc_engine_debug_random) printf (
"\n");
1899 set_query_sort (q, get_random_int_in_range (1, BY_NONE));
1902 get_random_boolean (),
1903 get_random_boolean (),
1904 get_random_boolean ());
1912 get_random_book (
void)
1918 get_random_account_tree (book);
1919 get_random_pricedb (book);
1925 get_random_session (
void)
1930 session = qof_session_new ();
1934 get_random_account_tree (book);
1935 get_random_pricedb (book);
1941 add_random_transactions_to_book (
QofBook *book, gint num_transactions)
1946 if (num_transactions <= 0)
return;
1948 g_return_if_fail (book);
1951 g_return_if_fail (accounts);
1955 while (num_transactions--)
1959 com = get_random_commodity_from_table (table);
1960 get_random_transaction_with_currency (book, com, accounts);
1962 g_list_free (accounts);
1966 make_random_changes_to_book (
QofBook *book)
1968 g_return_if_fail (book);
1970 make_random_changes_to_level (book, gnc_book_get_root_account (book));
1979 make_random_changes_to_session (
QofSession *session)
1981 g_return_if_fail (session);
1994 add_kvp_value_query (
const char *key,
KvpValue *value, gpointer data)
1999 kqd->path = g_slist_append (kqd->path, (gpointer) key);
2003 add_kvp_value_query, data);
2005 xaccQueryAddKVPMatch (kqd->q, kqd->path, value,
2006 QOF_COMPARE_EQUAL, kqd->where,
2009 node = g_slist_last (kqd->path);
2010 kqd->path = g_slist_remove_link (kqd->path, node);
2011 g_slist_free_1 (node);
2026 static gboolean include_price = TRUE;
2029 trans_query_include_price (gboolean include_price_in)
2031 include_price = include_price_in;
2035 get_random_query_type (
void)
2037 switch (get_random_int_in_range (0, 4))
2042 return SPLIT_KVP_QT;
2044 return TRANS_KVP_QT;
2046 return ACCOUNT_KVP_QT;
2055 make_trans_query (
Transaction *trans, TestQueryTypes query_types)
2062 if (query_types == RANDOM_QT)
2063 query_types = get_random_query_type ();
2065 q = qof_query_create_for(GNC_ID_SPLIT);
2070 if (query_types & SIMPLE_QT)
2077 TRUE, FALSE, QOF_COMPARE_CONTAINS, QOF_QUERY_AND);
2083 TRUE, FALSE, QOF_COMPARE_CONTAINS, QOF_QUERY_AND);
2089 TRUE, FALSE, QOF_COMPARE_CONTAINS, QOF_QUERY_AND);
2093 xaccQueryAddValueMatch (q, n, QOF_NUMERIC_MATCH_ANY,
2094 QOF_COMPARE_EQUAL, QOF_QUERY_AND);
2097 xaccQueryAddSharesMatch (q, n, QOF_COMPARE_EQUAL, QOF_QUERY_AND);
2102 xaccQueryAddSharePriceMatch (q, n, QOF_COMPARE_EQUAL, QOF_QUERY_AND);
2109 xaccQueryAddDateMatchTS (q, TRUE, ts, TRUE, ts, QOF_QUERY_AND);
2114 xaccQueryAddMemoMatch (q,
xaccSplitGetMemo (s), TRUE, FALSE, QOF_COMPARE_CONTAINS, QOF_QUERY_AND);
2118 cleared_match_t how;
2126 how = CLEARED_CLEARED;
2129 how = CLEARED_RECONCILED;
2132 how = CLEARED_FROZEN;
2135 how = CLEARED_VOIDED;
2138 failure (
"bad reconcile flag");
2143 xaccQueryAddClearedMatch (q, how, QOF_QUERY_AND);
2147 if (query_types & ACCOUNT_QT)
2156 Split * split = node->data;
2164 list = g_list_prepend (list, get_random_guid ());
2165 list = g_list_prepend (list, get_random_guid ());
2166 list = g_list_prepend (list, get_random_guid ());
2167 xaccQueryAddAccountGUIDMatch (q, list, QOF_GUID_MATCH_NONE, QOF_QUERY_AND);
2171 GncGUID * guid = get_random_guid ();
2173 list = g_list_prepend (list, guid);
2177 for (node = list; node; node = node->next)
2178 g_free (node->data);
2182 if (query_types & GUID_QT)
2185 GNC_ID_SPLIT, QOF_QUERY_AND);
2188 GNC_ID_TRANS, QOF_QUERY_AND);
2191 GNC_ID_ACCOUNT, QOF_QUERY_AND);
2194 if (query_types & SPLIT_KVP_QT)
2195 add_kvp_query (q, qof_instance_get_slots (QOF_INSTANCE (s)), GNC_ID_SPLIT);
2197 if (query_types & TRANS_KVP_QT)
2198 add_kvp_query (q, qof_instance_get_slots (QOF_INSTANCE (trans)), GNC_ID_TRANS);
2200 if (query_types & ACCOUNT_KVP_QT)
2201 add_kvp_query (q, qof_instance_get_slots (QOF_INSTANCE (a)), GNC_ID_ACCOUNT);
2207 daily_freq(
const GDate* start,
int multiplier)
2210 recurrenceSet(r, multiplier, PERIOD_DAY, start, WEEKEND_ADJ_NONE);
2215 once_freq(
const GDate *when)
2218 recurrenceSet(r, 1, PERIOD_ONCE, when, WEEKEND_ADJ_NONE);
2223 add_sx(gchar *name,
const GDate *start,
const GDate *end,
const GDate *last_occur,
Recurrence *r)
2228 xaccSchedXactionSetStartDate(sx, start);
2231 if (last_occur != NULL)
2232 xaccSchedXactionSetLastOccurDate(sx, last_occur);
2234 GList *recurrences = NULL;
2235 recurrences = g_list_append(recurrences, r);
2239 gnc_sxes_add_sx(gnc_book_get_schedxactions(book), sx);
2245 add_daily_sx(gchar *name,
const GDate *start,
const GDate *end,
const GDate *last_occur)
2247 return add_sx(name, start, end, last_occur, daily_freq(start, 1));
2251 add_once_sx(gchar *name,
const GDate *when)
2253 return add_sx(name, when, NULL, NULL, once_freq(when));
2261 gnc_sxes_del_sx(sxes, sx);
void xaccAccountSetType(Account *acc, GNCAccountType tip)
void xaccSplitSetValue(Split *s, gnc_numeric amt)
gnc_commodity * gnc_commodity_table_insert(gnc_commodity_table *table, gnc_commodity *comm)
GNCPrice * gnc_price_create(QofBook *book)
int xaccAccountTreeForEachTransaction(Account *acc, TransactionCallback proc, void *data)
void guid_replace(GncGUID *guid)
void gnc_sx_set_schedule(SchedXaction *sx, GList *schedule)
gnc_commodity_table * gnc_commodity_table_get_table(QofBook *book)
Transaction * xaccMallocTransaction(QofBook *book)
void xaccSplitSetAction(Split *split, const char *actn)
int gnc_commodity_get_fraction(const gnc_commodity *cm)
void gnc_account_append_child(Account *new_parent, Account *child)
Split * xaccTransGetSplit(const Transaction *trans, int i)
SplitList * xaccAccountGetSplitList(const Account *acc)
void qof_query_set_sort_order(QofQuery *q, QofQueryParamList *primary_sort_params, QofQueryParamList *secondary_sort_params, QofQueryParamList *tertiary_sort_params)
gboolean xaccSplitDestroy(Split *split)
gnc_numeric gnc_numeric_neg(gnc_numeric a)
KvpValueType
possible types in the union KvpValue
void gnc_price_unref(GNCPrice *p)
gboolean gnc_pricedb_add_price(GNCPriceDB *db, GNCPrice *p)
void gnc_commodity_set_fraction(gnc_commodity *cm, int fraction)
char xaccSplitGetReconcile(const Split *split)
gboolean gnc_commodity_equal(const gnc_commodity *a, const gnc_commodity *b)
void xaccAccountSetCode(Account *acc, const char *str)
QofBook * qof_book_new(void)
void xaccTransSetDescription(Transaction *trans, const char *desc)
void xaccTransSetNum(Transaction *trans, const char *xnum)
Use a 64-bit unsigned int timespec.
void xaccSplitSetReconcile(Split *split, char recn)
Transaction * xaccSplitGetParent(const Split *split)
void qof_query_set_sort_increasing(QofQuery *q, gboolean prim_inc, gboolean sec_inc, gboolean tert_inc)
const char * xaccTransGetNum(const Transaction *trans)
struct _QofQuery QofQuery
GNCPriceDB * gnc_pricedb_get_db(QofBook *book)
void kvp_frame_delete(KvpFrame *frame)
void xaccTransSetDateEnteredTS(Transaction *trans, const Timespec *ts)
gboolean gnc_numeric_negative_p(gnc_numeric a)
void xaccTransSetCurrency(Transaction *trans, gnc_commodity *curr)
void qof_query_set_max_results(QofQuery *q, int n)
void xaccTransDestroy(Transaction *trans)
void xaccAccountDestroy(Account *acc)
Transaction * xaccTransLookup(const GncGUID *guid, QofBook *book)
#define xaccAccountGetGUID(X)
void xaccSplitSetAmount(Split *s, gnc_numeric amt)
QofBook * qof_session_get_book(const QofSession *session)
Account handling public routines.
void qof_query_destroy(QofQuery *q)
void xaccTransVoid(Transaction *trans, const char *reason)
void xaccSplitSetMemo(Split *split, const char *memo)
GList * gnc_commodity_table_get_namespaces(const gnc_commodity_table *table)
void gnc_commodity_set_cusip(gnc_commodity *cm, const char *cusip)
gnc_commodity * gnc_commodity_new(QofBook *book, const char *fullname, const char *name_space, const char *mnemonic, const char *cusip, int fraction)
Anchor Scheduled Transaction info in a book. See src/doc/books.txt for design overview.
gboolean gnc_pricedb_foreach_price(GNCPriceDB *db, gboolean(*f)(GNCPrice *p, gpointer user_data), gpointer user_data, gboolean stable_order)
void kvp_frame_set_slot_nc(KvpFrame *frame, const gchar *key, KvpValue *value)
#define kvp_value_new_gnc_numeric
gboolean gnc_commodity_namespace_is_iso(const char *name_space)
const char * xaccTransGetDescription(const Transaction *trans)
void xaccTransCommitEdit(Transaction *trans)
gnc_numeric gnc_numeric_div(gnc_numeric x, gnc_numeric y, gint64 denom, gint how)
#define xaccSplitGetGUID(X)
void xaccTransBeginEdit(Transaction *trans)
gnc_numeric xaccSplitGetSharePrice(const Split *split)
void xaccTransUnvoid(Transaction *trans)
All type declarations for the whole Gnucash engine.
gboolean gnc_numeric_positive_p(gnc_numeric a)
gboolean gnc_pricedb_remove_price(GNCPriceDB *db, GNCPrice *p)
Split * xaccMallocSplit(QofBook *book)
#define xaccTransGetGUID(X)
GList * gnc_account_get_descendants(const Account *account)
CommodityList * gnc_commodity_table_get_commodities(const gnc_commodity_table *table, const char *name_space)
void xaccSchedXactionSetName(SchedXaction *sx, const gchar *newName)
gboolean xaccTransGetVoidStatus(const Transaction *trans)
void kvp_frame_for_each_slot(KvpFrame *f, void(*proc)(const gchar *key, KvpValue *value, gpointer data), gpointer data)
void gnc_commodity_set_fullname(gnc_commodity *cm, const char *fullname)
KvpValue * kvp_value_new_glist_nc(GList *lst)
gnc_numeric xaccSplitGetValue(const Split *split)
void xaccAccountBeginEdit(Account *acc)
Account * xaccSplitGetAccount(const Split *s)
gboolean xaccAccountHasAncestor(const Account *acc, const Account *ancestor)
gnc_commodity * xaccAccountGetCommodity(const Account *acc)
void gnc_commodity_set_mnemonic(gnc_commodity *cm, const char *mnemonic)
gnc_commodity * xaccTransGetCurrency(const Transaction *trans)
#define xaccAccountInsertSplit(acc, s)
struct KvpFrameImpl KvpFrame
#define QUERY_DEFAULT_SORT
Account * xaccMallocAccount(QofBook *book)
void xaccSplitSetDateReconciledTS(Split *split, Timespec *ts)
void gnc_commodity_table_remove(gnc_commodity_table *table, gnc_commodity *comm)
void gnc_commodity_set_namespace(gnc_commodity *cm, const char *name_space)
GNCNumericErrorCode gnc_numeric_check(gnc_numeric a)
KvpFrame * kvp_frame_new(void)
const char * xaccSplitGetMemo(const Split *split)
const char * xaccSplitGetAction(const Split *split)
SchedXaction * xaccSchedXactionMalloc(QofBook *book)
KvpFrame * kvp_value_get_frame(const KvpValue *value)
guint gnc_commodity_table_get_size(const gnc_commodity_table *tbl)
void xaccAccountSetDescription(Account *acc, const char *str)
void kvp_value_delete(KvpValue *value)
Scheduled Transactions public handling routines.
void xaccSchedXactionSetEndDate(SchedXaction *sx, const GDate *newEnd)
API for Transactions and Splits (journal entries)
void xaccAccountCommitEdit(Account *acc)
struct KvpValueImpl KvpValue
void xaccAccountSetName(Account *acc, const char *str)
SplitList * xaccTransGetSplitList(const Transaction *trans)
void xaccTransRollbackEdit(Transaction *trans)
void xaccTransGetDatePostedTS(const Transaction *trans, Timespec *ts)
void xaccTransSetDatePostedTS(Transaction *trans, const Timespec *ts)
void xaccAccountSetCommodity(Account *acc, gnc_commodity *com)
gnc_numeric xaccSplitGetAmount(const Split *split)