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