summaryrefslogtreecommitdiff
path: root/p2pvr/daemon/unittests/testRecording.cpp
blob: 720b868b137ecc3cda113b1e45cf387c37d495fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#define BOOST_TEST_MODULE Recording
#include <boost/test/unit_test.hpp>
#include <boost/filesystem/operations.hpp>
#include <testOptionsSource.h>
#include <Ice/ObjectAdapter.h>
#include <Ice/Service.h>
#include <scopeObject.h>
#include <maintenance.h>
#include <mockTuner.h>
#include "mockDevices.h"
#include "mockScheduler.h"
#include <si.h>
#include <recordings.h>
#include <linux/dvb/frontend.h>
#include <definedDirs.h>
#include "mockDefs.h"
#include "sqlSelectDeserializer.h"
#include "commonHelpers.h"
#include "serviceStreamer.h"
#include "temporaryIceAdapterObject.h"
#include <slicer/slicer.h>
#include <testAppInstance.h>

class Core : public CommonObjects, public TestAppInstance {
	public:
		Core()
		{
			int paramCount = 0;
			ic = Ice::initialize(paramCount, NULL);
			adapter = ic->createObjectAdapterWithEndpoints("Adp", "tcp -p 12005");
			TestOptionsSource::LoadTestOptions({
					{ "common.datasourceRoot", (RootDir / "datasources").string() },
				});
			adapter->add(new MockDevices(), ic->stringToIdentity("GlobalDevices"));
			adapter->add(new MockScheduler(), ic->stringToIdentity("Schedules"));
			adapter->add(new SI(), ic->stringToIdentity("SI"));
			adapter->add(new Recordings(), ic->stringToIdentity("Recordings"));
			adapter->add(new Maintenance(adapter, NULL), ic->stringToIdentity("Maintenance"));
			adapter->activate();

			r = P2PVR::RecordingsPrx::checkedCast(ic->stringToProxy("Recordings"));
			BOOST_REQUIRE(r);
			r->ice_ping();

			s = P2PVR::SIPrx::checkedCast(ic->stringToProxy("SI"));
			BOOST_REQUIRE(s);
			s->ice_ping();

			m = P2PVR::MaintenancePrx::checkedCast(ic->stringToProxy("Maintenance"));
			BOOST_REQUIRE(m);
			m->ice_ping();
		}

		~Core()
		{
			ic->destroy();
		}

		P2PVR::MaintenancePrx m;
		P2PVR::RecordingsPrx r;
		P2PVR::SIPrx s;

	protected:
		Ice::CommunicatorPtr ic;
		Ice::ObjectAdapterPtr adapter;
};

class MockTarget : public P2PVR::RawDataClient {
	public:
		MockTarget() : bytesReceived(0) { }

		bool NewData(const P2PVR::Data & data, const Ice::Current &) override
		{
			bytesReceived += data.size();
			return false;
		}

		unsigned int bytesReceived;
};

BOOST_GLOBAL_FIXTURE( StandardMockDatabase );

BOOST_FIXTURE_TEST_SUITE( RecordingCore, Core );

BOOST_AUTO_TEST_CASE( streamServiceToTarget )
{
	BOOST_CHECKPOINT("Create mock target");
	IceUtil::Handle<MockTarget> target = new MockTarget();
	TemporaryIceAdapterObject<P2PVR::RawDataClient> targetPrx(adapter, target);

	BOOST_CHECKPOINT("Create service streamer");
	auto ss = ServiceStreamerPtr(new ServiceStreamer(4170, targetPrx, ic, adapter));

	BOOST_CHECKPOINT("Start");
	ss->Start();
	sleep(2);

	BOOST_CHECKPOINT("Stop");
	ss->Stop();

	BOOST_MESSAGE("Received bytes: " << target->bytesReceived);
	BOOST_REQUIRE(target->bytesReceived > 150000);
}

BOOST_AUTO_TEST_SUITE_END();