summaryrefslogtreecommitdiff
path: root/cmps/tests
diff options
context:
space:
mode:
Diffstat (limited to 'cmps/tests')
-rw-r--r--cmps/tests/CredentialPersistence.cc103
-rw-r--r--cmps/tests/FScanTest.cc46
-rw-r--r--cmps/tests/MetaScanTest.cc54
3 files changed, 172 insertions, 31 deletions
diff --git a/cmps/tests/CredentialPersistence.cc b/cmps/tests/CredentialPersistence.cc
new file mode 100644
index 0000000..8e6df4b
--- /dev/null
+++ b/cmps/tests/CredentialPersistence.cc
@@ -0,0 +1,103 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: CredentialPersistence.cc
+ * Created: 03.07.2012, 14:16:35
+ * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
+ * Project: cmps - the backend (server) part of compound media player
+ *
+ * CMP - compound media player
+ *
+ * is a client/server mediaplayer intended to play any media from any workstation
+ * without the need to export or mount shares. cmps is an easy to use backend
+ * with a (ready to use) HTML-interface. Additionally the backend supports
+ * authentication via HTTP-digest authorization.
+ * cmpc is a client with vdr-like osd-menues.
+ *
+ * Copyright (c) 2012 Reinhard Mantey, some rights reserved!
+ * published under Creative Commons by-sa
+ * For details see http://creativecommons.org/licenses/by-sa/3.0/
+ *
+ * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp
+ *
+ * --------------------------------------------------------------
+ */
+#include <Principal.h>
+#include <Credentials.h>
+#include <stdlib.h>
+#include <iostream>
+
+/*
+ * Simple C++ Test Suite
+ */
+static void setupTestCredentials() {
+ Credentials.SetApplicationRealm("supportedUsers@myTestApp");
+ cPrincipal *p = new cPrincipal("Nasenbär", Credentials.ApplicationRealm());
+
+ p->CreateHash("Nasenwasser");
+ Credentials.Put(p->Name(), p);
+
+ p = new cPrincipal("Admin", Credentials.ApplicationRealm());
+ p->CreateHash("very secret");
+ Credentials.Put(p->Name(), p);
+
+ p = new cPrincipal("Sepp", Credentials.ApplicationRealm());
+ p->CreateHash("keine Ahnung");
+ Credentials.Put(p->Name(), p);
+}
+
+static void dumpCredentials() {
+ cCredentials::const_iterator principals = Credentials.begin();
+
+ while (principals != Credentials.end()) {
+ principals->second->Dump();
+ ++principals;
+ }
+
+}
+
+void test1()
+{
+ setupTestCredentials();
+ std::cout << "CredentialPersistence test 1" << std::endl;
+
+ int rv = Credentials.Store("/tmp/testCredentials.x9");
+
+ if (!rv) std::cout << "%TEST_FAILED% time=0 testname=test1 (CredentialPersistence) message=failed to write credentials" << std::endl;
+ else std::cout << "saved " << rv << " principals." << std::endl;
+
+ dumpCredentials();
+}
+
+void test2()
+{
+ std::cout << "CredentialPersistence test 2" << std::endl;
+
+ Credentials.Clear();
+
+ int rv = Credentials.Load("/tmp/testCredentials.x9");
+
+ if (!rv) std::cout << "%TEST_FAILED% time=0 testname=test2 (CredentialPersistence) message=failed to load credentials" << std::endl;
+ else std::cout << "loaded " << rv << " principals." << std::endl;
+
+ dumpCredentials();
+}
+
+int main(int argc, char** argv)
+{
+ std::cout << "%SUITE_STARTING% CredentialPersistence" << std::endl;
+ std::cout << "%SUITE_STARTED%" << std::endl;
+
+ std::cout << "%TEST_STARTED% test1 (CredentialPersistence)" << std::endl;
+ test1();
+ std::cout << "%TEST_FINISHED% time=0 test1 (CredentialPersistence)" << std::endl;
+
+ std::cout << "%TEST_STARTED% test2 (CredentialPersistence)\n" << std::endl;
+ test2();
+ std::cout << "%TEST_FINISHED% time=0 test2 (CredentialPersistence)" << std::endl;
+
+ std::cout << "%SUITE_FINISHED% time=0" << std::endl;
+
+ return (EXIT_SUCCESS);
+}
+
diff --git a/cmps/tests/FScanTest.cc b/cmps/tests/FScanTest.cc
index a426c0d..8ca4498 100644
--- a/cmps/tests/FScanTest.cc
+++ b/cmps/tests/FScanTest.cc
@@ -22,13 +22,15 @@
*
* --------------------------------------------------------------
*/
-#include <stdlib.h>
-#include <iostream>
#include <Audio.h>
#include <Movie.h>
-#include <PictuFSMediaScannerner.h>
+#include <Picture.h>
+#include <FSMediaScanner.h>
#include <MediaFactory.h>
+#include <MediaServerConfig.h>
#include <TimeMs.h>
+#include <stdlib.h>
+#include <iostream>
class FScanTest {
public:
@@ -66,30 +68,45 @@ void FScanTest::test3()
}
void FScanTest::test4()
-///< result from java pendant: FSScanner - scanning of 9970 media took 46 ms
-///< own result: found 9970 media, in 58 ms.
-///< file server (mostly recordings) found 2828 media, in 53525 ms.
-///< file server (added 18G audio) found 5698 media, in 44653 ms.
-///< file server (same files, fresh reboot) found 5698 media, in 54723 ms.
+///< result from java pendant: FSScanner - scanning of 9970 media took 46 ms
+///< own result: found 9970 media, in 58 ms.
+///< file server (mostly recordings) found 2828 media, in 53525 ms.
+///< file server (added 18G audio) found 5698 media, in 44653 ms.
+///< file server (same files, fresh reboot) found 5698 media, in 54723 ms.
+///< new own result using cFile found 10002 media, in 601 ms. (first run)
+///< new own result using cFile found 10002 media, in 177 ms. (second run)
+///< with mediascan found 10002 media, in 80570 ms.
+///< with mediascan and saving values found 10002 media, in 93675 ms.
+///< with mediascan, scanning each media found 10002 media, in 247096 ms.
+///< java - mediascan for each media scanning of 9312 media took 215037 ms. (with key file)
{
+ cMediaServerConfig config("/var/lib/cmp");
cFSMediaScanner scanner;
cAbstractMedia *media;
+ config.Load("srserver.conf");
+ config.SetAuthorizationRequired(false);
+ config.Dump();
+
std::cout << "FScanTest test 4" << std::endl;
- scanner.SetMediaFactory(new cMediaFactory("/media/video"));
+ scanner.SetMediaFactory(new cMediaFactory(config));
uint64_t start = cTimeMs::Now();
scanner.Refresh();
uint64_t end = cTimeMs::Now();
+ size_t grouped[cAbstractMedia::Unknown];
+ int mx = sizeof(grouped) / sizeof(size_t);
+ for (int i=0; i < mx; ++i) grouped[i] = 0;
for (size_t i=0; i < scanner.MediaPool().size(); ++i) {
media = (cAbstractMedia *) scanner.MediaPool()[i];
- std::cout << media->Name() << " [" << media->MimeType() << "] => " << media->AbsolutePath() << std::endl;
+ ++grouped[media->MediaType()];
+ media->Dump();
}
std::cout << std::endl << "found " << scanner.MediaPool().size() << " media, in " << end - start << " ms." << std::endl;
- const char *file2Search = "/pretty/unsupported/media/file/in/any/workstation.unknown";
+ const char *file2Search = "/pretty/unsupported/media/file/in/any/known.workstation";
// search (worst case)
start = cTimeMs::Now();
@@ -97,11 +114,18 @@ void FScanTest::test4()
end = cTimeMs::Now();
std::cout << "array search took " << end - start << " ms." << std::endl;
+
+ for (int i=0; i < mx; ++i) {
+ std::cout << cAbstractMedia::MediaType2Text(i) << " has " << grouped[i] << " members." << std::endl;
+ }
cFile::Cleanup();
}
int main(int argc, char** argv)
{
+ int MaxPossibleFileDescriptors = getdtablesize();
+
+ std::cout << "maximum of open files #" << MaxPossibleFileDescriptors << std::endl << std::endl;
uint64_t t0 = cTimeMs::Now();
std::cout << "%SUITE_STARTING% FScanTest" << std::endl;
std::cout << "%SUITE_STARTED%" << std::endl;
diff --git a/cmps/tests/MetaScanTest.cc b/cmps/tests/MetaScanTest.cc
index 918ad9f..1b57752 100644
--- a/cmps/tests/MetaScanTest.cc
+++ b/cmps/tests/MetaScanTest.cc
@@ -28,6 +28,8 @@
#include <ConfigReader.h>
#include <CommandReader.h>
#include <MediainfoReader.h>
+#include <MediaInfo/MediaInfo.h>
+#include <MediaServerConfig.h>
#include <iostream>
#include <stdlib.h>
#include <string.h>
@@ -35,8 +37,9 @@
#include <unistd.h>
#include <tr1/tuple>
-static void parseConfig(const char *FileName)
+void parseConfig(const char *FileName)
{
+#ifdef OLD_STUFF
cConfigReader *cr = new cConfigReader(new cLineReader(new cFileReader(new cFile(FileName))));
cConfigReader::ConfigEntry *ce;
@@ -46,9 +49,15 @@ static void parseConfig(const char *FileName)
}
cr->Close();
delete cr;
+#else
+ cMediaServerConfig msc("/var/lib/cmp");
+
+ msc.Load("srserver.conf");
+ msc.Dump();
+#endif
}
-static void dumpTextfile(const char *FileName)
+void dumpTextfile(const char *FileName)
{
cLineReader *lr = new cLineReader(new cFileReader(new cFile(FileName)));
const char *line;
@@ -59,32 +68,34 @@ static void dumpTextfile(const char *FileName)
delete lr;
}
-static void setupMediainfoReader(cMediainfoReader *mir)
+void setupMediainfo(void)
{
- mir->AddValuableKey("Format");
+ static const char *MetaKeys[] = {
+ "Format"
//Audio
- mir->AddValuableKey("Duration");
- mir->AddValuableKey("Album");
- mir->AddValuableKey("Track name");
- mir->AddValuableKey("Performer");
- mir->AddValuableKey("Bit rate");
+, "Duration"
+, "Album"
+, "Track name"
+, "Performer"
+, "Bit rate"
//Image
- mir->AddValuableKey("Width");
- mir->AddValuableKey("Height");
+, "Width"
+, "Height"
//Video
- mir->AddValuableKey("Display aspect ratio");
- mir->AddValuableKey("Scan type");
+, "Display aspect ratio"
+, "Scan type"
+, NULL
+ };
+ cMediainfoReader::Setup(MetaKeys);
}
-static void testMediaInfo(const char *FileName)
+void testMediaInfo(const char *FileName)
{
cCommandReader *cr = new cCommandReader("/usr/bin/mediainfo");
-// cFileReader *fr = new cFileReader(new cFile("mi.output"));
cMediainfoReader *mir = new cMediainfoReader(new cLineReader(cr));
cMediainfoReader::InfoEntry *ie;
cr->AddCommandParameter(FileName);
- setupMediainfoReader(mir);
while ((ie = mir->ReadEntry())) {
std::cout << "media info - [" << std::get<0>(*ie) << "] ==> " << std::get<1>(*ie) << std::endl;
delete ie;
@@ -98,6 +109,7 @@ void testMediaFiles(const char *FileName)
cLineReader *lr = new cLineReader(new cFileReader(new cFile(FileName)));
const char *line;
+ setupMediainfo();
while ((line = lr->ReadLine())) {
std::cout << std::endl << "media-test-file: " << line << std::endl;
testMediaInfo(line);
@@ -112,7 +124,7 @@ enum PipeFileDescriptors {
WRITE_FD = 1
};
-static void testCommandReader()
+void testCommandReader()
{
cCommandReader *cr = new cCommandReader("/bin/ls");
cLineReader *lr = new cLineReader(cr);
@@ -129,7 +141,9 @@ static void testCommandReader()
int main()
{
-// testMediaInfo("blah");
+ char buf[256];
+
+ std::cout << "working directory is: " << getcwd(buf, sizeof(buf)) << std::endl;
dumpTextfile("srclient.conf");
std::cout << std::endl << "===========================================" << std::endl << std::endl;
@@ -138,8 +152,8 @@ int main()
std::cout << std::endl << "===========================================" << std::endl << std::endl;
testCommandReader();
- std::cout << std::endl << "===========================================" << std::endl << std::endl;
- testMediaFiles("testMedia.files");
+// std::cout << std::endl << "===========================================" << std::endl << std::endl;
+// testMediaFiles("testMedia.txt");
cFile::Cleanup();
return 0;