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., 51 Franklin Street, Fifth Floor Boston, MA  02110-1301,  USA
00023  */
00024 
00025 #include <ctype.h>
00026 #include <glib.h>
00027 #include "qof.h"
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
00037 test_null_guid (void)
00038 {
00039     GUID g;
00040     GUID *gp;
00041 
00042     g = guid_new_return ();
00043     gp = guid_malloc ();
00044     guid_new (gp);
00045 
00046     do_test (guid_equal (guid_null (), guid_null ()), "null guids equal");
00047     do_test (!guid_equal (&g, gp), "two guids equal");
00048 }
00049 
00050 static void
00051 run_test (void)
00052 {
00053     int i;
00054     QofSession *sess;
00055     QofBook *book;
00056     QofEntity *eblk;
00057     QofCollection *col;
00058     QofIdType type;
00059 
00060     sess = qof_session_new ();
00061     book = qof_session_get_book (sess);
00062     do_test ((NULL != book), "book not created");
00063 
00064     col = qof_book_get_collection (book, "asdf");
00065     type = qof_collection_get_type (col);
00066 
00067 #define NENT 500123
00068     eblk = g_new0 (QofEntity, NENT);
00069     for (i = 0; i < NENT; i++)
00070     {
00071         QofEntity *ent = &eblk[i];
00072         guid_new (&ent->guid);
00073         do_test ((NULL == qof_collection_lookup_entity (col, &ent->guid)),
00074                  "duplicate guid");
00075         ent->e_type = type;
00076         qof_collection_insert_entity (col, ent);
00077     }
00078 
00079     /* Make valgrind happy -- destroy the session. */
00080     qof_session_destroy (sess);
00081 }
00082 
00083 int
00084 main (void)
00085 {
00086     guid_init ();
00087     g_log_set_always_fatal (G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING);
00088 
00089     test_null_guid ();
00090     run_test ();
00091 
00092     print_test_results ();
00093     exit (get_rv ());
00094     guid_shutdown ();
00095     return get_rv();
00096 }

Generated on Thu Jan 31 22:50:26 2008 for QOF by  doxygen 1.5.4