2006-09-25 19:40:49 +00:00
|
|
|
/** @file
|
|
|
|
|
|
|
|
$Id$
|
|
|
|
|
|
|
|
$Date$
|
|
|
|
$Author$
|
|
|
|
|
|
|
|
@copy © Marc Wäckerlin
|
|
|
|
@license LGPL, see file <a href="license.html">COPYING</a>
|
|
|
|
|
|
|
|
$Log$
|
|
|
|
|
|
|
|
1 2 3 4 5 6 7 8
|
|
|
|
5678901234567890123456789012345678901234567890123456789012345678901234567890
|
|
|
|
*/
|
2011-12-10 11:39:09 +00:00
|
|
|
#include <mrw/string.hxx>
|
|
|
|
#include <mrw/list.hxx>
|
2006-09-25 19:40:49 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include <cppunit/TestFixture.h>
|
|
|
|
#include <cppunit/ui/text/TestRunner.h>
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
#include <cppunit/extensions/TestFactoryRegistry.h>
|
2011-12-11 14:24:33 +00:00
|
|
|
#include <cppunit/XmlOutputter.h>
|
|
|
|
#include <fstream>
|
2006-09-25 19:40:49 +00:00
|
|
|
|
|
|
|
class StringTest: public CppUnit::TestFixture {
|
|
|
|
public:
|
|
|
|
void Join() {
|
|
|
|
std::list<std::string> l;
|
|
|
|
l<<"Hello"<<"World"<<"here"<<"I"<<"am";
|
2014-03-28 11:50:39 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::list<std::string>::size_type(5), l.size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("Hello World here I am"), mrw::join(l));
|
2006-09-25 19:40:49 +00:00
|
|
|
}
|
|
|
|
void Split() {
|
|
|
|
std::string text("Hello World here I am");
|
|
|
|
std::list<std::string> a(mrw::split(text)), b;
|
|
|
|
b<<"Hello"<<"World"<<"here"<<"I"<<"am";
|
|
|
|
CPPUNIT_ASSERT(equal(a.begin(), a.end(), b.begin()));
|
|
|
|
}
|
|
|
|
CPPUNIT_TEST_SUITE(StringTest);
|
|
|
|
CPPUNIT_TEST(Join);
|
|
|
|
CPPUNIT_TEST(Split);
|
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
};
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(StringTest);
|
|
|
|
|
2011-12-11 13:47:45 +00:00
|
|
|
int main(int argc, char** argv) try {
|
|
|
|
std::ofstream ofs((*argv+std::string(".xml")).c_str());
|
2006-09-25 19:40:49 +00:00
|
|
|
CppUnit::TextUi::TestRunner runner;
|
2011-12-11 13:47:45 +00:00
|
|
|
runner.setOutputter(new CppUnit::XmlOutputter(&runner.result(), ofs));
|
2006-09-25 19:40:49 +00:00
|
|
|
runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
|
|
|
|
return runner.run() ? 0 : 1;
|
2011-12-11 13:47:45 +00:00
|
|
|
} catch (std::exception& e) {
|
|
|
|
std::cerr<<"***Exception: "<<e.what()<<std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|