예제 #1
0
static void
test_object (void)
{
    QofBook *book = qof_book_new();

    do_test ((NULL != book), "book null");

    /* Test the global registration and lookup functions */
    {
        do_test (!qof_object_register (NULL), "register NULL");
        do_test (qof_object_register (&bus_obj), "register test object");
        do_test (!qof_object_register (&bus_obj), "register test object again");
        do_test (qof_object_lookup (TEST_MODULE_NAME) == &bus_obj,
                 "lookup our installed object");
        do_test (qof_object_lookup ("snm98sn snml say  dyikh9y9ha") == NULL,
                 "lookup non-existant object object");

        do_test (!g_strcmp0 (qof_object_get_type_label (TEST_MODULE_NAME),
                               _(TEST_MODULE_DESC)),
                 "test description return");
    }

    test_foreach (book, TEST_MODULE_NAME);
    test_printable (TEST_MODULE_NAME, (gpointer)1);
}
예제 #2
0
파일: SX-book.c 프로젝트: Mechtilde/gnucash
gboolean
gnc_sxtt_register (void)
{
    if (!qof_object_register(&sxes_object_def))
        return FALSE;
    if (!qof_object_register(&sxtg_object_def))
        return FALSE;
    return qof_object_register(&sxtt_object_def);
}
예제 #3
0
gboolean
SXRegister(void)
{
    static QofParam params[] =
    {
        {
            GNC_SX_NAME, QOF_TYPE_STRING, (QofAccessFunc)xaccSchedXactionGetName,
            (QofSetterFunc)xaccSchedXactionSetName
        },
        {
            GNC_SX_START_DATE, QOF_TYPE_DATE, (QofAccessFunc)xaccSchedXactionGetStartDate,
            (QofSetterFunc)xaccSchedXactionSetStartDate
        },
        {
            GNC_SX_LAST_DATE, QOF_TYPE_DATE, (QofAccessFunc)xaccSchedXactionGetLastOccurDate,
            (QofSetterFunc)xaccSchedXactionSetLastOccurDate
        },
        {
            GNC_SX_NUM_OCCUR, QOF_TYPE_INT64, (QofAccessFunc)xaccSchedXactionGetNumOccur,
            (QofSetterFunc)xaccSchedXactionSetNumOccur
        },
        {
            GNC_SX_REM_OCCUR, QOF_TYPE_INT64, (QofAccessFunc)xaccSchedXactionGetRemOccur,
            (QofSetterFunc)xaccSchedXactionSetRemOccur
        },
        { QOF_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL },
        { QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL },
        { NULL },
    };
    qof_class_register(GNC_SX_ID, NULL, params);
    return qof_object_register(&SXDesc);
}
예제 #4
0
파일: gncAddress.c 프로젝트: mlq/gnucash
gboolean gncAddressRegister (void)
{
    static QofParam params[] =
    {

        { ADDRESS_NAME,  QOF_TYPE_STRING, (QofAccessFunc)gncAddressGetName,  (QofSetterFunc)gncAddressSetName },
        { ADDRESS_ONE,   QOF_TYPE_STRING, (QofAccessFunc)gncAddressGetAddr1, (QofSetterFunc)gncAddressSetAddr1 },
        { ADDRESS_TWO,   QOF_TYPE_STRING, (QofAccessFunc)gncAddressGetAddr2, (QofSetterFunc)gncAddressSetAddr2 },
        { ADDRESS_THREE, QOF_TYPE_STRING, (QofAccessFunc)gncAddressGetAddr3, (QofSetterFunc)gncAddressSetAddr3 },
        { ADDRESS_FOUR,  QOF_TYPE_STRING, (QofAccessFunc)gncAddressGetAddr4, (QofSetterFunc)gncAddressSetAddr4 },
        { ADDRESS_PHONE, QOF_TYPE_STRING, (QofAccessFunc)gncAddressGetPhone, (QofSetterFunc)gncAddressSetPhone },
        { ADDRESS_FAX,   QOF_TYPE_STRING, (QofAccessFunc)gncAddressGetFax,   (QofSetterFunc)gncAddressSetFax },
        { ADDRESS_EMAIL, QOF_TYPE_STRING, (QofAccessFunc)gncAddressGetEmail, (QofSetterFunc)gncAddressSetEmail },
        { ADDRESS_OWNER, QOF_TYPE_CHOICE, (QofAccessFunc)qofAddressGetOwner, (QofSetterFunc)qofAddressSetOwner },
        { QOF_PARAM_BOOK, QOF_ID_BOOK,   (QofAccessFunc)qof_instance_get_book, NULL },
        { QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL },
        { NULL },
    };

    qof_class_register (GNC_ID_ADDRESS, (QofSortFunc)gncAddressCompare, params);
    if (!qof_choice_add_class(GNC_ID_CUSTOMER, GNC_ID_ADDRESS, ADDRESS_OWNER))
    {
        return FALSE;
    }

    return qof_object_register(&GncAddressDesc);
}
예제 #5
0
파일: gncJob.c 프로젝트: 573/gnucash
gboolean gncJobRegister (void)
{
    static QofParam params[] =
    {
        { JOB_ID, QOF_TYPE_STRING, (QofAccessFunc)gncJobGetID, (QofSetterFunc)gncJobSetID },
        { JOB_NAME, QOF_TYPE_STRING, (QofAccessFunc)gncJobGetName, (QofSetterFunc)gncJobSetName },
        { JOB_ACTIVE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncJobGetActive, (QofSetterFunc)gncJobSetActive },
        { JOB_REFERENCE, QOF_TYPE_STRING, (QofAccessFunc)gncJobGetReference, (QofSetterFunc)gncJobSetReference },
#ifdef GNUCASH_MAJOR_VERSION
        { JOB_OWNER, GNC_ID_OWNER, (QofAccessFunc)gncJobGetOwner, NULL },
#else
        { JOB_OWNER, QOF_TYPE_CHOICE, (QofAccessFunc)qofJobGetOwner, (QofSetterFunc)qofJobSetOwner },
#endif
        { QOF_PARAM_ACTIVE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncJobGetActive, NULL },
        { QOF_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL },
        { QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL },
        { NULL },
    };

    if (!qof_choice_create(GNC_ID_JOB))
    {
        return FALSE;
    }
    if (!qof_choice_add_class(GNC_ID_INVOICE, GNC_ID_JOB, INVOICE_OWNER))
    {
        return FALSE;
    }

    qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncJobCompare, params);
