diff options
Diffstat (limited to 'cmps/tests')
-rw-r--r-- | cmps/tests/CodecTest.cc | 77 | ||||
-rw-r--r-- | cmps/tests/ConnectionHandlerTest.cc | 153 | ||||
-rw-r--r-- | cmps/tests/DirTest.cc | 74 | ||||
-rw-r--r-- | cmps/tests/FScanTest.cc | 137 | ||||
-rw-r--r-- | cmps/tests/JSonTest.cc | 85 | ||||
-rw-r--r-- | cmps/tests/StringBuilderTest.cc | 124 | ||||
-rw-r--r-- | cmps/tests/URLTest.cc | 105 | ||||
-rw-r--r-- | cmps/tests/UTF8Test.cc | 96 |
8 files changed, 851 insertions, 0 deletions
diff --git a/cmps/tests/CodecTest.cc b/cmps/tests/CodecTest.cc new file mode 100644 index 0000000..071ff7b --- /dev/null +++ b/cmps/tests/CodecTest.cc @@ -0,0 +1,77 @@ +/** + * ======================== legal notice ====================== + * + * File: CodecTest.cc + * Created: 09.07.2012, 05:44:50 + * 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 <Codec.h> +#include <stdlib.h> +#include <iostream> + +static const char *TT[] = { + "130-H Karadayi featuring Fresh B. - Betüll Demir - Na Nay (2009).mp3" +, " 36 130 - R.I.O. ft Jerry Ropero vs. Mendonca - Do Rio-De Janeiro Berinbau (Bootleg Edit).mp3" +, "Das_Vermächtnis_der_Tempelritter (2012-07-02.22.10.36-0.rec)" +, NULL +, "http://localhost:12345/test/Mukke/130-H%20Karadayi%20featuring%20Fresh%20B.%20-%20Bet%C3%BCll%20Demir%20-%20Na%20Nay%20(2009).mp3" +, "http://localhost:12345/test/Mukke/36%20%20%20130%20-%20R.I.O.%20ft%20Jerry%20Ropero%20vs.%20Mendonca%20-%20Do%20Rio-De%20Janeiro%20Berinbau%20(Bootleg%20Edit).mp3" +, "http://localhost:12345/import/Das_Verm%C3%A4chtnis_der_Tempelritter/2012-07-02.22.10.36-0.rec" +, NULL +}; + +void test1() +{ + std::cout << "CodecTest test 1" << std::endl; + cURLEncoder *ue = new cURLEncoder(); + const char **p; + char *newText; + + for (p = TT; p && *p; ++p) { + newText = ue->Encode(*p); + std::cout << "original: " << *p << std::endl; + std::cout << "encoded.: " << newText << std::endl << std::endl; + } +} + +void test2() +{ + std::cout << "CodecTest test 2" << std::endl; + std::cout << "%TEST_FAILED% time=0 testname=test2 (CodecTest) message=error message sample" << std::endl; +} + +int main(int argc, char** argv) +{ + std::cout << "%SUITE_STARTING% CodecTest" << std::endl; + std::cout << "%SUITE_STARTED%" << std::endl; + + std::cout << "%TEST_STARTED% test1 (CodecTest)" << std::endl; + test1(); + std::cout << "%TEST_FINISHED% time=0 test1 (CodecTest)" << std::endl; + +// std::cout << "%TEST_STARTED% test2 (CodecTest)\n" << std::endl; +// test2(); +// std::cout << "%TEST_FINISHED% time=0 test2 (CodecTest)" << std::endl; + + std::cout << "%SUITE_FINISHED% time=0" << std::endl; + + return (EXIT_SUCCESS); +} + diff --git a/cmps/tests/ConnectionHandlerTest.cc b/cmps/tests/ConnectionHandlerTest.cc new file mode 100644 index 0000000..e32fbb3 --- /dev/null +++ b/cmps/tests/ConnectionHandlerTest.cc @@ -0,0 +1,153 @@ +/** + * ======================== legal notice ====================== + * + * File: ConnectionHandlerTest.cc + * 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 + * + * 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 <ConnectionHandler.h> +#include <ServerConfig.h> +#include <FilesystemScanner.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; + cFilesystemScanner *scanner; +}; + +cTestUnit::cTestUnit(const char* Name, cConnectionPoint &cp) + : config(12345) + , ch(cp, config) + , name(Name) + , scanner(NULL) +{ + config.SetAuthorizationRequired(false); + config.SetDocumentRoot("/media/video"); + config.SetAppIcon("/media/favicon.ico"); + + scanner = new cFilesystemScanner(); + if (!scanner) { + fprintf(stderr, "could not initialize application! (1)"); + exit(-1); + } + scanner->SetMediaFactory(new cMediaFactory(config.DocumentRoot())); + + cAbstractMediaRequestHandler::SetFilesystemScanner(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; + + return (EXIT_SUCCESS); +} + diff --git a/cmps/tests/DirTest.cc b/cmps/tests/DirTest.cc new file mode 100644 index 0000000..4a1f1a7 --- /dev/null +++ b/cmps/tests/DirTest.cc @@ -0,0 +1,74 @@ +/** + * ======================== legal notice ====================== + * + * File: DirTest.cc + * Created: 02.07.2012, 18:07:18 + * 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 <stdlib.h> +#include <iostream> +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/dir.h> + +/* + * Simple C++ Test Suite + */ + +void test1() +{ + struct direct *dirEntry; + DIR *dir = opendir("/media"); + + std::cout << "DirTest test 1" << std::endl; + if (!dir) + std::cout << "%TEST_FAILED% time=0 testname=test1 (DirTest) message=failed to open directory" << std::endl; + + while ((dirEntry = readdir(dir))) { + if (*dirEntry->d_name == '.') continue; + std::cout << "dir-entry: " << dirEntry->d_name << std::endl; + } + closedir(dir); +} + +void test2() +{ + std::cout << "DirTest test 2" << std::endl; + std::cout << "%TEST_FAILED% time=0 testname=test2 (DirTest) message=error message sample" << std::endl; +} + +int main(int argc, char** argv) +{ + std::cout << "%SUITE_STARTING% DirTest" << std::endl; + std::cout << "%SUITE_STARTED%" << std::endl; + + std::cout << "%TEST_STARTED% test1 (DirTest)" << std::endl; + test1(); + std::cout << "%TEST_FINISHED% time=0 test1 (DirTest)" << std::endl; + + std::cout << "%TEST_STARTED% test2 (DirTest)\n" << std::endl; + test2(); + std::cout << "%TEST_FINISHED% time=0 test2 (DirTest)" << 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 new file mode 100644 index 0000000..86f0895 --- /dev/null +++ b/cmps/tests/FScanTest.cc @@ -0,0 +1,137 @@ +/** + * ======================== legal notice ====================== + * + * File: FScanTest.cc + * Created: 02.07.2012, 16:57:48 + * 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 <stdlib.h> +#include <iostream> +#include <Audio.h> +#include <Movie.h> +#include <Picture.h> +#include <FilesystemScanner.h> +#include <MediaFactory.h> +#include <TimeMs.h> + +class FScanTest { +public: + static void test1(void); + static void test2(void); + static void test3(void); + static void test4(void); +}; + +void FScanTest::test1() +{ + std::cout << "FScanTest test 1" << std::endl; + + for (SupportedExtension *se = cAudio::knownExtensions; se && se->extension; ++se) { + std::cout << "Audio: known extension \"" << se->extension << "\" has type: " << se->mimeType << std::endl; + } +} + +void FScanTest::test2() +{ + std::cout << "FScanTest test 2" << std::endl; + + for (SupportedExtension *se = cMovie::knownExtensions; se && se->extension; ++se) { + std::cout << "Video: known extension \"" << se->extension << "\" has type: " << se->mimeType << std::endl; + } +} + +void FScanTest::test3() +{ + std::cout << "FScanTest test 3" << std::endl; + + for (SupportedExtension *se = cPicture::knownExtensions; se && se->extension; ++se) { + std::cout << "Picture: known extension \"" << se->extension << "\" has type: " << se->mimeType << std::endl; + } +} + +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. +{ + cFilesystemScanner scanner; + cAbstractMedia *media; + + std::cout << "FScanTest test 4" << std::endl; + scanner.SetMediaFactory(new cMediaFactory("/media")); + + uint64_t start = cTimeMs::Now(); + scanner.Refresh(); + uint64_t end = cTimeMs::Now(); + + for (size_t i=0; i < scanner.MediaPool().size(); ++i) { + media = (cAbstractMedia *) scanner.MediaPool()[i]; + + std::cout << media->Name() << " [" << media->MimeType() << "] => " << media->LogicalPath() << std::endl; + } + 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"; + + // search (worst case) + start = cTimeMs::Now(); + media = scanner.FindMedia(file2Search); + end = cTimeMs::Now(); + + std::cout << "array search took " << end - start << " ms." << std::endl; +} + +int main(int argc, char** argv) +{ + uint64_t t0 = cTimeMs::Now(); + std::cout << "%SUITE_STARTING% FScanTest" << std::endl; + std::cout << "%SUITE_STARTED%" << std::endl; + + std::cout << "%TEST_STARTED% test1 (FScanTest)" << std::endl; + uint64_t start = cTimeMs::Now(); + FScanTest::test1(); + uint64_t end = cTimeMs::Now(); + std::cout << "%TEST_FINISHED% time=" << (double)(end - start) / 1000 << " test1 (FScanTest)" << std::endl; + + std::cout << "%TEST_STARTED% test2 (FScanTest)" << std::endl; + start = cTimeMs::Now(); + FScanTest::test2(); + end = cTimeMs::Now(); + std::cout << "%TEST_FINISHED% time=" << (double)(end - start) / 1000 << " test2 (FScanTest)" << std::endl; + + std::cout << "%TEST_STARTED% test3 (FScanTest)" << std::endl; + start = cTimeMs::Now(); + FScanTest::test3(); + end = cTimeMs::Now(); + std::cout << "%TEST_FINISHED% time=" << (double)(end - start) / 1000 << " test3 (FScanTest)" << std::endl; + + std::cout << "%TEST_STARTED% test4 (FScanTest)" << std::endl; + start = cTimeMs::Now(); + FScanTest::test4(); + end = cTimeMs::Now(); + std::cout << "%TEST_FINISHED% time=" << (double)(end - start) / 1000 << " test4 (FScanTest)" << std::endl; + + std::cout << "%SUITE_FINISHED% time=" << (double)(cTimeMs::Now() - t0) / 1000 << std::endl; + + return (EXIT_SUCCESS); +} + diff --git a/cmps/tests/JSonTest.cc b/cmps/tests/JSonTest.cc new file mode 100644 index 0000000..21fc394 --- /dev/null +++ b/cmps/tests/JSonTest.cc @@ -0,0 +1,85 @@ +/** + * ======================== legal notice ====================== + * + * File: JSonTest.cc + * Created: 12.07.2012, 07:31:46 + * 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 <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/cmps/tests/StringBuilderTest.cc b/cmps/tests/StringBuilderTest.cc new file mode 100644 index 0000000..4a0443b --- /dev/null +++ b/cmps/tests/StringBuilderTest.cc @@ -0,0 +1,124 @@ +/** + * ======================== legal notice ====================== + * + * File: StringBuilderTest.cc + * Created: 06.07.2012, 18:28:08 + * 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 <stdlib.h> +#include <iostream> +#include <StringBuilder.h> + +/* + * Simple C++ Test Suite + */ + +void test1() +{ + cStringBuilder sb(16); + char buf[256] = {0}; + int blah = 0; + + std::cout << "StringBuilderTest test 1" << 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"); + + std::cout << "size of StringBuilder: " << sb.Size() << " bytes" << std::endl; + size_t bytesWritten = sb.Copy(buf, sizeof(buf)); + + 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; +} + +void test2() +{ + 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; + + 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. "); + + std::cout << "size of StringBuilder: " << sb.Size() << " bytes" << std::endl; + size_t bytesWritten = 0; + int chunkWritten = 0; + + 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; +} + +int main(int argc, char** argv) +{ + std::cout << "%SUITE_STARTING% StringBuilderTest" << std::endl; + std::cout << "%SUITE_STARTED%" << std::endl; + + 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; + + std::cout << "%SUITE_FINISHED% time=0" << std::endl; + + return (EXIT_SUCCESS); +} + diff --git a/cmps/tests/URLTest.cc b/cmps/tests/URLTest.cc new file mode 100644 index 0000000..9dc69c3 --- /dev/null +++ b/cmps/tests/URLTest.cc @@ -0,0 +1,105 @@ +/** + * ======================== legal notice ====================== + * + * File: URLTest.cc + * Created: 04.07.2012, 09:25:57 + * 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 <Url.h> +#include <Codec.h> +#include <stdlib.h> +//#include <string> +#include <string.h> +#include <iostream> +#include <stdio.h> +#include <tr1/unordered_map> + +void test1() +{ + std::cout << "URLTest test 1" << std::endl; + cUrl url("/blah/fasel.html"); + + url.AddParameter("Übergewicht", "ja&nein"); + url.AddParameter("test"); + url.AddParameter("mir ist", "(ü)bel"); + url.AddParameter("Ahnung", "keine < nennenswert"); + url.AddParameter("sonst", "fällt mir =nix= \"mehr\" ein"); + char *p = url.ToString(); + + url.Dump(); + std::cout << std::endl << "url0 is [" << p << "]" << std::endl; + std::cout << "path....: " << url.Path() << std::endl << std::endl; + + cUrl revURL(p); + + revURL.Dump(); + char *p1 = revURL.ToString(); + + std::cout << "url0 is [" << p << "]" << std::endl; + std::cout << "path....: " << url.Path() << std::endl; + std::cout << std::endl; + std::cout << "url1 is [" << p1 << "]" << std::endl; + std::cout << "path....: " << revURL.Path() << std::endl; + + if (strcmp(p, p1)) + std::cout << "%TEST_FAILED% time=0 testname=test1 (URLTest) message=initial url and reverse url did not match." << std::endl; + + free(p1); + free(p); + cUrl::CleanUp(); +} + +void test2() +{ + std::cout << "URLTest test 2" << std::endl; + std::tr1::unordered_map<std::string, std::string> pool; + + pool["blah"] = "fasel"; + pool["blub"] = "oups"; + pool["nase"] = "wasser"; + + std::string res = pool["fasel"]; + + if (res.empty()) + std::cout << "lookup of not existing key returned empty string" << std::endl; + std::cout << "nase ist " << pool["nase"] << std::endl; + std::cout << "fasel ist " << res << std::endl; + +// std::cout << "%TEST_FAILED% time=0 testname=test2 (URLTest) message=error message sample" << std::endl; +} + +int main(int argc, char** argv) +{ + std::cout << "%SUITE_STARTING% URLTest" << std::endl; + std::cout << "%SUITE_STARTED%" << std::endl; + + std::cout << "%TEST_STARTED% test1 (URLTest)" << std::endl; + test1(); + std::cout << "%TEST_FINISHED% time=0 test1 (URLTest)" << std::endl; + + std::cout << "%TEST_STARTED% test2 (URLTest)\n" << std::endl; + test2(); + std::cout << "%TEST_FINISHED% time=0 test2 (URLTest)" << std::endl; + + std::cout << "%SUITE_FINISHED% time=0" << std::endl; + + return (EXIT_SUCCESS); +} + diff --git a/cmps/tests/UTF8Test.cc b/cmps/tests/UTF8Test.cc new file mode 100644 index 0000000..70c7cc1 --- /dev/null +++ b/cmps/tests/UTF8Test.cc @@ -0,0 +1,96 @@ +/** + * ======================== legal notice ====================== + * + * File: UTF8Test.cc + * Created: 05.07.2012, 15:19:07 + * 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 <stdlib.h> +#include <iostream> +#include <stdio.h> +#include <string.h> + +static const char *testFile = "/usr/local/share/UTF8.Sample"; + +void test1() +{ + char buf[128]; + char *start, *end, *check0, *check1; + FILE *fp; + int bytesRead, bytes2Read, rest, i; + + std::cout << "UTF8Test test 1" << std::endl; + + if (fp = fopen(testFile, "r")) { + check0 = buf; + check1 = buf + sizeof(buf); + start = buf; + bytes2Read = sizeof(buf); + while (bytesRead = fread(start, sizeof(char), bytes2Read, fp)) { + start = buf; + while (start && start < (buf + sizeof(buf))) { + end = strchr(start, '\n'); + if (!end) { + if (start > buf) { + rest = buf + sizeof(buf) - start; + + for (i=0; i < rest; ++i) { + buf[i] = start[i]; + } + start = buf + rest; + bytes2Read = sizeof(buf) - rest; + break; + } + else break; + } + *end = 0; + printf("line looks like: >%s<\n", start); + start = end + 1; + } + } + fclose(fp); + } + else std::cout << "%TEST_FAILED% time=0 testname=test1 (UTF8Test) message=could not open file" << std::endl; +} + +void test2() +{ + std::cout << "UTF8Test test 2" << std::endl; + std::cout << "%TEST_FAILED% time=0 testname=test2 (UTF8Test) message=error message sample" << std::endl; +} + +int main(int argc, char** argv) +{ + std::cout << "%SUITE_STARTING% UTF8Test" << std::endl; + std::cout << "%SUITE_STARTED%" << std::endl; + + std::cout << "%TEST_STARTED% test1 (UTF8Test)" << std::endl; + test1(); + std::cout << "%TEST_FINISHED% time=0 test1 (UTF8Test)" << std::endl; + + std::cout << "%TEST_STARTED% test2 (UTF8Test)\n" << std::endl; + test2(); + std::cout << "%TEST_FINISHED% time=0 test2 (UTF8Test)" << std::endl; + + std::cout << "%SUITE_FINISHED% time=0" << std::endl; + + return (EXIT_SUCCESS); +} + |