From ed732e6a39ad9d66fe61996d542ae82b7741f7ef Mon Sep 17 00:00:00 2001 From: John Ralls Date: Sat, 18 Jun 2011 23:20:30 +0000 Subject: [PATCH] Unit test QofBook git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@20769 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/libqof/qof/test/test-qofbook.c | 587 ++++++++++++++++++++++++++++- 1 file changed, 585 insertions(+), 2 deletions(-) diff --git a/src/libqof/qof/test/test-qofbook.c b/src/libqof/qof/test/test-qofbook.c index 39f34611cc..1effaf4613 100644 --- a/src/libqof/qof/test/test-qofbook.c +++ b/src/libqof/qof/test/test-qofbook.c @@ -24,6 +24,8 @@ #include #include "qof.h" #include "qofbook-p.h" +#include "qofbookslots.h" +#include "test-stuff.h" static const gchar *suitename = "/qof/qofbook"; void test_suite_qofbook ( void ); @@ -33,6 +35,21 @@ typedef struct QofBook *book; } Fixture; +static struct +{ + guint param; + gpointer data; + gboolean called; + gchar* msg; +} test_struct; + +static struct +{ + gboolean col1_called; + gboolean col2_called; + gpointer data; +} col_struct; + static void setup( Fixture *fixture, gconstpointer pData ) { @@ -45,6 +62,52 @@ teardown( Fixture *fixture, gconstpointer pData ) qof_book_destroy( fixture->book ); } +/* use g_free on test_struct.msg after this function been called */ +static gboolean +handle_faults ( const char * log_domain, GLogLevelFlags log_level, const gchar *msg, gpointer user_data) +{ + test_struct.msg = (gchar *) g_strdup( msg ); + return FALSE; +} + +/* mock dirty callback function */ +static void +mock_dirty_cb (QofBook *book, gboolean dirty, gpointer user_data) +{ + test_struct.called = TRUE; + g_test_message( "Checking if book is valid" ); + g_assert( book ); + g_assert( QOF_IS_BOOK( book ) ); + g_test_message( "Checking parameters" ); + g_assert( dirty ); + g_assert( user_data == test_struct.data ); +} + +/* mock callback for qof_book_foreach_collection testing */ +static void +mock_foreach_collection (QofCollection *col, gpointer user_data) +{ + g_test_message( "Checking if collection and data passed correctly" ); + g_assert( col ); + g_assert( user_data == col_struct.data ); + if ( g_strcmp0( qof_collection_get_type(col), "my_type" ) == 0 ) + col_struct.col1_called = TRUE; + else if ( g_strcmp0( qof_collection_get_type(col), "my_type2" ) == 0 ) + col_struct.col2_called = TRUE; +} + +/* mock final callback function */ +static void +mock_final_cb (QofBook *book, gpointer key, gpointer user_data) +{ + test_struct.called = TRUE; + g_assert( book ); + g_assert( QOF_IS_BOOK( book ) ); + g_test_message( "Checking parameters" ); + g_assert_cmpstr( (gchar*)key, ==, "key" ); + g_assert_cmpstr( (gchar*)user_data, ==, "data" ); +} + static void test_book_readonly( Fixture *fixture, gconstpointer pData ) { @@ -114,9 +177,529 @@ test_book_validate_counter( void ) g_free(r); } +static void +test_book_get_string_option( Fixture *fixture, gconstpointer pData ) +{ + const char *opt_name = "Option Name"; + const char *opt_value = "Option Value"; + const char *opt_name_notset = "Not Set"; + g_assert( fixture->book != NULL ); + qof_book_set_string_option( fixture->book, opt_name, opt_value); + g_assert_cmpstr( qof_book_get_string_option( fixture->book, opt_name ), ==, opt_value); + g_assert_cmpstr( qof_book_get_string_option( fixture->book, opt_name_notset ), ==, NULL ); +} + +static void +test_book_set_string_option( Fixture *fixture, gconstpointer pData ) +{ + const char *opt_name = "Option Name"; + const char *opt_value = "Option Value"; + g_assert( fixture->book != NULL ); + qof_book_set_string_option( fixture->book, opt_name, opt_value); + g_assert( qof_book_not_saved( fixture->book ) ); +} + +static void +test_book_not_saved( Fixture *fixture, gconstpointer pData ) +{ + const char *opt_name = "Option Name"; + const char *opt_value = "Option Value"; + g_assert( fixture->book != NULL ); + g_assert( !qof_book_not_saved( fixture->book ) ); + qof_book_set_string_option( fixture->book, opt_name, opt_value ); + g_assert( qof_book_not_saved( fixture->book ) ); + qof_book_mark_saved( fixture->book ); + g_assert( !qof_book_not_saved( fixture->book ) ); + qof_book_mark_dirty( fixture-> book ); + g_assert( qof_book_not_saved( fixture->book ) ); +} + +static void +test_book_mark_saved( Fixture *fixture, gconstpointer pData ) +{ + time_t dirty_time, clean_time; + + qof_book_mark_dirty( fixture-> book ); + g_assert( qof_book_not_saved( fixture->book ) ); + dirty_time = qof_book_get_dirty_time( fixture->book ); + qof_book_mark_saved( fixture->book ); + clean_time = qof_book_get_dirty_time( fixture->book ); + g_assert( !qof_book_not_saved( fixture->book ) ); + g_assert( dirty_time != clean_time ); + g_assert( clean_time == 0); +} + +static void +test_book_get_counter( Fixture *fixture, gconstpointer pData ) +{ + const char *counter_name = "Counter name"; + const char *err_no_book = "No book"; + const char *err_invalid_cnt = "Invalid counter name"; + gint64 counter; + + /* need this as long as we have fatal warnings enabled */ + g_test_log_set_fatal_handler ( ( GTestLogFatalFunc )handle_faults, NULL ); + + counter = qof_book_get_counter( NULL, counter_name ); + g_assert_cmpint( counter, ==, -1 ); + g_assert( g_strrstr( test_struct.msg, err_no_book ) != NULL ); + g_free( test_struct.msg ); + + counter = qof_book_get_counter( fixture->book, NULL ); + g_assert_cmpint( counter, ==, -1 ); + g_assert( g_strrstr( test_struct.msg, err_invalid_cnt ) != NULL ); + g_free( test_struct.msg ); + + counter = qof_book_get_counter( fixture->book, '\0' ); + g_assert_cmpint( counter, ==, -1 ); + g_assert( g_strrstr( test_struct.msg, err_invalid_cnt ) != NULL ); + g_free( test_struct.msg ); + + counter = qof_book_get_counter( fixture->book, counter_name ); + g_assert_cmpint( counter, ==, 0 ); + + qof_book_increment_and_format_counter( fixture->book, counter_name ); + counter = qof_book_get_counter( fixture->book, counter_name ); + g_assert_cmpint( counter, ==, 1 ); +} + +static void +test_book_get_counter_format ( Fixture *fixture, gconstpointer pData ) +{ + const char *counter_name = "Counter name"; + const char *counter_name_not_set = "Counter name not set"; + const char *err_no_book = "No book"; + const char *err_invalid_cnt = "Invalid counter name"; + gchar *r; + gint64 counter; + + /* need this as long as we have fatal warnings enabled */ + g_test_log_set_fatal_handler ( ( GTestLogFatalFunc )handle_faults, NULL ); + + g_test_message( "Testing counter format when book is null" ); + r = qof_book_get_counter_format( NULL, counter_name ); + g_assert_cmpstr( r, ==, NULL ); + g_assert( g_strrstr( test_struct.msg, err_no_book ) != NULL ); + g_free( test_struct.msg ); + + g_test_message( "Testing counter format when counter name is null" ); + r = qof_book_get_counter_format( fixture->book, NULL ); + g_assert_cmpstr( r, ==, NULL ); + g_assert( g_strrstr( test_struct.msg, err_invalid_cnt ) != NULL ); + g_free( test_struct.msg ); + + g_test_message( "Testing counter format when counter name is empty string" ); + r = qof_book_get_counter_format( fixture->book, '\0' ); + g_assert_cmpstr( r, ==, NULL ); + g_assert( g_strrstr( test_struct.msg, err_invalid_cnt ) != NULL ); + g_free( test_struct.msg ); + + g_test_message( "Testing counter format with existing counter" ); + counter = qof_book_get_counter( fixture->book, counter_name ); + r = qof_book_get_counter_format( fixture->book, counter_name ); + g_assert_cmpstr( r, ==, "%.6" G_GINT64_FORMAT); + + g_test_message( "Testing counter format for default value" ); + r = qof_book_get_counter_format( fixture->book, counter_name ); + g_assert_cmpstr( r, ==, "%.6" G_GINT64_FORMAT); +} + +static void +test_book_increment_and_format_counter ( Fixture *fixture, gconstpointer pData ) +{ + const char *counter_name = "Counter name"; + const char *err_no_book = "No book"; + const char *err_invalid_cnt = "Invalid counter name"; + gchar *format; + gchar *r; + gint64 counter; + + /* need this as long as we have fatal warnings enabled */ + g_test_log_set_fatal_handler ( ( GTestLogFatalFunc )handle_faults, NULL ); + + g_test_message( "Testing increment and format when book is null" ); + r = qof_book_increment_and_format_counter( NULL, counter_name ); + g_assert_cmpstr( r, ==, NULL ); + g_free( r ); + g_assert( g_strrstr( test_struct.msg, err_no_book ) != NULL ); + g_free( test_struct.msg ); + + g_test_message( "Testing increment and format when counter name is null" ); + r = qof_book_increment_and_format_counter( fixture->book, NULL ); + g_assert_cmpstr( r, ==, NULL ); + g_free( r ); + g_assert( g_strrstr( test_struct.msg, err_invalid_cnt ) != NULL ); + g_free( test_struct.msg ); + + g_test_message( "Testing increment and format when counter name is empty string" ); + r = qof_book_increment_and_format_counter( fixture->book, '\0' ); + g_assert_cmpstr( r, ==, NULL ); + g_free( r ); + g_assert( g_strrstr( test_struct.msg, err_invalid_cnt ) != NULL ); + g_free( test_struct.msg ); + + g_test_message( "Testing increment and format with new counter" ); + r = qof_book_increment_and_format_counter( fixture->book, counter_name ); + counter = qof_book_get_counter( fixture->book, counter_name ); + format = qof_book_get_counter_format( fixture->book, counter_name ); + g_assert_cmpint( counter, ==, 1 ); + g_assert( qof_book_not_saved( fixture->book ) ); + g_assert_cmpstr( r, ==, g_strdup_printf( format, counter )); + g_free( r ); + + g_test_message( "Testing increment and format with existing counter" ); + r = qof_book_increment_and_format_counter( fixture->book, counter_name ); + counter = qof_book_get_counter( fixture->book, counter_name ); + format = qof_book_get_counter_format( fixture->book, counter_name ); + g_assert_cmpint( counter, ==, 2 ); + g_assert_cmpstr( r, ==, g_strdup_printf( format, counter )); + g_free( r ); +} + +static void +test_book_kvp_changed( Fixture *fixture, gconstpointer pData ) +{ + g_test_message( "Testing book is marked dirty after kvp_changed" ); + g_assert( !qof_book_not_saved( fixture->book ) ); + qof_book_kvp_changed( fixture->book ); + g_assert( qof_book_not_saved( fixture->book ) ); +} + +static void +test_book_use_trading_accounts( Fixture *fixture, gconstpointer pData ) +{ + const char *slot_path; + + /* create correct slot path */ + slot_path = (const char *) g_strconcat( KVP_OPTION_PATH, "/", OPTION_SECTION_ACCOUNTS, "/", OPTION_NAME_TRADING_ACCOUNTS, NULL ); + g_assert( slot_path != NULL ); + + g_test_message( "Testing when no trading accounts are used" ); + g_assert( qof_book_use_trading_accounts( fixture-> book ) == FALSE ); + + g_test_message( "Testing with incorrect slot path and correct value - t" ); + qof_book_set_string_option( fixture->book, OPTION_NAME_TRADING_ACCOUNTS, "t" ); + g_assert( qof_book_use_trading_accounts( fixture-> book ) == FALSE ); + + g_test_message( "Testing with existing trading accounts set to true - t" ); + qof_book_set_string_option( fixture->book, slot_path, "t" ); + g_assert( qof_book_use_trading_accounts( fixture-> book ) == TRUE ); + + g_test_message( "Testing with existing trading accounts and incorrect value - tt" ); + qof_book_set_string_option( fixture->book, slot_path, "tt" ); + g_assert( qof_book_use_trading_accounts( fixture-> book ) == FALSE ); + +} + +static void +test_book_mark_dirty( Fixture *fixture, gconstpointer pData ) +{ + QofBook *_empty = NULL; + time_t before, after; + guint param = (guint) g_test_rand_int(); + + g_test_message( "Testing when book is NULL" ); + qof_book_mark_dirty( _empty ); + g_assert( _empty == NULL ); + + g_test_message( "Testing when book is not dirty and dirty_cb is null" ); + g_assert_cmpint( qof_book_get_dirty_time( fixture->book ), ==, 0); + g_assert( fixture->book->dirty_cb == NULL ); + g_assert( qof_book_not_saved( fixture->book ) == FALSE ); + before = time( NULL ); + qof_book_mark_dirty( fixture->book ); + after = time( NULL ); + g_assert_cmpint( qof_book_get_dirty_time( fixture->book ), >=, before); + g_assert_cmpint( qof_book_get_dirty_time( fixture->book ), <=, after); + g_assert( qof_book_not_saved( fixture->book ) == TRUE ); + + g_test_message( "Testing when book is not dirty and dirty_cb is not null" ); + /* prepare conditions */ + qof_book_mark_saved( fixture->book ); + qof_book_set_dirty_cb( fixture->book, mock_dirty_cb, (gpointer) (¶m) ); + test_struct.data = (gpointer) (¶m); + test_struct.called = FALSE; + g_assert( fixture->book->dirty_cb != NULL ); + g_assert_cmpint( qof_book_get_dirty_time( fixture->book ), ==, 0); + g_assert( qof_book_not_saved( fixture->book ) == FALSE ); + /* run FUT */ + before = time( NULL ); + qof_book_mark_dirty( fixture->book ); + after = time( NULL ); + /* test output */ + g_assert_cmpint( qof_book_get_dirty_time( fixture->book ), >=, before); + g_assert_cmpint( qof_book_get_dirty_time( fixture->book ), <=, after); + g_assert( qof_book_not_saved( fixture->book ) == TRUE ); + g_assert( test_struct.called ); + + g_test_message( "Testing when book is dirty" ); + g_assert( qof_book_not_saved( fixture->book ) == TRUE ); + before = qof_book_get_dirty_time( fixture->book ); + qof_book_mark_dirty( fixture->book ); + g_assert( qof_book_not_saved( fixture->book ) == TRUE ); + after = qof_book_get_dirty_time( fixture->book ); + g_assert_cmpint( before, ==, after ); +} + +static void +test_book_get_dirty_time( Fixture *fixture, gconstpointer pData ) +{ + time_t before, after; + + g_test_message( "Testing time on saved book = 0" ); + g_assert( qof_book_not_saved( fixture->book ) == FALSE ); + g_assert_cmpint( qof_book_get_dirty_time( fixture->book ), ==, 0); + + g_test_message( "Testing time on dirty book is correct" ); + before = time( NULL ); + qof_book_mark_dirty( fixture->book ); + after = time( NULL ); + g_assert_cmpint( qof_book_get_dirty_time( fixture->book ), >=, before); + g_assert_cmpint( qof_book_get_dirty_time( fixture->book ), <=, after); + +} + +static void +test_book_set_dirty_cb( Fixture *fixture, gconstpointer pData ) +{ + const char * error_msg = "Already existing callback"; + + g_test_message( "Testing when callback is previously not set" ); + g_assert( fixture->book->dirty_cb == NULL ); + qof_book_set_dirty_cb( fixture->book, mock_dirty_cb, (gpointer) (&test_struct) ); + g_assert( fixture->book->dirty_cb == mock_dirty_cb ); + g_assert( fixture->book->dirty_data == &test_struct ); + + /* need this as long as we have fatal warnings enabled */ + g_test_log_set_fatal_handler ( ( GTestLogFatalFunc )handle_faults, NULL ); + + g_test_message( "Testing when callback was previously set" ); + g_assert( fixture->book->dirty_cb != NULL ); + qof_book_set_dirty_cb( fixture->book, NULL, NULL ); + g_assert( g_strrstr( test_struct.msg, error_msg ) != NULL ); + g_assert( fixture->book->dirty_cb == NULL ); + g_assert( fixture->book->dirty_data == NULL ); + g_free( test_struct.msg ); +} + +static void +test_book_shutting_down( Fixture *fixture, gconstpointer pData ) +{ + g_test_message( "Testing when book is null" ); + g_assert( qof_book_shutting_down( NULL ) == FALSE ); + g_test_message( "Testing when shutting down is true" ); + fixture->book->shutting_down = TRUE; + g_assert( qof_book_shutting_down( fixture->book ) == TRUE ); + g_test_message( "Testing when shutting down is false" ); + fixture->book->shutting_down = FALSE; + g_assert( qof_book_shutting_down( fixture->book ) == FALSE ); +} + +static void +test_book_set_get_data( Fixture *fixture, gconstpointer pData ) +{ + const char *key = "key"; + const char *data = "data"; + + g_assert( fixture->book->data_tables != NULL ); + g_test_message( "Testing when book is null" ); + qof_book_set_data( NULL, key, (gpointer) data ); + g_assert( qof_book_get_data( NULL, key ) == NULL ); + + g_test_message( "Testing when key is null" ); + qof_book_set_data( fixture->book, NULL, (gpointer) data ); + g_assert( qof_book_get_data( fixture->book, NULL) == NULL ); + + g_test_message( "Testing with book key not null, data null" ); + qof_book_set_data( fixture->book, key, NULL ); + g_assert( qof_book_get_data( fixture->book, key ) == NULL ); + + g_test_message( "Testing with book key data not null" ); + qof_book_set_data( fixture->book, key, (gpointer) data ); + g_assert_cmpstr( (const char *)qof_book_get_data( fixture->book, key ), ==, data ); +} + +static void +test_book_get_collection( Fixture *fixture, gconstpointer pData ) +{ + QofIdType my_type = "my type"; + QofCollection *m_col, *m_col2; + + g_test_message( "Testing when book is null" ); + g_assert( qof_book_get_collection( NULL, my_type ) == NULL ); + + g_test_message( "Testing when entity type is null" ); + g_assert( qof_book_get_collection( fixture->book, NULL ) == NULL ); + + g_test_message( "Testing when collection does not exist" ); + g_assert( fixture->book->hash_of_collections != NULL ); + g_assert( g_hash_table_lookup ( fixture->book->hash_of_collections, my_type ) == NULL ); + m_col = qof_book_get_collection( fixture->book, my_type ); + g_assert( m_col != NULL ); + + g_test_message( "Testing with existing collection" ); + g_assert( g_hash_table_lookup ( fixture->book->hash_of_collections, my_type ) != NULL ); + m_col2 = qof_book_get_collection( fixture->book, my_type ); + g_assert( m_col2 != NULL ); + g_assert( m_col == m_col2 ); +} + +static void +test_book_foreach_collection( Fixture *fixture, gconstpointer pData ) +{ + QofCollection *m_col, *m_col2; + QofIdType my_type = "my_type", my_type2 = "my_type2"; + guint param = (guint) g_test_rand_int(); + + /* need this as long as we have fatal warnings enabled */ + g_test_log_set_fatal_handler ( ( GTestLogFatalFunc )handle_faults, NULL ); + + g_test_message( "Testing when book is null" ); + m_col = qof_book_get_collection( fixture->book, my_type ); + m_col2 = qof_book_get_collection( fixture->book, my_type2 ); + col_struct.col1_called = FALSE; + col_struct.col2_called = FALSE; + col_struct.data = (gpointer) (¶m); + /* launch foreach make sure callback was not called and check warning msg */ + qof_book_foreach_collection( NULL, mock_foreach_collection, (gpointer)(¶m) ); + g_assert( !col_struct.col1_called ); + g_assert( !col_struct.col2_called ); + g_assert_cmpstr( test_struct.msg, ==, "qof_book_foreach_collection: assertion `book' failed" ); + g_free( test_struct.msg ); + + g_test_message( "Testing when cb is null" ); + /* launching with empty cb should still fail and produce warning */ + qof_book_foreach_collection( fixture->book, NULL, (gpointer)(¶m) ); + g_assert( !col_struct.col1_called ); + g_assert( !col_struct.col2_called ); + g_assert_cmpstr( test_struct.msg, ==, "qof_book_foreach_collection: assertion `cb' failed" ); + g_free( test_struct.msg ); + + g_test_message( "Testing when book and cb not null, user_data provided" ); + /* both cols have to be called */ + qof_book_foreach_collection( fixture->book, mock_foreach_collection, (gpointer)(¶m) ); + g_assert( col_struct.col1_called ); + g_assert( col_struct.col2_called ); +} + +static void +test_book_set_data_fin( void ) +{ + QofBook *book; + const char *key = "key"; + const char *data = "data"; + + /* init */ + book = qof_book_new(); + g_assert_cmpint( g_hash_table_size( book->data_tables ), ==, 0 ); + g_assert_cmpint( g_hash_table_size( book->data_table_finalizers ), ==, 0 ); + + g_test_message( "Testing when book is null" ); + qof_book_set_data_fin( NULL, key, (gpointer) data, mock_final_cb ); + /* assert nothing was set */ + g_assert_cmpint( g_hash_table_size( book->data_tables ), ==, 0 ); + g_assert_cmpint( g_hash_table_size( book->data_table_finalizers ), ==, 0 ); + + g_test_message( "Testing when key is null" ); + qof_book_set_data_fin( book, NULL, (gpointer) data, mock_final_cb ); + /* nothing set as well */ + g_assert_cmpint( g_hash_table_size( book->data_tables ), ==, 0 ); + g_assert_cmpint( g_hash_table_size( book->data_table_finalizers ), ==, 0 ); + + g_test_message( "Testing with book key not null, cb null" ); + qof_book_set_data_fin( book, key, (gpointer) data, NULL ); + /* now data is set cb not set */ + g_assert_cmpint( g_hash_table_size( book->data_tables ), ==, 1 ); + g_assert_cmpint( g_hash_table_size( book->data_table_finalizers ), ==, 0 ); + g_assert_cmpstr( (const char *)qof_book_get_data( book, key ), ==, data ); + + g_test_message( "Testing with all data set" ); + qof_book_set_data_fin( book, key, (gpointer) data, mock_final_cb ); + /* now we have all set */ + g_assert_cmpint( g_hash_table_size( book->data_tables ), ==, 1 ); + g_assert_cmpint( g_hash_table_size( book->data_table_finalizers ), ==, 1 ); + g_assert_cmpstr( (const char *)qof_book_get_data( book, key ), ==, data ); + g_assert( g_hash_table_lookup ( book->data_table_finalizers, (gpointer)key ) == mock_final_cb ); + + /* get rid of book make sure final cb is called */ + test_struct.called = FALSE; + qof_book_destroy( book ); + g_assert( test_struct.called ); +} + +static void +test_book_mark_closed( Fixture *fixture, gconstpointer pData ) +{ + g_test_message( "Testing when book is null" ); + g_assert_cmpstr( &fixture->book->book_open, ==, "y" ); + qof_book_mark_closed( NULL ); + g_assert_cmpstr( &fixture->book->book_open, ==, "y" ); + + g_test_message( "Testing when book is not null" ); + qof_book_mark_closed( fixture->book ); + g_assert_cmpstr( &fixture->book->book_open, ==, "n" ); +} + +static void +test_book_new_destroy( void ) +{ + QofBook *book; + const char *key = "key"; + const char *data = "data"; + + g_test_message( "Testing book creation and initial setup" ); + book = qof_book_new(); + g_assert( book ); + g_assert( QOF_IS_BOOK( book ) ); + + g_test_message( "Testing book initial setup" ); + g_assert( book->hash_of_collections ); + g_assert( book->data_tables ); + g_assert( book->data_table_finalizers ); + g_assert_cmpint( g_hash_table_size( book->hash_of_collections ), ==, 1 ); + g_assert( g_hash_table_lookup ( book->hash_of_collections, QOF_ID_BOOK ) != NULL ); + g_assert_cmpint( g_hash_table_size( book->data_tables ), ==, 0 ); + g_assert_cmpint( g_hash_table_size( book->data_table_finalizers ), ==, 0 ); + g_assert_cmpstr( &book->book_open, ==, "y"); + g_assert( !book->read_only ); + g_assert_cmpint( book->version, ==, 0 ); + + /* set finalizer */ + qof_book_set_data_fin( book, key, (gpointer) data, mock_final_cb ); + test_struct.called = FALSE; + + g_test_message( "Testing book destroy" ); + qof_book_destroy( book ); + g_assert( qof_book_shutting_down( book ) ); + g_assert( test_struct.called ); + g_assert( book->hash_of_collections ); + g_assert_cmpint( g_hash_table_size( book->hash_of_collections ), ==, 0 ); + g_assert( !book->data_tables ); + g_assert( !book->data_table_finalizers ); +} + void test_suite_qofbook ( void ) { - g_test_add( suitename, Fixture, NULL, setup, test_book_readonly, teardown ); - g_test_add_func( suitename, test_book_validate_counter ); + GNC_TEST_ADD( suitename, "readonly", Fixture, NULL, setup, test_book_readonly, teardown ); + GNC_TEST_ADD_FUNC( suitename, "validate counter", test_book_validate_counter ); + GNC_TEST_ADD( suitename, "get string option", Fixture, NULL, setup, test_book_get_string_option, teardown ); + GNC_TEST_ADD( suitename, "set string option", Fixture, NULL, setup, test_book_set_string_option, teardown ); + GNC_TEST_ADD( suitename, "not saved", Fixture, NULL, setup, test_book_not_saved, teardown ); + GNC_TEST_ADD( suitename, "mark saved", Fixture, NULL, setup, test_book_mark_saved, teardown ); + GNC_TEST_ADD( suitename, "get counter", Fixture, NULL, setup, test_book_get_counter, teardown ); + GNC_TEST_ADD( suitename, "get counter format", Fixture, NULL, setup, test_book_get_counter_format, teardown ); + GNC_TEST_ADD( suitename, "increment and format counter", Fixture, NULL, setup, test_book_increment_and_format_counter, teardown ); + GNC_TEST_ADD( suitename, "kvp changed", Fixture, NULL, setup, test_book_kvp_changed, teardown ); + GNC_TEST_ADD( suitename, "use trading accounts", Fixture, NULL, setup, test_book_use_trading_accounts, teardown ); + GNC_TEST_ADD( suitename, "mark dirty", Fixture, NULL, setup, test_book_mark_dirty, teardown ); + GNC_TEST_ADD( suitename, "dirty time", Fixture, NULL, setup, test_book_get_dirty_time, teardown ); + GNC_TEST_ADD( suitename, "set dirty callback", Fixture, NULL, setup, test_book_set_dirty_cb, teardown ); + GNC_TEST_ADD( suitename, "shutting down", Fixture, NULL, setup, test_book_shutting_down, teardown ); + GNC_TEST_ADD( suitename, "set get data", Fixture, NULL, setup, test_book_set_get_data, teardown ); + GNC_TEST_ADD( suitename, "get collection", Fixture, NULL, setup, test_book_get_collection, teardown ); + GNC_TEST_ADD( suitename, "foreach collection", Fixture, NULL, setup, test_book_foreach_collection, teardown ); + GNC_TEST_ADD_FUNC( suitename, "set data finalizers", test_book_set_data_fin ); + GNC_TEST_ADD( suitename, "mark closed", Fixture, NULL, setup, test_book_mark_closed, teardown ); + GNC_TEST_ADD_FUNC( suitename, "book new and destroy", test_book_new_destroy ); }