/*------------------------------------------------------------------------------ Copyright (c) 2004 Media Development Loan Fund This file is part of the LiveSupport project. http://livesupport.campware.org/ To report bugs, send an e-mail to bugs@campware.org LiveSupport is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. LiveSupport 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 LiveSupport; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Author : $Author: fgerlits $ Version : $Revision: 1.7 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/TestStorageClientTest.cxx,v $ ------------------------------------------------------------------------------*/ /* ============================================================ include files */ #ifdef HAVE_CONFIG_H #include "configure.h" #endif #if HAVE_UNISTD_H #include #else #error "Need unistd.h" #endif #include #include #include "TestStorageClient.h" #include "TestStorageClientTest.h" using namespace std; using namespace LiveSupport::Core; using namespace LiveSupport::Storage; /* =================================================== local data structures */ /* ================================================ local constants & macros */ CPPUNIT_TEST_SUITE_REGISTRATION(TestStorageClientTest); /** * The name of the configuration file for the storage client factory daemon. */ static const std::string configFileName = "etc/testStorage.xml"; /* =============================================== local function prototypes */ /* ============================================================= module code */ /*------------------------------------------------------------------------------ * Set up the test environment *----------------------------------------------------------------------------*/ void TestStorageClientTest :: setUp(void) throw () { try { Ptr::Ref parser( new xmlpp::DomParser(configFileName, true)); const xmlpp::Document * document = parser->get_document(); const xmlpp::Element * root = document->get_root_node(); tsc.reset(new TestStorageClient()); tsc->configure(*root); } catch (std::invalid_argument &e) { CPPUNIT_FAIL("semantic error in configuration file"); } catch (xmlpp::exception &e) { CPPUNIT_FAIL("error parsing configuration file"); } } /*------------------------------------------------------------------------------ * Clean up the test environment *----------------------------------------------------------------------------*/ void TestStorageClientTest :: tearDown(void) throw () { tsc.reset(); } /*------------------------------------------------------------------------------ * Test to see if the singleton Hello object is accessible *----------------------------------------------------------------------------*/ void TestStorageClientTest :: firstTest(void) throw (CPPUNIT_NS::Exception) { Ptr::Ref id1(new UniqueId(1)); Ptr::Ref id2(new UniqueId(2)); CPPUNIT_ASSERT(tsc->existsPlaylist(id1)); CPPUNIT_ASSERT(!tsc->existsPlaylist(id2)); Ptr::Ref playlist = tsc->getPlaylist(id1); CPPUNIT_ASSERT(playlist->getId()->getId() == id1->getId()); try { tsc->releasePlaylist(id1); } catch (std::invalid_argument &e) { std::string eMsg = "could not release playlist: "; eMsg += e.what(); CPPUNIT_FAIL(eMsg); } catch (std::logic_error &e) { std::string eMsg = "could not release playlist: "; eMsg += e.what(); CPPUNIT_FAIL(eMsg); } try { tsc->releasePlaylist(id2); CPPUNIT_FAIL("allowed to release non-existent playlist"); } catch (std::invalid_argument &e) { } catch (std::logic_error &e) { std::string eMsg = "release of non-existent playlist reports: "; eMsg += e.what(); CPPUNIT_FAIL(eMsg); } } /*------------------------------------------------------------------------------ * Testing the deletePlaylist method *----------------------------------------------------------------------------*/ void TestStorageClientTest :: deletePlaylistTest(void) throw (CPPUNIT_NS::Exception) { Ptr::Ref id1(new UniqueId(1)); Ptr::Ref id2(new UniqueId(2)); try { tsc->deletePlaylist(id2); CPPUNIT_FAIL("allowed to delete non-existent playlist"); } catch (std::invalid_argument &e) { } try { tsc->deletePlaylist(id1); } catch (std::invalid_argument &e) { CPPUNIT_FAIL("cannot delete existing playlist"); } try { tsc->deletePlaylist(id1); CPPUNIT_FAIL("allowed to delete non-existent playlist"); } catch (std::invalid_argument &e) { } } /*------------------------------------------------------------------------------ * Testing the getAllPlaylists method *----------------------------------------------------------------------------*/ void TestStorageClientTest :: getAllPlaylistsTest(void) throw (CPPUNIT_NS::Exception) { Ptr::Ref> >::Ref playlistVector = tsc->getAllPlaylists(); CPPUNIT_ASSERT(playlistVector->size() == 1); Ptr::Ref playlist = (*playlistVector)[0]; CPPUNIT_ASSERT((int) (playlist->getId()->getId()) == 1); } /*------------------------------------------------------------------------------ * Testing the createPlaylist method *----------------------------------------------------------------------------*/ void TestStorageClientTest :: createPlaylistTest(void) throw (CPPUNIT_NS::Exception) { Ptr::Ref playlist = tsc->createPlaylist(); CPPUNIT_ASSERT(tsc->existsPlaylist(playlist->getId())); } /*------------------------------------------------------------------------------ * Testing the audio clip operations *----------------------------------------------------------------------------*/ void TestStorageClientTest :: audioClipTest(void) throw (CPPUNIT_NS::Exception) { Ptr::Ref id2(new UniqueId(10002)); Ptr::Ref id7(new UniqueId(10077)); CPPUNIT_ASSERT(tsc->existsAudioClip(id2)); CPPUNIT_ASSERT(!tsc->existsAudioClip(id7)); Ptr::Ref audioClip = tsc->getAudioClip(id2); CPPUNIT_ASSERT(audioClip->getId()->getId() == id2->getId()); CPPUNIT_ASSERT(audioClip->getPlaylength()->total_seconds() == 30*60); Ptr::Ref> >::Ref audioClipVector = tsc->getAllAudioClips(); CPPUNIT_ASSERT(audioClipVector->size() == 2); audioClip = (*audioClipVector)[0]; CPPUNIT_ASSERT((int) (audioClip->getId()->getId()) == 10001); tsc->deleteAudioClip(id2); CPPUNIT_ASSERT(!tsc->existsAudioClip(id2)); }