node_t node_new() { node_t node; alloc_struct(sizeof(struct Node),(void **) &node); node->id = guid_new(); return node_init(node); }
GncGUID guid_new_return(void) { GncGUID guid; guid_new (&guid); return guid; }
static void test_null_guid(void) { GncGUID g; GncGUID *gp; g = guid_new_return(); gp = guid_new(); do_test(guid_equal(guid_null(), guid_null()), "null guids equal"); do_test(!guid_equal(&g, gp), "two guids equal"); guid_free(gp); }
static const char * auth_user (const char * name, const char *passwd) { GncGUID *guid; const char *session_auth_string; /* hack alert - XXX - we do no authentication whatsoever, * any user is allowed to login. We only reject null users. */ if (!name || !passwd) return NULL; guid = g_new (GncGUID, 1); guid_new (guid); logged_in_users = g_list_prepend (logged_in_users, guid); session_auth_string = guid_to_string (guid); /* THREAD UNSAFE */ return session_auth_string; }
static const char * auth_user (const char * name, const char *passwd, char *buff) { GncGUID *guid; const char *session_auth_string; /* hack alert - XXX - we do no authentication whatsoever, * any user is allowed to login. We only reject null users. */ if (!name || !passwd) return NULL; guid = guid_new(); logged_in_users = g_list_prepend (logged_in_users, guid); guid_to_string_buffer (guid, buff); return buff; }
void qof_instance_init_data (QofInstance *inst, QofIdType type, QofBook *book) { QofInstancePrivate *priv; QofCollection *col; QofIdType col_type; g_return_if_fail(QOF_IS_INSTANCE(inst)); priv = GET_PRIVATE(inst); g_return_if_fail(!priv->book); priv->book = book; col = qof_book_get_collection (book, type); g_return_if_fail(col != NULL); /* XXX We passed redundant info to this routine ... but I think that's * OK, it might eliminate programming errors. */ col_type = qof_collection_get_type(col); if (safe_strcmp(col_type, type)) { PERR ("attempt to insert \"%s\" into \"%s\"", type, col_type); return; } priv = GET_PRIVATE(inst); inst->e_type = CACHE_INSERT (type); do { guid_new(&priv->guid); if (NULL == qof_collection_lookup_entity (col, &priv->guid)) break; PWARN("duplicate id created, trying again"); } while (1); priv->collection = col; qof_collection_insert_entity (col, inst); }
static void test_employee (void) { QofBackend *be; QofBook *book; QofSession *session; GncEmployee *employee; session = qof_session_new(); qof_session_begin(session, QOF_STDOUT, FALSE, FALSE); book = qof_session_get_book(session); /* The book *must* have a backend to pass the test of the 'dirty' flag */ /* See the README file for details */ be = qof_book_get_backend (book); /* Test creation/destruction */ { do_test (gncEmployeeCreate (NULL) == NULL, "employee create NULL"); employee = gncEmployeeCreate (book); do_test (employee != NULL, "employee create"); do_test (qof_instance_get_book(QOF_INSTANCE(employee)) == book, "getbook"); gncEmployeeBeginEdit (employee); gncEmployeeDestroy (employee); success ("create/destroy"); } /* Test setting/getting routines; does the active flag get set right? */ { GncGUID guid; test_string_fcn (book, "Id", gncEmployeeSetID, gncEmployeeGetID); test_string_fcn (book, "Username", gncEmployeeSetUsername, gncEmployeeGetUsername); test_string_fcn (book, "Language", gncEmployeeSetLanguage, gncEmployeeGetLanguage); test_string_fcn (book, "Acl", gncEmployeeSetAcl, gncEmployeeGetAcl); test_numeric_fcn (book, "Workday", gncEmployeeSetWorkday, gncEmployeeGetWorkday); test_numeric_fcn (book, "Rate", gncEmployeeSetRate, gncEmployeeGetRate); test_bool_fcn (book, "Active", gncEmployeeSetActive, gncEmployeeGetActive); do_test (gncEmployeeGetAddr (employee) != NULL, "Addr"); guid_new (&guid); employee = gncEmployeeCreate (book); count++; gncEmployeeSetGUID (employee, &guid); do_test (guid_equal (&guid, qof_instance_get_guid(QOF_INSTANCE(employee))), "guid compare"); } #if 0 { GList *list; list = gncBusinessGetList (book, GNC_EMPLOYEE_MODULE_NAME, TRUE); do_test (list != NULL, "getList all"); do_test (g_list_length (list) == count, "correct length: all"); g_list_free (list); list = gncBusinessGetList (book, GNC_EMPLOYEE_MODULE_NAME, FALSE); do_test (list != NULL, "getList active"); do_test (g_list_length (list) == 1, "correct length: active"); g_list_free (list); } #endif { const char *str = get_random_string(); const char *res; GncAddress *addr; addr = gncEmployeeGetAddr (employee); gncAddressSetName (addr, str); res = qof_object_printable (GNC_ID_EMPLOYEE, employee); do_test (res != NULL, "Printable NULL?"); do_test (safe_strcmp (str, res) == 0, "Printable equals"); } }
static void save_slot( const gchar* key, KvpValue* value, gpointer data ) { slot_info_t* pSlot_info = (slot_info_t*)data; gsize curlen; g_return_if_fail( key != NULL ); g_return_if_fail( value != NULL ); g_return_if_fail( data != NULL ); // Ignore if we've already run into a failure if ( !pSlot_info->is_ok ) { return; } curlen = pSlot_info->path->len; pSlot_info->pKvpValue = value; if ( curlen != 0 ) { (void)g_string_append( pSlot_info->path, "/" ); } (void)g_string_append( pSlot_info->path, key ); pSlot_info->value_type = value->get_type(); switch ( pSlot_info->value_type ) { case KvpValue::Type::FRAME: { auto pKvpFrame = value->get<KvpFrame*>(); auto guid = guid_new(); slot_info_t *pNewInfo = slot_info_copy( pSlot_info, guid ); KvpValue *oldValue = pSlot_info->pKvpValue; pSlot_info->pKvpValue = new KvpValue{guid}; pSlot_info->is_ok = gnc_sql_do_db_operation( pSlot_info->be, OP_DB_INSERT, TABLE_NAME, TABLE_NAME, pSlot_info, col_table ); g_return_if_fail( pSlot_info->is_ok ); pKvpFrame->for_each_slot(save_slot, pNewInfo); delete pSlot_info->pKvpValue; pSlot_info->pKvpValue = oldValue; g_string_free( pNewInfo->path, TRUE ); g_slice_free( slot_info_t, pNewInfo ); } break; case KvpValue::Type::GLIST: { GncGUID guid = guid_new_return(); slot_info_t *pNewInfo = slot_info_copy( pSlot_info, &guid ); KvpValue *oldValue = pSlot_info->pKvpValue; pSlot_info->pKvpValue = new KvpValue{&guid}; pSlot_info->is_ok = gnc_sql_do_db_operation( pSlot_info->be, OP_DB_INSERT, TABLE_NAME, TABLE_NAME, pSlot_info, col_table ); g_return_if_fail( pSlot_info->is_ok ); for (auto cursor = value->get<GList*>(); cursor; cursor = cursor->next) { auto val = static_cast<KvpValue*>(cursor->data); save_slot("", val, pNewInfo); } delete pSlot_info->pKvpValue; pSlot_info->pKvpValue = oldValue; g_string_free( pNewInfo->path, TRUE ); g_slice_free( slot_info_t, pNewInfo ); } break; default: { pSlot_info->is_ok = gnc_sql_do_db_operation( pSlot_info->be, OP_DB_INSERT, TABLE_NAME, TABLE_NAME, pSlot_info, col_table ); } break; } (void)g_string_truncate( pSlot_info->path, curlen ); }
static void save_slot (const char* key, KvpValue* value, gpointer data) { slot_info_t* pSlot_info = (slot_info_t*)data; g_return_if_fail (value != NULL); g_return_if_fail (data != NULL); // Ignore if we've already run into a failure if (!pSlot_info->is_ok) { return; } auto curlen = pSlot_info->path.length(); pSlot_info->pKvpValue = value; if (curlen != 0) pSlot_info->path += "/"; pSlot_info->path += key; pSlot_info->value_type = value->get_type (); switch (pSlot_info->value_type) { case KvpValue::Type::FRAME: { auto pKvpFrame = value->get<KvpFrame*> (); auto guid = guid_new (); slot_info_t* pNewInfo = slot_info_copy (pSlot_info, guid); KvpValue* oldValue = pSlot_info->pKvpValue; pSlot_info->pKvpValue = new KvpValue {guid}; pSlot_info->is_ok = pSlot_info->be->do_db_operation(OP_DB_INSERT, TABLE_NAME, TABLE_NAME, pSlot_info, col_table); g_return_if_fail (pSlot_info->is_ok); pKvpFrame->for_each_slot (save_slot, pNewInfo); delete pSlot_info->pKvpValue; pSlot_info->pKvpValue = oldValue; delete pNewInfo; } break; case KvpValue::Type::GLIST: { GncGUID* guid = guid_new (); slot_info_t* pNewInfo = slot_info_copy (pSlot_info, guid); KvpValue* oldValue = pSlot_info->pKvpValue; pSlot_info->pKvpValue = new KvpValue {guid}; // Transfer ownership! pSlot_info->is_ok = pSlot_info->be->do_db_operation(OP_DB_INSERT, TABLE_NAME, TABLE_NAME, pSlot_info, col_table); g_return_if_fail (pSlot_info->is_ok); for (auto cursor = value->get<GList*> (); cursor; cursor = cursor->next) { auto val = static_cast<KvpValue*> (cursor->data); save_slot ("", val, pNewInfo); } delete pSlot_info->pKvpValue; pSlot_info->pKvpValue = oldValue; delete pNewInfo; } break; default: { pSlot_info->is_ok = pSlot_info->be->do_db_operation (OP_DB_INSERT, TABLE_NAME, TABLE_NAME, pSlot_info, col_table); } break; } pSlot_info->path.erase(curlen); }
static void test_vendor (void) { QofBook *book; GncVendor *vendor; book = qof_book_new(); /* Test creation/destruction */ { do_test (gncVendorCreate (NULL) == NULL, "vendor create NULL"); vendor = gncVendorCreate (book); do_test (vendor != NULL, "vendor create"); do_test (qof_instance_get_book (QOF_INSTANCE(vendor)) == book, "getbook"); gncVendorBeginEdit (vendor); gncVendorDestroy (vendor); success ("create/destroy"); } /* Test setting/getting routines; does the active flag get set right? */ { GncGUID guid; test_string_fcn (book, "Id", gncVendorSetID, gncVendorGetID); test_string_fcn (book, "Name", gncVendorSetName, gncVendorGetName); test_string_fcn (book, "Notes", gncVendorSetNotes, gncVendorGetNotes); //test_string_fcn (book, "Terms", gncVendorSetTerms, gncVendorGetTerms); //test_bool_fcn (book, "TaxIncluded", gncVendorSetTaxIncluded, gncVendorGetTaxIncluded); test_bool_fcn (book, "Active", gncVendorSetActive, gncVendorGetActive); do_test (gncVendorGetAddr (vendor) != NULL, "Addr"); guid_new (&guid); vendor = gncVendorCreate (book); count++; gncVendorSetGUID (vendor, &guid); do_test (guid_equal (&guid, qof_instance_get_guid(QOF_INSTANCE(vendor))), "guid compare"); } { GList *list; list = gncBusinessGetList (book, GNC_ID_VENDOR, TRUE); do_test (list != NULL, "getList all"); do_test (g_list_length (list) == count, "correct length: all"); g_list_free (list); list = gncBusinessGetList (book, GNC_ID_VENDOR, FALSE); do_test (list != NULL, "getList active"); do_test (g_list_length (list) == 1, "correct length: active"); g_list_free (list); } { const char *str = get_random_string(); const char *res; gncVendorSetName (vendor, str); res = qof_object_printable (GNC_ID_VENDOR, vendor); do_test (res != NULL, "Printable NULL?"); do_test (g_strcmp0 (str, res) == 0, "Printable equals"); } qof_book_destroy (book); }