test-guid.c

00001 /***************************************************************************
00002  *            test-guid.c
00003  *
00004  *  Test file created by Linas Vepstas <linas@linas.org>
00005  *  Try to create duplicate GUID's, which should never happen.
00006  *  October 2003
00007  *  Copyright  2003  Linas Vepstas <linas@linas.org>
00008  ****************************************************************************/
00009 /*
00010  *  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU General Public License for more details.
00019  *
00020  *  You should have received a copy of the GNU General Public License
00021  *  along with this program; if not, write to the Free Software
00022  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00023  */
00024  
00025 #include <ctype.h>
00026 #include <glib.h>
00027 
00028 #include "test-stuff.h"
00029 #include "test-engine-stuff.h"
00030 #include "qofbook.h"
00031 #include "qofid.h"
00032 #include "qofid-p.h"
00033 #include "qofsession.h"
00034 #include "guid.h"
00035 
00036 static void test_null_guid(void)
00037 {
00038   GUID g;
00039   GUID *gp;
00040 
00041   g = guid_new_return();
00042   gp = guid_malloc();
00043   guid_new(gp);
00044 
00045   do_test(guid_equal(guid_null(), guid_null()), "null guids equal");
00046   do_test(!guid_equal(&g, gp), "two guids equal");
00047 }
00048 
00049 static void
00050 run_test (void)
00051 {
00052   int i;
00053   QofSession *sess;
00054   QofBook *book;
00055   QofEntity *eblk;
00056   QofCollection *col;
00057   QofIdType type;
00058 
00059   sess = qof_session_new();
00060   book = qof_session_get_book (sess);
00061   do_test ((NULL != book), "book not created");
00062 
00063   col = qof_book_get_collection (book, "asdf");
00064   type = qof_collection_get_type (col);
00065   
00066 #define NENT 500123
00067   eblk = g_new0(QofEntity, NENT);
00068   for (i=0; i<NENT; i++)
00069   {
00070     QofEntity *ent = &eblk[i];
00071     guid_new(&ent->guid);
00072     do_test ((NULL == qof_collection_lookup_entity (col, &ent->guid)),
00073                                                   "duplicate guid");
00074          ent->e_type = type;
00075          qof_collection_insert_entity (col, ent);
00076   }
00077 
00078   /* Make valgrind happy -- destroy the session. */
00079   qof_session_destroy(sess);
00080 }
00081 
00082 int
00083 main (int argc, char **argv)
00084 {
00085   guid_init ();
00086   g_log_set_always_fatal( G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING );
00087 
00088   test_null_guid();
00089   run_test();
00090 
00091   print_test_results();
00092   exit(get_rv());
00093   guid_shutdown();
00094   return 0;
00095 }

Generated on Fri May 12 18:00:33 2006 for QOF by  doxygen 1.4.4