GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
test-guid.c
1 /***************************************************************************
2  * test-guid.c
3  *
4  * October 2003
5  * Copyright 2003 Linas Vepstas <[email protected]
6  ****************************************************************************/
7 /*
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301, USA.
22  */
23 
24 /* Test file created by Linas Vepstas <[email protected]>
25  * Try to create duplicate GncGUID's, which should never happen.
26  *
27  */
28 
29 #include "config.h"
30 #include <ctype.h>
31 #include <glib.h>
32 #include "cashobjects.h"
33 #include "test-stuff.h"
34 #include "test-engine-stuff.h"
35 #include "qof.h"
36 
37 #define NENT 50123
38 
39 static void test_null_guid(void)
40 {
41  GncGUID g;
42  GncGUID *gp;
43 
44  g = guid_new_return();
45  gp = guid_new();
46 
47  do_test(guid_equal(guid_null(), guid_null()), "null guids equal");
48  do_test(!guid_equal(&g, gp), "two guids equal");
49 
50  guid_free(gp);
51 }
52 
53 static void
54 run_test (void)
55 {
56  int i;
57  QofSession *sess;
58  QofBook *book;
59  QofInstance *ent;
60  QofCollection *col;
61  QofIdType type;
62  GncGUID guid;
63 
64  sess = get_random_session ();
65  book = qof_session_get_book (sess);
66  do_test ((NULL != book), "book not created");
67 
68  col = qof_book_get_collection (book, "asdf");
69  type = qof_collection_get_type (col);
70 
71  for (i = 0; i < NENT; i++)
72  {
73  ent = g_object_new(QOF_TYPE_INSTANCE, NULL);
74  guid_replace(&guid);
75  ent = g_object_new(QOF_TYPE_INSTANCE, "guid", &guid, NULL);
76  do_test ((NULL == qof_collection_lookup_entity (col, &guid)),
77  "duplicate guid");
78  ent->e_type = type;
80  do_test ((NULL != qof_collection_lookup_entity (col, &guid)),
81  "guid not found");
82  }
83 
84  /* Make valgrind happy -- destroy the session. */
85  qof_session_destroy(sess);
86 }
87 
88 int
89 main (int argc, char **argv)
90 {
91  qof_init();
92  if (cashobjects_register())
93  {
94  test_null_guid();
95  run_test ();
96  print_test_results();
97  }
98  qof_close();
99  return get_rv();
100 }
QofIdType e_type
Definition: qofinstance.h:69
void guid_replace(GncGUID *guid)
QofInstance * qof_collection_lookup_entity(const QofCollection *, const GncGUID *)
GncGUID guid_new_return(void)
GncGUID * guid_new(void)
Definition: guid.h:65
const gchar * QofIdType
Definition: qofid.h:85
QofBook * qof_session_get_book(const QofSession *session)
gboolean guid_equal(const GncGUID *guid_1, const GncGUID *guid_2)
void qof_collection_insert_entity(QofCollection *, QofInstance *)
void qof_close(void)
Safely close down the Query Object Framework.
QofIdType qof_collection_get_type(const QofCollection *)
const GncGUID * guid_null(void)
QofCollection * qof_book_get_collection(const QofBook *, QofIdType)
void qof_init(void)
Initialise the Query Object Framework.