QOF: test-guid.c Source File

QOF 0.7.5

test-guid.c
1 /***************************************************************************
2 * test-guid.c
3 *
4 * Test file created by Linas Vepstas <linas@linas.org>
5 * Try to create duplicate GUID's, which should never happen.
6 * October 2003
7 * Copyright 2003 Linas Vepstas <linas@linas.org>
8 ****************************************************************************/
9 /*
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301, USA
23 */
24
25 #include <ctype.h>
26 #include <glib.h>
27 #include "qof.h"
28 #include "test-stuff.h"
29 #include "test-engine-stuff.h"
30 #include "qofbook.h"
31 #include "qofid.h"
32 #include "qofid-p.h"
33 #include "qofsession.h"
34 #include "guid.h"
35
36 static void
37 test_null_guid (void)
38 {
39 GUID g;
40 GUID *gp;
41
42 g = guid_new_return ();
43 gp = guid_malloc ();
44 guid_new (gp);
45
46 do_test (guid_equal (guid_null (), guid_null ()), "null guids equal");
47 do_test (!guid_equal (&g, gp), "two guids equal");
48 }
49
50 static void
51 run_test (void)
52 {
53 int i;
54 QofSession *sess;
55 QofBook *book;
56 QofEntity *eblk;
57 QofCollection *col;
58 QofIdType type;
59
60 sess = qof_session_new ();
61 book = qof_session_get_book (sess);
62 do_test ((NULL != book), "book not created");
63
64 col = qof_book_get_collection (book, "asdf");
65 type = qof_collection_get_type (col);
66
67 #define NENT 500123
68 eblk = g_new0 (QofEntity, NENT);
69 for (i = 0; i < NENT; i++)
70 {
71 QofEntity *ent = &eblk[i];
72 guid_new (&ent->guid);
73 do_test ((NULL == qof_collection_lookup_entity (col, &ent->guid)),
74 "duplicate guid");
75 ent->e_type = type;
76 qof_collection_insert_entity (col, ent);
77 }
78
79 /* Make valgrind happy -- destroy the session. */
80 qof_session_destroy (sess);
81 }
82
83 int
84 main (void)
85 {
86 guid_init ();
87 g_log_set_always_fatal (G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING);
88
89 test_null_guid ();
90 run_test ();
91
92 print_test_results ();
93 exit (get_rv ());
94 guid_shutdown ();
95 return get_rv();
96 }
guid_equal
gboolean guid_equal(const GUID *guid_1, const GUID *guid_2)
Definition: guid.c:652
qofsession.h
Encapsulates a connection to a backend (persistent store)
QofIdType
const gchar * QofIdType
Definition: qofid.h:81
guid_new_return
GUID guid_new_return(void)
Definition: guid.c:538
guid_null
const GUID * guid_null(void)
Definition: guid.c:119
qof_book_get_collection
QofCollection * qof_book_get_collection(QofBook *book, QofIdType entity_type)
Definition: qofbook.c:220
_QofSession
Definition: qofsession-p.h:35
guid_malloc
GUID * guid_malloc(void)
Definition: guid.c:100
QofEntity_s
Definition: qofid.h:147
guid.h
globally unique ID User API
test-engine-stuff.h
This file declares testing functions for the engine.
qofid.h
QOF entity type identification system.
guid_shutdown
void guid_shutdown(void)
Definition: guid.c:477
QofCollection
struct QofCollection_s QofCollection
Definition: qofid.h:138
qof_collection_lookup_entity
QofEntity * qof_collection_lookup_entity(QofCollection *col, const GUID *guid)
Definition: qofid.c:321
qof_collection_get_type
QofIdType qof_collection_get_type(QofCollection *col)
Definition: qofid.c:175
_GUID
Definition: guid.h:53
guid_new
void guid_new(GUID *guid)
Definition: guid.c:487
qofbook.h
Encapsulate all the information about a dataset.
_QofBook
Definition: qofbook-p.h:48
guid_init
void guid_init(void)
Definition: guid.c:325
qof_collection_insert_entity
void qof_collection_insert_entity(QofCollection *, QofEntity *)
Definition: qofid.c:197