summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJesse Gilles <jgilles@multitech.com>2015-04-20 16:49:52 -0500
committerJesse Gilles <jgilles@multitech.com>2015-04-20 16:49:52 -0500
commit17b117e73df71925d73ee026b4f54aa1867ce0a5 (patch)
tree382610c8e598a77a961c5ceb32b9b614ed00e757 /test
downloadlibmts-17b117e73df71925d73ee026b4f54aa1867ce0a5.tar.gz
libmts-17b117e73df71925d73ee026b4f54aa1867ce0a5.tar.bz2
libmts-17b117e73df71925d73ee026b4f54aa1867ce0a5.zip
initial commit
Diffstat (limited to 'test')
-rw-r--r--test/CMakeLists.txt9
-rw-r--r--test/TestRunnerClient.cpp566
-rw-r--r--test/TestRunnerClient.h147
-rw-r--r--test/Test_MTS_Text.cpp392
-rw-r--r--test/Test_MTS_Text.h121
5 files changed, 1235 insertions, 0 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
new file mode 100644
index 0000000..602b159
--- /dev/null
+++ b/test/CMakeLists.txt
@@ -0,0 +1,9 @@
+project (TestRunnerClient)
+
+include_directories (../include)
+link_directories (..)
+
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -DCPPUNIT_MAIN=main")
+
+add_executable (TestRunnerClient TestRunnerClient.cpp Test_MTS_Text.cpp)
+target_link_libraries (TestRunnerClient cppunit mts rt pthread)
diff --git a/test/TestRunnerClient.cpp b/test/TestRunnerClient.cpp
new file mode 100644
index 0000000..fcb9c75
--- /dev/null
+++ b/test/TestRunnerClient.cpp
@@ -0,0 +1,566 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Gerhard Leonhartsberger.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+#include "TestRunnerClient.h"
+
+#ifdef CPPUNIT_MAIN
+
+#include "cppunit/XmlOutputter.h"
+#include "cppunit/TextOutputter.h"
+#include "cppunit/TestSuite.h"
+#include "cppunit/TestResult.h"
+#include "cppunit/TestFailure.h"
+#include "cppunit/SourceLine.h"
+#include "cppunit/Exception.h"
+#include "cppunit/extensions/TestFactoryRegistry.h"
+#include "cppunit/extensions/TestDecorator.h"
+#include "cppunit/ui/text/TestRunner.h"
+
+#include <iostream>
+#include <sstream>
+#include <typeinfo>
+#include <vector>
+
+#include <errno.h>
+#include <unistd.h>
+#include <sys/time.h>
+
+#ifdef _WIN32 // Bugzilla 40710
+#include <windows.h>
+#include <winbase.h>
+#include <winsock.h>
+#else
+#include <netinet/in.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#endif
+
+#define MAX_HOSTNAME_SIZE 255
+
+/*
+ * CppUnitServer protocol constants
+ */
+static const std::string TRACE_START = "%TRACES ";
+static const std::string TRACE_END = "%TRACEE ";
+static const std::string TEST_RUN_START = "%TESTC ";
+static const std::string TEST_START = "%TESTS ";
+static const std::string TEST_END = "%TESTE ";
+static const std::string TEST_ERROR = "%ERROR ";
+static const std::string TEST_FAILED = "%FAILED ";
+static const std::string TEST_RUN_END = "%RUNTIME";
+static const std::string TEST_STOPPED = "%TSTSTP ";
+static const std::string TEST_TREE = "%TSTTREE";
+
+TestRunnerClient::TestRunnerClient()
+{
+ fTestResult = 0;
+ fClientSocket = -1;
+ fPort = 0;
+ fKeepAlive = 0;
+ fDebugMode = 0;
+
+ fHost = (char *) malloc(MAX_HOSTNAME_SIZE);
+ strcpy(fHost, "");
+}
+
+TestRunnerClient::~TestRunnerClient() {
+
+ if (fHost != NULL) {
+ free(fHost);
+ }
+}
+
+int TestRunnerClient::Run()
+{
+ if (fDebugMode)
+ {
+ std::cerr << "TestRunnerClient: Starting client." << std::endl;
+ }
+
+ if (Connect() == -1) {
+ return -1;
+ }
+
+ InstallListeners();
+
+ RunTests();
+
+ UninstallListeners();
+
+ if(fTestResult != NULL)
+ {
+ fTestResult->stop();
+ fTestResult= NULL;
+ }
+
+ ShutDown();
+
+ return 0;
+}
+
+void TestRunnerClient::Init(int n, char *args[])
+{
+ ParseCommandLine(n, args);
+ DefineHostName();
+}
+
+void TestRunnerClient::ParseCommandLine(int n, char *args[])
+{
+ // parse all arguments passed by args
+ for(int i = 0; i < n; i++)
+ {
+ std::string arg(args[i]);
+
+ // port option
+ std::string portOption("-port=");
+ int pos = arg.find(portOption);
+ if(pos> -1)
+ {
+ std::string v = arg.substr(pos + portOption.length(), arg.length());
+ fPort = atoi(v.c_str());
+ }
+
+ // debug option
+ std::string debugOption("-debug");
+ pos = arg.find(debugOption);
+ if(pos> - 1)
+ {
+ fDebugMode = 1;
+ }
+ }
+}
+
+void TestRunnerClient::DefineHostName()
+{
+ // set fHost to hostname or localhost
+ int ret = gethostname(fHost, MAX_HOSTNAME_SIZE);
+ if (ret == -1)
+ {
+ strcpy(fHost, "localhost");
+ }
+}
+
+int TestRunnerClient::Connect()
+{
+
+#ifdef _WIN32 // Bugzilla 40710
+ if (fDebugMode)
+ {
+ std::cerr << "TestRunnerClient: Starting Windows Sockets WSAStartup()." << std:endl;
+ }
+
+ // start up Windows Sockets
+ WSADATA WSAData;
+ int result = WSAStartup (MAKEWORD(1, 1), &WSAData);
+ if (result != NO_ERROR)
+ {
+ std::cerr << "TestRunnerClient: WSAStartup() failed! Error code: " << result << std::endl;
+ return -1;
+ }
+#endif
+
+ if (fDebugMode)
+ {
+ std::cerr << "TestRunnerClient: Trying to connect to " << fHost << ":" << fPort << std::endl;
+ }
+
+ fClientSocket = socket(AF_INET, SOCK_STREAM, 0);
+ if (fClientSocket == -1)
+ {
+ std::cerr << "TestRunnerClient: Socket creation failed! error code: " << fClientSocket << std::endl;
+ return -1;
+ }
+
+ struct hostent *host = gethostbyname(fHost);
+ if (host == NULL)
+ {
+ std::cerr << "TestRunnerClient: Cannot find host address for " << fHost << "." << std::endl;
+ fClientSocket = -1;
+ return -1;
+ }
+
+ struct sockaddr_in name;
+ memset((void *)&name, 0, sizeof(struct sockaddr_in));
+ name.sin_family = AF_INET;
+ name.sin_port = htons(fPort);
+
+ memcpy(&name.sin_addr, host->h_addr, host->h_length);
+
+ if (fDebugMode) {
+ std::cerr << "TestRunnerClient: Waiting for the JVM to listen ... (trying 3 times)" << std::endl;
+ }
+
+ int ret = -1;
+ int j = 0;
+ while ((j < 3) && (ret == -1))
+ {
+ ret = ::connect(fClientSocket, (struct sockaddr *) &name, sizeof(struct sockaddr_in));
+ if (ret == -1)
+ {
+ if (fDebugMode) {
+ std::cerr << "TestRunnerClient: Connection request, waiting 1 second. "
+ << ((j-3)*-1) << " times left." << std::endl;
+ }
+ PrivateSleep(1000);
+ j++;
+ }
+ }
+ if (ret == -1)
+ {
+ std::cerr << "TestRunnerClient: No connection established. Error code: " << errno << std::endl;
+ fClientSocket = -1;
+ return -1;
+ }
+
+ if (fDebugMode) {
+ std::cerr << "TestRunnerClient: Connection established." << std::endl;
+ }
+ return 0;
+}
+
+void TestRunnerClient::InstallListeners()
+{
+ fTestResult = new CppUnit::TestResult();
+ fTestResult->addListener(this);
+ fTestResult->addListener(&resultCollector);
+}
+
+void TestRunnerClient::UninstallListeners()
+{
+ fTestResult->removeListener(this);
+}
+
+void TestRunnerClient::RunTests()
+{
+
+ CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry();
+ CppUnit::Test *suite = registry.makeTest();
+ int count = suite->countTestCases();
+ NotifyTestRunStarted(count);
+
+ if (count == 0)
+ {
+ NotifyTestRunEnded(0);
+ }
+
+ long startTime = CurrentTimeMillis();
+ if (fDebugMode)
+ {
+ std::cerr <<"TestRunnerClient: Start sending test case tree ..." << std::endl;
+ }
+
+ SendTestTree(suite);
+
+ int elapsedTime = CurrentTimeMillis() - startTime;
+ if (fDebugMode) {
+ std::cerr << "TestRunnerClient: Done sending test case tree. Elapsed time is "
+ << elapsedTime << "ms." << std::endl;
+ }
+
+ long testStartTime = CurrentTimeMillis();
+ if (fDebugMode) {
+ std::cerr << "TestRunnerClient: Test start time is " << testStartTime
+ << "ms." << std::endl;
+ }
+
+ suite->run(fTestResult);
+
+ if (fTestResult == NULL || fTestResult->shouldStop())
+ {
+ NotifyTestRunStopped(CurrentTimeMillis() - testStartTime);
+ }
+ else
+ {
+ NotifyTestRunEnded(CurrentTimeMillis() - testStartTime);
+ }
+}
+
+void TestRunnerClient::ShutDown()
+{
+ if (fClientSocket != -1)
+ {
+ if (fDebugMode) {
+ std::cerr << "TestRunnerClient: Closing connection to CppUnit sever at "
+ << fHost << ":" << fPort << std::endl;
+ }
+
+#ifdef _WIN32 // Bugzilla 40710
+ // TODO: std:err output for error return codes
+ closesocket(fClientSocket);
+ WSACleanup();
+#else
+ int result = close(fClientSocket);
+ if (result != 0)
+ {
+ std::cerr << "TestRunnerClient: Close connection error: " << errno << std::endl;
+ }
+#endif
+
+ fClientSocket = -1;
+ }
+}
+
+void TestRunnerClient::Stop()
+{
+ if (fTestResult != NULL)
+ {
+ fTestResult->stop();
+ }
+}
+
+void TestRunnerClient::SendTestTree(CppUnit::Test *test)
+{
+ if (typeid(*test) == typeid(CppUnit::TestDecorator))
+ {
+ class TmpClass : public CppUnit::TestDecorator {
+
+ public:
+ TmpClass(Test *t):CppUnit::TestDecorator(t)
+ {
+ // nothing to do
+ }
+
+ ~TmpClass() // Bugzilla 39894
+ {
+ // nothing to do
+ }
+
+ CppUnit::Test *getTest()
+ {
+ return m_test;
+ }
+ };
+
+ TmpClass *t = (TmpClass *)test;
+ SendTestTree(t->getTest());
+ }
+ else if (typeid(*test) == typeid(CppUnit::TestSuite))
+ {
+ CppUnit::TestSuite *suite = (CppUnit::TestSuite *)test;
+ const std::vector<CppUnit::Test *> &x = suite->getTests();
+
+ std::ostringstream os;
+ os << suite->getName() << ",true," << x.size();
+ NotifyTestTreeEntry(os.str());
+
+ for(unsigned int i=0; i < x.size(); i++)
+ {
+ SendTestTree(x[i]);
+ }
+ }
+ else
+ {
+ std::ostringstream os;
+ os << test->getName() << ",false," << test->countTestCases();
+ NotifyTestTreeEntry(os.str());
+ }
+}
+
+void TestRunnerClient::SendMessage(std::string msg)
+{
+ if (fClientSocket == -1)
+ {
+ return;
+ }
+
+#ifdef _WIN32 // Bugzilla 40710
+ send (fClientSocket, msg.c_str(), msg.length(), 0);
+ send (fClientSocket, "\n", 1, 0);
+#else
+ write(fClientSocket, msg.c_str(), msg.length());
+ write(fClientSocket, "\n", 1);
+#endif
+
+ if (fDebugMode)
+ {
+ std::cerr << "TestRunnerClient: Sent message \"" << msg << "\""
+ << std::endl;
+ }
+}
+
+void TestRunnerClient::NotifyTestRunStarted(int testCount)
+{
+ std::ostringstream os;
+ os << TEST_RUN_START << testCount;
+ SendMessage(os.str());
+}
+
+void TestRunnerClient::NotifyTestRunEnded(long elapsedTime)
+{
+ std::ostringstream os;
+ os << TEST_RUN_END << elapsedTime;
+ SendMessage(os.str());
+}
+
+void TestRunnerClient::NotifyTestRunStopped(long elapsedTime)
+{
+ std::ostringstream os;
+ os << TEST_STOPPED << elapsedTime;
+ SendMessage(os.str());
+}
+
+void TestRunnerClient::NotifyTestTreeEntry(std::string treeEntry)
+{
+ SendMessage(TEST_TREE + treeEntry);
+}
+
+void TestRunnerClient::NotifyTestStarted(std::string testName)
+{
+ SendMessage(TEST_START + testName);
+}
+
+void TestRunnerClient::NotifyTestEnded(std::string testName)
+{
+ SendMessage(TEST_END + testName);
+}
+
+void TestRunnerClient::NotifyTestFailed(std::string status, std::string testName, std::string trace)
+{
+ SendMessage(status + testName);
+ SendMessage(TRACE_START);
+ SendMessage(trace);
+ SendMessage(TRACE_END);
+}
+
+// From TestListener
+void TestRunnerClient::startTest(CppUnit::Test *test)
+{
+ NotifyTestStarted(test->getName());
+}
+
+// From TestListener
+void TestRunnerClient::addFailure(const CppUnit::TestFailure &failure)
+{
+ if(failure.isError())
+ {
+ NotifyTestFailed(TEST_ERROR,failure.failedTestName(),GetTrace(failure));
+ }
+ else
+ {
+ NotifyTestFailed(TEST_FAILED,failure.failedTestName(),GetTrace(failure));
+ }
+}
+
+// From TestListener
+void TestRunnerClient::endTest(CppUnit::Test *test)
+{
+ NotifyTestEnded(test->getName());
+}
+
+std::string TestRunnerClient::GetTrace(const CppUnit::TestFailure &failure)
+{
+ std::ostringstream os;
+
+ CppUnit::Exception *e=failure.thrownException();
+ if(e->sourceLine().lineNumber()!=-1)
+ {
+ os << "File " << e->sourceLine().fileName() << ":" << e->sourceLine().lineNumber() << "\n";
+ }
+ else
+ {
+ os << "File Unknown:1\n";
+ }
+ /* TODO: expected, actual value implementation
+ if(typeid(*e)==typeid(CppUnit::NotEqualException))
+ {
+ CppUnit::NotEqualException *ne=(CppUnit::NotEqualException *)e;
+
+ os << "Expected Value: " << ne->expectedValue() << "\n";
+ os << "Actual Value: " << ne->expectedValue() << "\n";
+ os << "Additional Message: " << ne->additionalMessage() << "\n";
+ }
+ else
+ {
+ End */
+ os << "Message: " << std::string(e->what()) << "\n";
+ /* } */
+
+ return(os.str());
+}
+
+long TestRunnerClient::CurrentTimeMillis()
+{
+#ifdef _WIN32 // Bugzilla 40710
+ unsigned long long p;
+ __asm__ __volatile__ ("rdtsc" : "=A" (p));
+ return (unsigned long)p;
+#else
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+
+ return((long)(tv.tv_sec*1000) + (tv.tv_usec/1000));
+#endif
+}
+
+void TestRunnerClient::PrivateSleep(int millisecs)
+{
+ struct timeval delta;
+ delta.tv_sec = (millisecs * 1000L) / 1000000L;
+ delta.tv_usec = (millisecs * 1000L) % 1000000L;
+ select (0, NULL, NULL, NULL, &delta);
+}
+
+CppUnit::TestResultCollector& TestRunnerClient::getResultCollector() {
+ return resultCollector;
+}
+
+/*!
+ * This is the main routine. The TestRunnerClient is initialized and run. The
+ * CppUnit tests are created, executed, and sent to the CppUnitServer.
+ * If no connection to the CppUnitServer was established the CppUnit tests are
+ * displayed on the console.
+ *
+ * @return <code>0</code> if the results of the CppUnit tests were sent to the
+ * CppUnitServer successfully.
+ * <code>-1</code> if a connection could not be established to the
+ * CppUnitServer.
+ */
+int CPPUNIT_MAIN(int n, char *arg[])
+{
+ std::ofstream xmlFileOut("cppunit_results.xml");
+
+ TestRunnerClient client;
+ client.Init(n, arg);
+ int ret = client.Run();
+ if (ret == -1)
+ {
+ //The Test Runner Client has failed
+ //Create the event manager and test controller
+
+ CppUnit::TestResult controller;
+
+ // Add a listener that collects test result
+ CppUnit::TestResultCollector result;
+ controller.addListener ( &result );
+
+ CppUnit::XmlOutputter xmlOutputter ( &result, xmlFileOut );
+ CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry();
+ CppUnit::Test *suite = registry.makeTest();
+
+ CppUnit::TextUi::TestRunner *runner = new CppUnit::TextUi::TestRunner();
+ runner->addTest(suite);
+ runner->run(controller);
+
+ // Output to XML
+ xmlOutputter.write();
+ } else {
+
+ CppUnit::TextOutputter textOutputter (&client.getResultCollector(), std::cout);
+ textOutputter.write();
+
+ // Output to XML
+ CppUnit::XmlOutputter xmlOutputter ( &client.getResultCollector(), xmlFileOut );
+ xmlOutputter.write();
+ }
+
+
+ xmlFileOut.close();
+}
+
+#endif /*CPPUNIT_MAIN*/
diff --git a/test/TestRunnerClient.h b/test/TestRunnerClient.h
new file mode 100644
index 0000000..4dc4460
--- /dev/null
+++ b/test/TestRunnerClient.h
@@ -0,0 +1,147 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Gerhard Leonhartsberger.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+#ifndef TESTRUNNERSERVER_H_
+#define TESTRUNNERSERVER_H_
+
+#ifdef CPPUNIT_MAIN
+
+#include "cppunit/TestResultCollector.h"
+#include "cppunit/TestListener.h"
+
+#include <vector>
+#include <string>
+#include <string.h>
+#include <stdlib.h>
+
+
+/*!
+ * Class <code>TestRunnerClient</code> handles the network connection to the
+ * <code>CppUnitServer</code> and executes all registered CppUnit tests.
+ * <p>
+ * The meta data of the CppUnit tests and the test results are sent to the
+ * <code>CppUnitServer</code> for displaying.
+ * </p>
+ * <p>
+ * For debugging purposes class <code>TestRunnerClient</code> displays debug
+ * messages on <code>std.cerr</code>. The debug modus is activated by specifying
+ * <code>debug</code> command line option. The command line is parsed by method
+ * <code>Init()</code>.
+ * </p>
+ * <p>
+ * Note: This class is not intended to be subclassed by clients. This class is
+ * based on the original <code>RemoteTestRunner</code> class provided by
+ * <code>org.eclipse.cdt.cppunit</code>.
+ * </p>
+ *
+ * @author Gerhard Leonhartsberger
+ */
+class TestRunnerClient: public CppUnit::TestListener
+{
+private:
+ CppUnit::TestResult *fTestResult;
+ CppUnit::TestResultCollector resultCollector;
+ int fClientSocket;
+ char *fHost;
+ int fPort;
+ int fDebugMode;
+ int fKeepAlive;
+
+public:
+ TestRunnerClient();
+ virtual ~TestRunnerClient();
+
+ CppUnit::TestResultCollector& getResultCollector();
+
+ /*!
+ * Initializes the <code>TestRunnerClient</code>.
+ * <p>
+ * The given <code>args</code> are parsed. The syntax for the arguments is
+ * defined in EBNF as follows: <code>{-option=value}</code>
+ * </p>
+ *
+ * @param n The number of arguments.
+ * @param args The argument values. Valid options are:
+ * <li><code>-debug</code> When present the TestRunnerClient
+ * is run in debug modus and displays debug messages.</li>
+ * <li><code>-port=number</code> Defines the port where
+ * CppUnitServer is listening for client connections.</li>
+ */
+ void Init(int n,char *args[]);
+
+ /*!
+ * Runs the TestRunnerClient. A trial to connect to the CppUnitServer is done.
+ * The test results are sent to the CppUnitServer.
+ *
+ * @return The return value is <code>0</code> when the CppUnitServer was connected successfully
+ * otherwise the return value is <code>-1</code>.
+ */
+ int Run();
+
+ /*!
+ * Stops processing <code>CppUnit</code> from executing tests.
+ */
+ void Stop();
+
+ /*!
+ * Method defined in <code>CppUnit::TestListener</code>.
+ */
+ void startTest(CppUnit::Test *test);
+
+ /*!
+ * Method defined in <code>CppUnit::TestListener</code>.
+ */
+ void addFailure(const CppUnit::TestFailure &failure);
+
+ /*!
+ * Method defined in <code>CppUnit::TestListener</code>.
+ */
+ void endTest(CppUnit::Test *test);
+
+private:
+ int Connect();
+ void RunTests();
+ void ShutDown();
+
+ // utility methods
+ void ParseCommandLine(int n, char *args[]);
+ void DefineHostName();
+ void InstallListeners();
+ void UninstallListeners();
+
+ /*!
+ * Sends the given test to the CppUnitView.
+ * <p>
+ * In case of test is of type CppUnit::Test the following protocol is sent:
+ * <code>TSTTREE name, false, testCaseCount</code>
+ * </p>
+ * <p>
+ * In case of test is of type CppUnit::TestSuite the following protocol is sent:
+ * TSTTREE name, true, testCount
+ * </p>
+ * @param test the CppUnit test
+ */
+ void SendTestTree(CppUnit::Test *test);
+ void SendMessage(std::string msg);
+
+ // Notification methods
+ void NotifyTestRunStarted(int testCount);
+ void NotifyTestRunEnded(long elapsedTime);
+ void NotifyTestRunStopped(long elapsedTime);
+ void NotifyTestTreeEntry(std::string treeEntry);
+ void NotifyTestStarted(std::string testName);
+ void NotifyTestEnded(std::string testName);
+ void NotifyTestFailed(std::string status, std::string testName, std::string trace);
+
+ std::string GetTrace(const CppUnit::TestFailure &failure);
+ long CurrentTimeMillis();
+ void PrivateSleep(int millisecs);
+};
+
+#endif /*CPPUNIT_MAIN*/
+#endif /*TESTRUNNERSERVER_H_*/
diff --git a/test/Test_MTS_Text.cpp b/test/Test_MTS_Text.cpp
new file mode 100644
index 0000000..b158fc1
--- /dev/null
+++ b/test/Test_MTS_Text.cpp
@@ -0,0 +1,392 @@
+#include "Test_MTS_Text.h"
+#include <mts/MTS_Logger.h>
+#include <sstream>
+
+CPPUNIT_TEST_SUITE_REGISTRATION(Test_MTS_Text);
+
+void Test_MTS_Text::testText__datetimeIsBefore() {
+ CPPUNIT_ASSERT(MTS::Text::datetimeIsBefore("08/10/12 12:00:00", "08/10/12 12:00:01"));
+ CPPUNIT_ASSERT(!MTS::Text::datetimeIsBefore("08/10/12 12:00:01", "08/10/12 12:00:00"));
+ CPPUNIT_ASSERT(MTS::Text::datetimeIsBefore("08/10/10 12:00:00", "08/10/12 12:00:00"));
+ CPPUNIT_ASSERT(MTS::Text::datetimeIsBefore("08/09/12 12:00:00", "08/10/12 12:00:01"));
+}
+
+void Test_MTS_Text::testis_base64() {
+ CPPUNIT_ASSERT(false);
+}
+
+void Test_MTS_Text::testbase64_encode() {
+ CPPUNIT_ASSERT(false);
+}
+
+void Test_MTS_Text::testbase64_decode() {
+ CPPUNIT_ASSERT(false);
+}
+
+void Test_MTS_Text::testText__time() {
+ CPPUNIT_ASSERT(false);
+}
+
+void Test_MTS_Text::testText__date() {
+ std::string sZero("Thu, 01 Jan 1970 00:00:02 GMT");
+
+ std::string sDate;
+ time_t iTime = 2;
+ tm* pTime = gmtime(&iTime);
+
+ sDate = MTS::Text::date(*pTime, MTS::Text::DATEFORMAT::RFC_1123);
+ printDebug("MTS::Text::date [%s]", sDate.c_str());
+ CPPUNIT_ASSERT(sZero == sDate);
+}
+
+void Test_MTS_Text::testText__split() {
+ std::string test = ",test";
+ std::vector<std::string> list = MTS::Text::split(test, ",");
+
+ CPPUNIT_ASSERT(list.size() == 2);
+ CPPUNIT_ASSERT(list[0] == "");
+ CPPUNIT_ASSERT(list[1] == "test");
+}
+
+void Test_MTS_Text::testText__split_limit() {
+ std::string path = "stats";
+ std::vector<std::string> parts = MTS::Text::split(path, '/', 3);
+ CPPUNIT_ASSERT(parts.size() == 1);
+ CPPUNIT_ASSERT(parts[0] == "stats");
+
+ std::string path1 = "stats/radio";
+ std::vector<std::string> parts1 = MTS::Text::split(path1, '/', 3);
+ CPPUNIT_ASSERT(parts1.size() == 2);
+ CPPUNIT_ASSERT(parts1[0] == "stats");
+ CPPUNIT_ASSERT(parts1[1] == "radio");
+
+ std::string path2 = "stats/radio/debug/hardware";
+ std::vector<std::string> parts2 = MTS::Text::split(path2, '/');
+ CPPUNIT_ASSERT(parts2.size() == 4);
+ CPPUNIT_ASSERT(parts2[0] == "stats");
+ CPPUNIT_ASSERT(parts2[1] == "radio");
+ CPPUNIT_ASSERT(parts2[2] == "debug");
+ CPPUNIT_ASSERT(parts2[3] == "hardware");
+
+ std::string path3 = "stats/radio/debug/hardware";
+ std::vector<std::string> parts3 = MTS::Text::split(path3, '/', -2);
+ CPPUNIT_ASSERT(parts3.size() == 4);
+ CPPUNIT_ASSERT(parts3[0] == "stats");
+ CPPUNIT_ASSERT(parts3[1] == "radio");
+ CPPUNIT_ASSERT(parts3[2] == "debug");
+}
+
+void Test_MTS_Text::testText__split_values() {
+ std::string path = "stats/radio/debug";
+ std::vector<std::string> parts = MTS::Text::split(path, '/', 3);
+ CPPUNIT_ASSERT(parts.size() == 3);
+ CPPUNIT_ASSERT(parts[0] == "stats");
+ CPPUNIT_ASSERT(parts[1] == "radio");
+ CPPUNIT_ASSERT(parts[2] == "debug");
+
+ std::string path1 = "stats/radio/debug/hardware";
+ std::vector<std::string> parts1 = MTS::Text::split(path1, '/', 3);
+ CPPUNIT_ASSERT(parts1.size() == 3);
+ CPPUNIT_ASSERT(parts1[0] == "stats");
+ CPPUNIT_ASSERT(parts1[1] == "radio");
+ CPPUNIT_ASSERT(parts1[2] == "debug/hardware");
+
+ std::string path2 = "stats/radio/debug/hardware";
+ std::vector<std::string> parts2 = MTS::Text::split(path2, '/', 2);
+ CPPUNIT_ASSERT(parts2.size() == 2);
+ CPPUNIT_ASSERT(parts2[0] == "stats");
+ CPPUNIT_ASSERT(parts2[1] == "radio/debug/hardware");
+}
+
+void Test_MTS_Text::testText__getLine() {
+
+ std::string line1("-----------------------------13456055954665194976790380");
+ std::string line2("Content-Disposition: form-data; name=\"archivo\"; filename=\"test\"");
+ std::string line3("Content-Type: application/octet-stream");
+ std::string line4("");
+ std::string line5("**HELLOWORLD**");
+ std::string line6("");
+ std::string line7("-----------------------------13456055954665194976790380--");
+
+ std::stringstream ss;
+ ss << line1 << "\n";
+ ss << line2 << "\n\r";
+ ss << line3 << "\n";
+ ss << line4 << "\r\n";
+ ss << line5 << "\n";
+ ss << line6 << "\n";
+ ss << line7 << "\n";
+
+ std::string test(ss.str());
+
+ size_t pos = 0;
+ CPPUNIT_ASSERT(line1 == MTS::Text::getLine(test, pos, pos));
+ CPPUNIT_ASSERT(line2 == MTS::Text::getLine(test, pos, pos));
+ CPPUNIT_ASSERT(line3 == MTS::Text::getLine(test, pos, pos));
+ CPPUNIT_ASSERT(line4 == MTS::Text::getLine(test, pos, pos));
+ CPPUNIT_ASSERT(line5 == MTS::Text::getLine(test, pos, pos));
+ CPPUNIT_ASSERT(line6 == MTS::Text::getLine(test, pos, pos));
+ CPPUNIT_ASSERT(line7 == MTS::Text::getLine(test, pos, pos));
+ CPPUNIT_ASSERT("" == MTS::Text::getLine(test, pos, pos));
+
+}
+
+void Test_MTS_Text::testText__trim() {
+ std::string test = " test ";
+ std::string result = MTS::Text::trim(test);
+ //std::printf("(%s)\n", result.c_str());
+ CPPUNIT_ASSERT(result == "test");
+
+ test = "test";
+ result = MTS::Text::trim(test);
+ //std::printf("before: (%s) after: (%s)\n", test.c_str(), result.c_str());
+ CPPUNIT_ASSERT(result == "test");
+
+ test = "test\t\t";
+ result = MTS::Text::trim(test);
+ //std::printf("before: (%s) after: (%s)\n", test.c_str(), result.c_str());
+ CPPUNIT_ASSERT(result == "test");
+
+ test = "\t\ttest";
+ result = MTS::Text::trim(test);
+ //std::printf("before: (%s) after: (%s)\n", test.c_str(), result.c_str());
+ CPPUNIT_ASSERT(result == "test");
+
+ test = "\ttest\t";
+ result = MTS::Text::trim(test);
+ //std::printf("before: (%s) after: (%s)\n", test.c_str(), result.c_str());
+ CPPUNIT_ASSERT(result == "test");
+
+ test = "\n\nte st\n\n";
+ result = MTS::Text::trim(test);
+ //std::printf("before: (%s) after: (%s)\n", test.c_str(), result.c_str());
+ CPPUNIT_ASSERT(result == "te st");
+
+ test = "\n\ntest\n\n";
+ result = MTS::Text::trim(test);
+ //std::printf("before: (%s) after: (%s)\n", test.c_str(), result.c_str());
+ CPPUNIT_ASSERT(result == "test");
+
+ test = "\n\rtest\n\r";
+ result = MTS::Text::trim(test);
+ //std::printf("before: (%s) after: (%s)\n", test.c_str(), result.c_str());
+ CPPUNIT_ASSERT(result == "test");
+
+ test = "test\n\r";
+ result = MTS::Text::trim(test);
+ //std::printf("before: (%s) after: (%s)\n", test.c_str(), result.c_str());
+ CPPUNIT_ASSERT(result == "test");
+
+ test = "\r\n\n\rtest\r\n\r\r\n\n\r\n";
+ result = MTS::Text::trim(test);
+ //std::printf("before: (%s) after: (%s)\n", test.c_str(), result.c_str());
+ CPPUNIT_ASSERT(result == "test");
+
+ test = " ";
+ result = MTS::Text::trim(test);
+ CPPUNIT_ASSERT(result == "");
+}
+
+
+void Test_MTS_Text::testText__strip() {
+ std::string phonenum = "(763) 785-3500";
+ std::string hw = "H*E*L*L*O WORLD!";
+ std::string result;
+ std::vector<uint8_t> vElements;
+
+ vElements.push_back('(');
+ vElements.push_back(')');
+ vElements.push_back(' ');
+ vElements.push_back('-');
+
+ result = MTS::Text::strip(phonenum, vElements);
+ CPPUNIT_ASSERT(result == "7637853500");
+
+ result = MTS::Text::strip(hw, '*');
+ CPPUNIT_ASSERT(result == "HELLO WORLD!");
+}
+
+
+void Test_MTS_Text::testText__toLowerCase() {
+ std::string test = "TeSt";
+ CPPUNIT_ASSERT(MTS::Text::toLowerCase(test) == "test");
+}
+
+void Test_MTS_Text::testText__toUpperCase() {
+ std::string test = "TeSt";
+ CPPUNIT_ASSERT(MTS::Text::toUpperCase(test) == "TEST");
+}
+
+void Test_MTS_Text::testText__toCapitalized() {
+ std::string test = "test";
+ CPPUNIT_ASSERT(MTS::Text::toCapitalized(test) == "Test");
+ test = "TEST\0";
+ CPPUNIT_ASSERT(MTS::Text::toCapitalized(test) == "Test");
+ test = "\0";
+ CPPUNIT_ASSERT(MTS::Text::toCapitalized(test) == "");
+ test = "a\0";
+ printDebug("[%s] [%s]", test.c_str(), MTS::Text::toCapitalized(test).c_str());
+ CPPUNIT_ASSERT(MTS::Text::toCapitalized(test) == "A");
+}
+
+void Test_MTS_Text::testText__toCamelCase() {
+ std::string test("Hello World");
+ CPPUNIT_ASSERT(MTS::Text::toCamelCase(test) == "helloWorld");
+}
+
+void Test_MTS_Text::testText__toBase64() {
+ CPPUNIT_ASSERT(false);
+}
+
+void Test_MTS_Text::testText__toBase64_1() {
+ CPPUNIT_ASSERT(false);
+}
+
+void Test_MTS_Text::testText__fromBase64() {
+ CPPUNIT_ASSERT(false);
+}
+
+void Test_MTS_Text::testText__widen() {
+ CPPUNIT_ASSERT(false);
+}
+
+void Test_MTS_Text::testText__narrow() {
+ CPPUNIT_ASSERT(false);
+}
+
+void Test_MTS_Text::testText__format() {
+ CPPUNIT_ASSERT(false);
+}
+
+void Test_MTS_Text::testText__format_1() {
+ CPPUNIT_ASSERT(false);
+}
+
+void Test_MTS_Text::testText__format_2() {
+ CPPUNIT_ASSERT(false);
+}
+
+void Test_MTS_Text::testText__format_3() {
+ CPPUNIT_ASSERT(false);
+}
+
+void Test_MTS_Text::testText__format_4() {
+ CPPUNIT_ASSERT(false);
+}
+
+void Test_MTS_Text::testText__format_5() {
+ CPPUNIT_ASSERT(false);
+}
+
+void Test_MTS_Text::testText__format_6() {
+ CPPUNIT_ASSERT(false);
+}
+
+void Test_MTS_Text::testText__format_7() {
+ CPPUNIT_ASSERT(false);
+}
+
+void Test_MTS_Text::testText__format_8() {
+ CPPUNIT_ASSERT(false);
+}
+
+void Test_MTS_Text::testText__format_9() {
+ CPPUNIT_ASSERT(false);
+}
+
+void Test_MTS_Text::testtoHexString() {
+ CPPUNIT_ASSERT(false);
+}
+
+void Test_MTS_Text::testText__formatHex() {
+ CPPUNIT_ASSERT(false);
+}
+
+void Test_MTS_Text::testText__formatHex_1() {
+ CPPUNIT_ASSERT(false);
+}
+
+void Test_MTS_Text::testText__formatHex_2() {
+ CPPUNIT_ASSERT(false);
+}
+
+void Test_MTS_Text::testText__formatHex_3() {
+ CPPUNIT_ASSERT(false);
+}
+
+void Test_MTS_Text::testText__formatHex_4() {
+ CPPUNIT_ASSERT(false);
+}
+
+void Test_MTS_Text::testText__formatHex_5() {
+ CPPUNIT_ASSERT(false);
+}
+
+void Test_MTS_Text::testText__formatHex_6() {
+ CPPUNIT_ASSERT(false);
+}
+
+void Test_MTS_Text::testText__formatHex_7() {
+ CPPUNIT_ASSERT(false);
+}
+
+void Test_MTS_Text::testText__formatHex_8() {
+ CPPUNIT_ASSERT(false);
+}
+
+void Test_MTS_Text::testText__parse() {
+ CPPUNIT_ASSERT(false);
+}
+
+void Test_MTS_Text::testText__parse_1() {
+ CPPUNIT_ASSERT(false);
+}
+
+void Test_MTS_Text::testText__parse_2() {
+ CPPUNIT_ASSERT(false);
+}
+
+void Test_MTS_Text::testText__parse_3() {
+ CPPUNIT_ASSERT(false);
+}
+
+void Test_MTS_Text::testText__parse_4() {
+ CPPUNIT_ASSERT(false);
+}
+
+void Test_MTS_Text::testText__parse_5() {
+ CPPUNIT_ASSERT(false);
+}
+
+void Test_MTS_Text::testText__parse_6() {
+ CPPUNIT_ASSERT(false);
+}
+
+void Test_MTS_Text::testText__parse_7() {
+ CPPUNIT_ASSERT(false);
+}
+
+void Test_MTS_Text::testText__parse_8() {
+ CPPUNIT_ASSERT(false);
+}
+
+void Test_MTS_Text::testText__parse_9() {
+ CPPUNIT_ASSERT(false);
+}
+
+void Test_MTS_Text::testText__parseHex() {
+ CPPUNIT_ASSERT(false);
+}
+
+void Test_MTS_Text::testText__parseHex_1() {
+ CPPUNIT_ASSERT(false);
+}
+
+void Test_MTS_Text::testText__parseHex_2() {
+ CPPUNIT_ASSERT(false);
+}
+
+void Test_MTS_Text::testText__parseHex_3() {
+ CPPUNIT_ASSERT(false);
+}
+
diff --git a/test/Test_MTS_Text.h b/test/Test_MTS_Text.h
new file mode 100644
index 0000000..d9a9ea3
--- /dev/null
+++ b/test/Test_MTS_Text.h
@@ -0,0 +1,121 @@
+#ifndef TEST_Test_MTS_Text
+#define TEST_Test_MTS_Text
+#include <mts/MTS_Text.h>
+#include "cppunit/extensions/HelperMacros.h"
+
+class Test_MTS_Text : public CppUnit::TestFixture {
+public:
+ void testis_base64();
+ void testbase64_encode();
+ void testbase64_decode();
+ void testText__time();
+ void testText__date();
+ void testText__split();
+ void testText__split_limit();
+ void testText__split_values();
+ void testText__getLine();
+ void testText__trim();
+ void testText__strip();
+ void testText__toLowerCase();
+ void testText__toUpperCase();
+ void testText__toCapitalized();
+ void testText__toCamelCase();
+ void testText__toBase64();
+ void testText__toBase64_1();
+ void testText__fromBase64();
+ void testText__widen();
+ void testText__narrow();
+ void testText__format();
+ void testText__format_1();
+ void testText__format_2();
+ void testText__format_3();
+ void testText__format_4();
+ void testText__format_5();
+ void testText__format_6();
+ void testText__format_7();
+ void testText__format_8();
+ void testText__format_9();
+ void testtoHexString();
+ void testText__formatHex();
+ void testText__formatHex_1();
+ void testText__formatHex_2();
+ void testText__formatHex_3();
+ void testText__formatHex_4();
+ void testText__formatHex_5();
+ void testText__formatHex_6();
+ void testText__formatHex_7();
+ void testText__formatHex_8();
+ void testText__parse();
+ void testText__parse_1();
+ void testText__parse_2();
+ void testText__parse_3();
+ void testText__parse_4();
+ void testText__parse_5();
+ void testText__parse_6();
+ void testText__parse_7();
+ void testText__parse_8();
+ void testText__parse_9();
+ void testText__parseHex();
+ void testText__parseHex_1();
+ void testText__parseHex_2();
+ void testText__parseHex_3();
+ void testText__datetimeIsBefore();
+ CPPUNIT_TEST_SUITE(Test_MTS_Text);
+// CPPUNIT_TEST(testis_base64);
+// CPPUNIT_TEST(testbase64_encode);
+// CPPUNIT_TEST(testbase64_decode);
+// CPPUNIT_TEST(testText__time);
+ CPPUNIT_TEST(testText__date);
+ CPPUNIT_TEST(testText__split);
+ CPPUNIT_TEST(testText__split_limit);
+ CPPUNIT_TEST(testText__split_values);
+ CPPUNIT_TEST(testText__getLine);
+ CPPUNIT_TEST(testText__trim);
+ CPPUNIT_TEST(testText__strip);
+ CPPUNIT_TEST(testText__toLowerCase);
+ CPPUNIT_TEST(testText__toUpperCase);
+ CPPUNIT_TEST(testText__toCapitalized);
+ CPPUNIT_TEST(testText__toCamelCase);
+// CPPUNIT_TEST(testText__toBase64);
+// CPPUNIT_TEST(testText__toBase64_1);
+// CPPUNIT_TEST(testText__fromBase64);
+// CPPUNIT_TEST(testText__widen);
+// CPPUNIT_TEST(testText__narrow);
+// CPPUNIT_TEST(testText__format);
+// CPPUNIT_TEST(testText__format_1);
+// CPPUNIT_TEST(testText__format_2);
+// CPPUNIT_TEST(testText__format_3);
+// CPPUNIT_TEST(testText__format_4);
+// CPPUNIT_TEST(testText__format_5);
+// CPPUNIT_TEST(testText__format_6);
+// CPPUNIT_TEST(testText__format_7);
+// CPPUNIT_TEST(testText__format_8);
+// CPPUNIT_TEST(testText__format_9);
+// CPPUNIT_TEST(testtoHexString);
+// CPPUNIT_TEST(testText__formatHex);
+// CPPUNIT_TEST(testText__formatHex_1);
+// CPPUNIT_TEST(testText__formatHex_2);
+// CPPUNIT_TEST(testText__formatHex_3);
+// CPPUNIT_TEST(testText__formatHex_4);
+// CPPUNIT_TEST(testText__formatHex_5);
+// CPPUNIT_TEST(testText__formatHex_6);
+// CPPUNIT_TEST(testText__formatHex_7);
+// CPPUNIT_TEST(testText__formatHex_8);
+// CPPUNIT_TEST(testText__parse);
+// CPPUNIT_TEST(testText__parse_1);
+// CPPUNIT_TEST(testText__parse_2);
+// CPPUNIT_TEST(testText__parse_3);
+// CPPUNIT_TEST(testText__parse_4);
+// CPPUNIT_TEST(testText__parse_5);
+// CPPUNIT_TEST(testText__parse_6);
+// CPPUNIT_TEST(testText__parse_7);
+// CPPUNIT_TEST(testText__parse_8);
+// CPPUNIT_TEST(testText__parse_9);
+// CPPUNIT_TEST(testText__parseHex);
+// CPPUNIT_TEST(testText__parseHex_1);
+// CPPUNIT_TEST(testText__parseHex_2);
+// CPPUNIT_TEST(testText__parseHex_3);
+ CPPUNIT_TEST(testText__datetimeIsBefore);
+ CPPUNIT_TEST_SUITE_END();
+};
+#endif