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.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
3.5 KiB

20 years ago
/** @file
$Id$
$Date$
$Author$
@copy © Marc Wäckerlin
@license LGPL, see file <a href="license.html">COPYING</a>
$Log$
Revision 1.2 2005/04/07 20:55:21 marc
Oops, there's a make distcheck...? Now it works.
20 years ago
Revision 1.1 2005/01/07 00:31:38 marc
initial version
*/
#include <mrw/configfile.hxx>
#include <mrw/file.hxx>
#include <mrw/stdext.hxx> // ifelse
20 years ago
#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>
#include <stdlib.h> // getenv
20 years ago
class ConfigFileTest: public CppUnit::TestFixture {
public:
void CheckFile() {
std::string srcdir(mrw::ifelse(getenv("srcdir"), "."));
mrw::File::copy(srcdir+"/configfile.ini", "configfile2.ini");
20 years ago
mrw::ConfigFileWriter config("configfile2.ini");
CPPUNIT_ASSERT_EQUAL(std::string("yyy"), config("", "xxx", ".")());
CPPUNIT_ASSERT_EQUAL(std::string(), config("Section", "abc", ".")());
CPPUNIT_ASSERT_EQUAL(std::string("hallo welt"),
config("Section", "def", ".")());
CPPUNIT_ASSERT_EQUAL(std::string(), config("Section", "ghi", ".")());
CPPUNIT_ASSERT_EQUAL(std::string("mn\n op qr\n st"),
config("Section", "jkl", ".")());
CPPUNIT_ASSERT_EQUAL(std::string("5678=90"),
config("Other Section", "1234", ".")());
CPPUNIT_ASSERT_EQUAL(std::string("some contents"),
config("Other Section", "here we are", ".")());
CPPUNIT_ASSERT_EQUAL(std::string(), config("Other Section", "here", ".")());
20 years ago
config("", "xxx", ".")="0";
config("Section", "abc", ".")="1";
CPPUNIT_ASSERT_EQUAL(std::string("sgadd"),
config("New Section", "a first one", "sgadd")());
20 years ago
config("Section", "def", ".")="Und=Tschuess";
config("Section", "ghi", ".")="3";
config("Section", "jkl", ".")="4";
config("Other Section", "1234", ".")="5";
config("Other Section", "here we are", ".")="6";
config("Other Section", "here", ".")="7";
CPPUNIT_ASSERT_EQUAL(std::string("."),
config("Other Section", "no no", ".")());
CPPUNIT_ASSERT_EQUAL(std::string("."),
config("Other Section", "no no no", ".")());
CPPUNIT_ASSERT_EQUAL(std::string("."),
config("Other Section", "yes", ".")());
CPPUNIT_ASSERT_EQUAL(std::string("dadaa"),
config("Section", "guguseli", "dadaa")());
CPPUNIT_ASSERT_EQUAL(std::string("dadaa"),
config("Section", "guguseli zwei", "dadaa")());
CPPUNIT_ASSERT_EQUAL(std::string("dadaa"),
config("Section", "guguseli drei", "dadaa")());
CPPUNIT_ASSERT_EQUAL(std::string("."),
config("New Section", "one more", ".")());
20 years ago
}
CPPUNIT_TEST_SUITE(ConfigFileTest);
CPPUNIT_TEST(CheckFile);
CPPUNIT_TEST_SUITE_END();
};
CPPUNIT_TEST_SUITE_REGISTRATION(ConfigFileTest);
int main(int argc, char** argv) try {
std::ofstream ofs((*argv+std::string(".xml")).c_str());
20 years ago
CppUnit::TextUi::TestRunner runner;
runner.setOutputter(new CppUnit::XmlOutputter(&runner.result(), ofs));
20 years ago
runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
return runner.run() ? 0 : 1;
} catch (std::exception& e) {
std::cerr<<"***Exception: "<<e.what()<<std::endl;
return 1;
}