diff --git a/xflaim/csharp/cstest/ImportTests.cs b/xflaim/csharp/cstest/ImportTests.cs new file mode 100644 index 0000000..277db76 --- /dev/null +++ b/xflaim/csharp/cstest/ImportTests.cs @@ -0,0 +1,308 @@ +//------------------------------------------------------------------------------ +// Desc: Import tests +// +// Tabs: 3 +// +// Copyright (c) 2006 Novell, Inc. All Rights Reserved. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the GNU General Public +// License as published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, contact Novell, Inc. +// +// To contact Novell about this file by physical or electronic mail, +// you may find current contact information at www.novell.com +// +// $Id$ +//------------------------------------------------------------------------------ + +using System; +using System.IO; +using System.Runtime.InteropServices; +using xflaim; + +namespace cstest +{ + + //-------------------------------------------------------------------------- + // Open database test. + //-------------------------------------------------------------------------- + public class ImportTests : Tester + { + private const string sDoc1 = + "" + + " " + + "00054613 " + + "1352 " + + "Margret Birkenfeld / Zachaus " + + "cddb/misc " + + " ID3G: 77 " + + "Wie erzahlen euch 1. Srophe " + + "Wir erzahlen Euch 2. Strophe " + + "Zachaus ist ein reicher Mann 1+2 Str " + + "Jericho " + + "Haruck, schnauf schnauf 1+2 Strophe " + + "Haruck, schnauf schnauf 3 Strophe " + + "Zachaus ist ein reicher Mann 3. Stophe " + + "Zachaus komm herunter! " + + "Wir erzahlen euch " + + "Leer ab jetzt Playback " + + "Wie erzahlen euch 1. Srophe Pb " + + "Wir erzahlen Euch 2. Strophe Pb " + + "Zachaus ist ein reicher Mann 1+2 Str Pb " + + "Jericho Pb " + + "Haruck, schnauf schnauf 1+2 Strophe Pb " + + "Haruck, schnauf schnauf 3 Strophe Pb " + + "Zachaus ist ein reicher Mann 3. Stophe Pb " + + "Zachaus komm herunter! Pb " + + "Wir erzahlen euch Pb " + + " "; + + private const string sDoc2 = " " + + " " + + "0008a40f " + + "2214 " + + "rundu... - Visur Ur Vinsabokinni " + + "cddb/misc " + + "Blessuo Solin Elskar Allt - Ur Augum Stirur Strjukio Fljott " + + "Heioloarkvaeoi " + + "Buxur, Vesti, Brok og Sko " + + "Gekk Eg Upp A Holinn" + + "Nu Blanar Yfir Berjamo - A Berjamo " + + "Orninn Flygur Fugla Haest - Solskrikjan - Min " + + "Nu Er Glatt I Borg Og Bae " + + "Smaladrengurinn - Klappa Saman Lofunum " + + "Stigur Hun Vio Stokkinn " + + "Dansi, Dansi, Dukkan Min " + + "Rioum Heim Til Hola - Gott Er Ao Rioa Sandana Mjuka " + + "Gryla - Jolasveinar Ganga Um Golf " + + "Erla, Gooa Erla " + + "Vio Skulum Ekki Hafa Hatt " + + "Sofa Urtu Born " + + " "; + + private const string sIndexDef = " " + + " " + + " " + + " " + + " " + + " " + + " "; + + public bool importTests( + Db db, + DbSystem dbSystem) + { + DOMNode doc = null; + IStream istream = null; + + // Create a document + + beginTest( "Import documents test"); + + // Document #1 + + try + { + istream = dbSystem.openBufferIStream( sDoc1); + } + catch (XFlaimException ex) + { + endTest( false, ex, "calling openBufferIStream - doc 1"); + return( false); + } + + try + { + doc = db.importDocument( istream, (uint)PredefinedXFlaimCollections.XFLM_DATA_COLLECTION, + doc, null); + } + catch (XFlaimException ex) + { + endTest( false, ex, "calling importDocument - doc 1"); + return( false); + } + + // Document #2 + + try + { + istream = dbSystem.openBufferIStream( sDoc2); + } + catch (XFlaimException ex) + { + endTest( false, ex, "calling openBufferIStream - doc 2"); + return( false); + } + + try + { + doc = db.importDocument( istream, (uint)PredefinedXFlaimCollections.XFLM_DATA_COLLECTION, + doc, null); + } + catch (XFlaimException ex) + { + endTest( false, ex, "calling importDocument - doc 2"); + return( false); + } + + // Index definition + + try + { + istream = dbSystem.openBufferIStream( sIndexDef); + } + catch (XFlaimException ex) + { + endTest( false, ex, "calling openBufferIStream - index def"); + return( false); + } + + try + { + doc = db.importDocument( istream, (uint)PredefinedXFlaimCollections.XFLM_DICT_COLLECTION, + doc, null); + } + catch (XFlaimException ex) + { + endTest( false, ex, "calling importDocument - index def"); + return( false); + } + endTest( false, true); + + return( true); + } + + public bool importTests( + string sDbName, + DbSystem dbSystem) + { + bool bOk = false; + Db db = null; + bool bStartedTrans = false; + RCODE rc; + + // Create the database + + beginTest( "Create database \"" + sDbName + "\""); + + for (;;) + { + rc = RCODE.NE_XFLM_OK; + try + { + XFLM_CREATE_OPTS createOpts = null; +#if false + XFLM_CREATE_OPTS createOpts = new XFLM_CREATE_OPTS(); + + createOpts.uiBlockSize = 8192; + createOpts.uiVersionNum = (uint)DBVersions.XFLM_CURRENT_VERSION_NUM; + createOpts.uiMinRflFileSize = 2000000; + createOpts.uiMaxRflFileSize = 20000000; + createOpts.bKeepRflFiles = 1; + createOpts.bLogAbortedTransToRfl = 1; + createOpts.eDefaultLanguage = Languages.FLM_DE_LANG; +#endif + db = dbSystem.dbCreate( sDbName, null, null, null, null, createOpts); + } + catch (XFlaimException ex) + { + rc = ex.getRCode(); + + if (rc != RCODE.NE_XFLM_FILE_EXISTS) + { + endTest( false, ex, "creating database"); + return( false); + } + } + if (rc == RCODE.NE_XFLM_OK) + { + break; + } + + // rc better be NE_XFLM_FILE_EXISTS - try to delete the file + + try + { + dbSystem.dbRemove( sDbName, null, null, true); + } + catch (XFlaimException ex) + { + endTest( false, ex, "removing database"); + return( false); + } + } + + // Start a transaction + + beginTest( "Start Update Transaction Test"); + try + { + db.transBegin( eDbTransType.XFLM_UPDATE_TRANS, 255, 0); + } + catch (XFlaimException ex) + { + endTest( false, ex, "starting update transaction"); + goto Exit; + } + endTest( false, true); + bStartedTrans = true; + + // Create a document + + if (!importTests( db, dbSystem)) + { + goto Exit; + } + + // Commit the transaction + + beginTest( "Commit Update Transaction Test"); + try + { + bStartedTrans = false; + db.transCommit(); + } + catch (XFlaimException ex) + { + endTest( false, ex, "committing update transaction"); + goto Exit; + } + endTest( false, true); + + bOk = true; + + Exit: + if (bStartedTrans) + { + db.transAbort(); + } + if (db != null) + { + db.close(); + db = null; + } + return( bOk); + } + } +} diff --git a/xflaim/csharp/cstest/cstest.cs b/xflaim/csharp/cstest/cstest.cs index 6156636..eb0d3c5 100644 --- a/xflaim/csharp/cstest/cstest.cs +++ b/xflaim/csharp/cstest/cstest.cs @@ -186,6 +186,14 @@ namespace cstest return; } + // Import tests + + ImportTests importTest = new ImportTests(); + if (!importTest.importTests( TEST_DB_NAME, dbSystem)) + { + return; + } + // Statistics test StatsTests statsTests = new StatsTests();