Replace xaccSplitCopy with xaccSplitCopyNoKvp and xaccSplitCopyKvp

Provides ability to copy a split without its KVP instead of having to directly access the KVP and replace it with an empty frame.
This commit is contained in:
John Ralls 2013-10-17 09:51:55 -07:00
parent c748f33b92
commit 4f5e228903
4 changed files with 25 additions and 24 deletions

View File

@ -407,7 +407,7 @@ xaccDupeSplit (const Split *s)
}
Split *
xaccSplitClone (const Split *s)
xaccSplitCloneNoKvp (const Split *s)
{
Split *split = g_object_new (GNC_TYPE_SPLIT, NULL);
@ -425,10 +425,8 @@ xaccSplitClone (const Split *s)
split->gains = GAINS_STATUS_UNKNOWN;
split->gains_split = NULL;
qof_instance_init_data(&split->inst, GNC_ID_SPLIT, qof_instance_get_book(s));
kvp_frame_delete(split->inst.kvp_data);
split->inst.kvp_data = kvp_frame_copy(s->inst.kvp_data);
qof_instance_init_data(&split->inst, GNC_ID_SPLIT,
qof_instance_get_book(s));
xaccAccountInsertSplit(s->acc, split);
if (s->lot)
{
@ -438,6 +436,11 @@ xaccSplitClone (const Split *s)
return split;
}
void
xaccSplitCopyKvp (const Split *from, Split *to)
{
to->inst.kvp_data = kvp_frame_copy(from->inst.kvp_data);
}
/*################## Added for Reg2 #################*/

View File

@ -146,7 +146,8 @@ struct _SplitClass
*/
void xaccFreeSplit (Split *split); /* frees memory */
Split * xaccSplitClone (const Split *s);
Split *xaccSplitCloneNoKvp (const Split *s);
void xaccSplitCopyKvp (const Split *from, Split *to);
Split *xaccDupeSplit (const Split *s);
void mark_split (Split *s);

View File

@ -621,7 +621,7 @@ xaccTransCloneNoKvp (const Transaction *from)
xaccTransBeginEdit(to);
for (node = from->splits; node; node = node->next)
{
split = xaccSplitClone(node->data);
split = xaccSplitCloneNoKvp(node->data);
split->parent = to;
to->splits = g_list_append (to->splits, split);
}
@ -636,8 +636,15 @@ Transaction *
xaccTransClone (const Transaction *from)
{
Transaction *to = xaccTransCloneNoKvp (from);
int i = 0;
int length = g_list_length (from->splits);
xaccTransBeginEdit (to);
to->inst.kvp_data = kvp_frame_copy (from->inst.kvp_data);
g_assert (g_list_length (to->splits) == length);
for (i = 0; i < length; ++i)
xaccSplitCopyKvp (g_list_nth_data (from->splits, i),
g_list_nth_data (to->splits, i));
xaccTransCommitEdit (to);
return to;
}

View File

@ -310,15 +310,15 @@ test_xaccDupeSplit (Fixture *fixture, gconstpointer pData)
g_assert (split->gains_split != f_split->gains_split);
}
/* xaccSplitClone
/* xaccSplitCloneNoKvp
Split *
xaccSplitClone (const Split *s)// C: 1
xaccSplitCloneNoKvp (const Split *s)// C: 1
*/
static void
test_xaccSplitClone (Fixture *fixture, gconstpointer pData)
test_xaccSplitCloneNoKvp (Fixture *fixture, gconstpointer pData)
{
Split *f_split = fixture->split;
Split *split = xaccSplitClone (f_split);
Split *split = xaccSplitCloneNoKvp (f_split);
g_assert (split != fixture->split);
g_assert (qof_instance_get_guid (split) != qof_instance_get_guid (f_split));
@ -331,7 +331,7 @@ test_xaccSplitClone (Fixture *fixture, gconstpointer pData)
g_assert (split->lot == f_split->lot);
g_assert_cmpstr (split->memo, ==, f_split->memo);
g_assert_cmpstr (split->action, ==, f_split->action);
g_assert (kvp_frame_compare (split->inst.kvp_data, f_split->inst.kvp_data) == 0);
g_assert (kvp_frame_is_empty (split->inst.kvp_data));
g_assert_cmpint (split->reconciled, ==, f_split->reconciled);
g_assert (timespec_equal (&(split->date_reconciled), &(f_split->date_reconciled)));
g_assert (gnc_numeric_equal (split->value, f_split->value));
@ -408,7 +408,7 @@ xaccSplitEqual(const Split *sa, const Split *sb,// C: 2 in 2 SCM: 1
static void
test_xaccSplitEqual (Fixture *fixture, gconstpointer pData)
{
Split *split1 = xaccSplitClone (fixture->split);
Split *split1 = xaccSplitCloneNoKvp (fixture->split);
Split *split2 = xaccDupeSplit (fixture->split);
gchar *msg01 = "[xaccSplitEqual] one is NULL";
gchar *msg02 = "[xaccSplitEqual] GUIDs differ";
@ -771,16 +771,6 @@ test_get_commodity_denom (Fixture *fixture, gconstpointer pData)
fixture->split->acc = acc;
g_assert_cmpint (fixture->func->get_commodity_denom (fixture->split), ==, denom);
}
/* xaccSplitGetSlots
KvpFrame *
xaccSplitGetSlots (const Split * s)// C: 17 in 8
Simple passthrough, no test.
*/
// Not Used
/* xaccSplitSetSlots_nc
void
xaccSplitSetSlots_nc(Split *s, KvpFrame *frm)//
*/
/* xaccSplitSetSharePriceAndAmount
void
xaccSplitSetSharePriceAndAmount (Split *s, gnc_numeric price, gnc_numeric amt)// C: 1
@ -1873,7 +1863,7 @@ test_suite_split (void)
GNC_TEST_ADD_FUNC (suitename, "gnc split set & get property", test_gnc_split_set_get_property);
GNC_TEST_ADD (suitename, "xaccMallocSplit", Fixture, NULL, setup, test_xaccMallocSplit, teardown);
GNC_TEST_ADD (suitename, "xaccDupeSplit", Fixture, NULL, setup, test_xaccDupeSplit, teardown);
GNC_TEST_ADD (suitename, "xaccSplitClone", Fixture, NULL, setup, test_xaccSplitClone, teardown);
GNC_TEST_ADD (suitename, "xaccSplitCloneNoKvp", Fixture, NULL, setup, test_xaccSplitCloneNoKvp, teardown);
GNC_TEST_ADD (suitename, "mark split", Fixture, NULL, setup, test_mark_split, teardown);
GNC_TEST_ADD (suitename, "xaccSplitEqualCheckBal", Fixture, NULL, setup, test_xaccSplitEqualCheckBal, teardown);
GNC_TEST_ADD (suitename, "xaccSplitEqual", Fixture, NULL, setup, test_xaccSplitEqual, teardown);