Add Account property "lot-next-id"

Replaces direct kvp access.
This commit is contained in:
John Ralls 2013-10-15 17:04:37 -07:00
parent 9ea9896620
commit 8d9d51a7f7
5 changed files with 144 additions and 8 deletions

View File

@ -85,6 +85,8 @@ enum
PROP_PLACEHOLDER, PROP_PLACEHOLDER,
PROP_FILTER, PROP_FILTER,
PROP_SORT_ORDER, PROP_SORT_ORDER,
PROP_LOT_NEXT_ID,
}; };
#define GET_PRIVATE(o) \ #define GET_PRIVATE(o) \
@ -283,6 +285,8 @@ gnc_account_get_property (GObject *object,
{ {
Account *account; Account *account;
AccountPrivate *priv; AccountPrivate *priv;
const gchar *key;
GValue *temp;
g_return_if_fail(GNC_IS_ACCOUNT(object)); g_return_if_fail(GNC_IS_ACCOUNT(object));
@ -378,6 +382,12 @@ gnc_account_get_property (GObject *object,
case PROP_SORT_ORDER: case PROP_SORT_ORDER:
g_value_set_string(value, xaccAccountGetSortOrder(account)); g_value_set_string(value, xaccAccountGetSortOrder(account));
break; break;
case PROP_LOT_NEXT_ID:
key = "lot-mgmt/next-id";
/* Pre-set the value in case the frame is empty */
g_value_set_int64 (value, 0);
qof_instance_get_kvp (QOF_INSTANCE (account), key, value);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break; break;
@ -392,6 +402,7 @@ gnc_account_set_property (GObject *object,
{ {
Account *account; Account *account;
gnc_numeric *number; gnc_numeric *number;
gchar *key = NULL;
g_return_if_fail(GNC_IS_ACCOUNT(object)); g_return_if_fail(GNC_IS_ACCOUNT(object));
@ -477,6 +488,10 @@ gnc_account_set_property (GObject *object,
case PROP_SORT_ORDER: case PROP_SORT_ORDER:
xaccAccountSetSortOrder(account, g_value_get_string(value)); xaccAccountSetSortOrder(account, g_value_get_string(value));
break; break;
case PROP_LOT_NEXT_ID:
key = "lot-mgmt/next-id";
qof_instance_set_kvp (QOF_INSTANCE (account), key, value);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break; break;
@ -834,6 +849,17 @@ gnc_account_class_init (AccountClass *klass)
"the sort order to be recalled.", "the sort order to be recalled.",
NULL, NULL,
G_PARAM_READWRITE)); G_PARAM_READWRITE));
g_object_class_install_property
(gobject_class,
PROP_LOT_NEXT_ID,
g_param_spec_int64 ("lot-next-id",
"Lot Next ID",
"Tracks the next id to use in gnc_lot_make_default.",
(gint64)1,
G_MAXINT64,
(gint64)1,
G_PARAM_READWRITE));
} }
static void static void

View File

@ -675,19 +675,19 @@ GNCLot * gnc_lot_make_default (Account *acc)
{ {
GNCLot * lot; GNCLot * lot;
gint64 id; gint64 id;
char buff[200]; gchar *buff;
lot = gnc_lot_new (qof_instance_get_book(acc)); lot = gnc_lot_new (qof_instance_get_book(acc));
/* Provide a reasonable title for the new lot */ /* Provide a reasonable title for the new lot */
xaccAccountBeginEdit (acc); xaccAccountBeginEdit (acc);
id = kvp_frame_get_gint64 (xaccAccountGetSlots (acc), "/lot-mgmt/next-id"); qof_instance_get (QOF_INSTANCE (acc), "lot-next-id", &id, NULL);
snprintf (buff, 200, ("%s %" G_GINT64_FORMAT), _("Lot"), id); buff = g_strdup_printf ("%s %" G_GINT64_FORMAT, _("Lot"), id);
kvp_frame_set_str (gnc_lot_get_slots (lot), "/title", buff); gnc_lot_set_title (lot, buff);
id ++; id ++;
kvp_frame_set_gint64 (xaccAccountGetSlots (acc), "/lot-mgmt/next-id", id); qof_instance_set (QOF_INSTANCE (acc), "lot-next-id", id, NULL);
qof_instance_set_dirty (QOF_INSTANCE(acc));
xaccAccountCommitEdit (acc); xaccAccountCommitEdit (acc);
g_free (buff);
return lot; return lot;
} }

View File

@ -113,8 +113,9 @@ noinst_PROGRAMS = ${TEST_PROGS} ${CHECK_PROGS}
test_engine_SOURCES = \ test_engine_SOURCES = \
test-engine.c \ test-engine.c \
utest-Account.c \ utest-Account.c \
utest-Budget.c \ utest-Budget.c \
utest-Invoice.c utest-Invoice.c \
test-engine-kvp-properties.c
test_engine_LDADD = \ test_engine_LDADD = \
libutest-Split.la \ libutest-Split.la \

View File

@ -0,0 +1,107 @@
/********************************************************************
* test-engine-kvp-properties.c: GLib g_test test suite for *
* KVP-based properties in several engine classes. *
* Copyright 2013 John Ralls <jralls@ceridwen.us> *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License*
* along with this program; if not, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
\********************************************************************/
/**
* Test Engine KVP Properties Acceptance testing for KVP Properties
* added to various engine classes to make private the internals of
* KVP storage used for a variety of parameters on several engine
* classes.
*/
#include <config.h>
#include <glib.h>
#include <qof.h>
#include <unittest-support.h>
#include "../Transaction.h"
#include "../Split.h"
#include "../Account.h"
#include "../SchedXAction.h"
#include "../gncCustomer.h"
#include "../gncEmployee.h"
#include "../gncJob.h"
#include "../gncVendor.h"
typedef struct
{
union
{
Account *acct;
Transaction *trans;
GncCustomer *cust;
GncEmployee *emp;
GncJob *job;
GncVendor *vend;
};
GSList *split;
} Fixture;
/* Prototype to shut clang up */
void test_suite_engine_kvp_properties (void);
/* Private QofInstance function needed for testing */
extern void qof_instance_mark_clean (QofInstance*);
const gchar *suitename = "/engine/kvp-properties";
static void
setup_account (Fixture *fixture, gconstpointer pData)
{
QofBook *book = qof_book_new ();
fixture->acct = xaccMallocAccount (book);
}
static void
teardown (Fixture *fixture, gconstpointer pData)
{
/* It doesn't actually matter which union member we use here, they're
* all QofInstances, so this will work for any of them.
*/
QofBook *book = qof_instance_get_book (QOF_INSTANCE (fixture->acct));
test_destroy (fixture->acct);
test_destroy (book);
}
static void
test_account_kvp_properties (Fixture *fixture, gconstpointer pData)
{
gint64 next_id = 12345678909876;
gint64 next_id_r;
qof_instance_set (QOF_INSTANCE (fixture->acct),
"lot-next-id", next_id,
NULL);
g_assert (qof_instance_is_dirty (QOF_INSTANCE (fixture->acct)));
qof_instance_mark_clean (QOF_INSTANCE (fixture->acct));
qof_instance_get (QOF_INSTANCE (fixture->acct),
"lot-next-id", &next_id_r,
NULL);
g_assert_cmpint (next_id, ==, next_id_r);
g_assert (!qof_instance_is_dirty (QOF_INSTANCE (fixture->acct)));
}
void test_suite_engine_kvp_properties (void)
{
GNC_TEST_ADD (suitename, "Account", Fixture, NULL, setup_account, test_account_kvp_properties, teardown);
}

View File

@ -31,6 +31,7 @@ extern void test_suite_budget();
extern void test_suite_gncInvoice(); extern void test_suite_gncInvoice();
extern void test_suite_transaction(); extern void test_suite_transaction();
extern void test_suite_split(); extern void test_suite_split();
extern void test_suite_engine_kvp_properties (void);
int int
main (int argc, main (int argc,
@ -49,6 +50,7 @@ main (int argc,
test_suite_gncInvoice(); test_suite_gncInvoice();
test_suite_transaction(); test_suite_transaction();
test_suite_split(); test_suite_split();
test_suite_engine_kvp_properties ();
return g_test_run( ); return g_test_run( );
} }