24 #include <unittest-support.h>
26 #include "../qofbackend-p.h"
28 static const gchar *suitename =
"/qof/qofinstance";
29 void test_suite_qofinstance (
void );
30 static gchar* error_message;
31 static gboolean is_called;
46 fatal_handler (
const char * log_domain,
47 GLogLevelFlags log_level,
51 error_message = (gchar *) g_strdup( msg );
56 setup(
Fixture *fixture, gconstpointer pData )
58 fixture->inst = g_object_new(QOF_TYPE_INSTANCE, NULL);
62 teardown(
Fixture *fixture, gconstpointer pData )
64 g_object_unref(fixture->inst);
68 test_instance_set_get_book(
Fixture *fixture, gconstpointer pData )
75 g_assert( QOF_IS_INSTANCE( fixture->inst ) );
77 g_test_message(
"Setting and getting book" );
81 g_test_message(
"Getting book when instance is null" );
89 test_instance_set_get_guid(
Fixture *fixture, gconstpointer pData )
101 g_assert( QOF_IS_INSTANCE( fixture->inst ) );
105 g_test_message(
"Setting new guid" );
108 qof_instance_set_guid( fixture->inst, gncGuid );
113 guid_free( gncGuid );
117 test_instance_new_destroy(
void )
124 gchar *msg1 =
"qof_instance_get_collection: assertion " _Q
"QOF_IS_INSTANCE(ptr)' failed";
125 gchar *msg2 =
"qof_instance_get_editlevel: assertion " _Q
"QOF_IS_INSTANCE(ptr)' failed";
126 gchar *msg3 =
"qof_instance_get_destroying: assertion " _Q
"QOF_IS_INSTANCE(ptr)' failed";
127 gchar *msg4 =
"qof_instance_get_dirty_flag: assertion " _Q
"QOF_IS_INSTANCE(ptr)' failed";
128 gchar *log_domain =
"qof";
129 guint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL, hdlr;
132 g_test_message(
"Testing qofinstance object initialization" );
133 inst = g_object_new(QOF_TYPE_INSTANCE, NULL);
134 g_assert( QOF_IS_INSTANCE( inst ) );
136 klass = QOF_INSTANCE_GET_CLASS( inst );
137 g_assert( QOF_IS_INSTANCE_CLASS( klass ) );
138 g_assert( klass->get_display_name == NULL );
139 g_assert( klass->refers_to_object == NULL );
140 g_assert( klass->get_typed_referring_object_list == NULL );
145 g_assert( inst->kvp_data );
146 g_object_get( inst,
"last-update", ×pec_priv, NULL);
147 g_assert_cmpint( timespec_priv->tv_sec, == , 0 );
148 g_assert_cmpint( timespec_priv->tv_nsec, == , -1 );
149 g_assert_cmpint( qof_instance_get_editlevel( inst ), == , 0 );
152 g_assert( qof_instance_get_infant( inst ) );
153 g_assert_cmpint( qof_instance_get_version( inst ), == , 0 );
154 g_assert_cmpint( qof_instance_get_version_check( inst ), == , 0 );
157 g_test_message(
"Testing object destruction" );
158 g_object_unref( inst );
161 g_assert( !QOF_IS_INSTANCE( inst ) );
163 g_test_log_set_fatal_handler ( ( GTestLogFatalFunc )fatal_handler, NULL );
164 hdlr = g_log_set_handler (log_domain, loglevel,
165 (GLogFunc)test_checked_handler, &check);
167 g_assert( g_strrstr( error_message,
"assertion " _Q
"QOF_IS_INSTANCE(ptr)' failed" ) != NULL );
168 g_free( error_message );
171 g_assert_cmpint( qof_instance_get_editlevel( inst ), == , 0 );
172 g_assert( g_strrstr( error_message,
"assertion " _Q
"QOF_IS_INSTANCE(ptr)' failed" ) != NULL );
173 g_free( error_message );
177 g_assert( g_strrstr( error_message,
"assertion " _Q
"QOF_IS_INSTANCE(ptr)' failed" ) != NULL );
178 g_free( error_message );
182 g_assert( g_strrstr( error_message,
"assertion " _Q
"QOF_IS_INSTANCE(ptr)' failed" ) != NULL );
183 g_free( error_message );
184 g_log_remove_handler (log_domain, hdlr);
188 test_instance_init_data(
void )
199 inst = g_object_new( QOF_TYPE_INSTANCE, NULL );
200 g_assert( QOF_IS_INSTANCE( inst ) );
202 g_assert( QOF_IS_BOOK( book ) );
204 g_test_log_set_fatal_handler ( ( GTestLogFatalFunc )fatal_handler, NULL );
206 g_test_message(
"Running test with correct initial data" );
217 g_assert_cmpstr( guid_id_before, != , guid_id_after );
222 g_assert_cmpstr( inst->
e_type, == , test_type );
226 g_object_unref( inst );
231 test_instance_get_set_slots(
Fixture *fixture, gconstpointer pData )
236 g_assert( fixture->inst );
237 kvp_frame = qof_instance_get_slots( fixture->inst );
238 g_assert( kvp_frame );
240 g_test_message(
"Test when kvp frame is the same" );
241 qof_instance_set_slots( fixture->inst, kvp_frame );
242 g_assert( kvp_frame == qof_instance_get_slots( fixture->inst ) );
245 g_test_message(
"Test when kvp frame is not the same" );
247 g_assert( kvp_frame != kvp_frame2 );
248 qof_instance_set_slots( fixture->inst, kvp_frame2 );
249 g_assert( kvp_frame2 == qof_instance_get_slots( fixture->inst ) );
252 g_test_message(
"Test when kvp frame is null" );
253 qof_instance_set_slots( fixture->inst, NULL );
254 g_assert( NULL == qof_instance_get_slots( fixture->inst ) );
260 test_instance_version_cmp(
void )
264 Timespec timespec_left, timespec_right;
267 left = g_object_new( QOF_TYPE_INSTANCE, NULL );
268 right = g_object_new( QOF_TYPE_INSTANCE, NULL );
270 g_test_message(
"Test both null" );
272 g_assert_cmpint( result, == , 0 );
274 g_test_message(
"Test left null" );
276 g_assert_cmpint( result, == , -1 );
278 g_test_message(
"Test right null" );
280 g_assert_cmpint( result, == , 1 );
282 g_test_message(
"Test left tv_sec lesser than right" );
283 timespec_left.tv_sec = 0;
284 timespec_right.tv_sec = 1;
285 qof_instance_set_last_update( left, timespec_left );
286 qof_instance_set_last_update( right, timespec_right );
288 g_assert_cmpint( result, == , -1 );
290 g_test_message(
"Test right tv_sec lesser than left" );
291 timespec_left.tv_sec = 1;
292 timespec_right.tv_sec = 0;
293 qof_instance_set_last_update( left, timespec_left );
294 qof_instance_set_last_update( right, timespec_right );
296 g_assert_cmpint( result, == , 1 );
298 g_test_message(
"Test left tv_nsec lesser than right" );
299 timespec_left.tv_sec = 1;
300 timespec_left.tv_nsec = 0;
301 timespec_right.tv_sec = 1;
302 timespec_right.tv_nsec = 1;
303 qof_instance_set_last_update( left, timespec_left );
304 qof_instance_set_last_update( right, timespec_right );
306 g_assert_cmpint( result, == , -1 );
308 g_test_message(
"Test right tv_sec lesser than left" );
309 timespec_left.tv_sec = 1;
310 timespec_left.tv_nsec = 1;
311 timespec_right.tv_sec = 1;
312 timespec_right.tv_nsec = 0;
313 qof_instance_set_last_update( left, timespec_left );
314 qof_instance_set_last_update( right, timespec_right );
316 g_assert_cmpint( result, == , 1 );
318 g_test_message(
"Test both equal" );
319 timespec_left.tv_sec = 1;
320 timespec_left.tv_nsec = 1;
321 timespec_right.tv_sec = 1;
322 timespec_right.tv_nsec = 1;
323 qof_instance_set_last_update( left, timespec_left );
324 qof_instance_set_last_update( right, timespec_right );
326 g_assert_cmpint( result, == , 0 );
329 g_object_unref( left );
330 g_object_unref( right );
334 test_instance_get_set_dirty(
Fixture *fixture, gconstpointer pData )
341 qof_instance_set_collection( fixture->inst, col );
344 g_test_message(
"Test get_dirty on empty instance returns false" );
345 g_assert( qof_instance_get_dirty( NULL ) == FALSE );
347 g_test_message(
"Test dirty in normal mode" );
351 g_assert( !qof_instance_get_dirty( fixture->inst ) );
352 qof_instance_set_dirty( fixture->inst );
355 g_assert( qof_instance_get_dirty( fixture->inst ) );
358 g_test_message(
"Test dirty in alternate mode" );
362 qof_instance_set_dirty_flag( fixture->inst, FALSE );
367 g_assert( !qof_instance_get_dirty( fixture->inst ) );
368 qof_instance_set_dirty( fixture->inst );
371 g_assert( qof_instance_get_dirty( fixture->inst ) );
374 qof_instance_set_collection( fixture->inst, NULL );
385 g_assert( QOF_INSTANCE_GET_CLASS( inst )->get_display_name == mock_get_display_name );
387 display_name = g_strdup_printf(
"Mock display name %p", inst );
392 test_instance_display_name(
Fixture *fixture, gconstpointer pData )
396 gchar *display_name, *default_display_name, *mock_display_name;
399 g_assert( fixture->inst );
403 qof_instance_set_collection( fixture->inst, col );
405 default_display_name = g_strdup_printf(
"Object %s %p", type, fixture->inst );
406 mock_display_name = g_strdup_printf(
"Mock display name %p", fixture->inst );
408 g_test_message(
"Test instance when display name not set" );
409 g_assert( QOF_INSTANCE_GET_CLASS( fixture->inst )->get_display_name == NULL );
411 g_assert( !is_called );
412 g_assert_cmpstr( display_name, == , default_display_name );
413 g_free( display_name );
415 g_test_message(
"Test instance when display name is set" );
416 QOF_INSTANCE_GET_CLASS( fixture->inst )->get_display_name = mock_get_display_name;
418 g_assert( is_called );
419 g_assert_cmpstr( display_name, == , mock_display_name );
420 g_free( display_name );
423 g_free( default_display_name );
424 g_free( mock_display_name );
425 qof_instance_set_collection( fixture->inst, NULL );
434 g_assert( be->begin == mock_backend_begin );
435 g_assert_cmpstr( inst->
e_type, == ,
"test type" );
440 test_instance_begin_edit(
Fixture *fixture, gconstpointer pData )
449 qof_backend_init( be );
452 g_assert( QOF_IS_BOOK( book ) );
453 qof_book_set_backend( book, be );
454 g_assert( fixture->inst );
455 fixture->inst->
e_type =
"test type";
457 g_assert_cmpint( qof_instance_get_editlevel( fixture->inst ), == , 0 );
459 g_test_message(
"Test when instance is null" );
461 g_assert( result == FALSE );
463 g_test_message(
"Test when instance's editlevel is >= 1" );
464 qof_instance_increase_editlevel( fixture->inst );
466 g_assert( result == FALSE );
467 g_assert_cmpint( qof_instance_get_editlevel( fixture->inst ), == , 2 );
469 g_test_message(
"Test when instance's editlevel is <= 0 and backend not set" );
470 qof_instance_reset_editlevel( fixture->inst );
472 g_assert( result == TRUE );
473 g_assert_cmpint( qof_instance_get_editlevel( fixture->inst ), == , 1 );
476 g_test_message(
"Test when instance's editlevel is <= 0 and backend is set" );
479 qof_instance_reset_editlevel( fixture->inst );
480 qof_instance_set_dirty_flag( fixture->inst, FALSE );
482 be->begin = mock_backend_begin;
484 g_assert( result == TRUE );
485 g_assert_cmpint( qof_instance_get_editlevel( fixture->inst ), == , 1 );
487 g_assert( is_called );
490 qof_book_set_backend( book, NULL );
492 qof_backend_destroy( be );
497 test_instance_commit_edit(
Fixture *fixture, gconstpointer pData )
500 gchar *msg =
"[qof_commit_edit()] unbalanced call - resetting (was -2)";
501 gchar *log_domain =
"qof.engine";
502 guint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL, hdlr;
505 g_test_message(
"Test when instance set to null" );
509 g_test_message(
"Test when instance's editlevel >= 2" );
510 qof_instance_increase_editlevel( fixture->inst );
511 qof_instance_increase_editlevel( fixture->inst );
512 g_assert_cmpint( qof_instance_get_editlevel( fixture->inst ), == , 2 );
514 g_assert_cmpint( qof_instance_get_editlevel( fixture->inst ), == , 1 );
517 g_test_message(
"Test when instance's editlevel = 1" );
519 g_assert_cmpint( qof_instance_get_editlevel( fixture->inst ), == , 0 );
522 g_test_message(
"Test when instance's editlevel < 0" );
523 g_test_log_set_fatal_handler ( ( GTestLogFatalFunc )fatal_handler, NULL );
524 hdlr = g_log_set_handler (log_domain, loglevel,
525 (GLogFunc)test_checked_handler, &check);
526 qof_instance_decrease_editlevel( fixture->inst );
527 g_assert_cmpint( qof_instance_get_editlevel( fixture->inst ), == , -1 );
529 g_assert_cmpint( qof_instance_get_editlevel( fixture->inst ), == , 0 );
530 g_assert_cmpstr( error_message, == ,
"[qof_commit_edit()] unbalanced call - resetting (was -2)" );
531 g_free( error_message );
532 g_log_remove_handler (log_domain, hdlr);
542 gboolean commit_called;
543 gboolean commit_with_err_called;
544 gboolean on_error_called;
545 gboolean on_free_called;
546 gboolean on_done_called;
555 g_assert( QOF_IS_INSTANCE( inst ) );
556 g_assert( commit_test_part2.inst == inst );
557 g_assert( commit_test_part2.be == be );
558 commit_test_part2.commit_called = TRUE;
566 g_assert( QOF_IS_INSTANCE( inst ) );
567 g_assert( commit_test_part2.inst == inst );
568 g_assert( commit_test_part2.be == be );
571 commit_test_part2.commit_with_err_called = TRUE;
579 g_assert( QOF_IS_INSTANCE( inst ) );
580 g_assert( commit_test_part2.err == be_error );
581 commit_test_part2.on_error_called = TRUE;
588 g_assert( QOF_IS_INSTANCE( inst ) );
589 g_assert( commit_test_part2.inst == inst );
590 commit_test_part2.on_done_called = TRUE;
597 g_assert( QOF_IS_INSTANCE( inst ) );
598 g_assert( commit_test_part2.inst == inst );
599 commit_test_part2.on_free_called = TRUE;
603 test_instance_commit_edit_part2(
Fixture *fixture, gconstpointer pData )
612 qof_backend_init( be );
615 g_assert( QOF_IS_BOOK( book ) );
616 qof_book_set_backend( book, be );
620 commit_test_part2.commit_called = FALSE;
621 commit_test_part2.commit_with_err_called = FALSE;
622 commit_test_part2.on_error_called = FALSE;
623 commit_test_part2.on_free_called = FALSE;
624 commit_test_part2.on_done_called = FALSE;
625 commit_test_part2.inst = fixture->inst;
626 commit_test_part2.be = be;
627 qof_instance_set_dirty_flag( fixture->inst, TRUE );
629 g_test_message(
"Test when instance's backend not set, callbacks not set" );
630 g_assert( qof_instance_get_infant( fixture->inst ) );
635 g_assert( !qof_instance_get_infant( fixture->inst ) );
636 g_assert( !commit_test_part2.commit_called );
637 g_assert( !commit_test_part2.commit_with_err_called );
638 g_assert( !commit_test_part2.on_error_called );
639 g_assert( !commit_test_part2.on_free_called );
640 g_assert( !commit_test_part2.on_done_called );
642 g_test_message(
"Test when instance's backend not set, do_free is true" );
643 qof_instance_set_destroying( fixture->inst, TRUE );
647 g_assert( !commit_test_part2.commit_called );
648 g_assert( !commit_test_part2.commit_with_err_called );
649 g_assert( !commit_test_part2.on_error_called );
650 g_assert( commit_test_part2.on_free_called );
651 g_assert( !commit_test_part2.on_done_called );
653 g_test_message(
"Test when instance's backend not set, do_free is false" );
654 qof_instance_set_destroying( fixture->inst, FALSE );
655 commit_test_part2.on_free_called = FALSE;
659 g_assert( !commit_test_part2.commit_called );
660 g_assert( !commit_test_part2.commit_with_err_called );
661 g_assert( !commit_test_part2.on_error_called );
662 g_assert( !commit_test_part2.on_free_called );
663 g_assert( commit_test_part2.on_done_called );
665 g_test_message(
"Test when instance's backend is set, all cb set, no error produced" );
667 qof_instance_set_destroying( fixture->inst, FALSE );
668 commit_test_part2.on_done_called = FALSE;
669 be->commit = mock_backend_commit;
673 g_assert( commit_test_part2.commit_called );
674 g_assert( !commit_test_part2.commit_with_err_called );
675 g_assert( !commit_test_part2.on_error_called );
676 g_assert( !commit_test_part2.on_free_called );
677 g_assert( commit_test_part2.on_done_called );
679 g_test_message(
"Test when instance's backend is set, all cb set, error produced" );
680 commit_test_part2.commit_called = FALSE;
681 commit_test_part2.on_done_called = FALSE;
682 be->commit = mock_backend_commit_with_error;
683 qof_instance_set_dirty_flag( fixture->inst, TRUE );
684 qof_instance_set_destroying( fixture->inst, TRUE );
689 g_assert( !commit_test_part2.commit_called );
690 g_assert( commit_test_part2.commit_with_err_called );
691 g_assert( commit_test_part2.on_error_called );
692 g_assert( !commit_test_part2.on_free_called );
693 g_assert( !commit_test_part2.on_done_called );
696 qof_book_set_backend( book, NULL );
698 qof_backend_destroy( be );
711 gboolean refers_to_object_called;
712 } refers_test_struct;
719 g_assert( refers_test_struct.inst == inst );
720 g_assert( refers_test_struct.ref == ref );
721 refers_test_struct.refers_to_object_called = TRUE;
726 test_instance_refers_to_object(
Fixture *fixture, gconstpointer pData )
730 ref = g_object_new( QOF_TYPE_INSTANCE, NULL );
731 g_assert( fixture->inst );
733 g_assert( QOF_INSTANCE_GET_CLASS( fixture->inst )->refers_to_object == NULL );
734 refers_test_struct.refers_to_object_called = FALSE;
735 refers_test_struct.inst = fixture->inst;
736 refers_test_struct.ref = ref;
738 g_test_message(
"Test when refers to object not set" );
740 g_assert( !refers_test_struct.refers_to_object_called );
742 g_test_message(
"Test when refers to object set" );
743 QOF_INSTANCE_GET_CLASS( fixture->inst )->refers_to_object = mock_refers_to_object;
745 g_assert( refers_test_struct.refers_to_object_called );
747 g_object_unref( ref );
755 } refers_test_struct_from_col;
762 g_assert( g_list_find( refers_test_struct_from_col.list, inst ) );
763 g_assert( refers_test_struct_from_col.ref == ref );
764 refers_test_struct_from_col.call_count++;
765 refers_test_struct.refers_to_object_called = TRUE;
770 test_instance_get_referring_object_list_from_collection(
void )
774 GList *inst_list = NULL;
775 GList *result = NULL;
779 gint32 list_length = g_test_rand_int_range( 0, 10 );
785 g_assert( QOF_IS_BOOK( book ) );
786 ref = g_object_new( QOF_TYPE_INSTANCE, NULL );
788 g_assert( QOF_IS_INSTANCE( ref ) );
789 QOF_INSTANCE_GET_CLASS( ref )->refers_to_object = NULL;
790 refers_test_struct_from_col.call_count = 0;
795 for (i = 0; i < list_length; i++ )
797 QofInstance *inst = g_object_new( QOF_TYPE_INSTANCE, NULL );
800 inst_list = g_list_append ( inst_list, inst );
801 g_assert_cmpint( g_list_length( inst_list ), == , (i + 1) );
803 g_assert_cmpint( list_length, == , g_list_length( inst_list ) );
805 g_test_message(
"Test when refers to object not set" );
810 g_assert_cmpint( refers_test_struct_from_col.call_count, == , 0 );
812 g_test_message(
"Test when refers to object is set" );
813 QOF_INSTANCE_GET_CLASS( ref )->refers_to_object = mock_refers_to_object_from_col;
814 refers_test_struct_from_col.list = inst_list;
815 refers_test_struct_from_col.ref = ref;
817 if ( list_length == 0 )
821 g_assert_cmpint( g_list_length( inst_list ), == , g_list_length( result ) );
822 g_assert_cmpint( g_list_length( inst_list ), == , refers_test_struct_from_col.call_count );
825 g_list_foreach( inst_list, (GFunc) g_object_unref, NULL );
826 g_list_free( inst_list );
827 g_list_free( result );
829 g_object_unref( ref );
837 gboolean get_typed_referring_object_list_called;
838 } get_typed_referring_object_list_struct;
843 GList* result = NULL;
847 g_assert( get_typed_referring_object_list_struct.inst == inst );
848 g_assert( get_typed_referring_object_list_struct.ref == ref );
849 get_typed_referring_object_list_struct.get_typed_referring_object_list_called = TRUE;
850 return g_list_append( result, (gpointer) inst );
854 test_instance_get_typed_referring_object_list(
void )
859 GList* result = NULL;
862 inst = g_object_new( QOF_TYPE_INSTANCE, NULL );
863 ref = g_object_new( QOF_TYPE_INSTANCE, NULL );
868 QOF_INSTANCE_GET_CLASS( inst )->refers_to_object = NULL;
869 QOF_INSTANCE_GET_CLASS( inst )->get_typed_referring_object_list = NULL;
871 get_typed_referring_object_list_struct.get_typed_referring_object_list_called = FALSE;
877 g_test_message(
"Test when get typed referring object list is not set" );
880 g_assert( !get_typed_referring_object_list_struct.get_typed_referring_object_list_called );
881 g_list_free( result );
883 g_test_message(
"Test when get typed referring object list is set" );
884 QOF_INSTANCE_GET_CLASS( inst )->get_typed_referring_object_list = mock_get_typed_referring_object_list;
885 get_typed_referring_object_list_struct.inst = inst;
886 get_typed_referring_object_list_struct.ref = ref;
889 g_assert_cmpint( g_list_length( result ), == , 1 );
890 g_assert( get_typed_referring_object_list_struct.get_typed_referring_object_list_called );
891 g_list_free( result );
894 g_object_unref( inst );
895 g_object_unref( ref );
901 guint refers_to_object_call_count;
902 guint get_typed_referring_object_list_count;
903 } get_referring_object_list_struct;
912 get_referring_object_list_struct.refers_to_object_call_count++;
923 get_referring_object_list_struct.get_typed_referring_object_list_count++;
928 test_instance_get_referring_object_list(
void )
936 gint32 col1_length = g_test_rand_int_range( 0, 10 );
937 gint32 col2_length = g_test_rand_int_range( 0, 10 );
938 GList* inst_list1 = NULL;
939 GList* inst_list2 = NULL;
940 GList* result = NULL;
946 g_assert( QOF_IS_BOOK( book ) );
947 ref1 = g_object_new( QOF_TYPE_INSTANCE, NULL );
949 ref2 = g_object_new( QOF_TYPE_INSTANCE, NULL );
953 QOF_INSTANCE_GET_CLASS( ref1 )->refers_to_object = NULL;
954 QOF_INSTANCE_GET_CLASS( ref1 )->get_typed_referring_object_list = NULL;
957 get_referring_object_list_struct.refers_to_object_call_count = 0;
958 get_referring_object_list_struct.get_typed_referring_object_list_count = 0;
963 for (i = 0; i < col1_length; i++ )
965 QofInstance *inst = g_object_new( QOF_TYPE_INSTANCE, NULL );
968 inst_list1 = g_list_append ( inst_list1, inst );
969 g_assert_cmpint( g_list_length( inst_list1 ), == , (i + 1) );
972 g_assert_cmpint( g_list_length( inst_list1 ), == , col1_length );
974 for (j = 0; j < col2_length; j++ )
976 QofInstance *inst = g_object_new( QOF_TYPE_INSTANCE, NULL );
979 inst_list2 = g_list_append ( inst_list2, inst );
980 g_assert_cmpint( g_list_length( inst_list2 ), == , (j + 1) );
983 g_assert_cmpint( g_list_length( inst_list2 ), == , col2_length );
985 g_test_message(
"Test object list returned for ref1 instance by default" );
988 g_assert_cmpint( get_referring_object_list_struct.refers_to_object_call_count, == , 0 );
990 g_test_message(
"Test object list returned for ref2 instance by default" );
993 g_assert_cmpint( get_referring_object_list_struct.refers_to_object_call_count, == , 0 );
1001 g_test_message(
"Test object list returned for ref1 instance when refers_to_object is set" );
1002 QOF_INSTANCE_GET_CLASS( ref1 )->refers_to_object = mock_simple_refers_to_object;
1005 g_assert_cmpint( g_list_length( result ), == , col1_length + 1 );
1006 g_assert_cmpint( get_referring_object_list_struct.refers_to_object_call_count, == , col1_length + 1 );
1007 g_list_free( result );
1009 g_test_message(
"Test object list returned for ref2 instance when refers_to_object is set" );
1010 get_referring_object_list_struct.refers_to_object_call_count = 0;
1013 g_assert_cmpint( g_list_length( result ), == , col2_length + 1 );
1014 g_assert_cmpint( get_referring_object_list_struct.refers_to_object_call_count, == , col2_length + 1 );
1015 g_list_free( result );
1017 g_test_message(
"Test object list returned for ref1 instance when refers_to_object is set and get typed set" );
1018 QOF_INSTANCE_GET_CLASS( ref1 )->get_typed_referring_object_list = mock_simple_get_typed_referring_object_list;
1019 get_referring_object_list_struct.refers_to_object_call_count = 0;
1020 get_referring_object_list_struct.get_typed_referring_object_list_count = 0;
1023 g_assert_cmpint( g_list_length( result ), == , col1_length + 1 );
1024 g_assert_cmpint( get_referring_object_list_struct.refers_to_object_call_count, == , col1_length + 1 );
1025 g_assert_cmpint( get_referring_object_list_struct.get_typed_referring_object_list_count, == , 2 );
1026 g_list_free( result );
1028 g_test_message(
"Test object list returned for ref2 instance when refers_to_object is set and get typed set" );
1029 get_referring_object_list_struct.refers_to_object_call_count = 0;
1030 get_referring_object_list_struct.get_typed_referring_object_list_count = 0;
1033 g_assert_cmpint( g_list_length( result ), == , col2_length + 1 );
1034 g_assert_cmpint( get_referring_object_list_struct.refers_to_object_call_count, == , col2_length + 1 );
1035 g_assert_cmpint( get_referring_object_list_struct.get_typed_referring_object_list_count, == , 2 );
1036 g_list_free( result );
1039 g_object_unref( ref1 );
1040 g_object_unref( ref2 );
1041 g_list_foreach( inst_list1, (GFunc) g_object_unref, NULL );
1042 g_list_foreach( inst_list2, (GFunc) g_object_unref, NULL );
1043 g_list_free( inst_list1 );
1044 g_list_free( inst_list2 );
1049 test_suite_qofinstance (
void )
1051 GNC_TEST_ADD( suitename,
"set get book",
Fixture, NULL, setup, test_instance_set_get_book, teardown );
1052 GNC_TEST_ADD( suitename,
"set get guid",
Fixture, NULL, setup, test_instance_set_get_guid, teardown );
1053 GNC_TEST_ADD_FUNC( suitename,
"instance new and destroy", test_instance_new_destroy );
1054 GNC_TEST_ADD_FUNC( suitename,
"init data", test_instance_init_data );
1055 GNC_TEST_ADD( suitename,
"get set slots",
Fixture, NULL, setup, test_instance_get_set_slots, teardown );
1056 GNC_TEST_ADD_FUNC( suitename,
"version compare", test_instance_version_cmp );
1057 GNC_TEST_ADD( suitename,
"get set dirty",
Fixture, NULL, setup, test_instance_get_set_dirty, teardown );
1058 GNC_TEST_ADD( suitename,
"display name",
Fixture, NULL, setup, test_instance_display_name, teardown );
1059 GNC_TEST_ADD( suitename,
"begin edit",
Fixture, NULL, setup, test_instance_begin_edit, teardown );
1060 GNC_TEST_ADD( suitename,
"commit edit",
Fixture, NULL, setup, test_instance_commit_edit, teardown );
1061 GNC_TEST_ADD( suitename,
"commit edit part 2",
Fixture, NULL, setup, test_instance_commit_edit_part2, teardown );
1062 GNC_TEST_ADD( suitename,
"instance refers to object",
Fixture, NULL, setup, test_instance_refers_to_object, teardown );
1063 GNC_TEST_ADD_FUNC( suitename,
"instance get referring object list from collection", test_instance_get_referring_object_list_from_collection );
1064 GNC_TEST_ADD_FUNC( suitename,
"instance get typed referring object list", test_instance_get_typed_referring_object_list);
1065 GNC_TEST_ADD_FUNC( suitename,
"instance get referring object list", test_instance_get_referring_object_list );
int qof_instance_version_cmp(const QofInstance *left, const QofInstance *right)
void qof_backend_set_error(QofBackend *be, QofBackendError err)
const GncGUID * qof_instance_get_guid(gconstpointer)
QofBook * qof_instance_get_book(gconstpointer)
gboolean qof_collection_is_dirty(const QofCollection *col)
QofInstance * qof_collection_lookup_entity(const QofCollection *, const GncGUID *)
QofBackendError
The errors that can be reported to the GUI & other front-end users.
void qof_set_alt_dirty_mode(gboolean enabled)
GList * qof_instance_get_referring_object_list_from_collection(const QofCollection *coll, const QofInstance *ref)
gboolean qof_instance_get_destroying(gconstpointer ptr)
QofBook * qof_book_new(void)
Use a 64-bit unsigned int timespec.
QofCollection * qof_instance_get_collection(gconstpointer inst)
gchar * guid_to_string_buff(const GncGUID *guid, gchar *buff)
gboolean qof_commit_edit(QofInstance *inst)
void qof_instance_init_data(QofInstance *, QofIdType, QofBook *)
gboolean qof_begin_edit(QofInstance *inst)
guint32 qof_instance_get_idata(gconstpointer inst)
gboolean guid_equal(const GncGUID *guid_1, const GncGUID *guid_2)
#define GUID_ENCODING_LENGTH
gboolean qof_instance_get_dirty_flag(gconstpointer ptr)
GList * qof_instance_get_typed_referring_object_list(const QofInstance *inst, const QofInstance *ref)
gboolean qof_commit_edit_part2(QofInstance *inst, void(*on_error)(QofInstance *, QofBackendError), void(*on_done)(QofInstance *), void(*on_free)(QofInstance *))
void qof_collection_mark_clean(QofCollection *)
const GncGUID * qof_entity_get_guid(gconstpointer)
void qof_collection_destroy(QofCollection *col)
GList * qof_instance_get_referring_object_list(const QofInstance *inst)
const GncGUID * guid_null(void)
void qof_instance_set_book(gconstpointer inst, QofBook *book)
struct KvpFrameImpl KvpFrame
KvpFrame * kvp_frame_new(void)
QofCollection * qof_book_get_collection(const QofBook *, QofIdType)
guint qof_collection_count(const QofCollection *col)
gboolean qof_instance_refers_to_object(const QofInstance *inst, const QofInstance *ref)
gboolean qof_get_alt_dirty_mode(void)
void qof_book_destroy(QofBook *book)
QofCollection * qof_collection_new(QofIdType type)
gchar * qof_instance_get_display_name(const QofInstance *inst)