summaryrefslogtreecommitdiff
path: root/p2pvr/daemon/unittests/testStorage.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'p2pvr/daemon/unittests/testStorage.cpp')
-rw-r--r--p2pvr/daemon/unittests/testStorage.cpp69
1 files changed, 28 insertions, 41 deletions
diff --git a/p2pvr/daemon/unittests/testStorage.cpp b/p2pvr/daemon/unittests/testStorage.cpp
index 973e93b..9e15662 100644
--- a/p2pvr/daemon/unittests/testStorage.cpp
+++ b/p2pvr/daemon/unittests/testStorage.cpp
@@ -1,7 +1,7 @@
#define BOOST_TEST_MODULE Storage
#include <boost/test/unit_test.hpp>
#include <boost/filesystem/operations.hpp>
-#include <testOptionsSource.h>
+#include <options.h>
#include <Ice/ObjectAdapter.h>
#include <Ice/Service.h>
#include <maintenance.h>
@@ -10,73 +10,60 @@
#include <storage.h>
#include <boost/lexical_cast.hpp>
#include <commonHelpers.h>
-#include <testAppInstance.h>
+#include <definedDirs.h>
+#include "mockDefs.h"
-const boost::filesystem::path rootDir = "/tmp/ut/p2pvr/recordings";
-class Core : public TestAppInstance {
+const boost::filesystem::path storageRootDir = "/tmp/ut/p2pvr/recordings";
+class TestService : public PQ::Mock, public IceTray::DryIce {
public:
- Core()
+ TestService() :
+ PQ::Mock("user=postgres dbname=postgres", "postgres", {
+ rootDir.parent_path().parent_path() / "datasources" / "schema.sql" }),
+ IceTray::DryIce({
+ R"C(--p2pvr.storage.muxercommand="")C",
+ std::string("--p2pvr.storage.root=" + storageRootDir.string()),
+ })
{
- int paramCount = 0;
- ic = Ice::initialize(paramCount, NULL);
- auto adapter = ic->createObjectAdapterWithEndpoints("Adp", "tcp -p 12004");
- TestOptionsSource::LoadTestOptions({
- { "p2pvr.storage.muxercommand", std::string() },
- { "p2pvr.storage.root", rootDir.string() },
- });
- adapter->add(new Storage(), ic->stringToIdentity("Storage"));
- adapter->activate();
-
- st = P2PVR::StoragePrx::checkedCast(ic->stringToProxy("Storage"));
- BOOST_REQUIRE(st);
- st->ice_ping();
}
-
- ~Core()
- {
- ic->destroy();
- }
-
- P2PVR::StoragePrx st;
-
- private:
- Ice::CommunicatorPtr ic;
};
-BOOST_FIXTURE_TEST_SUITE( StCore, Core )
+BOOST_GLOBAL_FIXTURE( TestService );
+
+BOOST_FIXTURE_TEST_SUITE( StCore, TestClient );
BOOST_AUTO_TEST_CASE( st_openWriteClose )
{
- boost::filesystem::remove_all(rootDir);
+ boost::filesystem::remove_all(storageRootDir);
std::string id = "made-up-storage-id";
- auto rdc = st->OpenForWrite(id);
+ auto rdc = storage->OpenForWrite(id);
+ BOOST_REQUIRE(rdc);
P2PVR::Data data;
data.resize(1024);
rdc->NewData(data);
- st->Close(rdc);
+ storage->Close(rdc);
- auto stSize = st->FileSize(id);
+ auto stSize = storage->FileSize(id);
BOOST_REQUIRE_EQUAL(1024, stSize);
- BOOST_REQUIRE_EQUAL(1024, boost::filesystem::file_size(rootDir / id));
+ BOOST_REQUIRE_EQUAL(1024, boost::filesystem::file_size(storageRootDir / id));
- st->Delete(id);
- BOOST_REQUIRE(!boost::filesystem::exists(rootDir / id));
+ storage->Delete(id);
+ BOOST_REQUIRE(!boost::filesystem::exists(storageRootDir / id));
}
BOOST_AUTO_TEST_CASE( st_notuniqueid )
{
- boost::filesystem::remove_all(rootDir);
+ boost::filesystem::remove_all(storageRootDir);
std::string id = "made-up-storage-id";
- auto rdc = st->OpenForWrite(id);
- st->Close(rdc);
+ auto rdc = storage->OpenForWrite(id);
+ storage->Close(rdc);
- BOOST_REQUIRE_THROW(st->OpenForWrite(id), P2PVR::StorageException);
- st->Delete(id);
+ BOOST_REQUIRE_THROW(storage->OpenForWrite(id), P2PVR::StorageException);
+ storage->Delete(id);
}
BOOST_AUTO_TEST_SUITE_END()