#ifdef GNUCASH_MAJOR_VERSION
    qofJobGetOwner(NULL);
    qofJobSetOwner(NULL, NULL);
#endif
    return qof_object_register (&gncJobDesc);
}
예제 #6
0
static void
test_qof_object_foreach( Fixture *fixture, gconstpointer pData )
{
    gint user_data;
    QofBook *book = NULL;
    QofCollection *col = NULL;

    /* setup */
    book = qof_book_new();
    g_assert( book );
    g_assert_cmpint( g_list_length( get_object_modules() ), == , 0 );
    qof_object_register( fixture->qofobject );
    g_assert_cmpint( g_list_length( get_object_modules() ), == , 1 );
    col = qof_book_get_collection( book, fixture->qofobject->e_type ); /* make col already exist */
    g_assert( col );

    g_test_message( "Test foreach and data" );
    foreach_cb_struct.user_data = ( gpointer ) &user_data;
    foreach_cb_struct.is_called = FALSE;
    foreach_cb_struct.col = col;
    foreach_cb_struct.cb = mock_instance_foreach_cb;
    fixture->qofobject->foreach = mock_foreach;
    qof_object_foreach( fixture->qofobject->e_type, book, mock_instance_foreach_cb, ( gpointer ) &user_data );
    g_assert( foreach_cb_struct.is_called == TRUE );

    qof_book_destroy( book );
}
예제 #7
0
static void
test_qof_object_new_instance( Fixture *fixture, gconstpointer pData )
{
    QofBook *book = NULL;
    QofInstance *inst = NULL;

    book = qof_book_new();
    g_assert( book );

    g_test_message( "Test null check" );
    g_assert( qof_object_new_instance( NULL, book ) == NULL );

    g_test_message( "Test non existing object type" );
    g_assert( qof_object_new_instance( "non existing type", book ) == NULL );

    g_test_message( "Test with registered object type and create not set" );
    g_assert( qof_object_register( fixture->qofobject ) );
    g_assert( qof_object_new_instance( fixture->qofobject->e_type, book ) == NULL );

    g_test_message( "Test with registered object type and create set" );
    object_create_struct.is_called = FALSE;
    object_create_struct.book = book;
    object_create_struct.inst = NULL;
    fixture->qofobject->create = mock_object_create;
    inst = qof_object_new_instance( fixture->qofobject->e_type, book );
    g_assert( inst );
    g_assert( object_create_struct.is_called == TRUE );
    g_assert( object_create_struct.inst == inst );

    g_object_unref( inst );
    qof_book_destroy( book );
}
예제 #8
0
static void
test_qof_object_compliance( Fixture *fixture, gconstpointer pData )
{
    g_assert( qof_object_register( fixture->qofobject ) );

    g_test_message( "Test when neither create nor foreach set" );
    g_assert( qof_object_compliance( fixture->qofobject->e_type, FALSE ) == FALSE );
    g_assert( qof_object_compliance( fixture->qofobject->e_type, TRUE ) == FALSE );

    g_test_message( "Test when only create set" );
    fixture->qofobject->create = mock_object_create;
    g_assert( qof_object_compliance( fixture->qofobject->e_type, FALSE ) == FALSE );
    g_assert( qof_object_compliance( fixture->qofobject->e_type, TRUE ) == FALSE );

    g_test_message( "Test when only foreach set" );
    fixture->qofobject->create = NULL;
    fixture->qofobject->foreach = mock_object_foreach;
    g_assert( qof_object_compliance( fixture->qofobject->e_type, FALSE ) == FALSE );
    g_assert( qof_object_compliance( fixture->qofobject->e_type, TRUE ) == FALSE );

    g_test_message( "Test when both set" );
    fixture->qofobject->create = mock_object_create;
    fixture->qofobject->foreach = mock_object_foreach;
    g_assert( qof_object_compliance( fixture->qofobject->e_type, FALSE ) == TRUE );
    g_assert( qof_object_compliance( fixture->qofobject->e_type, TRUE ) == TRUE );
}
예제 #9
0
gboolean gncEmployeeRegister (void)
{
    static QofParam params[] =
    {
        { EMPLOYEE_ID, QOF_TYPE_STRING, (QofAccessFunc)gncEmployeeGetID, (QofSetterFunc)gncEmployeeSetID },
        {
            EMPLOYEE_USERNAME, QOF_TYPE_STRING, (QofAccessFunc)gncEmployeeGetUsername,
            (QofSetterFunc)gncEmployeeSetUsername
        },
        {
            EMPLOYEE_LANGUAGE, QOF_TYPE_STRING, (QofAccessFunc)gncEmployeeGetLanguage,
            (QofSetterFunc)gncEmployeeSetLanguage
        },
        { EMPLOYEE_ACL, QOF_TYPE_STRING, (QofAccessFunc)gncEmployeeGetAcl, (QofSetterFunc)gncEmployeeSetAcl },
        {
            EMPLOYEE_WORKDAY, QOF_TYPE_NUMERIC, (QofAccessFunc)gncEmployeeGetWorkday,
            (QofSetterFunc)gncEmployeeSetWorkday
        },
        { EMPLOYEE_RATE, QOF_TYPE_NUMERIC, (QofAccessFunc)gncEmployeeGetRate, (QofSetterFunc)gncEmployeeSetRate },
        { EMPLOYEE_ADDR, GNC_ID_ADDRESS, (QofAccessFunc)gncEmployeeGetAddr, (QofSetterFunc)qofEmployeeSetAddr },
        { EMPLOYEE_CC,  GNC_ID_ACCOUNT, (QofAccessFunc)gncEmployeeGetCCard, (QofSetterFunc)gncEmployeeSetCCard },
        { QOF_PARAM_ACTIVE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncEmployeeGetActive, (QofSetterFunc)gncEmployeeSetActive },
        { QOF_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL },
        { QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL },
        { NULL },
    };

    qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncEmployeeCompare, params);

    return qof_object_register (&gncEmployeeDesc);
}
예제 #10
0
gboolean mygrandRegister (void)
{
    static QofParam params[] =
    {
        {
            OBJ_NAME,     QOF_TYPE_STRING,  (QofAccessFunc)grand_getName,
            (QofSetterFunc)grand_setName
        },
        {
            OBJ_AMOUNT,   QOF_TYPE_NUMERIC, (QofAccessFunc)grand_getAmount,
            (QofSetterFunc)grand_setAmount
        },
        {
            OBJ_DATE,     QOF_TYPE_DATE,    (QofAccessFunc)grand_getDate,
            (QofSetterFunc)grand_setDate
        },
        {
            OBJ_DISCOUNT, QOF_TYPE_DOUBLE,  (QofAccessFunc)grand_getDiscount,
            (QofSetterFunc)grand_setDiscount
        },
        {
            OBJ_ACTIVE,   QOF_TYPE_BOOLEAN, (QofAccessFunc)grand_getActive,
            (QofSetterFunc)grand_setActive
        },
        {
            OBJ_VERSION,  QOF_TYPE_INT32,   (QofAccessFunc)grand_getVersion,
            (QofSetterFunc)grand_setVersion
        },
        {
            OBJ_MINOR,    QOF_TYPE_INT64,	  (QofAccessFunc)grand_getMinor,
            (QofSetterFunc)grand_setMinor
        },
        {
            OBJ_FLAG,     QOF_TYPE_CHAR,    (QofAccessFunc)grand_getFlag,
            (QofSetterFunc)grand_setFlag
        },
        {
            OBJ_RELATIVE,	PARENT_MODULE_NAME, (QofAccessFunc)grand_getChild,
            (QofSetterFunc)grand_setChild
        },
        {
            OBJ_LIST,    QOF_TYPE_COLLECT,  (QofAccessFunc)grand_getDescend,
            (QofSetterFunc)grand_setDescend
        },
        { QOF_PARAM_BOOK, QOF_ID_BOOK,	(QofAccessFunc)qof_instance_get_book, NULL },
        { QOF_PARAM_GUID, QOF_TYPE_GUID,	(QofAccessFunc)qof_instance_get_guid, NULL },
        { NULL },
    };

    qof_class_register (GRAND_MODULE_NAME, NULL, params);
    /*  if(!qof_choice_create(GRAND_MODULE_NAME)) { return FALSE; }*/

    return qof_object_register (&grand_object_def);
}
예제 #11
0
static void
test_qof_object_get_type_label( Fixture *fixture, gconstpointer pData )
{
    g_assert( qof_object_get_type_label( NULL ) == NULL );

    g_test_message( "Test with non existing object" );
    g_assert( qof_object_get_type_label( "anytype" ) == NULL );

    g_test_message( "Test with existing registered object" );
    g_assert( qof_object_register( fixture->qofobject ) == TRUE );
    g_assert_cmpstr( qof_object_get_type_label( "my type object" ), == , "object desc" );
}
예제 #12
0
gboolean gncEntryRegister (void)
{
    static QofParam params[] =
    {
        { ENTRY_DATE, QOF_TYPE_DATE, (QofAccessFunc)gncEntryGetDate, (QofSetterFunc)gncEntrySetDate },
        { ENTRY_DATE_ENTERED, QOF_TYPE_DATE, (QofAccessFunc)gncEntryGetDateEntered, (QofSetterFunc)gncEntrySetDateEntered },
        { ENTRY_DESC, QOF_TYPE_STRING, (QofAccessFunc)gncEntryGetDescription, (QofSetterFunc)gncEntrySetDescription },
        { ENTRY_ACTION, QOF_TYPE_STRING, (QofAccessFunc)gncEntryGetAction, (QofSetterFunc)gncEntrySetAction },
        { ENTRY_NOTES, QOF_TYPE_STRING, (QofAccessFunc)gncEntryGetNotes, (QofSetterFunc)gncEntrySetNotes },
        { ENTRY_QTY, QOF_TYPE_NUMERIC, (QofAccessFunc)gncEntryGetQuantity, (QofSetterFunc)gncEntrySetQuantity },
        { ENTRY_IPRICE, QOF_TYPE_NUMERIC, (QofAccessFunc)gncEntryGetInvPrice, (QofSetterFunc)gncEntrySetInvPrice },
        { ENTRY_BPRICE, QOF_TYPE_NUMERIC, (QofAccessFunc)gncEntryGetBillPrice, (QofSetterFunc)gncEntrySetBillPrice },
        { ENTRY_INVOICE, GNC_ID_INVOICE, (QofAccessFunc)gncEntryGetInvoice, NULL },
        { ENTRY_IACCT, GNC_ID_ACCOUNT,  (QofAccessFunc)gncEntryGetInvAccount,  (QofSetterFunc)gncEntrySetInvAccount  },
        { ENTRY_BACCT, GNC_ID_ACCOUNT,  (QofAccessFunc)gncEntryGetBillAccount, (QofSetterFunc)gncEntrySetBillAccount },
        { ENTRY_BILL, GNC_ID_INVOICE, (QofAccessFunc)gncEntryGetBill, NULL },
        {
            ENTRY_INV_DISC_TYPE, QOF_TYPE_STRING, (QofAccessFunc)qofEntryGetInvDiscType,
            (QofSetterFunc)qofEntrySetInvDiscType
        },
        {
            ENTRY_INV_DISC_HOW, QOF_TYPE_STRING, (QofAccessFunc)qofEntryGetInvDiscHow,
            (QofSetterFunc)qofEntrySetInvDiscHow
        },
        {
            ENTRY_INV_TAXABLE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncEntryGetInvTaxable,
            (QofSetterFunc)gncEntrySetInvTaxable
        },
        {
            ENTRY_INV_TAX_INC, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncEntryGetInvTaxIncluded,
            (QofSetterFunc)gncEntrySetInvTaxIncluded
        },
        {
            ENTRY_BILL_TAXABLE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncEntryGetInvTaxable,
            (QofSetterFunc)gncEntrySetInvTaxable
        },
        {
            ENTRY_BILL_TAX_INC, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncEntryGetBillTaxIncluded,
            (QofSetterFunc)gncEntrySetBillTaxIncluded
        },
        { ENTRY_BILLABLE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncEntryGetBillable, (QofSetterFunc)gncEntrySetBillable },
        { ENTRY_BILLTO, GNC_ID_OWNER, (QofAccessFunc)gncEntryGetBillTo, (QofSetterFunc)gncEntrySetBillTo },
        { ENTRY_ORDER, GNC_ID_ORDER, (QofAccessFunc)gncEntryGetOrder, NULL },
        { QOF_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL },
        { QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL },
        { NULL },
    };

    qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncEntryCompare, params);

    return qof_object_register (&gncEntryDesc);
}
예제 #13
0
static void
test_qof_object_lookup( Fixture *fixture, gconstpointer pData )
{
    g_test_message( "Test null check" );
    g_assert( qof_object_lookup( NULL ) == NULL );

    g_test_message( "Test existing object lookup" );
    g_assert( qof_object_register( fixture->qofobject ) == TRUE );
    g_assert( qof_object_lookup( "my type object" ) == fixture->qofobject );

    g_test_message( "Test non existing object lookup" );
    g_assert( qof_object_lookup( "anytype" ) == NULL );
}
예제 #14
0
gboolean myparentRegister (void)
{
    static QofParam params[] =
    {
        {
            OBJ_NAME,     QOF_TYPE_STRING,  (QofAccessFunc)parent_getName,
            (QofSetterFunc)parent_setName
        },
        {
            OBJ_AMOUNT,   QOF_TYPE_NUMERIC, (QofAccessFunc)parent_getAmount,
            (QofSetterFunc)parent_setAmount
        },
        {
            OBJ_DATE,     QOF_TYPE_DATE,    (QofAccessFunc)parent_getDate,
            (QofSetterFunc)parent_setDate
        },
        {
            OBJ_DISCOUNT, QOF_TYPE_DOUBLE,  (QofAccessFunc)parent_getDiscount,
            (QofSetterFunc)parent_setDiscount
        },
        {
            OBJ_ACTIVE,   QOF_TYPE_BOOLEAN, (QofAccessFunc)parent_getActive,
            (QofSetterFunc)parent_setActive
        },
        {
            OBJ_VERSION,  QOF_TYPE_INT32,   (QofAccessFunc)parent_getVersion,
            (QofSetterFunc)parent_setVersion
        },
        {
            OBJ_MINOR,    QOF_TYPE_INT64,	  (QofAccessFunc)parent_getMinor,
            (QofSetterFunc)parent_setMinor
        },
        {
            OBJ_FLAG,     QOF_TYPE_CHAR,    (QofAccessFunc)parent_getFlag,
            (QofSetterFunc)parent_setFlag
        },
        {
            OBJ_RELATIVE,	CHILD_MODULE_NAME, (QofAccessFunc)parent_getChild,
            (QofSetterFunc)parent_setChild
        },
        { QOF_PARAM_BOOK, QOF_ID_BOOK,	(QofAccessFunc)qof_instance_get_book, NULL },
        { QOF_PARAM_GUID, QOF_TYPE_GUID,	(QofAccessFunc)qof_instance_get_guid, NULL },
        { NULL },
    };

    qof_class_register (PARENT_MODULE_NAME, NULL, params);

    return qof_object_register (&parent_object_def);
}
예제 #15
0
파일: gncTaxTable.c 프로젝트: mlq/gnucash
gboolean gncTaxTableRegister (void)
{
    static QofParam params[] =
    {
        { GNC_TT_NAME, 		QOF_TYPE_STRING, 	(QofAccessFunc)gncTaxTableGetName, 		(QofSetterFunc)gncTaxTableSetName },
        { GNC_TT_REFCOUNT, 	QOF_TYPE_INT64, 	(QofAccessFunc)gncTaxTableGetRefcount, 	(QofSetterFunc)gncTaxTableSetRefcount },
        { QOF_PARAM_BOOK, 	QOF_ID_BOOK, 		(QofAccessFunc)qof_instance_get_book, 	NULL },
        { QOF_PARAM_GUID, 	QOF_TYPE_GUID, 		(QofAccessFunc)qof_instance_get_guid, 	NULL },
        { NULL },
    };

    qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncTaxTableCompare, params);

    return qof_object_register (&gncTaxTableDesc);
}
예제 #16
0
static void
test_qof_object_register( Fixture *fixture, gconstpointer pData )
{
    GList *books = NULL;
    gint32 list_length = g_test_rand_int_range( 0, 5 );
    int i;
    QofObject *simple_object = NULL;

    for (i = 0; i < list_length; i++ )
    {
        QofBook *book = qof_book_new();
        g_assert( book );
        books = g_list_prepend ( books, book );
        g_assert_cmpint( g_list_length( books ), == , (i + 1) );
    }
    g_assert_cmpint( list_length, == , g_list_length( books ) );

    g_test_message( "Test null check" );
    g_assert( qof_object_register( NULL ) == FALSE );

    g_test_message( "Test new object register with book_begin specified" );
    fixture->qofobject->book_begin = mock_book_begin;
    book_begin_struct.books = books;
    book_begin_struct.call_count = 0;
    g_assert( qof_object_register( fixture->qofobject ) == TRUE );
    g_assert( qof_object_lookup( "my type object" ) == fixture->qofobject );
    g_assert_cmpint( book_begin_struct.call_count, == , list_length );

    g_test_message( "Test registering the same object one more time" );
    book_begin_struct.call_count = 0;
    g_assert( qof_object_register( fixture->qofobject ) == FALSE );
    g_assert( qof_object_lookup( "my type object" ) == fixture->qofobject );
    g_assert_cmpint( book_begin_struct.call_count, == , 0 );

    g_test_message( "Test new object register without book_begin specified" );
    simple_object = new_object( "my type simple", "simple desc", EMPTY );
    g_assert( qof_object_register( simple_object ) == TRUE );
    g_assert( qof_object_lookup( "my type simple" ) == simple_object );
    g_assert_cmpint( book_begin_struct.call_count, == , 0 );

    g_test_message( "Test register simple object one more time" );
    g_assert( qof_object_register( simple_object ) == FALSE );
    g_assert( qof_object_lookup( "my type simple" ) == simple_object );

    g_test_message( "Test book begin is called only one time when object is registered" );
    simple_object->book_begin = mock_book_begin;
    book_begin_struct.books = books;
    book_begin_struct.call_count = 0;
    g_assert( qof_object_register( simple_object ) == FALSE );
    g_assert_cmpint( book_begin_struct.call_count, == , 0 );

    g_list_foreach( books, (GFunc) qof_book_destroy, NULL );
    g_list_free( books );
    g_free( simple_object );
}
예제 #17
0
/*
 * Safely generates objects and registers them
 *
 * Input: min_objects - minimum number of objects to be generated (should be between 0 and 5)
 * 	  mock_filed - function in qofobject to be mocked
 * Output: number of generated objects
 */
