//------------------------------------------------------------------------------ // Desc: Import unit test // // Tabs: 3 // // Copyright (c) 2003-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: importtestsrv.cpp 3119 2006-01-19 13:39:12 -0700 (Thu, 19 Jan 2006) dsanders $ //------------------------------------------------------------------------------ #include "flmunittest.h" #if defined( FLM_NLM) #define DB_NAME_STR "SYS:\\IMP.DB" #else #define DB_NAME_STR "imp.db" #endif /**************************************************************************** Desc: ****************************************************************************/ class IImportTestImpl : public TestBase { public: const char * getName( void); RCODE execute( void); }; /**************************************************************************** Desc: ****************************************************************************/ RCODE getTest( IFlmTest ** ppTest) { RCODE rc = NE_XFLM_OK; if( (*ppTest = new IImportTestImpl) == NULL) { rc = NE_XFLM_MEM; goto Exit; } Exit: return( rc); } /**************************************************************************** Desc: ****************************************************************************/ const char * IImportTestImpl::getName( void) { return( "Import Test"); } /**************************************************************************** Desc: ****************************************************************************/ RCODE IImportTestImpl::execute( void) { RCODE rc = NE_XFLM_OK; FLMBOOL bDibCreated = FALSE; FLMBOOL bTransStarted = FALSE; IF_DirHdl * pDirHdl = NULL; IF_FileSystem * pFileSystem = NULL; FLMUINT uiCharCount = 0; char szTemp[ 64]; const char * pszDoc1 = "" " " "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 " " "; const char * pszDoc2 = " " " " "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 " " "; const char * pszIndexDef1 = " " " " " " " " " " " " " "; strcpy( m_szDetails, "No additional details."); beginTest( "Import Test Init", "Perform necessary initializations to carry out the import tests.", "(1) Get an F_DbSystem (2) Create a database (3) Start an " "update transaction.", ""); if ( RC_BAD( rc = initCleanTestState( DB_NAME_STR))) { MAKE_FLM_ERROR_STRING( "Failed to init test state.", m_szDetails, rc); goto Exit; } bDibCreated = TRUE; if ( RC_BAD( rc = m_pDb->transBegin( XFLM_UPDATE_TRANS, XFLM_NO_TIMEOUT))) { MAKE_FLM_ERROR_STRING( "transBegin failed.", m_szDetails, rc); goto Exit; } bTransStarted = TRUE; endTest("PASS"); beginTest( "Document Buffer Import Test", "Import some documents from in-memory XML data", "Self-Explanatory", ""); if( RC_BAD( rc = importBuffer( pszDoc1, XFLM_DATA_COLLECTION))) { goto Exit; } if( RC_BAD( rc = importBuffer( pszDoc2, XFLM_DATA_COLLECTION))) { goto Exit; } if( RC_BAD( rc = m_pDb->transCommit())) { MAKE_FLM_ERROR_STRING( "transCommit failed.", m_szDetails, rc); goto Exit; } if( RC_BAD( rc = m_pDb->transBegin( XFLM_UPDATE_TRANS, XFLM_NO_TIMEOUT))) { MAKE_FLM_ERROR_STRING( "transBegin failed.", m_szDetails, rc); goto Exit; } bTransStarted = TRUE; endTest("PASS"); beginTest( "Document File Import Test", "Import some documents from XML data files", "Import all .xml files in the current directory.", ""); m_pDbSystem->getFileSystem( &pFileSystem); if( RC_BAD( rc = pFileSystem->OpenDir( ".", ".xml", &pDirHdl))) { MAKE_FLM_ERROR_STRING( "OpenDir failed.", m_szDetails, rc); goto Exit; } m_szDetails[ 0] = '\0'; for (;;) { if( RC_BAD( rc = pDirHdl->Next())) { if ( rc == NE_XFLM_IO_NO_MORE_FILES) { rc = NE_XFLM_OK; break; } MAKE_FLM_ERROR_STRING("F_DirHdl::Next failed", m_szDetails, rc); goto Exit; } if( RC_BAD( rc = importFile( pDirHdl->CurrentItemName(), XFLM_DATA_COLLECTION))) { goto Exit; } f_sprintf( szTemp, "Imported: %s. ", pDirHdl->CurrentItemName()); uiCharCount += strlen( szTemp); if( uiCharCount < DETAILS_BUF_SIZ) { f_strcat( m_szDetails, szTemp); } } endTest("PASS"); beginTest( "Index Definition Import Test", "Import an index definition.", "Self-explanatory", "No Additional Info"); if( RC_BAD( rc = importBuffer( pszIndexDef1, XFLM_DICT_COLLECTION))) { goto Exit; } endTest("PASS"); Exit: if( pDirHdl) { pDirHdl->Release(); } if( pFileSystem) { pFileSystem->Release(); } if( RC_BAD( rc)) { endTest("FAIL"); } if( bTransStarted) { m_pDb->transCommit(); } shutdownTestState( DB_NAME_STR, bDibCreated); return( rc); }