test-guid.cpp (gnucash-5.0.tar.bz2) | : | test-guid.cpp (gnucash-5.1.tar.bz2) | ||
---|---|---|---|---|
skipping to change at line 31 | skipping to change at line 31 | |||
* 02110-1301, USA. | * 02110-1301, USA. | |||
*/ | */ | |||
/* Test file created by Linas Vepstas <linas@linas.org> | /* Test file created by Linas Vepstas <linas@linas.org> | |||
* Try to create duplicate GncGUID's, which should never happen. | * Try to create duplicate GncGUID's, which should never happen. | |||
* | * | |||
*/ | */ | |||
#include <guid.hpp> | #include <guid.hpp> | |||
#include <glib.h> | #include <glib.h> | |||
#include <vector> | ||||
#include <memory> | ||||
#include <config.h> | #include <config.h> | |||
#include <ctype.h> | #include <ctype.h> | |||
#include "cashobjects.h" | #include "cashobjects.h" | |||
#include "qofid.h" | ||||
#include "test-stuff.h" | #include "test-stuff.h" | |||
#include "test-engine-stuff.h" | #include "test-engine-stuff.h" | |||
#include "qof.h" | #include "qof.h" | |||
#define NENT 50123 | #define NENT 50123 | |||
static void test_null_guid(void) | static void test_null_guid(void) | |||
{ | { | |||
GncGUID g; | GncGUID g; | |||
GncGUID *gp; | GncGUID *gp; | |||
g = guid_new_return(); | g = guid_new_return(); | |||
gp = guid_new(); | gp = guid_new(); | |||
do_test(guid_equal(guid_null(), guid_null()), "null guids equal"); | do_test(guid_equal(guid_null(), guid_null()), "null guids equal"); | |||
do_test(!guid_equal(&g, gp), "two guids equal"); | do_test(!guid_equal(&g, gp), "two guids equal"); | |||
guid_free(gp); | guid_free(gp); | |||
} | } | |||
static void | static void | |||
free_entry (QofInstance* inst, void* data) | ||||
{ | ||||
g_object_unref (G_OBJECT(inst)); | ||||
} | ||||
static void | ||||
run_test (void) | run_test (void) | |||
{ | { | |||
int i; | ||||
QofSession *sess; | QofSession *sess; | |||
QofBook *book; | QofBook *book; | |||
QofInstance *ent; | ||||
QofCollection *col; | QofCollection *col; | |||
QofIdType type; | QofIdType type; | |||
GncGUID guid; | GncGUID guid; | |||
sess = get_random_session (); | sess = get_random_session (); | |||
book = qof_session_get_book (sess); | book = qof_session_get_book (sess); | |||
do_test ((NULL != book), "book not created"); | do_test ((NULL != book), "book not created"); | |||
col = qof_book_get_collection (book, "asdf"); | col = qof_book_get_collection (book, "asdf"); | |||
type = qof_collection_get_type (col); | type = qof_collection_get_type (col); | |||
for (i = 0; i < NENT; i++) | for (int i = 0; i < NENT; i++) | |||
{ | { | |||
ent = static_cast<QofInstance*>(g_object_new(QOF_TYPE_INSTANCE, NULL)); | ||||
guid_replace(&guid); | guid_replace(&guid); | |||
ent = static_cast<QofInstance*>(g_object_new(QOF_TYPE_INSTANCE, | auto ent = QOF_INSTANCE(g_object_new(QOF_TYPE_INSTANCE, "guid", &guid, N | |||
"guid", &guid, NULL)); | ULL)); | |||
do_test ((NULL == qof_collection_lookup_entity (col, &guid)), | do_test ((NULL == qof_collection_lookup_entity (col, &guid)), | |||
"duplicate guid"); | "duplicate guid"); | |||
ent->e_type = type; | ent->e_type = type; | |||
qof_collection_insert_entity (col, ent); | qof_collection_insert_entity (col, ent); | |||
do_test ((NULL != qof_collection_lookup_entity (col, &guid)), | do_test ((NULL != qof_collection_lookup_entity (col, &guid)), | |||
"guid not found"); | "guid not found"); | |||
} | } | |||
/* Make valgrind happy -- destroy the session. */ | /* Make valgrind happy -- destroy the session. */ | |||
qof_collection_foreach(col, free_entry, nullptr); | ||||
qof_session_destroy(sess); | qof_session_destroy(sess); | |||
} | } | |||
int | int | |||
main (int argc, char **argv) | main (int argc, char **argv) | |||
{ | { | |||
qof_init(); | qof_init(); | |||
if (cashobjects_register()) | if (cashobjects_register()) | |||
{ | { | |||
test_null_guid(); | test_null_guid(); | |||
End of changes. 9 change blocks. | ||||
6 lines changed or deleted | 14 lines changed or added |