static gint32
generate_and_register_objects( guint min_objects, MockFields mock_field )
{
    gint32 list_length = g_test_rand_int_range( min_objects, 5 );
    const char *types[5] = {"type1", "type2", "type3", "type4", "type5"};
    int i;

    g_assert_cmpint( min_objects, >= , 0 );
    g_assert_cmpint( min_objects, < , 5 );
    for (i = 0; i < list_length; i++ )
    {
        QofObject *object = new_object( types[i], "desc", mock_field );
        g_assert( object );
        g_assert( qof_object_register( object ) );
        g_assert_cmpint( g_list_length( get_object_modules() ), == , (i + 1) );
    }
    g_assert_cmpint( list_length, == , g_list_length( get_object_modules() ) );

    return list_length;
}
예제 #18
0
static void
test_qof_object_printable( Fixture *fixture, gconstpointer pData )
{
    gint param;

    g_test_message( "Test null checks" );
    g_assert( qof_object_printable( NULL, (gpointer)&param ) == NULL );
    g_assert( qof_object_printable( "test", NULL ) == NULL );

    g_test_message( "Test with non registered object" );
    g_assert( qof_object_printable( "test", (gpointer)&param ) == NULL );

    g_test_message( "Test with registered object and printable not set" );
    g_assert( qof_object_register( fixture->qofobject ) == TRUE );
    g_assert( qof_object_printable( "my type object", (gpointer)&param ) == NULL );

    g_test_message( "Test with registered object and printable set" );
    fixture->qofobject->printable = mock_printable;
    printable_struct.param = (gpointer)&param;
    g_assert_cmpstr( qof_object_printable( "my type object", (gpointer)&param ), == , "printable was called" );
}
예제 #19
0
gboolean gncBillTermRegister (void)
{
    static QofParam params[] =
    {
        { GNC_BILLTERM_NAME, 		QOF_TYPE_STRING,  (QofAccessFunc)gncBillTermGetName,			(QofSetterFunc)gncBillTermSetName },
        { GNC_BILLTERM_DESC, 		QOF_TYPE_STRING,  (QofAccessFunc)gncBillTermGetDescription,		(QofSetterFunc)gncBillTermSetDescription },
        { GNC_BILLTERM_TYPE, QOF_TYPE_STRING, (QofAccessFunc)qofBillTermGetType, (QofSetterFunc)qofBillTermSetType },
        { GNC_BILLTERM_DUEDAYS, 	QOF_TYPE_INT32,   (QofAccessFunc)gncBillTermGetDueDays, 		(QofSetterFunc)gncBillTermSetDueDays },
        { GNC_BILLTERM_DISCDAYS, 	QOF_TYPE_INT32,   (QofAccessFunc)gncBillTermGetDiscountDays,	(QofSetterFunc)gncBillTermSetDiscountDays },
        { GNC_BILLTERM_DISCOUNT, 	QOF_TYPE_NUMERIC, (QofAccessFunc)gncBillTermGetDiscount,		(QofSetterFunc)gncBillTermSetDiscount },
        { GNC_BILLTERM_CUTOFF, 		QOF_TYPE_INT32,   (QofAccessFunc)gncBillTermGetCutoff, 			(QofSetterFunc)gncBillTermSetCutoff },
        { GNC_BILLTERM_REFCOUNT, 	QOF_TYPE_INT64,   (QofAccessFunc)gncBillTermGetRefcount, 		NULL },
        { QOF_PARAM_BOOK, 			QOF_ID_BOOK, 	  (QofAccessFunc)qof_instance_get_book, 		NULL },
        { QOF_PARAM_GUID, 			QOF_TYPE_GUID, 	  (QofAccessFunc)qof_instance_get_guid, 		NULL },
        { NULL },
    };

    qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncBillTermCompare, params);

    return qof_object_register (&gncBillTermDesc);
}
예제 #20
0
static void
test_qof_object_foreach_sorted( Fixture *fixture, gconstpointer pData )
{
    int i;
    gint32 list_length = g_test_rand_int_range( 0, 5 );
    gint user_data;
    QofBook *book = NULL;
    QofCollection *col = NULL;
    foreach_for_sorted_struct.instances = NULL;

    /* setup */
    book = qof_book_new();
    g_assert( book );
    g_assert_cmpint( g_list_length( get_object_modules() ), == , 0 );
    qof_object_register( fixture->qofobject );
    g_assert_cmpint( g_list_length( get_object_modules() ), == , 1 );

    fixture->qofobject->foreach = mock_foreach_for_sorted;
    /* init instances */
    col = qof_book_get_collection( book, fixture->qofobject->e_type );
    for (i = 0; i < list_length; i++ )
    {
        QofInstance * inst = g_object_new( QOF_TYPE_INSTANCE, NULL );
        g_assert( QOF_IS_INSTANCE( inst ) );
        foreach_for_sorted_struct.instances = g_list_append( foreach_for_sorted_struct.instances, inst );
        qof_collection_insert_entity( col, inst );
    }
    g_assert_cmpint( list_length, == , g_list_length( foreach_for_sorted_struct.instances ) );

    foreach_for_sorted_struct.call_count = 0;
    foreach_for_sorted_struct.user_data = &user_data;
    qof_object_foreach_sorted( fixture->qofobject->e_type, book, mock_instance_foreach_cb_for_sorted, ( gpointer ) &user_data );
    g_assert_cmpint( list_length, == , foreach_for_sorted_struct.call_count );

    qof_book_destroy( book );
    g_list_free( foreach_for_sorted_struct.instances );
}
예제 #21
0
void
qof_gobject_register (QofType e_type, GObjectClass *obclass)
{
    int i;
    int j;
    QofParam *qof_param_list, *qpar;
    QofObject *class_def;
    GParamSpec **prop_list, *gparam;
    guint n_props;

    /* Get the GObject properties, convert to QOF properties */
    prop_list = g_object_class_list_properties (obclass, &n_props);

    qof_param_list = g_new0 (QofParam, n_props);
    paramList = g_slist_prepend (paramList, qof_param_list);

    PINFO ("object %s has %d props", e_type, n_props);
    j = 0;
    for (i = 0; i < n_props; i++)
    {
        gparam = prop_list[i];
        qpar = &qof_param_list[j];

        PINFO ("param %d %s is type %s",
               i, gparam->name, G_PARAM_SPEC_TYPE_NAME(gparam));

        qpar->param_name = g_param_spec_get_name (gparam);
        qpar->param_getfcn = (QofAccessFunc)qof_gobject_getter;
        qpar->param_setfcn = NULL;
        qpar->param_userdata = gparam;
        if ((G_IS_PARAM_SPEC_INT(gparam))  ||
                (G_IS_PARAM_SPEC_UINT(gparam)) ||
                (G_IS_PARAM_SPEC_ENUM(gparam)) ||
                (G_IS_PARAM_SPEC_FLAGS(gparam)))
        {
            qpar->param_type = QOF_TYPE_INT32;
            j++;
        }
        else if ((G_IS_PARAM_SPEC_INT64(gparam)) ||
                 (G_IS_PARAM_SPEC_UINT64(gparam)))
        {
            qpar->param_type = QOF_TYPE_INT64;
            j++;
        }
        else if (G_IS_PARAM_SPEC_BOOLEAN(gparam))
        {
            qpar->param_type = QOF_TYPE_BOOLEAN;
            j++;
        }
        else if (G_IS_PARAM_SPEC_STRING(gparam))
        {
            qpar->param_type = QOF_TYPE_STRING;
            j++;
        }
        else if ((G_IS_PARAM_SPEC_POINTER(gparam)) ||
                 (G_IS_PARAM_SPEC_OBJECT(gparam)))
        {
            /* No-op, silently ignore.  Someday we should handle this ...  */
        }
        else if ((G_IS_PARAM_SPEC_FLOAT(gparam)) ||
                 (G_IS_PARAM_SPEC_DOUBLE(gparam)))
        {
            qpar->param_getfcn = (QofAccessFunc) qof_gobject_double_getter;
            qpar->param_type = QOF_TYPE_DOUBLE;
            j++;
        }
        else if (G_IS_PARAM_SPEC_CHAR(gparam))
        {
            qpar->param_type = QOF_TYPE_CHAR;
            j++;
        }
        else
        {
            PWARN ("Unknown/unhandled parameter type %s on %s:%s\n",
                   G_PARAM_SPEC_TYPE_NAME(gparam), e_type, qpar->param_name);
        }
    }

    /* NULL-terminated list! */
    qof_param_list[j].param_type = NULL;

    qof_class_register (e_type, NULL, qof_param_list);

    /* ------------------------------------------------------ */
    /* Now do the class itself */
    class_def = g_new0 (QofObject, 1);
    classList = g_slist_prepend (classList, class_def);

    class_def->interface_version = QOF_OBJECT_VERSION;
    class_def->e_type = e_type;
    /* We could let the user specify a "nick" here, but
     * the actual class name seems reasonable, e.g. for debugging. */
    class_def->type_label = G_OBJECT_CLASS_NAME (obclass);
    class_def->create = NULL;
    class_def->book_begin = NULL;
    class_def->book_end = NULL;
    class_def->is_dirty = NULL;
    class_def->mark_clean = NULL;
    class_def->foreach = qof_gobject_foreach;
    class_def->printable = NULL;
    class_def->version_cmp = NULL;

    qof_object_register (class_def);
}