Confusion around qof_instance editlevel and test-account-object
Geert Janssens
geert.gnucash at kobaltwit.be
Sun Nov 5 11:21:55 EST 2017
Op zondag 5 november 2017 13:55:56 CET schreef Carwyn Nelson:
> Hi all,
>
> I’m wondering if anybody would be able to explain something to me that I’m
> finding a little confusing.
>
> I’m working with Aaron (lmat) on the cpp conversion of Account and as
> expected during the conversion some of the tests are failing. One of the
> tests that I’m working on fixing is the test-account-object test.
>
> I’m currently getting the following test failures:
> FAILURE end balance matches
> /home/carwyn/gnucash/libgnucash/engine/test/test-account-object.cpp:78
> FAILURE end2 balance matches
> /home/carwyn/gnucash/libgnucash/engine/test/test-account-object.cpp:80
>
> From reading the test I think its trying to do the following:
> Set the initial balance of the account to 5
> Remove 5 from the balance
> Assert that the balance of the account is 0
>
> The balance is currently -5 so it stands to reason that setting the initial
> balance to 5 is failing?
>
> The following code appears to be attempting to set the balance to 5:
> five = gnc_numeric_create(5, 1);
> qof_instance_increase_editlevel (acc);
> g_object_set(acc, "start-balance", &five, NULL);
> qof_instance_decrease_editlevel (acc);
> xaccAccountRecomputeBalance(acc);
> g_object_get(acc, "start-balance", &start, "end-balance", &end, NULL);
> end2 = xaccAccountGetBalance(acc);
>
> I’m getting quite confused as to how this would normally work. Account does
> not have a member variable called “start-balance” so how does gobject know
> how to set the start_balance?
gobject has a concept of "properties". "starting-balance" is such a property
which you can set with g_object_set and query with g_object_get. This property
gets defined in Account.c:738.
> Doing some step-through debugging just takes
> me to gobject.h which is basically a black hole from then onwards.
>
> Would somebody be able to point me in the right direction to how this is
> working so that I can work towards fixing the test.
>
As the property is defined as a boxed gnc_numeric, g_object_set will call
gnc_numeric_boxed_copy_func to store the value. You could break on that
function to verify it's really called.
In addition qof_instance_increase_editlevel and
qof_instance_decrease_editlevel should always be balanced. It works a bit like
BEGIN TRANSACTION/END TRANSACTION in sql. As long as the edit level is more
than 0, the changes are not really committed. It's possible
xaccAccountRecomputeBalance will not see the right start-balance. Did you add
qof_instance_increase_editlevel higher up ?
You could test whether gnc_numeric_boxed_copy_func is doing the right thing
(set a breakpoint there) when going into g_object_set.
There was a change in the function recently to handle null dereferencing and
fixing memory leaks. I don't know if your refactored code takes this into
account ?
Regards,
Geert
More information about the gnucash-devel
mailing list