Example #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);
}
Example #2
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 );
}
Example #3
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 );
}
Example #4
0
void
qof_object_foreach (QofIdTypeConst type_name, QofBook *book,
                    QofInstanceForeachCB cb, void * user_data)
{
    QofCollection *col;
    const QofObject *obj;

    if (!book || !type_name)
    {
        return;
    }
    PINFO ("type=%s", type_name);

    obj = qof_object_lookup (type_name);
    if (!obj)
    {
        PERR ("No object of type %s", type_name);
        return;
    }
    col = qof_book_get_collection (book, obj->e_type);
    if (!obj)
    {
        return;
    }
    if (obj->foreach)
    {
        obj->foreach (col, cb, user_data);
    }
    return;
}
Example #5
0
const char * qof_object_get_type_label (QofIdTypeConst type_name)
{
    const QofObject *obj;

    if (!type_name) return NULL;

    obj = qof_object_lookup (type_name);
    if (!obj) return NULL;

    return (obj->type_label);
}
Example #6
0
void *
qof_object_new_instance (QofIdTypeConst type_name, QofBook *book)
{
    const QofObject *obj;

    if (!type_name) return NULL;

    obj = qof_object_lookup (type_name);
    if (!obj) return NULL;

    if (obj->create)
        return (obj->create (book));

    return NULL;
}
Example #7
0
const char *
qof_object_printable (QofIdTypeConst type_name, void * obj)
{
    const QofObject *b_obj;

    if (!type_name || !obj) return NULL;

    b_obj = qof_object_lookup (type_name);
    if (!b_obj) return NULL;

    if (b_obj->printable)
        return (b_obj->printable (obj));

    return NULL;
}
Example #8
0
bool
qof_object_compliance (QofIdTypeConst type_name, bool warn)
{
    const QofObject *obj;

    obj = qof_object_lookup(type_name);
    if ((obj->create == NULL) || (obj->foreach == NULL))
    {
        if (warn)
        {
            PINFO (" Object type %s is not fully QOF compliant", obj->e_type);
        }
        return false;
    }
    return true;
}