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.cpp83
1 files changed, 83 insertions, 0 deletions
diff --git a/p2pvr/daemon/unittests/testStorage.cpp b/p2pvr/daemon/unittests/testStorage.cpp
new file mode 100644
index 0000000..5480566
--- /dev/null
+++ b/p2pvr/daemon/unittests/testStorage.cpp
@@ -0,0 +1,83 @@
+#define BOOST_TEST_MODULE Storage
+#include <boost/test/unit_test.hpp>
+#include <boost/filesystem/operations.hpp>
+#include <testOptionsSource.h>
+#include <Ice/ObjectAdapter.h>
+#include <Ice/Service.h>
+#include <maintenance.h>
+#include <mockTuner.h>
+#include <si.h>
+#include <storage.h>
+#include <boost/lexical_cast.hpp>
+#include <commonHelpers.h>
+
+const boost::filesystem::path rootDir = "/tmp/ut/p2pvr/recordings";
+class Core {
+ public:
+ Core()
+ {
+ 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_AUTO_TEST_CASE( st_openWriteClose )
+{
+ boost::filesystem::remove_all(rootDir);
+ std::string id = "made-up-storage-id";
+
+ auto rdc = st->OpenForWrite(id);
+
+ P2PVR::Data data;
+ data.resize(1024);
+
+ rdc->NewData(data);
+
+ st->Close(rdc);
+
+ auto stSize = st->FileSize(id);
+ BOOST_REQUIRE_EQUAL(1024, stSize);
+ BOOST_REQUIRE_EQUAL(1024, boost::filesystem::file_size(rootDir / id));
+
+ st->Delete(id);
+ BOOST_REQUIRE(!boost::filesystem::exists(rootDir / id));
+}
+
+BOOST_AUTO_TEST_CASE( st_notuniqueid )
+{
+ boost::filesystem::remove_all(rootDir);
+ std::string id = "made-up-storage-id";
+
+ auto rdc = st->OpenForWrite(id);
+ st->Close(rdc);
+
+ BOOST_REQUIRE_THROW(st->OpenForWrite(id), P2PVR::StorageException);
+ st->Delete(id);
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
+