GnuCash 2.4.99
utest-Account.c
00001 /********************************************************************
00002  * utest-Account.c: GLib g_test test suite for Account.c.           *
00003  * Copyright 2011 John Ralls <jralls@ceridwen.us>                   *
00004  *                                                                  *
00005  * This program is free software; you can redistribute it and/or    *
00006  * modify it under the terms of the GNU General Public License as   *
00007  * published by the Free Software Foundation; either version 2 of   *
00008  * the License, or (at your option) any later version.              *
00009  *                                                                  *
00010  * This program is distributed in the hope that it will be useful,  *
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
00013  * GNU General Public License for more details.                     *
00014  *                                                                  *
00015  * You should have received a copy of the GNU General Public License*
00016  * along with this program; if not, contact:                        *
00017  *                                                                  *
00018  * Free Software Foundation           Voice:  +1-617-542-5942       *
00019  * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
00020  * Boston, MA  02110-1301,  USA       gnu@gnu.org                   *
00021 ********************************************************************/
00022 #include "config.h"
00023 #include <string.h>
00024 #include <glib.h>
00025 #include <unittest-support.h>
00026 #include <gnc-event.h>
00027 /* Add specific headers for this class */
00028 #include "../Account.h"
00029 #include "../AccountP.h"
00030 #include "../Split.h"
00031 #include "../Transaction.h"
00032 #include "../gnc-lot.h"
00033 
00034 
00035 static const gchar *suitename = "/engine/Account";
00036 void test_suite_account (void);
00037 
00038 typedef struct
00039 {
00040     Account *acct;
00041     AccountTestFunctions *func;
00042 } Fixture;
00043 
00044 typedef struct
00045 {
00046     GNCAccountType type;
00047     char *name;
00048     char *parent;
00049     char *code;
00050     char *desc;
00051     char *color;
00052     char *notes;
00053     char *num;
00054     GNCPolicy *policy;
00055 } AccountParms;
00056 
00057 typedef struct
00058 {
00059     char *memo;
00060     char *account;
00061     char reconciled;
00062     gnc_numeric amount;
00063     gnc_numeric value;
00064     guint lotnum;
00065 } SplitParms;
00066 
00067 typedef struct
00068 {
00069     gchar *desc;
00070     gint date_offset;
00071     SplitParms splits[2];
00072 } TxnParms;
00073 
00074 typedef struct
00075 {
00076     guint num_accounts;
00077     AccountParms **accounts;
00078     guint num_txns;
00079     TxnParms **txns;
00080 } SetupData;
00081 
00082 static AccountParms bad_names[] =
00083 {
00084     {ACCT_TYPE_NONE, "foo:bar", "", "", "", "", "", "", NULL},
00085     {ACCT_TYPE_NONE, "baz", "", "", "", "", "", "", NULL},
00086     {ACCT_TYPE_NONE, "waldo:pepper", "", "", "", "", "", "", NULL}
00087 };
00088 
00089 static AccountParms good_names[] =
00090 {
00091     {ACCT_TYPE_NONE, "foo", "", "", "", "", "", "", NULL},
00092     {ACCT_TYPE_NONE, "baz", "foo", "", "", "", "", "", NULL},
00093     {ACCT_TYPE_NONE, "waldo", "baz", "", "", "", "", "", NULL}
00094 };
00095 
00096 static SetupData bad_data = {3, (AccountParms**)(&bad_names), 0, NULL};
00097 static SetupData good_data = {3, (AccountParms**)(&good_names), 0, NULL};
00098 
00099 static AccountParms some_names[] =
00100 {
00101     {ACCT_TYPE_NONE, "foo", "root", "", "", "", "", "", NULL},
00102     {ACCT_TYPE_NONE, "baz", "foo", "", "", "", "", "", NULL},
00103     {ACCT_TYPE_NONE, "bar", "root", "", "", "", "", "", NULL},
00104     {ACCT_TYPE_NONE, "meh", "bar", "", "", "", "", "", NULL},
00105 
00106 };
00107 
00108 static TxnParms some_txns[] =
00109 {
00110     {
00111         "waldo", -9, {
00112             {"waldo_baz", "baz", NREC, { -150000, 100}, {0, 1}, 0},
00113             {"waldo_meh", "meh", NREC, {150000, 100}, {0, 1}, 0}
00114         }
00115     },
00116     {
00117         "pepper", -7, {
00118             {"pepper_baz", "baz", CREC, { -12345, 100}, {0, 1}, 0},
00119             {"pepper_meh", "meh", CREC, {12345, 100}, {0, 1}, 0}
00120         }
00121     },
00122     {
00123         "salt", -2, {
00124             {"salt_baz", "baz", YREC, { -31415, 100}, {0, 1}, 0},
00125             {"salt_meh", "meh", YREC, {31415, 100}, {0, 1}, 0}
00126         }
00127     },
00128     {
00129         "pork", 3, {
00130             {"pork_baz", "baz", YREC, {23746, 100}, {0, 1}, 0},
00131             {"pork_meh", "meh", YREC, { -23746, 100}, {0, 1}, 0}
00132         }
00133     },
00134     {
00135         "sausage", 5, {
00136             {"sausage_baz", "baz", NREC, { -1143, 100}, {0, 1}, 0},
00137             {"sausage_meh", "meh", NREC, {1143, 100}, {0, 1}, 0}
00138         }
00139     }
00140 };
00141 
00142 static SetupData some_data = {4, (AccountParms**)(&some_names),
00143                               5, (TxnParms**)(&some_txns)
00144                              };
00145 
00146 static AccountParms complex_accts[] =
00147 {
00148     {ACCT_TYPE_EXPENSE, "expense", "root", "3000", "", "", "", "", NULL},
00149     {ACCT_TYPE_EXPENSE, "ordinary", "expense", "3100", "", "", "", NULL},
00150     {ACCT_TYPE_EXPENSE, "deductible", "expense", "3200", "", "", "", NULL},
00151     {ACCT_TYPE_INCOME, "income", "root", "4000", "", "", "", "", NULL},
00152     {ACCT_TYPE_INCOME, "taxable", "income", "4100", "", "", "", "", NULL},
00153     {ACCT_TYPE_INCOME, "exempt", "income", "4200", "", "", "", "", NULL},
00154     {ACCT_TYPE_INCOME, "wage", "taxable", "4150", "", "", "", "", NULL},
00155     {ACCT_TYPE_INCOME, "div", "taxable", "4140", "", "", "", "", NULL},
00156     {ACCT_TYPE_INCOME, "div1", "taxable", "4140", "", "", "", "", NULL},
00157     {ACCT_TYPE_INCOME, "qdiv", "div1", "4141", "", "", "", "", NULL},
00158     {ACCT_TYPE_INCOME, "odiv", "div1", "4142", "", "", "", "", NULL},
00159     {ACCT_TYPE_INCOME, "int", "taxable", "4160", "", "", "", "", NULL},
00160     {ACCT_TYPE_INCOME, "ltcg", "taxable", "4120", "", "", "", "", NULL},
00161     {ACCT_TYPE_INCOME, "stcg", "taxable", "4110", "", "", "", "", NULL},
00162     {ACCT_TYPE_INCOME, "int", "exempt", "4210", "", "", "", "", NULL},
00163     {ACCT_TYPE_INCOME, "div", "exempt", "4230", "", "", "", "", NULL},
00164     {ACCT_TYPE_INCOME, "gift", "exempt", "4220", "", "", "", "", NULL},
00165     {ACCT_TYPE_ASSET, "assets", "root", "2000", "", "", "", "", NULL},
00166     {ACCT_TYPE_BANK, "bank", "assets", "2300", "", "", "", "", NULL},
00167     {ACCT_TYPE_ASSET, "broker", "assets", "2200", "", "", NULL},
00168     {ACCT_TYPE_BANK, "money", "broker", "2210", "", "", NULL},
00169     {ACCT_TYPE_STOCK, "stocks", "broker", "2220", "", "", NULL},
00170     {ACCT_TYPE_EXPENSE, "food", "ordinary", "3110", "", "", "", NULL},
00171     {ACCT_TYPE_EXPENSE, "utilities", "ordinary", "3150", "", "", "", NULL},
00172     {ACCT_TYPE_EXPENSE, "auto", "ordinary", "3120", "", "", "", NULL},
00173     {ACCT_TYPE_EXPENSE, "mortgage-int", "deductible", "3230", "", "", "", NULL},
00174     {ACCT_TYPE_EXPENSE, "medical", "deductible", "3220", "", "", "", NULL},
00175     {ACCT_TYPE_STOCK, "foo", "stocks", "2221", "", "", NULL},
00176     {ACCT_TYPE_STOCK, "bar", "stocks", "2222", "", "", NULL},
00177     /* Note the repetition of the stock account "baz". The variations are
00178      * used to test gnc_account_merge_children. */
00179     {ACCT_TYPE_STOCK, "baz", "stocks", "2223", "baz", "", NULL},
00180     {ACCT_TYPE_STOCK, "baz2", "stocks", "2223", "baz", "", NULL},
00181     {ACCT_TYPE_MUTUAL, "baz", "stocks", "2223", "baz", "", NULL},
00182     {ACCT_TYPE_STOCK, "baz", "stocks", "2223", "baz company", "", NULL},
00183     {ACCT_TYPE_STOCK, "baz", "stocks", "2224", "baz", "", NULL},
00184 
00185 };
00186 
00187 static TxnParms lot_txns[] =
00188 {
00189     {
00190         "funding", -12, {
00191             {"funding_money", "money", NREC, {1000000, 100}, {0, 1}, 0},
00192             {"funding_gift", "gift", NREC, {1000000, 100}, {0, 1}, 0}
00193         }
00194     },
00195     {
00196         "waldo", -9, {
00197             {"waldo_baz", "baz", NREC, {1500, 1}, {150899, 100}, 1},
00198             {"waldo_money", "money", NREC, { -150899, 100}, {0, 1}, 0}
00199         }
00200     },
00201     {
00202         "pepper", -7, {
00203             {"pepper_baz", "baz", CREC, { -500, 1}, { -69101, 100}, 1},
00204             {"pepper_money", "money", CREC, {69101, 100}, {0, 1}, 0}
00205         }
00206     },
00207     {
00208         "salt", -2, {
00209             {"salt_baz", "baz", YREC, {1000, 1}, {120899, 10}, 2},
00210             {"salt_money", "money", YREC, { -120899, 100}, {0, 1}, 0}
00211         }
00212     },
00213     {
00214         "pork", 3, {
00215             {"pork_baz", "baz", YREC, { -1000, 1}, { -79101, 100}, 1},
00216             {"pork_money", "money", YREC, {79101, 100}, {0, 1}, 0}
00217         }
00218     },
00219     {
00220         "sausage", 5, {
00221             {"sausage_baz", "baz", NREC, { -500, 1}, { -74101, 100}, 2},
00222             {"sausage_mmoney", "money", NREC, {74101, 100}, {0, 1}, 0}
00223         }
00224     },
00225     {
00226         "pork", 3, {
00227             {"pork_baz2", "baz2", YREC, { -1000, 1}, { -79101, 100}, 1},
00228             {"pork_money", "money", YREC, {79101, 100}, {0, 1}, 0}
00229         }
00230     },
00231     {
00232         "sausage", 5, {
00233             {"sausage_baz2", "baz2", NREC, { -500, 1}, { -74101, 100}, 2},
00234             {"sausage_mmoney", "money", NREC, {74101, 100}, {0, 1}, 0}
00235         }
00236     },
00237     {
00238         "links", 1, {
00239             {"links_baz", "baz", NREC, {500, 1}, {60899, 100}, 3},
00240             {"links_mmoney", "money", NREC, { -60899, 100}, {0, 1}, 0}
00241         }
00242     }
00243 };
00244 
00245 static SetupData complex = {G_N_ELEMENTS (complex_accts),
00246                             (AccountParms**)(&complex_accts), 0, NULL
00247                            };
00248 
00249 static SetupData complex_data = {G_N_ELEMENTS (complex_accts),
00250                                  (AccountParms**)(&complex_accts),
00251                                  G_N_ELEMENTS (lot_txns),
00252                                  (TxnParms**)(&lot_txns)
00253                                 };
00254 
00255 static Split*
00256 insert_split (Account *parent, Transaction *txn, SplitParms *p)
00257 {
00258     QofBook *book = gnc_account_get_book (parent);
00259     Split *split = xaccMallocSplit (book);
00260     Account *acct = gnc_account_lookup_by_name (parent, p->account);
00261     LotList* lotlist = xaccAccountGetLotList (acct);
00262     GNCLot* lot = NULL;
00263     g_assert (acct != NULL);
00264     xaccSplitSetParent (split, txn);
00265     xaccSplitSetMemo (split, p->memo);
00266     xaccSplitSetReconcile (split, (p->reconciled ? p->reconciled : NREC));
00267     g_object_set (split,
00268                   "account", acct,
00269                   "memo", p->memo,
00270                   "amount", &(p->amount),
00271                   "value", &(p->value),
00272                   NULL);
00273 
00274     gnc_account_insert_split (acct, split);
00275     if (p->lotnum == 0)
00276         return split;
00277 
00278     if (p->lotnum > g_list_length (lotlist))
00279         lot = gnc_lot_new (book);
00280     else
00281         lot = GNC_LOT (g_list_nth_data (lotlist, p->lotnum - 1));
00282 
00283     gnc_lot_add_split (lot, split);
00284     return split;
00285 }
00286 
00287 static void
00288 setup (Fixture *fixture, gconstpointer pData)
00289 {
00290     QofBook *book = qof_book_new ();
00291     Account *root = gnc_account_create_root (book), *acct = NULL;
00292     SetupData *parms = (SetupData *)pData;
00293     TxnParms *t_arr;
00294     AccountParms *p_arr;
00295     GHashTable *accts = g_hash_table_new (g_str_hash, g_str_equal);
00296     guint ind;
00297 
00298     g_hash_table_insert (accts, "root", root);
00299     fixture->func = _utest_account_fill_functions ();
00300     if (parms == NULL)
00301     {
00302         fixture->acct = root;
00303         return;
00304     }
00305     acct = root;
00306 
00307     p_arr  = (AccountParms*)parms->accounts;
00308     for (ind = 0; ind < parms->num_accounts; ind++)
00309     {
00310         Account *child = xaccMallocAccount (book);
00311         AccountParms p = p_arr[ind];
00312         if (p.parent && strlen (p.parent) > 0)
00313         {
00314             Account *parent = g_hash_table_lookup (accts, p.parent);
00315             g_assert (parent != NULL);
00316             gnc_account_append_child (parent, child);
00317         }
00318         else
00319             gnc_account_append_child (acct, child);
00320         acct = child;
00321         xaccAccountSetType (acct, p.type);
00322         if (p.name)
00323         {
00324             xaccAccountSetName (acct, p.name);
00325             g_hash_table_insert (accts, p.name, acct);
00326         }
00327         if (p.code)
00328             xaccAccountSetCode (acct, p.code);
00329         if (p.desc)
00330             xaccAccountSetDescription (acct, p.desc);
00331         if (p.color)
00332             xaccAccountSetColor (acct, p.color);
00333         if (p.notes)
00334             xaccAccountSetNotes (acct, p.notes);
00335         if (p.num)
00336             xaccAccountSetLastNum (acct, p.num);
00337         if (p.policy)
00338             gnc_account_set_policy (acct, p.policy);
00339     }
00340 
00341     t_arr  = (TxnParms*)parms->txns;
00342     for (ind = 0; ind < parms->num_txns; ind++)
00343     {
00344         Transaction *txn = xaccMallocTransaction (book);
00345         TxnParms p = t_arr[ind];
00346         GDate *date = g_date_new ();
00347         g_date_set_time_t (date, time (0));
00348         xaccTransBeginEdit (txn);
00349         if (p.desc)
00350             xaccTransSetDescription (txn, p.desc);
00351         if (p.date_offset < 0)
00352             g_date_subtract_days (date, (guint)(-p.date_offset));
00353         else
00354             g_date_add_days (date, (guint)(p.date_offset));
00355         xaccTransSetDatePostedGDate (txn, *date);
00356         insert_split (root, txn, &p.splits[0]);
00357         insert_split (root, txn, &p.splits[1]);
00358         /* xaccTransCommitEdit () does a bunch of scrubbing that we don't need */
00359         qof_commit_edit (QOF_INSTANCE (txn));
00360     }
00361     fixture->acct = acct;
00362     g_hash_table_destroy (accts);
00363     gnc_set_account_separator (":");
00364 }
00365 
00366 static void
00367 teardown ( Fixture *fixture, gconstpointer pData)
00368 {
00369     Account *parent = NULL, *child = fixture->acct;
00370     qof_book_destroy (gnc_account_get_book (child));
00371     /* No need to free the last account, qof_book_destroy did that */
00372     g_free (fixture->func);
00373 }
00374 
00375 
00376 /* gnc_get_account_separator_string
00377 const gchar *
00378 gnc_get_account_separator_string (void)// C: 31 in 7 SCM: 64 in 6*/
00379 //Simple Getter. No Test.
00380 /* static void
00381 test_gnc_get_account_separator_string (Fixture *fixture, gconstpointer pData)
00382 {
00383 }*/
00384 /* gnc_get_account_separator
00385 gunichar
00386 gnc_get_account_separator (void)// C: 8 in 4 */
00387 //Simple Getter. No Test.
00388 /* gnc_set_account_separator
00389 void
00390 gnc_set_account_separator (const gchar *separator)// C: 5 in 3 */
00391 static void
00392 test_gnc_set_account_separator ()
00393 {
00394     gchar sep_str[6];
00395     const gunichar pass_sep = 0xE5A;
00396     const gunichar fail_sep = 0x92A;
00397     const gunichar default_sep = ':';
00398     gunichar sep = gnc_get_account_separator ();
00399 
00400     g_assert (sep == default_sep);
00401     memset (sep_str, 0, sizeof (sep_str));
00402     g_unichar_to_utf8 (fail_sep, sep_str);
00403     gnc_set_account_separator (sep_str);
00404     sep = gnc_get_account_separator ();
00405     g_assert (sep != fail_sep);
00406     g_assert (sep == default_sep);
00407     memset (sep_str, 0, sizeof (sep_str));
00408     g_unichar_to_utf8 (pass_sep, sep_str);
00409     gnc_set_account_separator (sep_str);
00410     sep = gnc_get_account_separator ();
00411     g_assert (sep == pass_sep);
00412 }
00413 /* Note: gnc_account_name_violations and gnc_account_list_name_violations should work with unicode. Change the functions and the tests accordingly. */
00414 /* gnc_account_name_violations_errmsg
00415 gchar *gnc_account_name_violations_errmsg (const gchar *separator, GList* invalid_account_names)// C: 6 in 4 */
00416 static void
00417 test_gnc_account_name_violations_errmsg ()
00418 {
00419     GList *badnames = NULL, *nonames = NULL, *node = NULL;
00420     gchar *separator = ":", *message, *validation_message, *account_list = NULL;
00421     /* FUT wants to free the strings, so we alloc them */
00422     badnames = g_list_prepend (badnames, g_strdup ("Foo:bar"));
00423     badnames = g_list_prepend (badnames, g_strdup ("baz"));
00424     badnames = g_list_prepend (badnames, g_strdup ("waldo:pepper"));
00425     message = gnc_account_name_violations_errmsg (separator, nonames);
00426     for (node = badnames; node; node = g_list_next (node))
00427     {
00428         if (!account_list)
00429             account_list = g_strdup (node->data);
00430         else
00431         {
00432             gchar *tmp_list = g_strconcat ( account_list, "\n",
00433                                             node->data, NULL);
00434             g_free (account_list);
00435             account_list = tmp_list;
00436         }
00437     }
00438     message = gnc_account_name_violations_errmsg (separator, nonames);
00439     g_assert (message == NULL);
00440     validation_message = g_strdup_printf (
00441                              "The separator character \"%s\" is used in one or more account "
00442                              "names.\n\nThis will result in unexpected behaviour. "
00443                              "Either change the account names or choose another separator "
00444                              "character.\n\nBelow you will find the list of invalid account names:\n"
00445                              "%s", separator, account_list);
00446     message = gnc_account_name_violations_errmsg (separator, badnames);
00447     g_assert_cmpstr ( message, == , validation_message);
00448     g_free (validation_message);
00449     g_free (message);
00450 }
00451 /* This should be qof_BOOK_list_name_violations */
00452 /* gnc_account_list_name_violations
00453 GList *gnc_account_list_name_violations (QofBook *book, const gchar *separator)// C: 6 in 4 */
00454 static void
00455 test_gnc_account_list_name_violations (Fixture *fixture, gconstpointer pData)
00456 {
00457     guint log_level = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL;
00458     gchar *log_domain = "gnc.engine";
00459     gchar *msg = "gnc_account_list_name_violations: assertion `separator != NULL' failed";
00460     TestErrorStruct check = { log_level, log_domain, msg, 0 };
00461     GList *results, *res_iter;
00462     gchar *sep = ":";
00463     QofBook *book = gnc_account_get_book (fixture->acct);
00464     /* Because of GLib bug 653052, we have to set the logging user_data to
00465      * affect the test_log_fatal_handler
00466      */
00467     GLogFunc oldlogger = g_log_set_default_handler ((GLogFunc)test_null_handler, &check);
00468     g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_checked_handler, &check);
00469     g_assert (gnc_account_list_name_violations (NULL, NULL) == NULL);
00470     g_assert_cmpint (check.hits, ==, 1);
00471     g_assert (gnc_account_list_name_violations (book, NULL) == NULL);
00472     g_assert_cmpint (check.hits, ==, 2);
00473     g_assert (gnc_account_list_name_violations (NULL, sep) == NULL);
00474     g_log_set_default_handler (oldlogger, NULL);
00475     results = gnc_account_list_name_violations (book, sep);
00476     g_assert_cmpuint (g_list_length (results), == , 2);
00477     g_assert_cmpint (check.hits, ==, 2);
00478     for (res_iter = results; res_iter; res_iter = g_list_next (res_iter))
00479         test_free (res_iter->data);
00480     g_list_free (results);
00481 }
00482 /* mark_account
00483 void
00484 mark_account (Account *acc)// C: 2 in 1 */
00485 /*Simple passthrough of qof_instance_set_dirty; Don't test.*/
00486 // Not Used
00487 /* gnc_account_init
00488 G_DEFINE_TYPE (Account, gnc_account, QOF_TYPE_INSTANCE)
00489 static void
00490 gnc_account_init (Account* acc)// 1
00491 */
00492 /* test_gnc_account_create_and_destroy (void):
00493  * Tests the following functions:
00494  * gnc_account_init ()
00495  * gnc_account_class_init ()
00496  * gnc_account_get_property ()
00497  * gnc_account_set_property ()
00498  * xaccAccountGetColor ()
00499  * xaccAccountGetNotes ()
00500  *
00501  * Exercises the following functions, may not thoroughly test them:
00502  * xaccAccountSetName ()
00503  * xaccAccountSetCode ()
00504  * xaccAccountSetDescription ()
00505  * xaccAccountSetColor ()
00506  * xaccAccountSetNotes ()
00507  * xaccAccountSetType ()
00508  * xaccAccountSetCommodity ()
00509  * xaccAccountSetCommoditySCU ()
00510  * xaccAccountSetNotStdSCU ()
00511  * gnc_account_set_sort_dirty ()
00512  * gnc_account_set_balance ()
00513  * gnc_account_set_start_balance ()
00514  * gnc_account_set_start_cleared_balance ()
00515  * gnc_account_set_start_reconciled_balance ()
00516  * gnc_account_set_policy ()
00517  * xaccAccountSetMark () *** Not Used ***
00518  * xaccAccountSetTaxRelated ()
00519  * xaccAccountSetTaxUSCode ()
00520  * xaccAccountSetTaxUSPayerNameSource ()
00521  * xaccAccountSetTaxUSCopyNumber ()
00522  * xaccAccountSetHidden ()
00523  * xaccAccountSetPlaceholder ()
00524 
00525  * Note very well that this is only the GObject portion of creating
00526  * and destroying Account objects. There are other parts (which is a
00527  * major problem), see in particular the note at test_xaccFreeAccount.
00528  */
00529 
00530 static void
00531 test_gnc_account_create_and_destroy (void)
00532 {
00533     Account *acc = g_object_new (GNC_TYPE_ACCOUNT, NULL);
00534     gchar *name, *fname, *code, *desc, *color, *notes, *tax_code, *tax_src;
00535     GNCAccountType type;
00536     gnc_commodity *commo;
00537     gint commo_scu, mark;
00538     gboolean non_std_scu, sort_dirty, bal_dirty, tax_rel, hide, hold;
00539     gint64 copy_num;
00540     gnc_numeric *start_bal, *start_clr_bal, *start_rec_bal;
00541     gnc_numeric *end_bal, *end_clr_bal, *end_rec_bal;
00542     GNCPolicy *pol;
00543 
00544     g_object_get (acc,
00545                   "name", &name,
00546                   "fullname", &fname,
00547                   "code", &code,
00548                   "description", &desc,
00549                   "color", &color,
00550                   "notes", &notes,
00551                   "type", &type,
00552                   "commodity", &commo,
00553                   "commodity_scu", &commo_scu,
00554                   "non-std-scu", &non_std_scu,
00555                   "sort-dirty", &sort_dirty,
00556                   "balance-dirty", &bal_dirty,
00557                   "start-balance", &start_bal,
00558                   "start-cleared-balance", &start_clr_bal,
00559                   "start-reconciled-balance", &start_rec_bal,
00560                   "end-balance", &end_bal,
00561                   "end-cleared-balance", &end_clr_bal,
00562                   "end-reconciled-balance", &end_rec_bal,
00563                   "policy", &pol,
00564                   "acct-mark", &mark,
00565                   "tax-related", &tax_rel,
00566                   "tax-code", &tax_code,
00567                   "tax-source", &tax_src,
00568                   "tax-copy-number", &copy_num,
00569                   "hidden", &hide,
00570                   "placeholder", &hold,
00571                   NULL);
00572 
00573     g_assert_cmpstr (name, == , "");
00574     g_assert_cmpstr (fname, == , "");
00575     g_assert_cmpstr (code, == , "");
00576     g_assert_cmpstr (desc, == , "");
00577     g_assert (!color);
00578     g_assert (!notes);
00579     g_assert (type == ACCT_TYPE_NONE);
00580     g_assert (!commo);
00581     g_assert (!commo_scu);
00582     g_assert (!non_std_scu);
00583     g_assert (!sort_dirty);
00584     g_assert (!bal_dirty);
00585     g_assert (gnc_numeric_zero_p (*end_bal));
00586     g_assert (gnc_numeric_zero_p (*end_clr_bal));
00587     g_assert (gnc_numeric_zero_p (*end_rec_bal));
00588     g_assert (gnc_numeric_zero_p (*start_bal));
00589     g_assert (gnc_numeric_zero_p (*start_clr_bal));
00590     g_assert (gnc_numeric_zero_p (*start_rec_bal));
00591     g_assert (pol == xaccGetFIFOPolicy ());
00592     g_assert (!mark);
00593     g_assert (!tax_rel);
00594     g_assert (!tax_code);
00595     g_assert (!tax_src);
00596     g_assert (copy_num == 1);
00597     g_assert (!hide);
00598     g_assert (!hold);
00599     g_assert (gnc_account_get_parent (acc) == NULL);
00600     g_assert (gnc_account_get_children (acc) == NULL);
00601     g_assert (xaccAccountGetLotList (acc) == NULL);
00602     g_assert (xaccAccountGetSplitList (acc) == NULL);
00603     g_free (name);
00604     g_free (fname);
00605     g_free (code);
00606     g_free (desc);
00607     g_free (color);
00608     g_free (notes);
00609     g_free (tax_code);
00610     g_free (tax_src);
00611 
00612     g_object_unref (acc);
00613     /* There's no good way to test that the object has been properly
00614      * destroyed; on the other hand, that's GObject's job.
00615      */
00616 
00617 }
00618 /* xaccInitAccount
00619 static void
00620 xaccInitAccount (Account * acc, QofBook *book)// 3
00621 Simple pass-through for qof_instance_init_data ()
00622 */
00623 /* gnc_account_get_book
00624 QofBook *
00625 gnc_account_get_book (const Account *account)// C: 30 in 21 SCM: 8 in 4
00626 Simple pass-through for qof_instance_get_book ()
00627 */
00628 /* gnc_coll_get_root_account
00629 static Account *
00630 gnc_coll_get_root_account (QofCollection *col)// 3
00631 Simple pass-through for qof_collection_get_data ()
00632 */
00633 
00634 /* test_gnc_book_set_get_root_account:
00635  * Tests the following:
00636  * gnc_coll_set_root_account ()
00637  * gnc_coll_get_root_account ()
00638  * gnc_book_set_root_account ()
00639  * gnc_book_get_root_account ()
00640  * Note that the first two are static helper functions which
00641  * generalize the second pair -- but in vain, because they're used
00642  * only in one place.
00643  */
00644 static void
00645 test_gnc_book_set_get_root_account (Fixture *fixture, gconstpointer pData)
00646 {
00647     guint log_level = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL;
00648     gchar *log_domain = "gnc.account";
00649     gchar *msg = "[gnc_book_set_root_account()] cannot mix and match books freely!";
00650     TestErrorStruct check = { log_level, log_domain, msg, 0 };
00651     Account *acc1, *acc2;
00652     QofBook* book1 = qof_book_new ();
00653     GLogFunc oldlogger;
00654     QofBook *book2 = gnc_account_get_book (fixture->acct);
00655     acc1 = gnc_book_get_root_account (NULL);
00656     g_assert (!acc1);
00657     /* Check that an account is created, and that it isn't the same as the
00658      * one in fixture.
00659      */
00660     acc1 = gnc_book_get_root_account (book1);
00661     g_assert (acc1);
00662     g_assert (acc1 != fixture->acct);
00663     /* Now try to set the book's root account to the fixture
00664      * accout. Should throw an error.
00665      */
00666     oldlogger = g_log_set_default_handler ((GLogFunc)test_null_handler, &check);
00667     g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_checked_handler,
00668                                   &check);
00669     gnc_book_set_root_account (book1, fixture->acct);
00670     g_assert (gnc_book_get_root_account (book1) == acc1);
00671     g_assert_cmpint (check.hits, ==, 1);
00672     g_log_set_default_handler (oldlogger, NULL);
00673     /* Check that if we set the same root, it stays set */
00674     gnc_book_set_root_account (book2, fixture->acct);
00675     g_assert (gnc_book_get_root_account (book2) == fixture->acct);
00676     /* Create a new account in book1 and check that we can set it to root */
00677     acc2 = xaccMallocAccount (book1);
00678     gnc_book_set_root_account (book1, acc2);
00679     g_assert (gnc_book_get_root_account (book1) != acc1);
00680     g_assert (gnc_book_get_root_account (book1) == acc2);
00681     /* Clean up */
00682     /* acc1 gets freed by setting the root accout to acc2
00683         g_object_unref (acc1);
00684     */
00685     g_object_unref (book1);
00686     g_object_unref (acc2);
00687 }
00688 
00689 /* xaccMallocAccount
00690 Account *
00691 xaccMallocAccount (QofBook *book)// C: 24 in 17 SCM: 9 in 6*/
00692 static void
00693 test_xaccMallocAccount (void)
00694 {
00695     QofBook *book = qof_book_new ();
00696     Account *acc;
00697     TestSignal signal = test_signal_new (NULL, QOF_EVENT_CREATE, NULL);
00698     gpointer handler_data = (gpointer)0xabcdef;
00699     acc = xaccMallocAccount (book);
00700     g_assert (acc != NULL);
00701     test_signal_assert_hits (signal, 1);
00702     test_signal_free (signal);
00703     g_object_unref (book);
00704     g_object_unref (acc);
00705 }
00706 
00707 /* gnc_account_create_root
00708 Account *
00709 gnc_account_create_root (QofBook *book)// C: 5 in 3 */
00710 static void
00711 test_gnc_account_create_root (void)
00712 {
00713     QofBook *book = qof_book_new ();
00714     QofCollection *coll = qof_book_get_collection (book, GNC_ID_ROOT_ACCOUNT);
00715     Account *acc;
00716     gchar *name;
00717     AccountTestFunctions *func = _utest_account_fill_functions ();
00718     /* Can't use gnc_book_get_root_account, it creates one if it doesn't
00719      * yet exist */
00720     g_assert (func->coll_get_root_account (coll) == NULL);
00721     acc = gnc_account_create_root (book);
00722     g_assert (acc);
00723     g_object_get (acc, "name", &name, NULL);
00724     g_assert_cmpstr (name, == , "Root Account");
00725     g_assert (gnc_book_get_root_account (book) == acc);
00726     g_object_unref (book);
00727     g_object_unref (acc);
00728     g_free (func);
00729     g_free (name);
00730 }
00731 /* xaccCloneAccountCommon
00732 static Account *
00733 xaccCloneAccountCommon (const Account *from, QofBook *book)// 3
00734 */
00735 static void
00736 test_xaccCloneAccount (Fixture *fixture, gconstpointer pData)
00737 {
00738     Account *clone;
00739     QofBook *book = gnc_account_get_book (fixture->acct);
00740     guint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL;
00741     gchar *msg1 = "xaccCloneAccount: assertion `GNC_IS_ACCOUNT(from)' failed";
00742     gchar *msg2 = "xaccCloneAccount: assertion `QOF_IS_BOOK(book)' failed";
00743     TestErrorStruct check = { loglevel, "gnc.engine", msg1, 0 };
00744     GLogFunc oldlogger;
00745     AccountPrivate *acct_p, *clone_p;
00746     oldlogger = g_log_set_default_handler ((GLogFunc)test_null_handler, &check);
00747     g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_checked_handler, &check);
00748     clone = xaccCloneAccount (NULL, book);
00749     g_assert (clone == NULL);
00750     g_assert_cmpint (check.hits, ==, 1);
00751     check.msg = msg2;
00752     clone = xaccCloneAccount (fixture->acct, NULL);
00753     g_assert (clone == NULL);
00754     g_assert_cmpint (check.hits, ==, 2);
00755     g_log_set_default_handler (oldlogger, NULL);
00756     /* Now test the real clone */
00757     clone = xaccCloneAccount (fixture->acct, book);
00758     g_assert (clone);
00759     acct_p = fixture->func->get_private (fixture->acct);
00760     clone_p = fixture->func->get_private (clone);
00761     g_assert (clone_p->type == acct_p->type);
00762     g_assert (clone_p->accountName == acct_p->accountName);
00763     g_assert (clone_p->accountCode == acct_p->accountCode);
00764     g_assert (clone_p->description == acct_p->description);
00765     g_assert (kvp_frame_compare (clone->inst.kvp_data,
00766                                  fixture->acct->inst.kvp_data) == 0);
00767     g_assert (gnc_commodity_equal (clone_p->commodity, acct_p->commodity));
00768     g_assert (clone_p->commodity_scu == acct_p->commodity_scu);
00769     g_assert (clone_p->non_standard_scu == acct_p->non_standard_scu);
00770     /* Clean Up */
00771     g_object_unref (clone);
00772 
00773 }
00774 /* xaccFreeOneChildAccount
00775 static void
00776 xaccFreeOneChildAccount (Account *acc, gpointer dummy)// 2
00777 No need to test, it's a passthrough for xaccAccountDestroy
00778 */
00779 /* xaccFreeAccountChildren
00780 static void
00781 xaccFreeAccountChildren (Account *acc)// 3
00782 */
00783 static void
00784 test_xaccFreeAccountChildren (Fixture *fixture, gconstpointer pData)
00785 {
00786     Account *root = gnc_account_get_root (fixture->acct);
00787     AccountPrivate *priv = fixture->func->get_private (root);
00788     g_assert_cmpuint (g_list_length (priv->children), > , 0);
00789     fixture->func->xaccFreeAccountChildren (root);
00790     /* We'd like to check for the child actually having been freed, but
00791      * there's not good way to do that. */
00792     g_assert_cmpuint (g_list_length (priv->children), == , 0);
00793     qof_book_destroy (gnc_account_get_book (root));
00794     /* No need to unref the root account, qof_book_destroy did that. */
00795     g_free (fixture->func);
00796 }
00797 /* xaccFreeAccount
00798 static void
00799 xaccFreeAccount (Account *acc)//
00800 The approved way to call this is via xaccAccountDestroy-->xaccAccountCommitEdit-->qof_instance_commit_edit2-->acc_free-->xaccFreeAccount
00801 
00802 Note that none of this is called by gnc_account_dispose, and xaccFreeAccount calls unref on itself. (Not run dispose, unref.)
00803 
00804 This "works" as follows:
00805 xaccAccountDestroy sets a "destroying" flag in qof_instance and calls xaccAccountCommitEdit.
00806 xaccAccountCommitEdit checks the flag and finding it true:
00807    calls xaccFreeACcountChildren
00808    tests qof_book_shutting_down and either deletes the split list for the account (trusting the Transaction code to delete the splits if it is shutting down) or deletes the actual splits while it's clearing the list. (What happens to the references in the transactions then? It's calling xaccSplitDestroy, not g_oject_unref!)
00809    Again checking that the book isn't shutting down:
00810       run destroy_pending_splits_for_account
00811       destroy all of the lots in the lots list (again, destroy, not unref or even dispose)
00812   free the lot list (regardless of whether the book is shuttin down) and NULL the pointer
00813   set the instance dirty
00814 unconditionally calls qof_commit_edit_part2 with acc_free
00815 qof_commit_edit_part2:
00816    calls the backend's commit if there is one
00817    calls acc_free
00818    calls acc_done (which only fires off a qof_event, so we'll ignore it)
00819 acc_free removes the account from the parent if there is one and calls xaccFreeAccount, then calls xaccFreeAccount
00820 xaccFreeAccount calls:
00821     xaccFreeAccountChildren
00822     destroys the lots (unless commitEdit did so already) and NULLs the pointer
00823     destroys the splits unless commitEdit did so already
00824     removes the name, code, and description strings from the string cache
00825     zeroes out the priv structure variables
00826     unrefs the account (should call run_dispose).
00827 dispose calls parent->dispose.
00828 
00829 acc_free
00830 */
00831 /* Aside from being broken (the assert at the end of freeing the splits fails),
00832    Account deallocation is implemented wrong. We don't run this test, and the function will be replaced when the time comes. */
00833 static void
00834 test_xaccFreeAccount (Fixture *fixture, gconstpointer pData)
00835 {
00836     gchar *msg1 = "[xaccFreeAccount()]  instead of calling xaccFreeAccount(), please call \n"
00837                   " xaccAccountBeginEdit(); xaccAccountDestroy(); \n";
00838     gchar *msg2 = "xaccTransGetSplitIndex: assertion `trans && split' failed";
00839     guint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL;
00840     TestErrorStruct check1 = { loglevel, "gnc.account", msg1, 0 };
00841     TestErrorStruct check2 = { loglevel, "gnc.engine", msg2, 0 };
00842     GLogLevelFlags oldmask1, oldmask2;
00843     QofBook *book = gnc_account_get_book (fixture->acct);
00844     Account *parent = gnc_account_get_parent (fixture->acct);
00845     AccountPrivate *p_priv = fixture->func->get_private (parent);
00846     const guint numItems = 3;
00847     guint i = 0;
00848     guint hdlr1, hdlr2;
00849     gnc_commodity *commodity = gnc_commodity_new (book, "US Dollar", "CURRENCY", "USD", "0", 100);
00850     test_add_error (&check1);
00851     test_add_error (&check2);
00852     hdlr1 = g_log_set_handler ("gnc.account", loglevel,
00853                                (GLogFunc)test_checked_handler, &check1);
00854     hdlr2 = g_log_set_handler ("gnc.engine", loglevel,
00855                                (GLogFunc)test_checked_handler, &check2);
00856     g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_list_handler, NULL);
00857     for (i = 0; i < numItems; i++)
00858     {
00859         Split *split = xaccMallocSplit (book);
00860         xaccSplitSetAccount (split, parent);
00861         gnc_account_insert_split (parent, split);
00862         xaccAccountInsertLot (parent, gnc_lot_new (book));
00863     }
00864     xaccAccountSetCommodity (parent, commodity);
00865     /* Check that we've got children, lots, and splits to remove */
00866     g_assert (p_priv->children != NULL);
00867     g_assert (p_priv->lots != NULL);
00868     g_assert (p_priv->splits != NULL);
00869     g_assert (p_priv->parent != NULL);
00870     g_assert (p_priv->commodity != NULL);
00871     g_assert_cmpint (check1.hits, ==, 0);
00872     g_assert_cmpint (check2.hits, ==, 0);
00873     /* Now set the other private parts to something so that they can be set back */
00874     p_priv->cleared_balance = gnc_numeric_create ( 5, 12);
00875     p_priv->reconciled_balance = gnc_numeric_create ( 5, 12);
00876     p_priv->balance = gnc_numeric_create ( 5, 12);
00877     p_priv->balance_dirty = TRUE;
00878     p_priv->sort_dirty = TRUE;
00879     fixture->func->xaccFreeAccount (parent);
00880     g_assert_cmpint (check1.hits, ==, 6);
00881     g_assert_cmpint (check2.hits, ==, 6);
00882     /* cleanup what's left */
00883     g_log_remove_handler ("gnc.account", hdlr1);
00884     g_log_remove_handler ("gnc.engine", hdlr2);
00885     test_clear_error_list ();
00886     qof_book_destroy (book);
00887     g_free (fixture->func);
00888 }
00889 /* xaccAccountBeginEdit
00890 void
00891 xaccAccountBeginEdit (Account *acc)// C: 80 in 29 SCM: 15 in 9
00892 
00893 No test, just a passthrough.
00894 */
00895 /* static void
00896 test_xaccAccountBeginEdit (Fixture *fixture, gconstpointer pData)
00897 {
00898 }*/
00899 /* on_done
00900 static void on_done (QofInstance *inst)// 2
00901 ***Callback for qof_commit_edit_part2
00902 No test, just queues a qof event.
00903 */
00904 /* static void
00905 test_on_done (Fixture *fixture, gconstpointer pData)
00906 {
00907 }*/
00908 /* on_err
00909 static void on_err (QofInstance *inst, QofBackendError errcode)// 2
00910 ***Callback for qof_commit_edit_part2
00911 */
00912 /* static void
00913 test_on_err (Fixture *fixture, gconstpointer pData)
00914 No test, just a pass-through.
00915 {
00916 }*/
00917 /* acc_free
00918 static void acc_free (QofInstance *inst)// 2
00919 ***Callback for qof_commit_edit_part2
00920 No test, just a passthrough -- plus see comment at test_xaccFreeAccount, which is what this is a passtrough of.
00921 */
00922 /* static void
00923 test_acc_free (Fixture *fixture, gconstpointer pData)
00924 {
00925 }*/
00926 /* destroy_pending_splits_for_account
00927 static void
00928 destroy_pending_splits_for_account (QofInstance *ent, gpointer acc)// 2
00929 
00930 Pass-through, no test.
00931 */
00932 /* static void
00933 test_destroy_pending_splits_for_account (Fixture *fixture, gconstpointer pData)
00934 {
00935 }*/
00936 /* xaccAccountCommitEdit
00937 void
00938 xaccAccountCommitEdit (Account *acc)// C: 65 in 26 SCM: 11 in 7
00939 Also tests:
00940   xaccAccountDestroy
00941 */
00942 static void
00943 test_xaccAccountCommitEdit (Fixture *fixture, gconstpointer pData)
00944 {
00945     gchar *msg1 = "[xaccFreeAccount()]  instead of calling xaccFreeAccount(), please call \n"
00946                   " xaccAccountBeginEdit(); xaccAccountDestroy(); \n";
00947     gchar *msg2 = "xaccTransGetSplitIndex: assertion `trans && split' failed";
00948     guint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL;
00949     TestErrorStruct check1 = { loglevel, "gnc.account", msg1, 0 };
00950     TestErrorStruct check2 = { loglevel, "gnc.engine", msg2, 0 };
00951     guint hdlr1, hdlr2;
00952     TestSignal sig1, sig2;
00953     QofBook *book = gnc_account_get_book (fixture->acct);
00954     Account *parent = gnc_account_get_parent (fixture->acct);
00955     AccountPrivate *p_priv = fixture->func->get_private (parent);
00956     const guint numItems = 3;
00957     guint i = 0;
00958     gnc_commodity *commodity = gnc_commodity_new (book, "US Dollar", "CURRENCY", "USD", "0", 100);
00959     test_add_error (&check1);
00960     test_add_error (&check2);
00961     hdlr1 = g_log_set_handler ("gnc.account", loglevel,
00962                                (GLogFunc)test_checked_handler, &check1);
00963     hdlr2 = g_log_set_handler ("gnc.engine", loglevel,
00964                                (GLogFunc)test_checked_handler, &check2);
00965     g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_list_handler, NULL);
00966     for (i = 0; i < numItems; i++)
00967     {
00968         Split *split = xaccMallocSplit (book);
00969         xaccSplitSetAccount (split, parent);
00970         gnc_account_insert_split (parent, split);
00971         xaccAccountInsertLot (parent, gnc_lot_new (book));
00972     }
00973     xaccAccountSetCommodity (parent, commodity);
00974     /* Check that we've got children, lots, and splits to remove */
00975     g_assert (p_priv->children != NULL);
00976     g_assert (p_priv->lots != NULL);
00977     g_assert (p_priv->splits != NULL);
00978     g_assert (p_priv->parent != NULL);
00979     g_assert (p_priv->commodity != NULL);
00980     g_assert_cmpint (check1.hits, ==, 0);
00981     g_assert_cmpint (check2.hits, ==, 0);
00982 
00983     sig1 = test_signal_new (&parent->inst, QOF_EVENT_MODIFY, NULL);
00984     sig2 = test_signal_new (&parent->inst, QOF_EVENT_DESTROY, NULL);
00985     /* Now we're ready to start testing. */
00986     xaccAccountBeginEdit (parent);
00987     xaccAccountCommitEdit (parent);
00988     /* Make sure that the account didn't get destroyed */
00989     test_signal_assert_hits (sig1, 1);
00990     test_signal_assert_hits (sig2, 0);
00991     g_assert (p_priv->children != NULL);
00992     g_assert (p_priv->lots != NULL);
00993     g_assert (p_priv->splits != NULL);
00994     g_assert (p_priv->parent != NULL);
00995     g_assert (p_priv->commodity != NULL);
00996     g_assert_cmpint (check1.hits, ==, 0);
00997     g_assert_cmpint (check2.hits, ==, 0);
00998     /* xaccAccountDestroy destroys the account by calling
00999      * qof_instance_set_destroying (), then xaccAccountCommitEdit ();
01000      */
01001     xaccAccountBeginEdit (parent);
01002     xaccAccountDestroy (parent);
01003     /* So this time we make sure that the account is destroyed */
01004     test_signal_assert_hits (sig1, 2);
01005     test_signal_assert_hits (sig2, 1);
01006     g_assert_cmpint (check1.hits, ==, 2);
01007     g_assert_cmpint (check2.hits, ==, 12);
01008     /* And clean up */
01009     test_signal_free (sig1);
01010     test_signal_free (sig2);
01011     g_log_remove_handler ("gnc.account", hdlr1);
01012     g_log_remove_handler ("gnc.engine", hdlr2);
01013     test_clear_error_list ();
01014     qof_book_destroy (book);
01015     g_free (fixture->func);
01016 }
01017 /* xaccAcctChildrenEqual
01018 static gboolean
01019 xaccAcctChildrenEqual (const GList *na,// 2
01020 */
01021 /* static void
01022 test_xaccAcctChildrenEqual (Fixture *fixture, gconstpointer pData)
01023 {
01024 }*/
01025 /* xaccAccountEqual
01026 gboolean
01027 xaccAccountEqual (const Account *aa, const Account *ab, gboolean check_guids)// C: 8 in 6
01028 Test support only; don't test for now.
01029 */
01030 /* static void
01031 test_xaccAccountEqual (Fixture *fixture, gconstpointer pData)
01032 {
01033 }*/
01034 /*
01035   The following are getters and setters, unworthy of testing:
01036   gnc_account_get_sort_dirty *** Test Only ***
01037   gnc_account_set_sort_dirty
01038   gnc_account_get_balance_dirty *** Test Only ***
01039   gnc_account_set_balance_dirty
01040 */
01041 /* gnc_account_find_split *** Test Only ***
01042  */
01043 /* gnc_account_insert_split
01044 gboolean
01045 gnc_account_insert_split (Account *acc, Split *s)// C: 5 in 3
01046 
01047 Also tests gnc_account_remove_split ()
01048 */
01049 static void
01050 test_gnc_account_insert_remove_split (Fixture *fixture, gconstpointer pData)
01051 {
01052     QofBook *book = gnc_account_get_book (fixture->acct);
01053     Split *split1 = xaccMallocSplit (book);
01054     Split *split2 = xaccMallocSplit (book);
01055     Split *split3 = xaccMallocSplit (book);
01056     TestSignal sig1, sig2, sig3;
01057     AccountPrivate *priv = fixture->func->get_private (fixture->acct);
01058     gint hdlr1, hdlr2, hdlr3;
01059     gchar *msg1 = "gnc_account_insert_split: assertion `GNC_IS_ACCOUNT(acc)' failed";
01060     gchar *msg2 = "gnc_account_insert_split: assertion `GNC_IS_SPLIT(s)' failed";
01061     guint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL;
01062 //    gchar *log_domain = "gnc.engine";
01063     TestErrorStruct check1 = { loglevel, "gnc.engine", msg1, 0 };
01064     TestErrorStruct check2 = { loglevel, "gnc.engine", msg2, 0 };
01065     TestErrorStruct check3 = { loglevel, "gnc.engine", NULL, 0 };
01066     guint logger;
01067     sig1 = test_signal_new (&fixture->acct->inst, QOF_EVENT_MODIFY, NULL);
01068     sig2 = test_signal_new (&fixture->acct->inst, GNC_EVENT_ITEM_ADDED, split1);
01069 
01070     test_add_error (&check1);
01071     test_add_error (&check2);
01072     logger = g_log_set_handler ("gnc.engine", loglevel,
01073                                 (GLogFunc)test_null_handler, &check3);
01074     g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_list_handler, NULL);
01075 
01076     /* Check that the call fails with invalid account and split (throws) */
01077     g_assert (!gnc_account_insert_split (NULL, split1));
01078     g_assert_cmpuint (g_list_length (priv->splits), == , 0);
01079     g_assert (!priv->sort_dirty);
01080     g_assert (!priv->balance_dirty);
01081     test_signal_assert_hits (sig1, 0);
01082     test_signal_assert_hits (sig2, 0);
01083     g_assert (!gnc_account_insert_split (fixture->acct, NULL));
01084     g_assert_cmpuint (g_list_length (priv->splits), == , 0);
01085     g_assert (!priv->sort_dirty);
01086     g_assert (!priv->balance_dirty);
01087     test_signal_assert_hits (sig1, 0);
01088     test_signal_assert_hits (sig2, 0);
01089     /* g_assert (!gnc_account_insert_split (fixture->acct, (Split*)priv)); */
01090     /* g_assert_cmpuint (g_list_length (priv->splits), == , 0); */
01091     /* g_assert (!priv->sort_dirty); */
01092     /* g_assert (!priv->balance_dirty); */
01093     /* test_signal_assert_hits (sig1, 0); */
01094     /* test_signal_assert_hits (sig2, 0); */
01095     g_assert_cmpint (check1.hits, ==, 1);
01096     g_assert_cmpint (check2.hits, ==, 1);
01097     g_assert_cmpint (check3.hits, ==, 0);
01098     g_log_remove_handler ("gnc.engine", logger);
01099     test_clear_error_list ();
01100 
01101     /* Check that it works the first time */
01102     g_assert (gnc_account_insert_split (fixture->acct, split1));
01103     g_assert_cmpuint (g_list_length (priv->splits), == , 1);
01104     g_assert (!priv->sort_dirty);
01105     g_assert (priv->balance_dirty);
01106     test_signal_assert_hits (sig1, 1);
01107     test_signal_assert_hits (sig2, 1);
01108     /* Check that it fails if the split has already been added once */
01109     g_assert (!gnc_account_insert_split (fixture->acct, split1));
01110     /* Free up hdlr2 and set up hdlr2 */
01111     test_signal_free (sig2);
01112     sig3 = test_signal_new (&fixture->acct->inst, GNC_EVENT_ITEM_ADDED, split2);
01113     /* Now add a second split to the account and check that sort_dirty isn't set. We have to bump the editlevel to force this. */
01114     g_assert (gnc_account_insert_split (fixture->acct, split2));
01115     g_assert_cmpuint (g_list_length (priv->splits), == , 2);
01116     g_assert (!priv->sort_dirty);
01117     g_assert (priv->balance_dirty);
01118     test_signal_assert_hits (sig1, 2);
01119     test_signal_assert_hits (sig3, 1);
01120     /* One more add, incrementing the editlevel to get sort_dirty set. */
01121     test_signal_free (sig3);
01122     sig3 = test_signal_new (&fixture->acct->inst, GNC_EVENT_ITEM_ADDED, split3);
01123     qof_instance_increase_editlevel (fixture->acct);
01124     g_assert (gnc_account_insert_split (fixture->acct, split3));
01125     qof_instance_decrease_editlevel (fixture->acct);
01126     g_assert_cmpuint (g_list_length (priv->splits), == , 3);
01127     g_assert (priv->sort_dirty);
01128     g_assert (priv->balance_dirty);
01129     test_signal_assert_hits (sig1, 3);
01130     test_signal_assert_hits (sig3, 1);
01131     /* Finally delete a split. It's going to recompute the balance, so
01132      * balance_dirty will be false. */
01133     test_signal_free (sig3);
01134     sig3 = test_signal_new (&fixture->acct->inst, GNC_EVENT_ITEM_REMOVED,
01135                             split3);
01136     g_assert (gnc_account_remove_split (fixture->acct, split3));
01137     g_assert_cmpuint (g_list_length (priv->splits), == , 2);
01138     g_assert (priv->sort_dirty);
01139     g_assert (!priv->balance_dirty);
01140     test_signal_assert_hits (sig1, 4);
01141     test_signal_assert_hits (sig3, 1);
01142    /* And do it again to make sure that it fails when the split has
01143      * already been removed */
01144     g_assert (!gnc_account_remove_split (fixture->acct, split3));
01145     g_assert_cmpuint (g_list_length (priv->splits), == , 2);
01146     g_assert (priv->sort_dirty);
01147     g_assert (!priv->balance_dirty);
01148     test_signal_assert_hits (sig1, 4);
01149     test_signal_assert_hits (sig3, 1);
01150 
01151     /* Clean up the handlers */
01152     test_signal_free (sig3);
01153     test_signal_free (sig1);
01154 }
01155 /* xaccAccountSortSplits
01156 void
01157 xaccAccountSortSplits (Account *acc, gboolean force)// C: 4 in 2
01158 Make static?
01159 Passthrough, no test.
01160 */
01161 /* xaccAccountBringUpToDate
01162 static void
01163 xaccAccountBringUpToDate (Account *acc)// 3
01164 Passthrough, no test.
01165 */
01166 /* xaccAccountSetGUID
01167 void
01168 xaccAccountSetGUID (Account *acc, const GncGUID *guid)// C: 5 in 4
01169 Getter/Setter, no test.
01170 * Naughty function: GUID should be set at object construction and be invariant thereafter.
01171  */
01172 /* xaccAccountLookup
01173 Account *
01174 xaccAccountLookup (const GncGUID *guid, QofBook *book)// C: 37 in 28 SCM: 2 in 1
01175 Passthrough, no test.
01176 */
01177 /* More getters/setters:
01178         xaccAccountGetMark *** Test Only ***
01179         xaccAccountSetMark *** Not Used ***
01180         xaccClearMark *** Not Used ***
01181         xaccClearMarkDown
01182         gnc_account_get_policy
01183         gnc_account_set_policy
01184 */
01185 /* xaccAccountRemoveLot
01186 void
01187 xaccAccountRemoveLot (Account *acc, GNCLot *lot)// C: 6 in 4 */
01188 static void
01189 test_xaccAccountInsertRemoveLot (Fixture *fixture, gconstpointer pData)
01190 {
01191     QofBook *book = gnc_account_get_book (fixture->acct);
01192     GNCLot *lot = gnc_lot_new (book);
01193     Account *parent = gnc_account_get_parent (fixture->acct);
01194     TestSignal sig1 = test_signal_new (QOF_INSTANCE (lot),
01195                                        QOF_EVENT_ADD, NULL);
01196     TestSignal sig2 = test_signal_new (&fixture->acct->inst,
01197                                        QOF_EVENT_MODIFY, NULL);
01198     TestSignal sig3 = test_signal_new (QOF_INSTANCE (lot),
01199                                        QOF_EVENT_REMOVE, NULL);
01200     TestSignal sig4 = test_signal_new (&parent->inst, QOF_EVENT_MODIFY, NULL);
01201 
01202     AccountPrivate *a_priv = fixture->func->get_private (fixture->acct);
01203     AccountPrivate *p_priv = fixture->func->get_private (parent);
01204 
01205     g_assert_cmpuint (g_list_length (a_priv->lots), == , 0);
01206     g_assert_cmpuint (g_list_length (p_priv->lots), == , 0);
01207     xaccAccountInsertLot (fixture->acct, lot);
01208     g_assert (gnc_lot_get_account (lot) == fixture->acct);
01209     g_assert_cmpuint (g_list_length (a_priv->lots), == , 1);
01210     test_signal_assert_hits (sig1, 1);
01211     test_signal_assert_hits (sig2, 1);
01212     /* Make sure that inserting again doesn't do anything */
01213     xaccAccountInsertLot (fixture->acct, lot);
01214     g_assert (gnc_lot_get_account (lot) == fixture->acct);
01215     g_assert_cmpuint (g_list_length (a_priv->lots), == , 1);
01216     test_signal_assert_hits (sig1, 1);
01217     test_signal_assert_hits (sig2, 1);
01218     /* Check that inserting the lot into a different account changes the lot */
01219     xaccAccountInsertLot (parent, lot);
01220     g_assert (gnc_lot_get_account (lot) == parent);
01221     g_assert_cmpuint (g_list_length (a_priv->lots), == , 0);
01222     g_assert_cmpuint (g_list_length (p_priv->lots), == , 1);
01223     test_signal_assert_hits (sig1, 2);
01224     test_signal_assert_hits (sig4, 1);
01225     test_signal_assert_hits (sig2, 1);
01226     /* Check that removing the lot works */
01227     xaccAccountRemoveLot (parent, lot);
01228     /* The following test should fail, but it doesn't because of an
01229      * error in the routine: When removing a lot from an account, the
01230      * account reference in the lot object should be NULLed. */
01231     g_assert (gnc_lot_get_account (lot) != NULL);
01232     g_assert_cmpuint (g_list_length (a_priv->lots), == , 0);
01233     g_assert_cmpuint (g_list_length (p_priv->lots), == , 0);
01234     test_signal_assert_hits (sig3, 1);
01235     test_signal_assert_hits (sig4, 2);
01236     test_signal_assert_hits (sig2, 1);
01237     /* Check that destroying the lot removes its reference */
01238     /* Because the lot's account pointer doesn't get nulled when the lot
01239      * is removed, we have to do that for the next test to work: */
01240     gnc_lot_set_account (lot, NULL);
01241     xaccAccountInsertLot (parent, lot);
01242     g_assert_cmpuint (g_list_length (p_priv->lots), == , 1);
01243     g_assert (gnc_lot_get_account (lot) == parent);
01244     gnc_lot_destroy (lot);
01245     /* Destroying the lot should remove it from the account; Not Happening. */
01246     g_assert_cmpuint (g_list_length (p_priv->lots), != , 0);
01247     test_signal_assert_hits (sig1, 3);
01248     /* We get a modify only on the insert, since there is no remove when
01249      * the lot is destroyed. */
01250     test_signal_assert_hits (sig4, 3);
01251     /* Same thing: There should be a "removed" signal on the lot, but
01252      * since it isn't removed, no signal. */
01253     test_signal_assert_hits (sig3, 1);
01254     test_signal_free (sig1);
01255     test_signal_free (sig2);
01256     test_signal_free (sig3);
01257     test_signal_free (sig4);
01258 
01259 }
01260 /*
01261 static void
01262 xaccPreSplitMove (Split *split, gpointer dummy)// 2
01263 static void
01264 xaccPostSplitMove (Split *split, Account *accto)// 2
01265 void
01266 xaccAccountMoveAllSplits (Account *accfrom, Account *accto)// C: 5 in 3
01267 
01268 * All of the work is done in other classes which in turn call other
01269 * Account functions (gnc_account_add_split and
01270 * gnc_account_remove_split). Mock classes with the functions that call
01271 * those wouldn't really achieve anything, since the actual functions
01272 * could break by failing to call gnc_account_*_split and the test
01273 * wouldn't know.
01274 */
01275 
01276 /* xaccAccountRecomputeBalance
01277 void
01278 xaccAccountRecomputeBalance (Account * acc)// C: 9 in 5 */
01279 static void
01280 test_xaccAccountRecomputeBalance (Fixture *fixture, gconstpointer pData)
01281 {
01282     AccountPrivate *priv = fixture->func->get_private (fixture->acct);
01283     gnc_numeric bal = gnc_numeric_zero (), rec_bal = gnc_numeric_zero (),
01284                 clr_bal = gnc_numeric_zero ();
01285     SetupData *sdata = (SetupData*)pData;
01286     TxnParms* t_arr;
01287     int ind;
01288     g_assert (sdata != NULL);
01289     t_arr = (TxnParms*)sdata->txns;
01290     for (ind = 0; ind < sdata->num_txns; ind++)
01291     {
01292         SplitParms p = t_arr[ind].splits[1];
01293         bal = gnc_numeric_add_fixed (bal, p.amount);
01294         if (p.reconciled != NREC)
01295             clr_bal = gnc_numeric_add_fixed (clr_bal, p.amount);
01296         if (p.reconciled == YREC || p.reconciled == FREC)
01297             rec_bal = gnc_numeric_add_fixed (rec_bal, p.amount);
01298     }
01299     g_assert (gnc_numeric_zero_p (priv->starting_balance));
01300     g_assert (gnc_numeric_zero_p (priv->balance));
01301     priv->balance_dirty = TRUE;
01302     xaccAccountRecomputeBalance (fixture->acct);
01303     g_assert (gnc_numeric_zero_p (priv->starting_balance));
01304     g_assert (gnc_numeric_eq (priv->balance, bal));
01305     g_assert (gnc_numeric_eq (priv->cleared_balance, clr_bal));
01306     g_assert (gnc_numeric_eq (priv->reconciled_balance, rec_bal));
01307     g_assert (!priv->balance_dirty);
01308 }
01309 
01310 /* xaccAccountOrder
01311 int
01312 xaccAccountOrder (const Account *aa, const Account *ab)// C: 11 in 3 */
01313 static void
01314 test_xaccAccountOrder ( )
01315 {
01316     Account *aa = NULL, *ab = NULL;
01317     QofBook *book = qof_book_new ();
01318 
01319 
01320     g_assert (xaccAccountOrder (aa, ab) == 0);
01321     aa = xaccMallocAccount (book);
01322     g_assert (xaccAccountOrder (aa, ab) == -1);
01323     g_assert (xaccAccountOrder (ab, aa) == 1);
01324 
01325     ab = xaccMallocAccount (book);
01326     g_object_set (G_OBJECT (aa),
01327                   "code", "3333",
01328                   "type", ACCT_TYPE_ASSET,
01329                   "name", "foo",
01330                   NULL);
01331     g_object_set (G_OBJECT (ab),
01332                   "code", "3333",
01333                   "type", ACCT_TYPE_ASSET,
01334                   "name", "foo",
01335                   NULL);
01336 
01337     g_assert_cmpint (xaccAccountOrder (aa, aa), == , 0);
01338     g_assert_cmpint (xaccAccountOrder (aa, ab), == ,
01339                      qof_instance_guid_compare (aa, ab));
01340     g_object_set (G_OBJECT (ab), "name", "bar", NULL);
01341     g_assert_cmpint (xaccAccountOrder (aa, ab), > , 0);
01342     g_object_set (G_OBJECT (ab), "name", "waldo", NULL);
01343     g_assert_cmpint (xaccAccountOrder (aa, ab), < , 0);
01344 
01345     g_object_set (G_OBJECT (ab), "type", ACCT_TYPE_BANK, NULL);
01346     g_test_message ("The next test should fail: There's an error in the sort"
01347                     " sequence that causes ACCT_TYPE_BANK to sort last"
01348                     " instead of first\n");
01349     g_assert_cmpint (xaccAccountOrder (aa, ab), < , 0);
01350     g_object_set (G_OBJECT (ab), "type", ACCT_TYPE_STOCK, NULL);
01351     g_assert_cmpint (xaccAccountOrder (aa, ab), > , 0);
01352     g_object_set (G_OBJECT (ab),
01353                   "type", ACCT_TYPE_INCOME,
01354                   "name", "bar",
01355                   NULL);
01356     g_assert_cmpint (xaccAccountOrder (aa, ab), < , 0);
01357 
01358     g_object_set (G_OBJECT (ab), "code", "2222",
01359                   "name", "waldo",
01360                   NULL);
01361     g_assert_cmpint (xaccAccountOrder (aa, ab), > , 0);
01362     g_object_set (G_OBJECT (ab),
01363                   "code", "4444",
01364                   "type", ACCT_TYPE_STOCK,
01365                   "name", "bar",
01366                   NULL);
01367     g_assert_cmpint (xaccAccountOrder (aa, ab), < , 0);
01368 
01369     xaccAccountBeginEdit (aa);
01370     xaccAccountDestroy (aa);
01371     xaccAccountBeginEdit (ab);
01372     xaccAccountDestroy (ab);
01373     g_object_unref (book);
01374 }
01375 /* qof_xaccAccountOrder
01376 static int
01377 qof_xaccAccountOrder (const Account **aa, const Account **ab)// 2
01378 Pass-through
01379 */
01380 /*
01381  * The following functions are tested in get/set above:
01382  * xaccAccountSetType
01383  * xaccAccountSetName
01384  * xaccAccountSetCode
01385  * xaccAccountSetDescription
01386  * xaccAccountSetColor
01387  * xaccAccountSetNotes
01388  * xaccAccountSetCommodity
01389  * xaccAccountSetCommoditySCU
01390  * xaccAccountGetCommoditySCUi
01391  * xaccAccountGetCommoditySCU
01392  * xaccAccountSetNonStdSCU
01393  * xaccAccountGetNonStdSCU
01394  */
01395 /* DxaccAccountSetCurrency
01396 void
01397 DxaccAccountSetCurrency (Account * acc, gnc_commodity * currency)// C: 7 in 5
01398 Deprecated, don't test
01399 
01400 */
01401 
01402 /* qofAccountSetParent
01403 static void
01404 qofAccountSetParent (Account *acc, QofInstance *parent)// 2
01405 */
01406 static void
01407 test_qofAccountSetParent (Fixture *fixture, gconstpointer pData)
01408 {
01409     Account *root = gnc_account_get_root (fixture->acct);
01410     Account *old_parent = gnc_account_get_parent (fixture->acct);
01411     AccountTestFunctions *func = _utest_account_fill_functions ();
01412     g_assert (root != old_parent);
01413     /* qofAccountSetParent doesn't check to see if the parent is already
01414      * set, nor does gnc_account_append_child, which is the passed-through
01415      * function.
01416      */
01417     func->qofAccountSetParent (fixture->acct, QOF_INSTANCE (root));
01418     g_assert (root == gnc_account_get_parent (fixture->acct));
01419     g_assert (qof_instance_get_dirty (QOF_INSTANCE (fixture->acct)));
01420     g_assert (qof_instance_get_dirty (QOF_INSTANCE (root)));
01421     g_assert (qof_instance_get_dirty (QOF_INSTANCE (old_parent)));
01422 }
01423 /* gnc_account_append_child
01424 void
01425 gnc_account_append_child (Account *new_parent, Account *child)// C: 29 in 18 SCM: 7 in 4*/
01426 /* gnc_account_remove_child
01427 void
01428 gnc_account_remove_child (Account *parent, Account *child)// C: 4 in 2 */
01429 static void
01430 test_gnc_account_append_remove_child (Fixture *fixture, gconstpointer pData)
01431 {
01432     QofBook *book = gnc_account_get_book (fixture->acct);
01433     QofBook *fbook = qof_book_new ();
01434     Account *froot = gnc_account_create_root (fbook);
01435     Account *account = xaccMallocAccount (fbook);
01436     gchar *logdomain = "gnc.account";
01437     gchar *msg1 = "[gnc_account_append_child()] reparenting accounts across books is not correctly supported\n";
01438     gchar *msg2 = "[gnc_account_remove_child()] account not a child of parent";
01439     guint log_handler = 0;
01440     TestErrorStruct check_warn = {G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL, "gnc.account", msg1, 0 };
01441     TestErrorStruct check_err = {G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL, "gnc.account", msg2, 0 };
01442     TestSignal sig1, sig2, sig3;
01443     AccountTestFunctions *func = _utest_account_fill_functions ();
01444     AccountPrivate *frpriv = func->get_private (froot),
01445                     *apriv = func->get_private (fixture->acct);
01446     const GncGUID *acct_guid = qof_instance_get_guid (QOF_INSTANCE (account));
01447     sig1 = test_signal_new (QOF_INSTANCE (account), QOF_EVENT_ADD, NULL);
01448     sig2 = test_signal_new (QOF_INSTANCE (account), QOF_EVENT_DESTROY, NULL);
01449     sig3 = test_signal_new (QOF_INSTANCE (account), QOF_EVENT_CREATE, NULL);
01450 
01451     gnc_account_append_child (froot, account);
01452     g_assert (gnc_account_get_parent (account) == froot);
01453     test_signal_assert_hits (sig1, 1);
01454     test_signal_assert_hits (sig2, 0);
01455     test_signal_assert_hits (sig3, 0);
01456     g_assert_cmpint (check_warn.hits, ==, 0);
01457     g_assert_cmpint (check_err.hits, ==, 0);
01458     g_assert (qof_instance_get_dirty (QOF_INSTANCE (froot)));
01459     g_assert (qof_instance_get_dirty (QOF_INSTANCE (account)));
01460     g_assert (g_list_find (frpriv->children, account));
01461     g_assert (qof_collection_lookup_entity (
01462                   qof_book_get_collection (fbook, GNC_ID_ACCOUNT),
01463                   acct_guid));
01464     log_handler = g_log_set_handler (logdomain, G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, (GLogFunc)test_null_handler, &check_warn);
01465     g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_checked_handler, &check_warn);
01466     gnc_account_append_child (fixture->acct, account);
01467     g_log_remove_handler (logdomain, log_handler);
01468     g_assert_cmpstr (msg1, == , check_warn.msg);
01469     g_assert (gnc_account_get_parent (account) == fixture->acct);
01470     test_signal_assert_hits (sig1, 2);
01471     test_signal_assert_hits (sig2, 1);
01472     test_signal_assert_hits (sig3, 1);
01473     g_assert_cmpint (check_warn.hits, ==, 1);
01474     g_assert_cmpint (check_err.hits, ==, 0);
01475     g_assert (!qof_collection_lookup_entity (
01476                   qof_book_get_collection (fbook, GNC_ID_ACCOUNT),
01477                   acct_guid));
01478     g_assert (qof_collection_lookup_entity (
01479                   qof_book_get_collection (book, GNC_ID_ACCOUNT),
01480                   acct_guid));
01481     g_assert (qof_instance_get_dirty (QOF_INSTANCE (fixture->acct)));
01482     g_assert (g_list_find (frpriv->children, account) == NULL);
01483     g_assert (g_list_find (apriv->children, account));
01484 
01485     test_signal_free (sig1);
01486     test_signal_free (sig2);
01487     test_signal_free (sig3);
01488     sig1 = test_signal_new (&account->inst, QOF_EVENT_REMOVE, NULL);
01489     sig2 = test_signal_new (&(fixture->acct)->inst, QOF_EVENT_MODIFY, NULL);
01490     log_handler = g_log_set_handler (logdomain, G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL,
01491                                      (GLogFunc)test_null_handler, &check_err);
01492     g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_checked_handler, &check_err);
01493     gnc_account_remove_child (froot, account);
01494     g_log_remove_handler (logdomain, log_handler);
01495 
01496     test_signal_assert_hits (sig1, 0);
01497     test_signal_assert_hits (sig2, 0);
01498     g_assert_cmpint (check_err.hits, ==, 1);
01499     g_assert_cmpint (check_warn.hits, ==, 1);
01500 
01501     gnc_account_remove_child (fixture->acct, account);
01502     g_assert (gnc_account_get_parent (account) == NULL);
01503     g_assert (g_list_find (apriv->children, account) == NULL);
01504     test_signal_assert_hits (sig1, 1);
01505     test_signal_assert_hits (sig2, 1);
01506     g_assert_cmpint (check_warn.hits, ==, 1);
01507     g_assert_cmpint (check_err.hits, ==, 1);
01508     test_signal_free (sig1);
01509     test_signal_free (sig2);
01510     xaccAccountBeginEdit (account);
01511     xaccAccountDestroy (account);
01512     xaccAccountBeginEdit (froot);
01513     xaccAccountDestroy (froot);
01514     g_object_unref (fbook);
01515 
01516 }
01517 /* Simple Getters or passthroughs, no tests:
01518  * gnc_account_get_parent
01519  * gnc_account_get_root
01520  * gnc_account_is_root
01521  * gnc_account_get_children
01522  * gnc_account_get_children_sorted
01523  * gnc_account_n_children
01524  * gnc_account_child_index
01525  * gnc_account_nth_child
01526  */
01527 /* gnc_account_n_descendants
01528 gint
01529 gnc_account_n_descendants (const Account *account)// C: 12 in 6 */
01530 static void
01531 test_gnc_account_n_descendants (Fixture *fixture, gconstpointer pData)
01532 {
01533     g_assert_cmpint (
01534         gnc_account_n_descendants (
01535             gnc_account_get_root (fixture->acct)), == , 4);
01536 }
01537 /* gnc_account_get_current_depth
01538 gint
01539 gnc_account_get_current_depth (const Account *account)// C: 4 in 2 SCM: 12 in 4*/
01540 static void
01541 test_gnc_account_get_current_depth (Fixture *fixture, gconstpointer pData)
01542 {
01543     g_assert_cmpint (
01544         gnc_account_get_current_depth (fixture->acct), == , 2);
01545 }
01546 /* gnc_account_get_tree_depth
01547 gint
01548 gnc_account_get_tree_depth (const Account *account)// C: 4 in 2 SCM: 3 in 3*/
01549 static void
01550 test_gnc_account_get_tree_depth (Fixture *fixture, gconstpointer pData)
01551 {
01552     /* Magic result value based on depth of the "complex" AccountParms array. */
01553     g_assert_cmpint (
01554         gnc_account_get_tree_depth (
01555             gnc_account_get_root (fixture->acct)), == , 5);
01556     g_assert_cmpint (
01557         gnc_account_get_tree_depth (fixture->acct), == , 1);
01558 }
01559 /* gnc_account_get_descendants
01560 GList *
01561 gnc_account_get_descendants (const Account *account)// C: 24 in 17 SCM: 6 in 6*/
01562 static void
01563 print_account (gpointer item, gpointer data)
01564 {
01565     Account *account = (Account *)item;
01566     gchar *name, *code, *desc;
01567     GNCAccountType type;
01568     const gchar *typestr;
01569     g_object_get (account,
01570                   "type", &type,
01571                   "name", &name,
01572                   "code", &code,
01573                   "description", &desc,
01574                   NULL);
01575     typestr = xaccAccountGetTypeStr (type);
01576     g_test_message ("%s: %s, %s %s", typestr, code, name, desc);
01577     g_free (code);
01578     g_free (name);
01579     g_free (desc);
01580 }
01581 
01582 static void
01583 test_gnc_account_get_descendants (Fixture *fixture, gconstpointer pData)
01584 {
01585 
01586     GList *list = gnc_account_get_descendants (
01587                       gnc_account_get_root (fixture->acct));
01588     g_assert (list != NULL);
01589     g_assert_cmpuint (g_list_length (list), == , 34);
01590     g_assert_cmpint (g_list_index (list, fixture->acct), == , 33);
01591     g_list_free (list);
01592     list = gnc_account_get_descendants (fixture->acct);
01593     g_assert (list == NULL);
01594 }
01595 /* gnc_account_get_descendants_sorted
01596 GList *
01597 gnc_account_get_descendants_sorted (const Account *account)// C: 6 in 4 SCM: 62 in 46*/
01598 static void
01599 test_gnc_account_get_descendants_sorted (Fixture *fixture, gconstpointer pData)
01600 {
01601     GList *list = gnc_account_get_descendants_sorted (
01602                       gnc_account_get_root (fixture->acct));
01603     g_assert (list != NULL);
01604     g_list_foreach (list, print_account, NULL);
01605     g_assert_cmpuint (g_list_length (list), == , 34);
01606     g_assert_cmpint (g_list_index (list, fixture->acct), == , 10);
01607     g_list_free (list);
01608 }
01609 /* gnc_account_lookup_by_name
01610 Account *
01611 gnc_account_lookup_by_name (const Account *parent, const char * name)// C: 22 in 12 */
01612 static void
01613 test_gnc_account_lookup_by_name (Fixture *fixture, gconstpointer pData)
01614 {
01615     Account *root, *target;
01616     gchar *code;
01617     root = gnc_account_get_root (fixture->acct);
01618     target = gnc_account_lookup_by_name (root, "income");
01619     g_assert (target != NULL);
01620     g_object_get (target, "code", &code, NULL);
01621     g_assert_cmpstr (code, == , "4000");
01622     target = gnc_account_lookup_by_name (target, "int");
01623     g_assert (target != NULL);
01624     g_free (code);
01625     g_object_get (target, "code", &code, NULL);
01626     g_assert_cmpstr (code, == , "4160");
01627     target = gnc_account_lookup_by_name (root, "bank");
01628     g_assert (target != NULL);
01629     g_free (code);
01630     g_object_get (target, "code", &code, NULL);
01631     g_assert_cmpstr (code, == , "2300");
01632     target = gnc_account_lookup_by_name (target, "int");
01633     g_assert (target == NULL);
01634     g_free (code);
01635 
01636 }
01637 /* gnc_account_lookup_by_code
01638 Account *
01639 gnc_account_lookup_by_code (const Account *parent, const char * code)// C: 5 in 3 */
01640 static void
01641 test_gnc_account_lookup_by_code (Fixture *fixture, gconstpointer pData)
01642 {
01643     Account *root, *target;
01644     gchar *name;
01645     root = gnc_account_get_root (fixture->acct);
01646     target = gnc_account_lookup_by_code (root, "3100");
01647     g_assert (target != NULL);
01648     g_object_get (target, "name", &name, NULL);
01649     g_assert_cmpstr (name, == , "ordinary");
01650     g_free (name);
01651     target = gnc_account_lookup_by_code (target, "3150");
01652     g_assert (target != NULL);
01653     g_object_get (target, "name", &name, NULL);
01654     g_assert_cmpstr (name, == , "utilities");
01655     target = gnc_account_lookup_by_code (target, "2100");
01656     g_assert (target == NULL);
01657     g_free (name);
01658 }
01659 /* gnc_account_lookup_by_full_name_helper
01660 static Account *
01661 gnc_account_lookup_by_full_name_helper (const Account *parent,// 3
01662 */
01663 static void
01664 test_gnc_account_lookup_by_full_name_helper ( Fixture *fixture,
01665         gconstpointer pData )
01666 {
01667     Account *root, *target;
01668     gchar *names1[] = {"income", "taxable", "int", NULL};
01669     gchar *names2[] =  {"income", "exempt", "int", NULL};
01670     gchar *names3[] = {"expense", "taxable", "int", NULL};
01671     gchar *code;
01672     AccountTestFunctions *func = _utest_account_fill_functions ();
01673 
01674     root = gnc_account_get_root (fixture->acct);
01675     target = func->gnc_account_lookup_by_full_name_helper (root, names1);
01676     g_assert (target != NULL);
01677     g_object_get (target, "code", &code, NULL);
01678     g_assert_cmpstr (code, == , "4160");
01679     g_free (code);
01680     target = func->gnc_account_lookup_by_full_name_helper (root, names2);
01681     g_assert (target != NULL);
01682     g_object_get (target, "code", &code, NULL);
01683     g_assert_cmpstr (code, == , "4210");
01684     target = func->gnc_account_lookup_by_full_name_helper (root, names3);
01685     g_assert (target == NULL);
01686     g_free (code);
01687 }
01688 /* gnc_account_lookup_by_full_name
01689 Account *
01690 gnc_account_lookup_by_full_name (const Account *any_acc,// C: 15 in 11 SCM: 8 in 4*/
01691 static void
01692 test_gnc_account_lookup_by_full_name (Fixture *fixture, gconstpointer pData)
01693 {
01694     Account *root, *target;
01695     gchar *names1 = "income:taxable:int";
01696     gchar *names2 =  "income:exempt:int";
01697     gchar *names3 = "expense:taxable:int";
01698     gchar *code;
01699     AccountTestFunctions *func = _utest_account_fill_functions ();
01700 
01701     root = gnc_account_get_root (fixture->acct);
01702     target = gnc_account_lookup_by_full_name (root, names1);
01703     g_assert (target != NULL);
01704     g_object_get (target, "code", &code, NULL);
01705     g_assert_cmpstr (code, == , "4160");
01706     g_free (code);
01707     target = gnc_account_lookup_by_full_name (root, names2);
01708     g_assert (target != NULL);
01709     g_object_get (target, "code", &code, NULL);
01710     g_assert_cmpstr (code, == , "4210");
01711     target = gnc_account_lookup_by_full_name (root, names3);
01712     g_assert (target == NULL);
01713     g_free (code);
01714 }
01715 
01716 static void
01717 thunk (Account *s, gpointer data)
01718 {
01719     guint *counter = (guint*)data;
01720     g_assert (GNC_IS_ACCOUNT (s));
01721     ++(*counter);
01722 }
01723 
01724 static gpointer
01725 thunk2 (Account *s, gpointer data)
01726 {
01727     guint *counter = (guint*)data;
01728     gchar *name;
01729     g_assert (GNC_IS_ACCOUNT (s));
01730     g_object_get (G_OBJECT (s), "name", &name, NULL);
01731     if (!g_strcmp0 (name, "int"))
01732     {
01733         g_free (name);
01734         return s;
01735     }
01736     g_free (name);
01737     ++(*counter);
01738     return NULL;
01739 }
01740 /* gnc_account_foreach_child
01741 void
01742 gnc_account_foreach_child (const Account *acc,// C: 6 in 3 */
01743 static void
01744 test_gnc_account_foreach_child (Fixture *fixture, gconstpointer pData)
01745 {
01746     Account *root = gnc_account_get_root (fixture->acct);
01747     Account *begin = gnc_account_lookup_by_code (root, "4000");
01748     guint counter = 0;
01749     gnc_account_foreach_child (begin, thunk, &counter);
01750     g_assert_cmpint (counter, == , 2);
01751 }
01752 /* gnc_account_foreach_child_until  *** Not Used ***
01753 gpointer
01754 gnc_account_foreach_child_until (const Account *acc,// C: 4 in 2 */
01755 /*static void
01756 test_gnc_account_foreach_child_until (Fixture *fixture, gconstpointer pData)
01757 {
01758     Account *root = gnc_account_get_root (fixture->acct);
01759     Account *first = gnc_account_lookup_by_code (root, "4000");
01760     Account *second = gnc_account_lookup_by_code (root, "4100");
01761     Account *expected = gnc_account_lookup_by_code (root, "4160");
01762     Account *result;
01763     guint counter = 0;
01764     result = gnc_account_foreach_child_until (first, thunk2, &counter);
01765     g_assert_cmpint (counter, ==, 2);
01766     g_assert (result == NULL);
01767     counter = 0;
01768     result = gnc_account_foreach_child_until (second, thunk2, &counter);
01769     g_assert (result == expected);
01770     g_assert_cmpint (counter, ==, 3);
01771     }*/
01772 /* gnc_account_foreach_descendant
01773 void
01774 gnc_account_foreach_descendant (const Account *acc,// C: 23 in 14 */
01775 static void
01776 test_gnc_account_foreach_descendant (Fixture *fixture, gconstpointer pData)
01777 {
01778     Account *root = gnc_account_get_root (fixture->acct);
01779     Account *begin = gnc_account_lookup_by_code (root, "4000");
01780     guint counter = 0;
01781     gnc_account_foreach_descendant (begin, thunk, &counter);
01782     g_assert_cmpint (counter, == , 13);
01783 }
01784 /* gnc_account_foreach_descendant_until
01785 gpointer
01786 gnc_account_foreach_descendant_until (const Account *acc,// C: 8 in 6 */
01787 static void
01788 test_gnc_account_foreach_descendant_until (Fixture *fixture, gconstpointer pData)
01789 {
01790     Account *root = gnc_account_get_root (fixture->acct);
01791     Account *first = gnc_account_lookup_by_code (root, "2000");
01792     Account *second = gnc_account_lookup_by_code (root, "4000");
01793     Account *expected = gnc_account_lookup_by_code (root, "4160");
01794     Account *result;
01795     guint counter = 0;
01796     result = gnc_account_foreach_descendant_until (first, thunk2, &counter);
01797     g_assert_cmpint (counter, == , 11);
01798     g_assert (result == NULL);
01799     counter = 0;
01800     result = gnc_account_foreach_descendant_until (second, thunk2, &counter);
01801     g_assert (result == expected);
01802     g_assert_cmpint (counter, == , 6);
01803 }
01804 /* More getter/setters:
01805  * xaccAccountGetType
01806  * qofAccountGetTypeString
01807  * qofAccountSetType
01808  * xaccAccountGetName
01809  * xaccAccountGetCode
01810  * xaccAccountGetDescription
01811  * xaccAccountGetColor
01812  * xaccAccountGetNotes
01813  * xaccAccountGetCommodity
01814  * gnc_account_set_start_balance
01815  * gnc_account_set_start_cleared_balance
01816  * gnc_account_set_start_reconciled_balance
01817  * xaccAccountGetBalance
01818  * xaccAccountGetClearedBalance C: 1
01819  * xaccAccountGetReconciledBalance
01820  */
01821 /* gnc_account_get_full_name
01822 gchar *
01823 gnc_account_get_full_name (const Account *account)// C: 38 in 21 SCM: 29 in 19*/
01824 static void
01825 test_gnc_account_get_full_name (Fixture *fixture, gconstpointer pData)
01826 {
01827     gchar *result;
01828     result = gnc_account_get_full_name (NULL);
01829     g_assert (result != NULL);
01830     g_assert_cmpstr (result, == , "");
01831     g_free (result);
01832     result = gnc_account_get_full_name (gnc_account_get_root (fixture->acct));
01833     g_assert (result != NULL);
01834     g_assert_cmpstr (result, == , "");
01835     g_free (result);
01836     result = gnc_account_get_full_name (fixture->acct);
01837     g_assert (result != NULL);
01838     g_assert_cmpstr (result, == , "foo:baz:waldo");
01839     g_free (result);
01840 
01841 }
01842 
01843 /* DxaccAccountGetCurrency
01844 gnc_commodity *
01845 DxaccAccountGetCurrency (const Account *acc)// C: 9 in 5
01846 Deprecated, Don't test.
01847 */
01848 /* xaccAccountGetProjectedMinimumBalance
01849 gnc_numeric
01850 xaccAccountGetProjectedMinimumBalance (const Account *acc)// C: 4 in 2 */
01851 static void
01852 test_xaccAccountGetProjectedMinimumBalance (Fixture *fixture, gconstpointer pData)
01853 {
01854     gnc_numeric val, bal = gnc_numeric_zero ();
01855     gfloat dval;
01856     gfloat dbal = 0.0;
01857     SetupData *sdata = (SetupData*)pData;
01858     TxnParms* t_arr;
01859     int ind;
01860     gint min_ind = 4;
01861     g_assert (sdata != NULL);
01862     t_arr = (TxnParms*)sdata->txns;
01863     for (ind = 0; ind < min_ind; ind++)
01864     {
01865         SplitParms p = t_arr[ind].splits[1];
01866         bal = gnc_numeric_add_fixed (bal, p.amount);
01867     }
01868     dbal = gnc_numeric_to_double (bal);
01869     val = xaccAccountGetProjectedMinimumBalance (fixture->acct);
01870     dval = gnc_numeric_to_double (val);
01871     g_assert_cmpfloat (dval, == , 0.0);
01872     xaccAccountRecomputeBalance (fixture->acct);
01873     val = xaccAccountGetProjectedMinimumBalance (fixture->acct);
01874     dval = gnc_numeric_to_double (val);
01875     g_assert_cmpfloat (dval, == , dbal);
01876 }
01877 /* xaccAccountGetBalanceAsOfDate
01878 gnc_numeric
01879 xaccAccountGetBalanceAsOfDate (Account *acc, time_t date)// C: 12 in 7 SCM: 4 in 4*/
01880 static void
01881 test_xaccAccountGetBalanceAsOfDate (Fixture *fixture, gconstpointer pData)
01882 {
01883     gnc_numeric val, bal = gnc_numeric_zero ();
01884     gfloat dval;
01885     gfloat dbal = 0.0;
01886     SetupData *sdata = (SetupData*)pData;
01887     TxnParms* t_arr;
01888     int ind;
01889     gint min_ind = 2;
01890     gint offset = 24 * 3600 * 3; /* 3 days in seconds */
01891     g_assert (sdata != NULL);
01892     t_arr = (TxnParms*)sdata->txns;
01893     for (ind = 0; ind < min_ind; ind++)
01894     {
01895         SplitParms p = t_arr[ind].splits[1];
01896         bal = gnc_numeric_add_fixed (bal, p.amount);
01897     }
01898     dbal = gnc_numeric_to_double (bal);
01899     xaccAccountRecomputeBalance (fixture->acct);
01900     val = xaccAccountGetBalanceAsOfDate (fixture->acct, (time (0) - offset));
01901     dval = gnc_numeric_to_double (val);
01902     g_assert_cmpfloat (dval, == , dbal);
01903 }
01904 /* xaccAccountGetPresentBalance
01905 gnc_numeric
01906 xaccAccountGetPresentBalance (const Account *acc)// C: 4 in 2 */
01907 static void
01908 test_xaccAccountGetPresentBalance (Fixture *fixture, gconstpointer pData)
01909 {
01910     gnc_numeric val, bal = gnc_numeric_zero ();
01911     gfloat dval;
01912     gfloat dbal = 0.0;
01913     SetupData *sdata = (SetupData*)pData;
01914     TxnParms* t_arr;
01915     int ind;
01916     gint min_ind = 3;
01917     g_assert (sdata != NULL);
01918     t_arr = (TxnParms*)sdata->txns;
01919     for (ind = 0; ind < min_ind; ind++)
01920     {
01921         SplitParms p = t_arr[ind].splits[1];
01922         bal = gnc_numeric_add_fixed (bal, p.amount);
01923     }
01924     dbal = gnc_numeric_to_double (bal);
01925     xaccAccountRecomputeBalance (fixture->acct);
01926     val = xaccAccountGetPresentBalance (fixture->acct);
01927     dval = gnc_numeric_to_double (val);
01928     g_assert_cmpfloat (dval, == , dbal);
01929 }
01930 /*
01931  * xaccAccountConvertBalanceToCurrency
01932  * xaccAccountConvertBalanceToCurrencyAsOfDate are wrappers around
01933  * gnc_pricedb_convert_balance_latest_price and
01934  * gnc_pricedb_convert_balance_nearest_price. Don't test.
01935  *
01936  * The rest of these are convenience functions that wrap
01937  * xaccAccountConvertBalanceToCurrency* with one of the balance getter
01938  * functions tested immediately above and one of the recursion
01939  * functions, tested above those. There's no point in testing them.
01940  *
01941  * xaccAccountGetXxxBalanceInCurrency
01942  * xaccAccountGetXxxBalanceAsOfDateInCurrency
01943  * xaccAccountBalanceHelper
01944  * xaccAccountBalanceAsOfDateHelper
01945  * xaccAccountGetXxxBalanceInCurrencyRecursive
01946  * xaccAccountGetXxxBalanceAsOfDateInCurrencyRecursive
01947  * xaccAccountGetBalanceInCurrency
01948  * xaccAccountGetClearedBalanceInCurrency
01949  * xaccAccountGetReconciledBalanceInCurrency
01950  * xaccAccountGetPresentBalanceInCurrency
01951  * xaccAccountGetProjectedMinimumBalanceInCurrency
01952  * xaccAccountGetBalanceAsOfDateInCurrency
01953  * xaccAccountGetBalanceChangeForPeriod
01954  */
01955 /*
01956  * Yet more getters & setters:
01957  * xaccAccountGetSplitList
01958  * xaccAccountGetLotList
01959  */
01960 /* xaccAccountFindOpenLots
01961 LotList *
01962 xaccAccountFindOpenLots (const Account *acc,// C: 24 in 13 */
01963 
01964 static gboolean
01965 bogus_lot_match_func_true (GNCLot *lot, gpointer p_data)
01966 {
01967     return TRUE;
01968 }
01969 
01970 static gboolean
01971 bogus_lot_match_func_false (GNCLot *lot, gpointer p_data)
01972 {
01973     return FALSE;
01974 }
01975 
01976 static guint count_sorts = 0;
01977 static gint
01978 bogus_lot_sort_func (gconstpointer a, gconstpointer b)
01979 {
01980     ++count_sorts;
01981     return 0;
01982 }
01983 
01984 static void
01985 test_xaccAccountFindOpenLots (Fixture *fixture, gconstpointer pData)
01986 {
01987     Account *root = gnc_account_get_root (fixture->acct);
01988     Account *acct = gnc_account_lookup_by_name (root, "baz");
01989     LotList* lots;
01990 
01991     g_assert (acct);
01992     lots = xaccAccountFindOpenLots (acct, NULL, NULL, NULL);
01993     g_assert (g_list_length (lots) == 2);
01994     if (lots) g_list_free (lots);
01995     lots = xaccAccountFindOpenLots (acct, bogus_lot_match_func_true,
01996                                     NULL, NULL);
01997     g_assert (g_list_length (lots) == 2);
01998     if (lots) g_list_free (lots);
01999     lots = xaccAccountFindOpenLots (acct, bogus_lot_match_func_false,
02000                                     NULL, NULL);
02001     g_assert (g_list_length (lots) == 0);
02002     if (lots) g_list_free (lots);
02003     lots = xaccAccountFindOpenLots (acct, NULL, NULL, bogus_lot_sort_func);
02004     g_assert_cmpint (count_sorts, == , 1);
02005     g_assert (g_list_length (lots) == 2);
02006     if (lots) g_list_free (lots);
02007     count_sorts = 0;
02008 }
02009 
02010 static gpointer
02011 bogus_for_each_lot_func (GNCLot *lot, gpointer data)
02012 {
02013     guint *count = data;
02014     ++*count;
02015     return (*count > 4 ? lot : NULL);
02016 }
02017 
02018 /* xaccAccountForEachLot
02019 gpointer
02020 xaccAccountForEachLot (const Account *acc,// C: 2 in 2 */
02021 static void
02022 test_xaccAccountForEachLot (Fixture *fixture, gconstpointer pData)
02023 {
02024     Account *root = gnc_account_get_root (fixture->acct);
02025     Account *acct = gnc_account_lookup_by_name (root, "baz");
02026     guint count_calls = 0;
02027 
02028     g_assert (acct);
02029     xaccAccountForEachLot (acct, bogus_for_each_lot_func, &count_calls);
02030     g_assert_cmpint (count_calls, == , 3);
02031     xaccAccountForEachLot (acct, bogus_for_each_lot_func, &count_calls);
02032     g_assert_cmpint (count_calls, == , 5);
02033 }
02034 /* These getters and setters look in KVP, so I guess their delegators instead:
02035  * xaccAccountGetTaxRelated
02036  * xaccAccountSetTaxRelated
02037  * xaccAccountGetTaxUSCode
02038  * xaccAccountSetTaxUSCode
02039  * xaccAccountGetTaxUSPayerNameSource
02040  * xaccAccountSetTaxUSPayerNameSource
02041  * xaccAccountGetTaxUSCopyNumber
02042  * xaccAccountSetTaxUSCopyNumber
02043  * xaccAccountGetPlaceholder
02044  * xaccAccountSetPlaceholder
02045  * xaccAccountGetDescendantPlaceholder
02046  * xaccAccountGetHidden
02047  * xaccAccountSetHidden
02048  * xaccAccountIsHidden
02049 */
02050 /* xaccAccountHasAncestor
02051 gboolean
02052 xaccAccountHasAncestor (const Account *acc, const Account * ancestor)// C: 5 in 3 */
02053 static void
02054 test_xaccAccountHasAncestor (Fixture *fixture, gconstpointer pData)
02055 {
02056     Account *root = gnc_account_get_root (fixture->acct);
02057     Account *ltcg = gnc_account_lookup_by_name (root, "ltcg");
02058     Account *income = gnc_account_lookup_by_name (root, "income");
02059     Account *expense = gnc_account_lookup_by_name (root, "expense");
02060 
02061     g_assert (root);
02062     g_assert (ltcg);
02063     g_assert (income);
02064     g_assert (expense);
02065     g_assert (xaccAccountHasAncestor (fixture->acct, root));
02066     g_assert (xaccAccountHasAncestor (ltcg, income));
02067     g_assert (!xaccAccountHasAncestor (ltcg, expense));
02068 
02069 }
02070 /* xaccAccountTypeEnumAsString
02071  * xaccAccountStringToType
02072  * xaccAccountStringToEnum
02073  * xaccAccountGetTypeStr
02074  * xaccAccountIsPriced
02075 const char *
02076 xaccAccountTypeEnumAsString (GNCAccountType type)// C: 5 in 3 */
02077 static void
02078 test_xaccAccountType_Stuff (void)
02079 {
02080     GNCAccountType  type;
02081     gint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL;
02082     gchar *logdomain = "gnc.account";
02083     gchar *msg1 = g_strdup_printf ("[xaccAccountTypeEnumAsString()] asked to translate unknown account type %d.\n", ACCT_TYPE_LAST);
02084     gchar *msg2 = "[xaccAccountStringToType()] asked to translate unknown account type string (null).\n";
02085     gchar *msg3 = "[xaccAccountStringToType()] asked to translate unknown account type string LAST.\n";
02086     guint loghandler = 0;
02087     TestErrorStruct check1 = { loglevel, logdomain, msg1, 0 };
02088     TestErrorStruct check2 = { loglevel, logdomain, msg2, 0 };
02089     TestErrorStruct check3 = { loglevel, logdomain, msg3, 0 };
02090     Account *acc = g_object_new (GNC_TYPE_ACCOUNT, NULL);
02091 
02092     for (type = ACCT_TYPE_NONE; type < ACCT_TYPE_LAST; type++)
02093     {
02094         const gchar *typename = xaccAccountTypeEnumAsString (type);
02095         const gchar *typestr;
02096         gchar *typestr_uc;
02097 
02098         g_assert (typename);
02099         g_assert_cmpint (xaccAccountStringToEnum (typename), == , type);
02100         if (type < 0 || type >= NUM_ACCOUNT_TYPES)
02101             continue;
02102 
02103         typestr = xaccAccountGetTypeStr (type);
02104         typestr_uc = g_ascii_strup (typestr, strlen (typestr));
02105         if (type == ACCT_TYPE_PAYABLE || type == ACCT_TYPE_RECEIVABLE)
02106         {
02107             gchar *cmpstr = g_strconcat ("A/", typename, NULL);
02108             g_assert_cmpstr (typestr_uc, == , cmpstr);
02109             g_free (cmpstr);
02110         }
02111         else if (type == ACCT_TYPE_CREDIT)
02112         {
02113             gchar *cmpstr = g_strconcat (typename, " CARD", NULL);
02114             g_assert_cmpstr (typestr_uc, == , cmpstr);
02115             g_free (cmpstr);
02116         }
02117         else if (type == ACCT_TYPE_MUTUAL)
02118         {
02119             gchar *cmpstr = g_strconcat (typename, " FUND", NULL);
02120             g_assert_cmpstr (typestr_uc, == , cmpstr);
02121             g_free (cmpstr);
02122         }
02123         else
02124             g_assert_cmpstr (typestr_uc, == , typename);
02125         g_free (typestr_uc);
02126 
02127         g_object_set (acc, "type", type, NULL);
02128         if (type == ACCT_TYPE_STOCK || type == ACCT_TYPE_MUTUAL ||
02129                 type == ACCT_TYPE_CURRENCY)
02130             g_assert (xaccAccountIsPriced (acc));
02131         else
02132             g_assert (!xaccAccountIsPriced (acc));
02133 
02134     }
02135     g_object_unref (acc);
02136 
02137     loghandler = g_log_set_handler (logdomain, loglevel,
02138                                     (GLogFunc)test_null_handler, &check1);
02139     g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_checked_handler, &check1);
02140     g_assert (!xaccAccountTypeEnumAsString (ACCT_TYPE_LAST));
02141     g_assert_cmpint (check1.hits, ==, 1);
02142 
02143     g_log_remove_handler (logdomain, loghandler);
02144     g_free (msg1);
02145     loghandler = g_log_set_handler (logdomain, loglevel,
02146                                     (GLogFunc)test_null_handler, &check2);
02147     g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_checked_handler, &check2);
02148     g_assert (!xaccAccountStringToType (NULL, &type));
02149     g_assert_cmpint (check2.hits, ==, 1);
02150 
02151     g_log_remove_handler (logdomain, loghandler);
02152     loghandler = g_log_set_handler (logdomain, loglevel,
02153                                     (GLogFunc)test_null_handler, &check3);
02154     g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_checked_handler, &check3);
02155     g_assert (!xaccAccountStringToType ("LAST", &type));
02156     g_assert_cmpint (check3.hits, ==, 1);
02157 
02158     g_log_remove_handler (logdomain, loghandler);
02159 
02160 
02161 }
02162 /* xaccParentAccountTypesCompatibleWith
02163  * xaccAccountTypesCompatible
02164 guint32
02165 xaccParentAccountTypesCompatibleWith (GNCAccountType type)// C: 5 in 3 */
02166 static void
02167 test_xaccAccountType_Compatibility (void)
02168 {
02169     guint32 bank_compat = ((1 << ACCT_TYPE_BANK)       |
02170                            (1 << ACCT_TYPE_CASH)       |
02171                            (1 << ACCT_TYPE_ASSET)      |
02172                            (1 << ACCT_TYPE_STOCK)      |
02173                            (1 << ACCT_TYPE_MUTUAL)     |
02174                            (1 << ACCT_TYPE_CURRENCY)   |
02175                            (1 << ACCT_TYPE_CREDIT)     |
02176                            (1 << ACCT_TYPE_LIABILITY)  |
02177                            (1 << ACCT_TYPE_RECEIVABLE) |
02178                            (1 << ACCT_TYPE_PAYABLE)    |
02179                            (1 << ACCT_TYPE_ROOT));
02180     guint32 expense_compat = ((1 << ACCT_TYPE_INCOME)     |
02181                               (1 << ACCT_TYPE_EXPENSE)    |
02182                               (1 << ACCT_TYPE_ROOT));
02183     guint32 equity_compat = ((1 << ACCT_TYPE_EQUITY) | (1 << ACCT_TYPE_ROOT));
02184     guint32 trading_compat = ((1 << ACCT_TYPE_TRADING) | (1 << ACCT_TYPE_ROOT));
02185     guint32 compat;
02186     GNCAccountType  type;
02187     gchar *msg1 = g_strdup_printf ("[xaccParentAccountTypesCompatibleWith()] bad account type: %d", ACCT_TYPE_ROOT);
02188     gchar *msg2 = g_strdup_printf ("[xaccParentAccountTypesCompatibleWith()] bad account type: %d", ACCT_TYPE_SAVINGS);
02189     gchar *logdomain = "gnc.account";
02190     guint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL;
02191     TestErrorStruct check1 = { loglevel, logdomain, msg1, 0 };
02192     TestErrorStruct check2 = { loglevel, logdomain, msg2, 0 };
02193     gint loghandler;
02194 
02195     for (type = ACCT_TYPE_BANK; type < NUM_ACCOUNT_TYPES; type++)
02196     {
02197         GNCAccountType child;
02198         if (type == ACCT_TYPE_ROOT)
02199         {
02200             loghandler = g_log_set_handler (logdomain, loglevel,
02201                                             (GLogFunc)test_null_handler, &check1);
02202             g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_checked_handler,
02203                                           &check1);
02204             compat = xaccParentAccountTypesCompatibleWith (type);
02205             g_log_remove_handler (logdomain, loghandler);
02206             g_assert_cmpint (compat, == , 0);
02207             g_assert_cmpint (check1.hits, ==, 1);
02208             g_free (msg1);
02209             continue;
02210         }
02211         compat = xaccParentAccountTypesCompatibleWith (type);
02212 
02213         if (type <= ACCT_TYPE_CURRENCY || type == ACCT_TYPE_PAYABLE
02214                 || type == ACCT_TYPE_RECEIVABLE)
02215             g_assert_cmpint (compat, == , bank_compat);
02216         else if (type == ACCT_TYPE_INCOME || type == ACCT_TYPE_EXPENSE)
02217             g_assert_cmpint (compat, == , expense_compat);
02218         else if (type == ACCT_TYPE_EQUITY)
02219             g_assert_cmpint (compat, == , equity_compat);
02220         else if (type == ACCT_TYPE_TRADING)
02221             g_assert_cmpint (compat, == , trading_compat);
02222         for (child = ACCT_TYPE_NONE; child < ACCT_TYPE_LAST; child++)
02223             if (1 << child & compat)
02224                 g_assert (xaccAccountTypesCompatible (type, child));
02225             else
02226                 g_assert (!xaccAccountTypesCompatible (type, child));
02227     }
02228 
02229     loghandler = g_log_set_handler (logdomain, loglevel,
02230                                     (GLogFunc)test_null_handler, &check2);
02231     g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_checked_handler, &check2);
02232     compat = xaccParentAccountTypesCompatibleWith (++type);
02233     g_log_remove_handler (logdomain, loghandler);
02234     g_assert_cmpint (compat, == , 0);
02235     g_assert_cmpint (check2.hits, ==, 1);
02236     g_free (msg2);
02237 }
02238 /* More KVP getters & setters
02239  * xaccAccountGetReconcileLastDate
02240  * xaccAccountSetReconcileLastDate
02241  * xaccAccountGetReconcilePostponeDate
02242  * xaccAccountSetReconcilePostponeDate
02243  * xaccAccountGetReconcilePostponeBalance
02244  * xaccAccountSetReconcilePostponeBalance
02245  * xaccAccountClearReconcilePostpone
02246  * xaccAccountGetAutoInterestXfer
02247  * xaccAccountSetAutoInterestXfer
02248  * xaccAccountGetLastNum
02249  * xaccAccountSetLastNum
02250  * xaccAccountSetReconcileChildrenStatus
02251  * xaccAccountGetReconcileChildrenStatus
02252  * xaccAccountGetReconcileLastInterval
02253  * xaccAccountSetReconcileLastInterval
02254  * dxaccAccountSetPriceSrc
02255  * dxaccAccountSetQuoteTZ
02256  * dxaccAccountGetQuoteTZ
02257  */
02258 /* finder_help_function
02259 static void
02260 finder_help_function (const Account *acc, const char *description,// 3
02261 Helper function, fully exercised by the following two public functions
02262 */
02263 /* xaccAccountFindSplitByDesc
02264 Split *
02265 xaccAccountFindSplitByDesc (const Account *acc, const char *description)// C: 5 in 3 */
02266 
02267 static void
02268 test_xaccAccountFindSplitByDesc (Fixture *fixture, gconstpointer pData)
02269 {
02270     Account *root = gnc_account_get_root (fixture->acct);
02271     Account *baz = gnc_account_lookup_by_name (root, "baz");
02272     gchar *memo;
02273     Split *split = xaccAccountFindSplitByDesc (baz, "pepper");
02274     g_assert (split);
02275     g_object_get (split, "memo", &memo, NULL);
02276     g_assert_cmpstr (memo, == , "pepper_baz");
02277     g_free (memo);
02278 }
02279 /* xaccAccountFindTransByDesc
02280 Transaction *
02281 xaccAccountFindTransByDesc (const Account *acc, const char *description)// C: 5 in 3 */
02282 static void
02283 test_xaccAccountFindTransByDesc (Fixture *fixture, gconstpointer pData)
02284 {
02285     Account *root = gnc_account_get_root (fixture->acct);
02286     Account *baz = gnc_account_lookup_by_name (root, "baz");
02287     gchar *desc;
02288     Transaction *txn = xaccAccountFindTransByDesc (baz, "pepper");
02289     g_assert (txn);
02290     g_object_get (txn, "description", &desc, NULL);
02291     g_assert_cmpstr (desc, == , "pepper");
02292     g_free (desc);
02293 }
02294 /* gnc_account_join_children
02295 void
02296 gnc_account_join_children (Account *to_parent, Account *from_parent)// C: 4 in 2 SCM: 3 in 3*/
02297 static void
02298 test_gnc_account_join_children (Fixture *fixture, gconstpointer pData)
02299 {
02300     Account *root = gnc_account_get_root (fixture->acct);
02301     Account *broker = gnc_account_lookup_by_name (root, "broker");
02302     Account *income = gnc_account_lookup_by_name (root, "income");
02303     gint broker_desc = gnc_account_n_descendants (broker);
02304     gint income_desc = gnc_account_n_descendants (income);
02305 
02306     g_test_message ("The following should fail because of account type incompatibility. It doesn't, which is a bug.");
02307     gnc_account_join_children (income, broker);
02308     g_assert_cmpint (gnc_account_n_descendants (income), == ,
02309                      broker_desc + income_desc);
02310 
02311 
02312 }
02313 /* gnc_account_merge_children
02314 void
02315 gnc_account_merge_children (Account *parent)// C: 4 in 2 SCM: 2 in 2*/
02316 static void
02317 test_gnc_account_merge_children (Fixture *fixture, gconstpointer pData)
02318 {
02319     Account *root = gnc_account_get_root (fixture->acct);
02320     Account *stocks = gnc_account_lookup_by_name (root, "stocks");
02321     Account *baz = gnc_account_lookup_by_name (root, "baz");
02322     Account *baz2 = gnc_account_lookup_by_name (root, "baz2");
02323     Account *taxable = gnc_account_lookup_by_name (root, "taxable");
02324     Account *expense = gnc_account_lookup_by_name (root, "expense");
02325     Account *div = gnc_account_lookup_by_name (root, "div");
02326     Account *div1 = gnc_account_lookup_by_name (root, "div1");
02327     gint stocks_desc = gnc_account_n_descendants (stocks);
02328     gint taxable_desc = gnc_account_n_descendants (taxable);
02329     gint expense_desc = gnc_account_n_descendants (expense);
02330     gfloat stocks_balance = gnc_numeric_to_double (
02331                                 xaccAccountGetBalance (stocks));
02332     gfloat baz_balance = gnc_numeric_to_double (xaccAccountGetBalance (baz));
02333     gfloat baz2_balance = gnc_numeric_to_double (xaccAccountGetBalance (baz2));
02334     TestSignal sig1, sig2, sig3, sig4, sig5;
02335     /* This segment doesn't test because of problems with resetting
02336      * the accounts on the splits. It will have to be rewritten with a
02337      * mock Split object
02338     gchar *logdomain = "gnc.engine";
02339     gint loglevel =  G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL;
02340     gchar *msg = "[xaccSplitCommitEdit ()] Account grabbed split prematurely.";
02341     TestErrorStruct check = { loglevel, logdomain, msg, 0 };
02342     guint hdlr = g_log_set_handler (logdomain, loglevel,
02343                            (GLogFunc)test_null_handler, &check);
02344     g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_checked_handler, &check);
02345 
02346     sig1 = test_signal_new (QOF_INSTANCE (baz), QOF_EVENT_MODIFY, NULL);
02347     sig2 = test_signal_new (QOF_INSTANCE (baz2), QOF_EVENT_MODIFY, NULL);
02348     sig3 = test_signal_new (QOF_INSTANCE (baz2), QOF_EVENT_DESTROY, NULL);
02349 
02350     gnc_account_foreach_descendant (stocks, (AccountCb)print_account, NULL);
02351     g_object_set (baz2, "name", "baz", NULL);
02352     gnc_account_merge_children (stocks);
02353     gnc_account_foreach_descendant (stocks, (AccountCb)print_account, NULL);
02354     g_assert_cmpint (gnc_account_n_descendants (stocks), ==, stocks_desc - 1);
02355     g_assert_cmpfloat (gnc_numeric_to_double (xaccAccountGetBalance (stocks)),
02356                ==, stocks_balance);
02357     g_assert_cmpfloat (gnc_numeric_to_double (xaccAccountGetBalance (baz)),
02358                ==, baz_balance + baz2_balance);
02359     test_signal_assert_hits (sig1, 0);
02360     test_signal_assert_hits (sig2, 0);
02361     test_signal_assert_hits (sig3, 1);
02362     test_signal_free (sig1);
02363     test_signal_free (sig2);
02364     test_signal_free (sig3);
02365     g_log_remove_handler (logdomain, hdlr);
02366     g_free (msg);
02367     */
02368     sig4 = test_signal_new (QOF_INSTANCE (div), QOF_EVENT_MODIFY, NULL);
02369     sig5 = test_signal_new (QOF_INSTANCE (div1), QOF_EVENT_MODIFY, NULL);
02370     g_object_set (div1, "name", "div", NULL);
02371     gnc_account_merge_children (taxable);
02372     g_assert_cmpint (gnc_account_n_descendants (taxable), == , taxable_desc - 1);
02373     test_signal_assert_hits (sig4, 1);
02374     test_signal_assert_hits (sig5, 4);
02375     test_signal_free (sig4);
02376     test_signal_free (sig5);
02377     gnc_account_merge_children (expense);
02378     g_assert_cmpint (gnc_account_n_descendants (expense), == , expense_desc);
02379 }
02380 /* xaccSplitsBeginStagedTransactionTraversals
02381  * xaccAccountBeginStagedTransactionTraversals
02382  * gnc_account_tree_begin_staged_transaction_traversals
02383  * xaccAccountStagedTransactionTraversal
02384  * gnc_account_tree_staged_transaction_traversal
02385  * Static helper functions for xaccAccount (Tree)?ForEach ()
02386  */
02387 /* xaccTransactionTraverse
02388 gboolean
02389 xaccTransactionTraverse (Transaction *trans, int stage)// Used only by xaccSplitTransactionTraverses (not used) delete.
02390 */
02391 /* xaccSplitTransactionTraverse
02392 gboolean
02393 xaccSplitTransactionTraverse (Split *split, int stage)// Not used, delete.
02394 */
02395 /* do_one_split
02396  * do_one_account
02397  Trivial helper functions
02398 */
02399 typedef struct
02400 {
02401     guint count;
02402     gchar *name;
02403 } Thunkdata;
02404 
02405 static gint
02406 thunk3 (Transaction *txn, gpointer data)
02407 {
02408     Thunkdata *td = (Thunkdata*)data;
02409     ++(td->count);
02410     if (td->name)
02411     {
02412         gchar *txn_desc;
02413         gboolean result;
02414         g_object_get (txn, "description", &txn_desc, NULL);
02415         result = g_strcmp0 (td->name, txn_desc) == 0;
02416         g_free (txn_desc);
02417         if (result)
02418             return td->count;
02419     }
02420     return 0;
02421 }
02422 
02423 /* xaccAccountTreeForEachTransaction
02424 int
02425 xaccAccountTreeForEachTransaction (Account *acc, TransactionCallback proc,
02426                                    void *data);// C: 302 in 89 SCM: 1158 in 142*/
02427 static void
02428 test_xaccAccountTreeForEachTransaction (Fixture *fixture, gconstpointer pData )
02429 {
02430     Thunkdata td = {0, NULL};
02431     Account *root = gnc_account_get_root (fixture->acct);
02432     gint result;
02433     result = xaccAccountTreeForEachTransaction (root, thunk3, &td);
02434     g_assert_cmpint (td.count, == , 9);
02435     g_assert_cmpint (result, == , 0);
02436     td.count = 0;
02437     td.name = "pepper";
02438     result = xaccAccountTreeForEachTransaction (root, thunk3, &td);
02439     g_assert_cmpint (td.count, == , result);
02440     g_assert_cmpint (result, < , 9);
02441 }
02442 /* xaccAccountForEachTransaction
02443 gint
02444 xaccAccountForEachTransaction (const Account *acc, TransactionCallback proc,// C: 8 in 4 */
02445 static void
02446 test_xaccAccountForEachTransaction (Fixture *fixture, gconstpointer pData )
02447 {
02448     Thunkdata td = {0, NULL};
02449     Account *root = gnc_account_get_root (fixture->acct);
02450     Account *money = gnc_account_lookup_by_name (root, "money");
02451     gint result;
02452     result = xaccAccountForEachTransaction (root, thunk3, &td);
02453     g_assert_cmpint (td.count, == , 0);
02454     g_assert (money);
02455     result = xaccAccountForEachTransaction (money, thunk3, &td);
02456     g_assert_cmpint (td.count, == , 9);
02457     g_assert_cmpint (result, == , 0);
02458     td.count = 0;
02459     td.name = "pepper";
02460     result = xaccAccountForEachTransaction (money, thunk3, &td);
02461     g_assert_cmpint (td.count, == , result);
02462     g_assert_cmpint (result, < , 9);
02463 }
02464 
02465 
02466 void
02467 test_suite_account (void)
02468 {
02469 
02470     GNC_TEST_ADD_FUNC (suitename, "gnc set account separator", test_gnc_set_account_separator);
02471     GNC_TEST_ADD_FUNC (suitename, "gnc account name violations errmsg", test_gnc_account_name_violations_errmsg);
02472     GNC_TEST_ADD (suitename, "gnc account list name violations", Fixture, &bad_data, setup, test_gnc_account_list_name_violations,  teardown);
02473     GNC_TEST_ADD_FUNC (suitename, "account create and destroy", test_gnc_account_create_and_destroy);
02474     GNC_TEST_ADD (suitename, "book set/get root account", Fixture, NULL, setup, test_gnc_book_set_get_root_account, teardown);
02475     GNC_TEST_ADD_FUNC (suitename, "xaccMallocAccount", test_xaccMallocAccount);
02476 
02477     GNC_TEST_ADD_FUNC (suitename, "gnc account create root", test_gnc_account_create_root);
02478     GNC_TEST_ADD (suitename, "xaccCloneAccount", Fixture, NULL, setup, test_xaccCloneAccount,  teardown );
02479     /*Destroys the account, so we have to do the tear down in the test function */
02480     GNC_TEST_ADD (suitename, "xaccFreeAccountChildren", Fixture,  &good_data, setup, test_xaccFreeAccountChildren,  NULL);
02481     /* See comment at the beginning of test_xaccFreeAccount */
02482     GNC_TEST_ADD (suitename, "xaccFreeAccount", Fixture, &good_data, setup, test_xaccFreeAccount,  NULL );
02483     GNC_TEST_ADD (suitename, "xaccAccountCommitEdit", Fixture, &good_data, setup, test_xaccAccountCommitEdit,  NULL );
02484 // GNC_TEST_ADD (suitename, "xaccAcctChildrenEqual", Fixture, NULL, setup, test_xaccAcctChildrenEqual,  teardown );
02485 // GNC_TEST_ADD (suitename, "xaccAccountEqual", Fixture, NULL, setup, test_xaccAccountEqual,  teardown );
02486     GNC_TEST_ADD (suitename, "gnc account insert & remove split", Fixture, NULL, setup, test_gnc_account_insert_remove_split,  teardown );
02487     GNC_TEST_ADD (suitename, "xaccAccount Insert and Remove Lot", Fixture, &good_data, setup, test_xaccAccountInsertRemoveLot,  teardown );
02488     GNC_TEST_ADD (suitename, "xaccAccountRecomputeBalance", Fixture, &some_data, setup, test_xaccAccountRecomputeBalance,  teardown );
02489     GNC_TEST_ADD_FUNC (suitename, "xaccAccountOrder", test_xaccAccountOrder );
02490     GNC_TEST_ADD (suitename, "qofAccountSetParent", Fixture, &some_data, setup, test_qofAccountSetParent,  teardown );
02491     GNC_TEST_ADD (suitename, "gnc account append/remove child", Fixture, NULL, setup, test_gnc_account_append_remove_child,  teardown );
02492     GNC_TEST_ADD (suitename, "gnc account n descendants", Fixture, &some_data, setup, test_gnc_account_n_descendants,  teardown );
02493     GNC_TEST_ADD (suitename, "gnc account get current depth", Fixture, &some_data, setup, test_gnc_account_get_current_depth,  teardown );
02494     GNC_TEST_ADD (suitename, "gnc account get tree depth", Fixture, &complex, setup, test_gnc_account_get_tree_depth,  teardown );
02495     GNC_TEST_ADD (suitename, "gnc account get descendants", Fixture, &complex, setup, test_gnc_account_get_descendants,  teardown );
02496     GNC_TEST_ADD (suitename, "gnc account get descendants sorted", Fixture, &complex, setup, test_gnc_account_get_descendants_sorted,  teardown );
02497     GNC_TEST_ADD (suitename, "gnc account lookup by name", Fixture, &complex, setup, test_gnc_account_lookup_by_name,  teardown );
02498     GNC_TEST_ADD (suitename, "gnc account lookup by code", Fixture, &complex, setup, test_gnc_account_lookup_by_code,  teardown );
02499     GNC_TEST_ADD (suitename, "gnc account lookup by full name helper", Fixture, &complex, setup, test_gnc_account_lookup_by_full_name_helper,  teardown );
02500     GNC_TEST_ADD (suitename, "gnc account lookup by full name", Fixture, &complex, setup, test_gnc_account_lookup_by_full_name,  teardown );
02501     GNC_TEST_ADD (suitename, "gnc account foreach child", Fixture, &complex, setup, test_gnc_account_foreach_child,  teardown );
02502     GNC_TEST_ADD (suitename, "gnc account foreach descendant", Fixture, &complex, setup, test_gnc_account_foreach_descendant,  teardown );
02503     GNC_TEST_ADD (suitename, "gnc account foreach descendant until", Fixture, &complex, setup, test_gnc_account_foreach_descendant_until,  teardown );
02504     GNC_TEST_ADD (suitename, "gnc account get full name", Fixture, &good_data, setup, test_gnc_account_get_full_name,  teardown );
02505     GNC_TEST_ADD (suitename, "xaccAccountGetProjectedMinimumBalance", Fixture, &some_data, setup, test_xaccAccountGetProjectedMinimumBalance,  teardown );
02506     GNC_TEST_ADD (suitename, "xaccAccountGetBalanceAsOfDate", Fixture, &some_data, setup, test_xaccAccountGetBalanceAsOfDate,  teardown );
02507     GNC_TEST_ADD (suitename, "xaccAccountGetPresentBalance", Fixture, &some_data, setup, test_xaccAccountGetPresentBalance,  teardown );
02508     GNC_TEST_ADD (suitename, "xaccAccountFindOpenLots", Fixture, &complex_data, setup, test_xaccAccountFindOpenLots,  teardown );
02509     GNC_TEST_ADD (suitename, "xaccAccountForEachLot", Fixture, &complex_data, setup, test_xaccAccountForEachLot,  teardown );
02510 
02511     GNC_TEST_ADD (suitename, "xaccAccountHasAncestor", Fixture, &complex, setup, test_xaccAccountHasAncestor,  teardown );
02512     GNC_TEST_ADD_FUNC (suitename, "AccountType Stuff", test_xaccAccountType_Stuff );
02513     GNC_TEST_ADD_FUNC (suitename, "AccountType Compatibility", test_xaccAccountType_Compatibility);
02514     GNC_TEST_ADD (suitename, "xaccAccountFindSplitByDesc", Fixture, &complex_data, setup, test_xaccAccountFindSplitByDesc,  teardown );
02515     GNC_TEST_ADD (suitename, "xaccAccountFindTransByDesc", Fixture, &complex_data, setup, test_xaccAccountFindTransByDesc,  teardown );
02516     GNC_TEST_ADD (suitename, "gnc account join children", Fixture, &complex, setup, test_gnc_account_join_children,  teardown );
02517     GNC_TEST_ADD (suitename, "gnc account merge children", Fixture, &complex_data, setup, test_gnc_account_merge_children,  teardown );
02518     GNC_TEST_ADD (suitename, "xaccAccountForEachTransaction", Fixture, &complex_data, setup, test_xaccAccountForEachTransaction,  teardown );
02519     GNC_TEST_ADD (suitename, "xaccAccountTreeForEachTransaction", Fixture, &complex_data, setup, test_xaccAccountTreeForEachTransaction,  teardown );
02520 
02521 
02522 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines