diff options
Diffstat (limited to 'tests')
9 files changed, 253 insertions, 13 deletions
diff --git a/tests/ConnectionHandlerTest/ConnectionHandlerTest.cbp b/tests/ConnectionHandlerTest/ConnectionHandlerTest.cbp index b2d783b..31d9050 100644 --- a/tests/ConnectionHandlerTest/ConnectionHandlerTest.cbp +++ b/tests/ConnectionHandlerTest/ConnectionHandlerTest.cbp @@ -38,12 +38,13 @@ </Build> <Compiler> <Add option="-Wall" /> - <Add option="-std=gnu++0x -fomit-frame-pointer -fPIC -pthread -Wall -Wno-parentheses -Wno-switch -Wdisabled-optimization -Wpointer-arith -Wredundant-decls -Wwrite-strings -Wtype-limits -Wundef -fno-math-errno -fno-signed-zeros -fno-tree-vectorize -Werror=implicit-function-declaration -ansi" /> + <Add option="-std=gnu++0x -fomit-frame-pointer -fPIC -pthread -Wall -Wno-parentheses -Wno-switch -Wdisabled-optimization -Wpointer-arith -Wredundant-decls -Wwrite-strings -Wtype-limits -Wundef -fno-math-errno -fno-signed-zeros -fno-tree-vectorize -Werror=implicit-function-declaration" /> <Add option="-D_REENTRANT" /> <Add option="-D_GNU_SOURCE=1" /> <Add directory="../../cmps/serverlib/include" /> <Add directory="../../libs/fsScan/include" /> <Add directory="../../libs/networking/include" /> + <Add directory="../../libs/IO/include" /> <Add directory="../../libs/util/include" /> <Add directory="../../libs/vdr/include" /> </Compiler> @@ -51,12 +52,14 @@ <Add library="../../cmps/serverlib/libserverlib.a" /> <Add library="../../libs/fsScan/libfsScan.a" /> <Add library="../../libs/networking/libnetworking.a" /> + <Add library="../../libs/IO/libIO.a" /> <Add library="../../libs/util/libutil.a" /> <Add library="../../libs/vdr/libvdr.a" /> <Add library="ssl" /> <Add library="crypt" /> <Add library="pthread" /> <Add library="rt" /> + <Add library="pcrecpp" /> </Linker> <Unit filename="ConnectionHandlerTest.cc" /> <Extensions> diff --git a/tests/ConnectionHandlerTest/ConnectionHandlerTest.cc b/tests/ConnectionHandlerTest/ConnectionHandlerTest.cc index 1dc3659..89dc56d 100644 --- a/tests/ConnectionHandlerTest/ConnectionHandlerTest.cc +++ b/tests/ConnectionHandlerTest/ConnectionHandlerTest.cc @@ -6,7 +6,7 @@ */ #include <ConnectionHandler.h> #include <ServerConfig.h> -#include <FilesystemScanner.h> +#include <FSMediaScanner.h> #include <MediaFactory.h> #include <MediaListHandler.h> #include <MediaFileHandler.h> @@ -36,11 +36,11 @@ private: cServerConfig config; cConnectionHandler ch; const char *name; - cFilesystemScanner *scanner; + cFSMediaScanner *scanner; }; cTestUnit::cTestUnit(const char* Name, cConnectionPoint &cp) - : config(12345) + : config("/var/lib/cmp") , ch(cp, config) , name(Name) , scanner(NULL) @@ -49,14 +49,14 @@ cTestUnit::cTestUnit(const char* Name, cConnectionPoint &cp) config.SetDocumentRoot("/media/video"); config.SetAppIcon("/media/favicon.ico"); - scanner = new cFilesystemScanner(); + scanner = new cFSMediaScanner(); if (!scanner) { 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(); @@ -130,6 +130,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/tests/ConnectionHandlerTest/ConnectionHandlerTest.layout b/tests/ConnectionHandlerTest/ConnectionHandlerTest.layout index b29fcb8..130e1dc 100644 --- a/tests/ConnectionHandlerTest/ConnectionHandlerTest.layout +++ b/tests/ConnectionHandlerTest/ConnectionHandlerTest.layout @@ -3,7 +3,7 @@ <ActiveTarget name="Debug" /> <File name="ConnectionHandlerTest.cc" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <Cursor> - <Cursor1 position="1092" topLine="3" /> + <Cursor1 position="916" topLine="0" /> </Cursor> </File> </CodeBlocks_layout_file> diff --git a/tests/ConnectionHandlerTest/ConnectionHandlerTest.layout.save b/tests/ConnectionHandlerTest/ConnectionHandlerTest.layout.save index b29fcb8..130e1dc 100644 --- a/tests/ConnectionHandlerTest/ConnectionHandlerTest.layout.save +++ b/tests/ConnectionHandlerTest/ConnectionHandlerTest.layout.save @@ -3,7 +3,7 @@ <ActiveTarget name="Debug" /> <File name="ConnectionHandlerTest.cc" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <Cursor> - <Cursor1 position="1092" topLine="3" /> + <Cursor1 position="916" topLine="0" /> </Cursor> </File> </CodeBlocks_layout_file> diff --git a/tests/CredentialPersistence/CredentialPersistence.cbp b/tests/CredentialPersistence/CredentialPersistence.cbp index 0a5cfce..6bb20e4 100644 --- a/tests/CredentialPersistence/CredentialPersistence.cbp +++ b/tests/CredentialPersistence/CredentialPersistence.cbp @@ -30,7 +30,7 @@ </Build> <Compiler> <Add option="-Wall" /> - <Add option="-std=gnu++0x -fomit-frame-pointer -fPIC -pthread -Wall -Wno-parentheses -Wno-switch -Wdisabled-optimization -Wpointer-arith -Wredundant-decls -Wwrite-strings -Wtype-limits -Wundef -fno-math-errno -fno-signed-zeros -fno-tree-vectorize -Werror=implicit-function-declaration -ansi" /> + <Add option="-std=gnu++0x -fomit-frame-pointer -fPIC -pthread -Wall -Wno-parentheses -Wno-switch -Wdisabled-optimization -Wpointer-arith -Wredundant-decls -Wwrite-strings -Wtype-limits -Wundef -fno-math-errno -fno-signed-zeros -fno-tree-vectorize -Werror=implicit-function-declaration" /> <Add option="-D_REENTRANT" /> <Add option="-D_GNU_SOURCE=1" /> <Add directory="../../cmps/serverlib/include" /> diff --git a/tests/CredentialPersistence/CredentialPersistence.layout b/tests/CredentialPersistence/CredentialPersistence.layout index abb8444..f0df7b3 100644 --- a/tests/CredentialPersistence/CredentialPersistence.layout +++ b/tests/CredentialPersistence/CredentialPersistence.layout @@ -3,7 +3,7 @@ <ActiveTarget name="Debug" /> <File name="CredentialPersistence.cc" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <Cursor> - <Cursor1 position="99" topLine="0" /> + <Cursor1 position="98" topLine="0" /> </Cursor> </File> </CodeBlocks_layout_file> diff --git a/tests/CredentialPersistence/CredentialPersistence.layout.save b/tests/CredentialPersistence/CredentialPersistence.layout.save index abb8444..f0df7b3 100644 --- a/tests/CredentialPersistence/CredentialPersistence.layout.save +++ b/tests/CredentialPersistence/CredentialPersistence.layout.save @@ -3,7 +3,7 @@ <ActiveTarget name="Debug" /> <File name="CredentialPersistence.cc" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <Cursor> - <Cursor1 position="99" topLine="0" /> + <Cursor1 position="98" topLine="0" /> </Cursor> </File> </CodeBlocks_layout_file> diff --git a/tests/FilesystemTest/main.cpp b/tests/FilesystemTest/main.cpp new file mode 100644 index 0000000..2196a45 --- /dev/null +++ b/tests/FilesystemTest/main.cpp @@ -0,0 +1,234 @@ +/* + * 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.cbp b/tests/JSonTest/JSonTest.cbp index 9328615..3ce250a 100644 --- a/tests/JSonTest/JSonTest.cbp +++ b/tests/JSonTest/JSonTest.cbp @@ -30,7 +30,7 @@ </Build> <Compiler> <Add option="-Wall" /> - <Add option="-std=gnu++0x -fomit-frame-pointer -fPIC -pthread -Wall -Wno-parentheses -Wno-switch -Wdisabled-optimization -Wpointer-arith -Wredundant-decls -Wwrite-strings -Wtype-limits -Wundef -fno-math-errno -fno-signed-zeros -fno-tree-vectorize -Werror=implicit-function-declaration -ansi" /> + <Add option="-std=gnu++0x -fomit-frame-pointer -fPIC -pthread -Wall -Wno-parentheses -Wno-switch -Wdisabled-optimization -Wpointer-arith -Wredundant-decls -Wwrite-strings -Wtype-limits -Wundef -fno-math-errno -fno-signed-zeros -fno-tree-vectorize -Werror=implicit-function-declaration" /> <Add option="-D_REENTRANT" /> <Add option="-D_GNU_SOURCE=1" /> <Add directory="../../libs/fsScan/include" /> |