summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgeronimo <geronimo013@gmx.de>2012-07-31 05:38:25 (GMT)
committergeronimo <geronimo013@gmx.de>2012-07-31 05:38:25 (GMT)
commit76c51473ee29a9103201618c8dbbc11fe9b7149e (patch)
treed1327f73c64ba281fccb8bdae6932460ebfd3292
parent5e04292eb7545b06cc7ea66605eda8342f220b15 (diff)
downloadcmp-76c51473ee29a9103201618c8dbbc11fe9b7149e.tar.gz
cmp-76c51473ee29a9103201618c8dbbc11fe9b7149e.tar.bz2
no more need for separated tests for code::blocks - netbeans is smarter in handling testcases
-rw-r--r--cmps/tests/ConnectionHandlerTest.cc11
-rw-r--r--cmps/tests/JSonTest.cc2
-rw-r--r--cmps/tests/MetaScanTest.cc132
-rw-r--r--cmps/tests/StringBuilderTest.cc133
-rw-r--r--tests/ConnectionHandlerTest/ConnectionHandlerTest.cc138
-rw-r--r--tests/CredentialPersistence/CredentialPersistence.cc85
-rw-r--r--tests/FilesystemTest/main.cpp234
-rw-r--r--tests/JSonTest/JSonTest.cc68
-rw-r--r--tests/MetaScanTest/main.cpp146
-rw-r--r--tests/StringBuilderTest/main.cpp76
10 files changed, 105 insertions, 920 deletions
diff --git a/cmps/tests/ConnectionHandlerTest.cc b/cmps/tests/ConnectionHandlerTest.cc
index 8ff3cce..c9e1099 100644
--- a/cmps/tests/ConnectionHandlerTest.cc
+++ b/cmps/tests/ConnectionHandlerTest.cc
@@ -2,7 +2,7 @@
* ======================== legal notice ======================
*
* File: ConnectionHandlerTest.cc
- * Created: 10.07.2012, 05
+ * Created: 10.07.2012, 05:48:23
* Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
* Project: cmps - the backend (server) part of compound media player
*
@@ -58,7 +58,7 @@ private:
};
cTestUnit::cTestUnit(const char* Name, cConnectionPoint &cp)
- : config(12345)
+ : config("/var/lib/cmp")
, ch(cp, config)
, name(Name)
, scanner(NULL)
@@ -72,9 +72,9 @@ cTestUnit::cTestUnit(const char* Name, cConnectionPoint &cp)
fprintf(stderr, "could not initialize application! (1)");
exit(-1);
}
- scanner->SetMediaFactory(new cMediaFactory(config.DocumentRoot()));
+ scanner->SetMediaFactory(new cMediaFactory(config));
- cAbstractMediaRequestHandler::SetFilesystemScanner(scanner);
+ cAbstractMediaRequestHandler::SetFSMediaScanner(scanner);
cConnectionHandler::RegisterRequestHandler("/cmd", new cCommandHandler());
cMediaListHandler *listHandler = new cMediaListHandler();
@@ -148,6 +148,9 @@ int main(int argc, char** argv)
std::cout << "%SUITE_FINISHED% time=" << (double)(cTimeMs::Now() - t0) / 1000 << std::endl;
+ cFile::Cleanup();
+ cUrl::Cleanup();
+
return (EXIT_SUCCESS);
}
diff --git a/cmps/tests/JSonTest.cc b/cmps/tests/JSonTest.cc
index 422a845..777b8b5 100644
--- a/cmps/tests/JSonTest.cc
+++ b/cmps/tests/JSonTest.cc
@@ -2,7 +2,7 @@
* ======================== legal notice ======================
*
* File: JSonTest.cc
- * Created: 12.07.2012, 07
+ * Created: 12.07.2012, 07:31
* Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
* Project: cmps - the backend (server) part of compound media player
*
diff --git a/cmps/tests/MetaScanTest.cc b/cmps/tests/MetaScanTest.cc
index 8b293f9..918ad9f 100644
--- a/cmps/tests/MetaScanTest.cc
+++ b/cmps/tests/MetaScanTest.cc
@@ -26,18 +26,14 @@
#include <FileReader.h>
#include <LineReader.h>
#include <ConfigReader.h>
+#include <CommandReader.h>
+#include <MediainfoReader.h>
#include <iostream>
#include <stdlib.h>
#include <string.h>
-#include <errno.h>
-#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
-#include <wait.h>
#include <tr1/tuple>
-#include <util.h>
-
-static void testPipe(const char *chk = NULL);
static void parseConfig(const char *FileName)
{
@@ -52,11 +48,43 @@ static void parseConfig(const char *FileName)
delete cr;
}
+static void dumpTextfile(const char *FileName)
+{
+ cLineReader *lr = new cLineReader(new cFileReader(new cFile(FileName)));
+ const char *line;
+
+ while ((line = lr->ReadLine())) {
+ std::cout << "line: " << line << std::endl;
+ }
+ delete lr;
+}
+
+static void setupMediainfoReader(cMediainfoReader *mir)
+{
+ mir->AddValuableKey("Format");
+ //Audio
+ mir->AddValuableKey("Duration");
+ mir->AddValuableKey("Album");
+ mir->AddValuableKey("Track name");
+ mir->AddValuableKey("Performer");
+ mir->AddValuableKey("Bit rate");
+ //Image
+ mir->AddValuableKey("Width");
+ mir->AddValuableKey("Height");
+ //Video
+ mir->AddValuableKey("Display aspect ratio");
+ mir->AddValuableKey("Scan type");
+}
+
static void testMediaInfo(const char *FileName)
{
- cMediainfoReader *mir = new cMediainfoReader(new cLineReader(new cCommandReader("/usr/bin/mediainfo")));
+ 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;
@@ -65,7 +93,7 @@ static void testMediaInfo(const char *FileName)
delete mir;
}
-static void testMediaFiles(const char *FileName)
+void testMediaFiles(const char *FileName)
{
cLineReader *lr = new cLineReader(new cFileReader(new cFile(FileName)));
const char *line;
@@ -88,93 +116,21 @@ static void testCommandReader()
{
cCommandReader *cr = new cCommandReader("/bin/ls");
cLineReader *lr = new cLineReader(cr);
- char *line;
+ const char *line;
- cr.AddCommandParameter("-al");
- cr.AddCommandParameter("--color");
+ cr->AddCommandParameter("-al");
+ cr->AddCommandParameter("--color");
while ((line = lr->ReadLine())) {
std::cout << "from command: " << line << std::endl;
}
+ delete lr;
};
-static void testPipe(const char *chk)
-{
- int parent2Child[2];
- int child2Parent[2];
- pid_t pid;
- std::string dataReadFromChild;
- char buffer[BufferSize + 1];
- ssize_t readResult;
- bool run = true;
- int status;
-
- ASSERT_IS(0, pipe(parent2Child));
- ASSERT_IS(0, pipe(child2Parent));
-
- switch (pid = fork()) {
- case -1:
- FAIL("fork failed");
- exit(-1);
-
- case 0: /* child */
- ASSERT_NOT(-1, dup2(parent2Child[READ_FD], STDIN_FILENO));
- ASSERT_NOT(-1, dup2(child2Parent[WRITE_FD], STDOUT_FILENO));
- ASSERT_NOT(-1, dup2(child2Parent[WRITE_FD], STDERR_FILENO));
- ASSERT_IS(0, close(parent2Child[WRITE_FD]));
- ASSERT_IS(0, close(child2Parent[READ_FD]));
-
- if (chk) {
- execlp("mediainfo", "mediainfo", chk, NULL);
- }
- else execlp("ls", "ls", "-al", "--color", NULL);
- FAIL("this line should never be reached!");
- exit(-1);
-
- default: /* parent */
- std::cout << "child " << pid << " process running ..." << std::endl;
-
- ASSERT_IS(0, close(parent2Child[READ_FD]));
- ASSERT_IS(0, close(child2Parent[WRITE_FD]));
-
- while (run) {
- switch (readResult = read(child2Parent[READ_FD], buffer, BufferSize)) {
- case 0: /* end of file, or non-blocking read. */
- std::cout << "End of File reached ..." << std::endl
- << "Data received was ("
- << dataReadFromChild.size() << "):" << std::endl
- << dataReadFromChild << std::endl;
- ASSERT_IS(pid, waitpid(pid, &status, 0));
-
- std::cout << std::endl
- << "child exit status is: " << WEXITSTATUS(status) << std::endl << std::endl;
-// exit(0);
- run = false;
- break;
-
- case -1:
- if ((errno == EINTR) || (errno == EAGAIN)) {
- errno = 0;
- }
- else {
- FAIL("read() failed");
- run = false;
- } break;
-
- default:
- dataReadFromChild.append(buffer, readResult);
- break;
- }
- }
- }
-}
-
-
-// mediainfo ${media} | grep "Scan type"
-// ffmpeg -i ${media}
int main()
{
- parseConfig("srclient.conf");
+// testMediaInfo("blah");
+ dumpTextfile("srclient.conf");
std::cout << std::endl << "===========================================" << std::endl << std::endl;
parseConfig("srserver.conf");
@@ -182,8 +138,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.files");
cFile::Cleanup();
return 0;
diff --git a/cmps/tests/StringBuilderTest.cc b/cmps/tests/StringBuilderTest.cc
index bb07d2e..9814411 100644
--- a/cmps/tests/StringBuilderTest.cc
+++ b/cmps/tests/StringBuilderTest.cc
@@ -22,103 +22,76 @@
*
* --------------------------------------------------------------
*/
-#include <stdlib.h>
-#include <iostream>
#include <StringBuilder.h>
+#include <FileReader.h>
+#include <LineReader.h>
+#include <File.h>
+#include <string.h>
+#include <iostream>
-/*
- * Simple C++ Test Suite
- */
+#define NEW_LINE '\n'
-void test1()
-{
- cStringBuilder sb(16);
- char buf[256] = {0};
- int blah = 0;
+void rangeTests()
+{ // 12345678901
+ static const char *sample = "Hello World";
+ cStringBuilder *sb;
+ int chunkSize = strlen(sample) - 4;
+ char *result;
- std::cout << "StringBuilderTest test 1" << std::endl;
+ std::cout << sample << " has length: " << strlen(sample) << std::endl;
- sb.Append("Alle ma herhören!\n").Append("Jetzt jibbet wat uff de Ohren!\n");
- sb.Append("Ausgewählt: ").Append(true, "Ja", "Nein").Append("\n");
- sb.Append("Dezimal: ").Append(3.1478910).Append("\n");
- sb.Append("Integer: ").Append(127).Append("\n");
- sb.Append("große Zahl: ").Append(98765432123456789l).Append("\n");
+ for (int i=0; i < 6; ++i) {
+ std::cout << "check chunkSize of " << chunkSize + i << std::endl;
+ sb = new cStringBuilder(chunkSize + i);
- std::cout << "size of StringBuilder: " << sb.Size() << " bytes" << std::endl;
- size_t bytesWritten = sb.Copy(buf, sizeof(buf));
+ sb->Append(sample).Append(NEW_LINE);
+ result = sb->toString();
- if (bytesWritten != sb.Size())
- std::cout << "%TEST_FAILED% time=0 testname=test1 (StringBuilderTest) message=length after copy differ." << std::endl;
- else std::cout << "OK" << std::endl << "=====================" << std::endl << buf << "===================" << std::endl;
+ std::cout << "assembled text looks like: " << std::endl << result;
+ free(result);
+ delete sb;
+ }
}
-void test2()
+void basicTests()
{
- cStringBuilder sb;
- char buf[512] = {0};
- int blah=0;
- std::cout << "StringBuilderTest test 2" << std::endl;
-// std::cout << "%TEST_FAILED% time=0 testname=test2 (StringBuilderTest) message=error message sample" << std::endl;
+ cStringBuilder sb(179);
- sb.Append("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore "
- "et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. "
- "Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit "
- "amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna "
- "aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd "
- "gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur "
- "sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam "
- "voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea "
- "takimata sanctus est Lorem ipsum dolor sit amet. ");
- sb.Append("На берегу пустынных волн\n").Append("Стоял он, дум великих полн,\n");
- sb.Append("И вдаль глядел. Пред ним широко\n").Append("Река неслася; бедный чёлн\n");
- sb.Append("По ней стремился одиноко.\n").Append("По мшистым, топким берегам\n");
- sb.Append("Чернели избы здесь и там,\n").Append("Приют убогого чухонца;\n");
- sb.Append("И лес, неведомый лучам\n").Append("В тумане спрятанного солнца,\n");
- sb.Append("Кругом шумел.\n");
- sb.Append("Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore "
- "eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum "
- "zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer "
- "adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. ");
- sb.Append("Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex "
- "ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie "
- "consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim "
- "qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. ");
- sb.Append("Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat "
- "facer possim assum. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh "
- "euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis "
- "nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. ");
- sb.Append("Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore "
- "eu feugiat nulla facilisis. ");
+ sb.Append("hello World").Append(NEW_LINE);
+ sb.Append("logical default true: ").Append(true).Append(NEW_LINE);
+ sb.Append("logical default false: ").Append(false).Append(NEW_LINE);
+ sb.Append("logical true value: ").Append(true, "true", "false").Append(NEW_LINE);
+ sb.Append("logical false value: ").Append(false, "true", "false").Append(NEW_LINE);
+ sb.Append("double: ").Append(3.1456789).Append(NEW_LINE);
+ sb.Append("unsigned long: ").Append((size_t) 91237485l).Append(NEW_LINE);
+ sb.Append("long: ").Append(1234567890l).Append(NEW_LINE);
+ sb.Append("int: ").Append(512).Append(NEW_LINE);
- std::cout << "size of StringBuilder: " << sb.Size() << " bytes" << std::endl;
- size_t bytesWritten = 0;
- int chunkWritten = 0;
+ char *result = sb.toString();
- while ((chunkWritten = sb.Copy(buf, sizeof(buf))) > 0) {
- bytesWritten += chunkWritten;
- std::cout << "==========================================" << std::endl << buf;
- std::cout << "==========================================" << std::endl;
- }
- if (bytesWritten != sb.Size())
- std::cout << "%TEST_FAILED% time=0 testname=test2 (StringBuilderTest) message=size mismatch after write" << std::endl;
- else std::cout << "OK" << std::endl;
+ std::cout << "sizeof assembled text: " << sb.Size() << std::endl;
+ std::cout << "assembled text looks like:" << std::endl << result;
+
+ free(result);
}
-int main(int argc, char** argv)
+void lineReaderTest()
{
- std::cout << "%SUITE_STARTING% StringBuilderTest" << std::endl;
- std::cout << "%SUITE_STARTED%" << std::endl;
+ cLineReader lr(new cFileReader(new cFile("srclient.conf")));
+ const char *line = NULL;
- std::cout << "%TEST_STARTED% test1 (StringBuilderTest)" << std::endl;
- test1();
- std::cout << "%TEST_FINISHED% time=0 test1 (StringBuilderTest)" << std::endl;
-
- std::cout << "%TEST_STARTED% test2 (StringBuilderTest)\n" << std::endl;
- test2();
- std::cout << "%TEST_FINISHED% time=0 test2 (StringBuilderTest)" << std::endl;
+ while ((line = lr.ReadLine())) {
+ std::cout << "line: " << line << std::endl;
+ }
+ lr.Close();
+ cFile::Cleanup();
+}
- std::cout << "%SUITE_FINISHED% time=0" << std::endl;
+int main()
+{
+ lineReaderTest();
+ basicTests();
+ rangeTests();
- return (EXIT_SUCCESS);
+ return 0;
}
-
diff --git a/tests/ConnectionHandlerTest/ConnectionHandlerTest.cc b/tests/ConnectionHandlerTest/ConnectionHandlerTest.cc
deleted file mode 100644
index 89dc56d..0000000
--- a/tests/ConnectionHandlerTest/ConnectionHandlerTest.cc
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * File: ConnectionHandlerTest.cc
- * Author: django
- *
- * Created on 10.07.2012, 05:48:23
- */
-#include <ConnectionHandler.h>
-#include <ServerConfig.h>
-#include <FSMediaScanner.h>
-#include <MediaFactory.h>
-#include <MediaListHandler.h>
-#include <MediaFileHandler.h>
-#include <CommandHandler.h>
-#include <JSonListAssembler.h>
-#include <HTMLListAssembler.h>
-#include <HTTPRequest.h>
-#include <HTTPResponse.h>
-#include <TimeMs.h>
-#include <stdlib.h>
-#include <iostream>
-#include <stdio.h>
-#include <sys/types.h>
-
-class cTestUnit {
-public:
- cTestUnit(const char *Name, cConnectionPoint &cp);
- ~cTestUnit();
-
- void test1(void);
- void test2(void);
-
- const char *Name(void) const { return name; }
- void SetUp(void);
-
-private:
- cServerConfig config;
- cConnectionHandler ch;
- const char *name;
- cFSMediaScanner *scanner;
-};
-
-cTestUnit::cTestUnit(const char* Name, cConnectionPoint &cp)
- : config("/var/lib/cmp")
- , ch(cp, config)
- , name(Name)
- , scanner(NULL)
-{
- config.SetAuthorizationRequired(false);
- config.SetDocumentRoot("/media/video");
- config.SetAppIcon("/media/favicon.ico");
-
- scanner = new cFSMediaScanner();
- if (!scanner) {
- fprintf(stderr, "could not initialize application! (1)");
- exit(-1);
- }
- scanner->SetMediaFactory(new cMediaFactory(config));
-
- cAbstractMediaRequestHandler::SetFSMediaScanner(scanner);
- cConnectionHandler::RegisterRequestHandler("/cmd", new cCommandHandler());
- cMediaListHandler *listHandler = new cMediaListHandler();
-
- listHandler->SetListAssembler("json", new cJSonListAssembler());
- listHandler->SetDefaultListAssembler(new cHTMLListAssembler());
- cConnectionHandler::RegisterRequestHandler("/", listHandler);
- cConnectionHandler::RegisterDefaultHandler(new cMediaFileHandler());
-}
-
-cTestUnit::~cTestUnit()
-{
- cCommandHandler::Cleanup();
- delete scanner;
-}
-
-void cTestUnit::SetUp()
-{
- if (scanner) scanner->Refresh();
-}
-
-void cTestUnit::test1()
-{
- std::cout << "ConnectionHandlerTest test 1" << std::endl;
-
- cHTTPRequest rq(cHTTPRequest::GET, "/");
-
- rq.SetHeader("Host", "localhost:43567");
- rq.SetHeader("User-Agent", "TestUnit");
- rq.SetHeader("Accept", "image/png,image/*;q=0.8,*/*;q=0.5");
- rq.SetHeader("Accept-Language", "de-de,de;q=0.8,en-us;q=0.5,en;q=0.3");
- rq.SetHeader("Accept-Encoding", "gzip,deflate");
- rq.SetHeader("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
- rq.SetHeader("Keep-Alive", "300");
- rq.SetHeader("Connection", "keep-alive");
-
- rq.Dump();
- cHTTPResponse *res = ch.ProcessRequest(rq);
-
- std::cout << "response looks like ..." << std::endl;
- res->Dump();
- delete res;
-}
-
-void cTestUnit::test2()
-{
- std::cout << "ConnectionHandlerTest test 2" << std::endl;
- std::cout << "%TEST_FAILED% time=0 testname=test2 (ConnectionHandlerTest) message=error message sample" << std::endl;
-}
-
-int main(int argc, char** argv)
-{
- uint64_t t0 = cTimeMs::Now();
- cConnectionPoint localHost("localhost", 40902);
- cTestUnit unit("ConnectionHandlerTest", localHost);
-
- unit.SetUp();
- std::cout << "%SUITE_STARTING% " << unit.Name() << std::endl;
- std::cout << "%SUITE_STARTED%" << std::endl;
-
- std::cout << "%TEST_STARTED% test1 (" << unit.Name() << ")" << std::endl;
- uint64_t start = cTimeMs::Now();
- unit.test1();
- uint64_t end = cTimeMs::Now();
- std::cout << "%TEST_FINISHED% time=" << (double)(end - start) / 1000 << " test1 (" << unit.Name() << ")" << std::endl;
-
- std::cout << "%TEST_STARTED% test2 (" << unit.Name() << ")\n" << std::endl;
- start = cTimeMs::Now();
- unit.test2();
- end = cTimeMs::Now();
- std::cout << "%TEST_FINISHED% time=" << (double)(end - start) / 1000 << " test2 (" << unit.Name() << ")" << std::endl;
-
- std::cout << "%SUITE_FINISHED% time=" << (double)(cTimeMs::Now() - t0) / 1000 << std::endl;
-
- cFile::Cleanup();
- cUrl::Cleanup();
-
- return (EXIT_SUCCESS);
-}
-
diff --git a/tests/CredentialPersistence/CredentialPersistence.cc b/tests/CredentialPersistence/CredentialPersistence.cc
deleted file mode 100644
index 8dc2347..0000000
--- a/tests/CredentialPersistence/CredentialPersistence.cc
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * File: CredentialPersistence.cc
- * Author: django
- *
- * Created on 03.07.2012, 14:16:35
- */
-#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/tests/FilesystemTest/main.cpp b/tests/FilesystemTest/main.cpp
deleted file mode 100644
index 2196a45..0000000
--- a/tests/FilesystemTest/main.cpp
+++ /dev/null
@@ -1,234 +0,0 @@
-/*
- * File: FileSystemTest.cc
- * Author: django
- *
- * Created on 21.07.2012, 12:40:48
- */
-
-#include <stdlib.h>
-#include <iostream>
-#include <FileSystem.h>
-#include <File.h>
-#include <StringBuilder.h>
-#include <LegacyVdrRecording.h>
-#include <VdrRecording.h>
-#include <DVDImage.h>
-#include <Audio.h>
-#include <Picture.h>
-#include <Logging.h>
-#include <TimeMs.h>
-#include <Url.h>
-#include <string.h>
-
-int visitor(void *opaque, cFile *Parent, const char *Name)
-{
- cFile *child = new cFile(*Parent, Name);
-
- std::cout << Parent->Name() << " - has child-entry: " << Name << std::endl;
- if (child->IsDirectory()) {
- child->VisitFiles(visitor, opaque);
- }
- char *uri = child->toURI();
- const char *path = child->AbsolutePath();
-
- std::cout << "child does ";
- if (!child->Exists()) std::cout << "NOT ";
- std::cout << "exists ..." << std::endl;
- std::cout << path << " - has URI: " << uri << std::endl << std::endl;
- free(uri);
- delete child;
-
- return 0;
-}
-
-void test1()
-{
- std::cout << "FileSystemTest test 1" << std::endl;
-// cFile *lf = new cFile("/var/lib/video.00");
- cFile *lf = new cFile("/var/local/blah/fasel");
- const char *path = lf->AbsolutePath();
-
- std::cout << "got file: " << path << std::endl;
-
- lf->VisitFiles(visitor, NULL);
-
-// cFile *epgData = new cFile(*lf, "epg.data");
-//
-// path = epgData->AbsolutePath();
-// std::cout << "got file: " << path << std::endl;
-
-#ifndef REDNOSE
- cFile *f = new cFile("/media/xchange/");
- path = f->AbsolutePath();
-
- std::cout << "got file: " << path << std::endl;
- cFile *other = f->Parent();
-
- other->SetVirtualRoot(true);
- path = other->AbsolutePath();
- std::cout << "parent is file: " << path << std::endl;
-
- cFile *newOne = new cFile(*other, "/video/test/blah");
-
- path = newOne->AbsolutePath();
- std::cout << "assembled file: " << path << std::endl;
-
- cFile *again = new cFile("/media/audio/Collection/Rock/Idol, Billy");
-
- path = again->AbsolutePath();
- std::cout << "re-assembled file: " << path << std::endl;
-
- std::cout << path << " does ";
- if (!again->Exists()) std::cout << "NOT ";
- std::cout << "exists" << std::endl;
-
- again->VisitFiles(visitor, NULL);
-
- delete again;
- delete newOne;
- delete other;
- delete f;
-// delete epgData;
-#endif
- delete lf;
- cUrl::Cleanup();
- cFile::Cleanup();
-}
-
-int check4Media(void *opaque, cFile *Parent, const char *Name)
-{
- if (!opaque) return -1;
- std::vector<cAbstractMedia *> *pool = (std::vector<cAbstractMedia *> *) opaque;
- cFile *curFile = new cFile(*Parent, Name);
- const char *mimeType = NULL;
- cAbstractMedia *rv = NULL;
-
- if (!curFile) {
- esyslog("ERROR: out of memory!");
- return -1;
- }
- if (!curFile->Exists()) {
- delete curFile;
- return -1;
- }
- if (curFile->IsDirectory()) {
- static const char *keyFiles[] = { "001.vdr", "00001.ts", "VIDEO_TS/VIDEO_TS.IFO", NULL };
- cFile *tmp;
- const char *check;
- int n=0;
-
- for (const char **kf = keyFiles; kf && *kf; ++kf, ++n) {
- tmp = new cFile(*curFile, *kf);
- check = tmp ? tmp->AbsolutePath() : NULL;
-
- if (tmp->Exists() && tmp->IsFile() && !tmp->IsDirectory()) {
- switch (n) {
- case 0: rv = new cLegacyVdrRecording(*curFile); break;
- case 1: rv = new cVdrRecording(*curFile); break;
- default: rv = new cDVDImage(*curFile); break;
- }
- }
- delete tmp;
- }
- if (!rv) curFile->VisitFiles(check4Media, opaque);
- }
- else {
- const char *extension = strrchr(Name, '.');
-
- if (!extension) {
- delete curFile;
-
- return -1;
- }
- ++extension;
- mimeType = cMovie::ContentType(extension);
- if (mimeType) rv = new cMovie(*curFile, mimeType);
- else {
- mimeType = cAudio::ContentType(extension);
- if (mimeType) rv = new cAudio(*curFile, mimeType);
- else {
- mimeType = cPicture::ContentType(extension);
- if (mimeType) rv = new cPicture(*curFile, mimeType);
- }
- }
- }
- delete curFile;
- if (rv) {
- pool->push_back(rv);
- return 0;
- }
- else return -1;
-}
-
-void test2()
-{
- std::cout << "FileSystemTest test 2" << std::endl;
- cFile relative("srclient.conf");
- const char *path = relative.AbsolutePath();
-
- std::cout << "relative path is now: " << path << std::endl;
- cUrl::Cleanup();
- cFile::Cleanup();
-}
-
-void test3()
-{
- std::cout << "FileSystemTest test 3" << std::endl;
- cFile mediaRoot("/media");
- cFile &startScan = mediaRoot; //("/media/images");
-
- if (!mediaRoot.Exists() || !mediaRoot.IsDirectory())
- std::cout << "%TEST_FAILED% time=0 testname=test3 (FileSystemTest) message=error message sample" << std::endl;
- if (!startScan.Exists() || !startScan.IsDirectory())
- std::cout << "%TEST_FAILED% time=0 testname=test3 (FileSystemTest) message=error message sample" << std::endl;
-
- mediaRoot.SetVirtualRoot();
- std::vector<cAbstractMedia *> mediaPool;
-
- uint64_t start = cTimeMs::Now();
- startScan.VisitFiles(check4Media, &mediaPool);
- uint64_t end = cTimeMs::Now();
-
- for (size_t i=0; i < mediaPool.size(); ++i) {
- std::cout << "pool entry: " << mediaPool[i]->Name() << std::endl;
- }
- //19: got 9998 media in 8081ms.
- // ==9779== total heap usage: 637,920 allocs, 637,918 frees, 172,023,271 bytes allocated
- //01: got 5739 media in 88165ms.
- // ==2605== total heap usage: 924,253 allocs, 924,247 frees, 259,567,759 bytes allocated
- std::cout << "got " << mediaPool.size() << " media in " << (end - start) << "ms." << std::endl;
- for (size_t i=0; i < mediaPool.size(); ++i) {
- delete mediaPool[i];
- }
- cUrl::Cleanup();
- cFile::Cleanup();
-}
-
-int main(int argc, char** argv)
-{
- uint64_t t0 = cTimeMs::Now();
- std::cout << "%SUITE_STARTING% FileSystemTest" << std::endl;
- std::cout << "%SUITE_STARTED%" << std::endl;
-
- std::cout << "%TEST_STARTED% test1 (FileSystemTest)" << std::endl;
- uint64_t start = cTimeMs::Now();
- test1();
- uint64_t end = cTimeMs::Now();
- std::cout << "%TEST_FINISHED% time=" << (double)(end - start) / 1000 << " test1 (FileSystemTest)" << std::endl;
-
- std::cout << "%TEST_STARTED% test2 (FileSystemTest)\n" << std::endl;
- start = cTimeMs::Now();
- test2();
- end = cTimeMs::Now();
- std::cout << "%TEST_FINISHED% time=" << (double)(end - start) / 1000 << " test2 (FileSystemTest)" << std::endl;
-
- std::cout << "%TEST_STARTED% test3 (FileSystemTest)\n" << std::endl;
- start = cTimeMs::Now();
- test3();
- end = cTimeMs::Now();
- std::cout << "%TEST_FINISHED% time=" << (double)(end - start) / 1000 << " test3 (FileSystemTest)" << std::endl;
-
- std::cout << "%SUITE_FINISHED% time=" << (double)(cTimeMs::Now() - t0) / 1000 << std::endl;
-
- return (EXIT_SUCCESS);
-}
diff --git a/tests/JSonTest/JSonTest.cc b/tests/JSonTest/JSonTest.cc
deleted file mode 100644
index c4500c1..0000000
--- a/tests/JSonTest/JSonTest.cc
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * File: JSonTest.cc
- * Author: django
- *
- * Created on 12.07.2012, 07:31:46
- */
-
-#include <StringBuilder.h>
-#include <JSonWriter.h>
-#include <stdlib.h>
-#include <iostream>
-
-/*
- * Simple C++ Test Suite
- */
-
-void test1()
-{
- char buf[512] = {0};
- cStringBuilder sb;
- cJSonWriter jw(sb);
-
- std::cout << "JSonTest test 1" << std::endl;
-
- jw.Object().Key("total").Value(123);
- jw.Key("errorCode").Value(-1);
- jw.Key("testmode").Value(true);
- jw.Key("results").Array();
-
- for (int i=0; i < 3; ++i) {
- jw.Object().Key("counter").Value(i);
- jw.Key("nase").Value("bär");
- jw.EndObject();
- }
- jw.EndArray();
- jw.Key("fasel").Value("blub");
- jw.EndObject();
-
- std::cout << "size of json-Object: " << sb.Size() << std::endl;
- sb.Copy(buf, sizeof(buf));
-
- std::cout << "json object looks like" << std::endl << buf << std::endl;
-}
-
-void test2()
-{
- std::cout << "JSonTest test 2" << std::endl;
- std::cout << "%TEST_FAILED% time=0 testname=test2 (JSonTest) message=error message sample" << std::endl;
-}
-
-int main(int argc, char** argv)
-{
- std::cout << "%SUITE_STARTING% JSonTest" << std::endl;
- std::cout << "%SUITE_STARTED%" << std::endl;
-
- std::cout << "%TEST_STARTED% test1 (JSonTest)" << std::endl;
- test1();
- std::cout << "%TEST_FINISHED% time=0 test1 (JSonTest)" << std::endl;
-
-// std::cout << "%TEST_STARTED% test2 (JSonTest)\n" << std::endl;
-// test2();
-// std::cout << "%TEST_FINISHED% time=0 test2 (JSonTest)" << std::endl;
-
- std::cout << "%SUITE_FINISHED% time=0" << std::endl;
-
- return (EXIT_SUCCESS);
-}
-
diff --git a/tests/MetaScanTest/main.cpp b/tests/MetaScanTest/main.cpp
deleted file mode 100644
index 99eec78..0000000
--- a/tests/MetaScanTest/main.cpp
+++ /dev/null
@@ -1,146 +0,0 @@
-/**
- * ======================== legal notice ======================
- *
- * File: MetaScanTest.cc
- * Created: 27.07.2012, 10:03
- * 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 <File.h>
-#include <FileReader.h>
-#include <LineReader.h>
-#include <ConfigReader.h>
-#include <CommandReader.h>
-#include <MediainfoReader.h>
-#include <iostream>
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <tr1/tuple>
-
-static void parseConfig(const char *FileName)
-{
- cConfigReader *cr = new cConfigReader(new cLineReader(new cFileReader(new cFile(FileName))));
- cConfigReader::ConfigEntry *ce;
-
- while ((ce = cr->ReadEntry())) {
- std::cout << "config entry [" << std::get<0>(*ce) << "] => " << std::get<1>(*ce) << std::endl;
- delete ce;
- }
- cr->Close();
- delete cr;
-}
-
-static void dumpTextfile(const char *FileName)
-{
- cLineReader *lr = new cLineReader(new cFileReader(new cFile(FileName)));
- const char *line;
-
- while ((line = lr->ReadLine())) {
- std::cout << "line: " << line << std::endl;
- }
- delete lr;
-}
-
-static void setupMediainfoReader(cMediainfoReader *mir)
-{
- mir->AddValuableKey("Format");
- //Audio
- mir->AddValuableKey("Duration");
- mir->AddValuableKey("Album");
- mir->AddValuableKey("Track name");
- mir->AddValuableKey("Performer");
- mir->AddValuableKey("Bit rate");
- //Image
- mir->AddValuableKey("Width");
- mir->AddValuableKey("Height");
- //Video
- mir->AddValuableKey("Display aspect ratio");
- mir->AddValuableKey("Scan type");
-}
-
-static 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;
- }
- mir->Close();
- delete mir;
-}
-
-void testMediaFiles(const char *FileName)
-{
- cLineReader *lr = new cLineReader(new cFileReader(new cFile(FileName)));
- const char *line;
-
- while ((line = lr->ReadLine())) {
- std::cout << std::endl << "media-test-file: " << line << std::endl;
- testMediaInfo(line);
- }
- lr->Close();
- delete lr;
-}
-
-static const short BufferSize = 100;
-enum PipeFileDescriptors {
- READ_FD = 0,
- WRITE_FD = 1
-};
-
-static void testCommandReader()
-{
- cCommandReader *cr = new cCommandReader("/bin/ls");
- cLineReader *lr = new cLineReader(cr);
- const char *line;
-
- cr->AddCommandParameter("-al");
- cr->AddCommandParameter("--color");
-
- while ((line = lr->ReadLine())) {
- std::cout << "from command: " << line << std::endl;
- }
- delete lr;
-};
-
-int main()
-{
-// testMediaInfo("blah");
- dumpTextfile("srclient.conf");
-
- std::cout << std::endl << "===========================================" << std::endl << std::endl;
- parseConfig("srserver.conf");
-
- std::cout << std::endl << "===========================================" << std::endl << std::endl;
- testCommandReader();
-
- std::cout << std::endl << "===========================================" << std::endl << std::endl;
- testMediaFiles("testMedia.files");
-
- cFile::Cleanup();
- return 0;
-}
diff --git a/tests/StringBuilderTest/main.cpp b/tests/StringBuilderTest/main.cpp
deleted file mode 100644
index c06034a..0000000
--- a/tests/StringBuilderTest/main.cpp
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * small tests for class StringBuilder
- */
-#include <StringBuilder.h>
-#include <FileReader.h>
-#include <LineReader.h>
-#include <File.h>
-#include <string.h>
-#include <iostream>
-
-#define NEW_LINE '\n'
-
-void rangeTests()
-{ // 12345678901
- static const char *sample = "Hello World";
- cStringBuilder *sb;
- int chunkSize = strlen(sample) - 4;
- char *result;
-
- std::cout << sample << " has length: " << strlen(sample) << std::endl;
-
- for (int i=0; i < 6; ++i) {
- std::cout << "check chunkSize of " << chunkSize + i << std::endl;
- sb = new cStringBuilder(chunkSize + i);
-
- sb->Append(sample).Append(NEW_LINE);
- result = sb->toString();
-
- std::cout << "assembled text looks like: " << std::endl << result;
- free(result);
- delete sb;
- }
-}
-
-void basicTests()
-{
- cStringBuilder sb(179);
-
- sb.Append("hello World").Append(NEW_LINE);
- sb.Append("logical default true: ").Append(true).Append(NEW_LINE);
- sb.Append("logical default false: ").Append(false).Append(NEW_LINE);
- sb.Append("logical true value: ").Append(true, "true", "false").Append(NEW_LINE);
- sb.Append("logical false value: ").Append(false, "true", "false").Append(NEW_LINE);
- sb.Append("double: ").Append(3.1456789).Append(NEW_LINE);
- sb.Append("unsigned long: ").Append((size_t) 91237485l).Append(NEW_LINE);
- sb.Append("long: ").Append(1234567890l).Append(NEW_LINE);
- sb.Append("int: ").Append(512).Append(NEW_LINE);
-
- char *result = sb.toString();
-
- std::cout << "sizeof assembled text: " << sb.Size() << std::endl;
- std::cout << "assembled text looks like:" << std::endl << result;
-
- free(result);
-}
-
-void lineReaderTest()
-{
- cLineReader lr(new cFileReader(new cFile("srclient.conf")));
- const char *line = NULL;
-
- while ((line = lr.ReadLine())) {
- std::cout << "line: " << line << std::endl;
- }
- lr.Close();
- cFile::Cleanup();
-}
-
-int main()
-{
- lineReaderTest();
- basicTests();
- rangeTests();
-
- return 0;
-}