added a test case for importPlaylist();

this finishes #1664, and illustrates #1672
This commit is contained in:
fgerlits 2006-05-12 16:52:47 +00:00
parent 65854d7073
commit 62d4276521
2 changed files with 94 additions and 9 deletions

View file

@ -46,17 +46,19 @@
#include "WebStorageClient.h" #include "WebStorageClient.h"
#include "LiveSupport/Core/SessionId.h" #include "LiveSupport/Core/SessionId.h"
#include "LiveSupport/Core/XmlRpcException.h" #include "LiveSupport/Core/XmlRpcException.h"
#include "LiveSupport/Core/XmlRpcCommunicationException.h" #include "LiveSupport/Core/XmlRpcCommunicationException.h"
#include "LiveSupport/Core/XmlRpcMethodFaultException.h" #include "LiveSupport/Core/XmlRpcMethodFaultException.h"
#include "LiveSupport/Core/XmlRpcMethodResponseException.h" #include "LiveSupport/Core/XmlRpcMethodResponseException.h"
#include "LiveSupport/Core/XmlRpcInvalidArgumentException.h" #include "LiveSupport/Core/XmlRpcInvalidArgumentException.h"
#include "LiveSupport/Core/XmlRpcIOException.h" #include "LiveSupport/Core/XmlRpcIOException.h"
#include "LiveSupport/Core/FileTools.h"
#include "WebStorageClientTest.h" #include "WebStorageClientTest.h"
using namespace std; using namespace std;
using namespace boost::posix_time;
using namespace LiveSupport::Core; using namespace LiveSupport::Core;
using namespace LiveSupport::Authentication; using namespace LiveSupport::Authentication;
using namespace LiveSupport::Storage; using namespace LiveSupport::Storage;
@ -871,8 +873,10 @@ void
WebStorageClientTest :: exportPlaylistTest(void) WebStorageClientTest :: exportPlaylistTest(void)
throw (CPPUNIT_NS::Exception) throw (CPPUNIT_NS::Exception)
{ {
exportPlaylistHelper(StorageClientInterface::internalFormat); Ptr<UniqueId>::Ref playlistId(new UniqueId(1));
exportPlaylistHelper(StorageClientInterface::smilFormat);
exportPlaylistHelper(playlistId, StorageClientInterface::internalFormat);
exportPlaylistHelper(playlistId, StorageClientInterface::smilFormat);
} }
@ -881,7 +885,8 @@ WebStorageClientTest :: exportPlaylistTest(void)
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
void void
WebStorageClientTest :: exportPlaylistHelper( WebStorageClientTest :: exportPlaylistHelper(
StorageClientInterface::ExportFormatType format) Ptr<UniqueId>::Ref playlistId,
StorageClientInterface::ExportFormatType format)
throw (CPPUNIT_NS::Exception) throw (CPPUNIT_NS::Exception)
{ {
Ptr<SessionId>::Ref sessionId; Ptr<SessionId>::Ref sessionId;
@ -890,7 +895,6 @@ WebStorageClientTest :: exportPlaylistHelper(
); );
CPPUNIT_ASSERT(sessionId); CPPUNIT_ASSERT(sessionId);
Ptr<UniqueId>::Ref playlistId(new UniqueId(1));
Ptr<Glib::ustring>::Ref url(new Glib::ustring("")); Ptr<Glib::ustring>::Ref url(new Glib::ustring(""));
Ptr<Glib::ustring>::Ref token; Ptr<Glib::ustring>::Ref token;
@ -899,13 +903,83 @@ WebStorageClientTest :: exportPlaylistHelper(
); );
CPPUNIT_ASSERT(token); CPPUNIT_ASSERT(token);
CPPUNIT_ASSERT(url); CPPUNIT_ASSERT(url);
CPPUNIT_ASSERT(*url != ""); CPPUNIT_ASSERT_NO_THROW(
// TODO: test accessibility of the URL? FileTools::copyUrlToFile(*url, "tmp/testExportedPlaylist.tar")
);
CPPUNIT_ASSERT_NO_THROW( CPPUNIT_ASSERT_NO_THROW(
wsc->exportPlaylistClose(token); wsc->exportPlaylistClose(token);
); );
// TODO: test non-accessibility of the URL?
CPPUNIT_ASSERT_NO_THROW(
authentication->logout(sessionId);
);
}
/*------------------------------------------------------------------------------
* Testing the importPlaylist() function.
*----------------------------------------------------------------------------*/
void
WebStorageClientTest :: importPlaylistTest(void)
throw (CPPUNIT_NS::Exception)
{
Ptr<SessionId>::Ref sessionId;
CPPUNIT_ASSERT_NO_THROW(
sessionId = authentication->login("root", "q")
);
CPPUNIT_ASSERT(sessionId);
Ptr<UniqueId>::Ref playlistId;
CPPUNIT_ASSERT_NO_THROW(
playlistId = wsc->createPlaylist(sessionId)
);
Ptr<Playlist>::Ref playlist;
CPPUNIT_ASSERT_NO_THROW(
playlist = wsc->editPlaylist(sessionId, playlistId)
);
Ptr<UniqueId>::Ref audioClipId(new UniqueId(0x10001));
Ptr<AudioClip>::Ref audioClip;
CPPUNIT_ASSERT_NO_THROW(
audioClip = wsc->getAudioClip(sessionId, audioClipId)
);
Ptr<time_duration>::Ref relativeOffset(new time_duration(0,0,0,0));
CPPUNIT_ASSERT_NO_THROW(
playlist->addAudioClip(audioClip, relativeOffset)
);
CPPUNIT_ASSERT_NO_THROW(
wsc->savePlaylist(sessionId, playlist)
);
exportPlaylistHelper(playlistId, StorageClientInterface::internalFormat);
// importing a playlist already in the storage: error
Ptr<Glib::ustring>::Ref path(new Glib::ustring(
"tmp/testExportedPlaylist.tar"));
CPPUNIT_ASSERT_THROW(
wsc->importPlaylist(sessionId, path),
XmlRpcMethodFaultException
);
// deleting the playlist from the storage...
CPPUNIT_ASSERT_NO_THROW(
wsc->reset()
);
sessionId.reset();
CPPUNIT_ASSERT_NO_THROW(
sessionId = authentication->login("root", "q")
);
CPPUNIT_ASSERT(sessionId);
// ... and then importing it: this should be OK
CPPUNIT_ASSERT_NO_THROW(
wsc->importPlaylist(sessionId, path)
);
CPPUNIT_ASSERT_NO_THROW( CPPUNIT_ASSERT_NO_THROW(
authentication->logout(sessionId); authentication->logout(sessionId);

View file

@ -81,6 +81,7 @@ class WebStorageClientTest : public BaseTestMethod
CPPUNIT_TEST(browseTest); CPPUNIT_TEST(browseTest);
CPPUNIT_TEST(createBackupTest); CPPUNIT_TEST(createBackupTest);
CPPUNIT_TEST(exportPlaylistTest); CPPUNIT_TEST(exportPlaylistTest);
CPPUNIT_TEST(importPlaylistTest);
CPPUNIT_TEST(remoteSearchTest); CPPUNIT_TEST(remoteSearchTest);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
@ -99,7 +100,9 @@ class WebStorageClientTest : public BaseTestMethod
* Auxiliary function for exportPlaylistTest(). * Auxiliary function for exportPlaylistTest().
*/ */
void void
exportPlaylistHelper(StorageClientInterface::ExportFormatType format) exportPlaylistHelper(
Ptr<UniqueId>::Ref playlistId,
StorageClientInterface::ExportFormatType format)
throw (CPPUNIT_NS::Exception); throw (CPPUNIT_NS::Exception);
protected: protected:
@ -192,6 +195,14 @@ class WebStorageClientTest : public BaseTestMethod
void void
exportPlaylistTest(void) throw (CPPUNIT_NS::Exception); exportPlaylistTest(void) throw (CPPUNIT_NS::Exception);
/**
* Testing the importPlaylist() function.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
importPlaylistTest(void) throw (CPPUNIT_NS::Exception);
/** /**
* Testing the remoteSearchXxxx() functions. * Testing the remoteSearchXxxx() functions.
* *