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;
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 }