C++ Library containing a lot of needful things: Stack Trace, Command Line Parser, Resource Handling, Configuration Files, Unix Command Execution, Directories, Regular Expressions, Tokenizer, Function Trace, Standard Extensions.
81 lines
2.6 KiB
81 lines
2.6 KiB
/** @file |
|
|
|
$Id$ |
|
|
|
$Date$ |
|
$Author$ |
|
|
|
@copy © Marc Wäckerlin |
|
@license LGPL, see file <a href="license.html">COPYING</a> |
|
|
|
$Log$ |
|
Revision 1.2 2005/01/07 00:35:17 marc |
|
initial version |
|
|
|
Revision 1.1 2004/12/17 16:26:58 marc |
|
initial version |
|
|
|
|
|
*/ |
|
|
|
#include <mrw/tokenizer.hxx> |
|
#include <mrw/list.hxx> |
|
#include <algorithm> |
|
|
|
#include <cppunit/TestFixture.h> |
|
#include <cppunit/ui/text/TestRunner.h> |
|
#include <cppunit/extensions/HelperMacros.h> |
|
#include <cppunit/extensions/TestFactoryRegistry.h> |
|
#include <cppunit/XmlOutputter.h> |
|
#include <fstream> |
|
|
|
class TokenizerTest: public CppUnit::TestFixture { |
|
public: |
|
void CheckNonGreedy() { |
|
const std::string aux[] = {"first", "second", "third", "", "fifth"}; |
|
std::list<std::string> a(aux, aux+sizeof(aux)/sizeof(std::string)), b; |
|
mrw::Tokenizer token("first,second,third,,fifth", false, ","); |
|
while (token) b<<token(); |
|
CPPUNIT_ASSERT(equal(a.begin(), a.end(), b.begin())); |
|
} |
|
void CheckGreedy() { |
|
const std::string aux[] = {"Hello", "world", "here", "I", "am"}; |
|
std::list<std::string> a(aux, aux+sizeof(aux)/sizeof(std::string)), b; |
|
mrw::Tokenizer token("Hello world, here I am!", true, " \t\n,.?!"); |
|
while (token) b<<token(); |
|
CPPUNIT_ASSERT(equal(a.begin(), a.end(), b.begin())); |
|
} |
|
void CheckReset() { |
|
const std::string aux[] = {"first", "second", "third", "", "fifth"}; |
|
std::list<std::string> a(aux, aux+sizeof(aux)/sizeof(std::string)), b; |
|
mrw::Tokenizer token("first,second,third,,fifth", false, ","); |
|
while (token) b<<token(); |
|
CPPUNIT_ASSERT(equal(a.begin(), a.end(), b.begin())); |
|
const std::string aux2[] = {"a", "b", "c", "d", "e"}; |
|
std::list<std::string> a2(aux2, aux2+sizeof(aux2)/sizeof(std::string)), |
|
b2, b3; |
|
token.reset("a,b,c,d,e"); |
|
while (token) b2<<token(); |
|
CPPUNIT_ASSERT(equal(a2.begin(), a2.end(), b2.begin())); |
|
token.reset(); |
|
while (token) b3<<token(); |
|
CPPUNIT_ASSERT(equal(a2.begin(), a2.end(), b3.begin())); |
|
} |
|
CPPUNIT_TEST_SUITE(TokenizerTest); |
|
CPPUNIT_TEST(CheckNonGreedy); |
|
CPPUNIT_TEST(CheckGreedy); |
|
CPPUNIT_TEST(CheckReset); |
|
CPPUNIT_TEST_SUITE_END(); |
|
}; |
|
CPPUNIT_TEST_SUITE_REGISTRATION(TokenizerTest); |
|
|
|
int main(int argc, char** argv) try { |
|
std::ofstream ofs((*argv+std::string(".xml")).c_str()); |
|
CppUnit::TextUi::TestRunner runner; |
|
runner.setOutputter(new CppUnit::XmlOutputter(&runner.result(), ofs)); |
|
runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); |
|
return runner.run() ? 0 : 1; |
|
} catch (std::exception& e) { |
|
std::cerr<<"***Exception: "<<e.what()<<std::endl; |
|
return 1; |
|
}
|
|
|