From 48ca7f876fa5f45a34bfd2d63f1804e5cb5e6a2b Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Fri, 10 Dec 2010 16:40:17 +0200 Subject: [PATCH 1/1] =?utf8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?utf8?q?=D0=BD=D1=8B=20=D1=8E=D0=BD=D0=B8=D1=82-=D1=82=D0=B5=D1=81=D1=82?= =?utf8?q?=D1=8B=20=D0=B4=D0=BB=D1=8F=20=D0=BD=D0=BE=D0=B2=D0=BE=D0=B9=20?= =?utf8?q?=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D0=B8=20C?= =?utf8?q?ONFIGFILE?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- tests/Makefile | 6 ++- tests/test_conffiles.cpp | 94 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 tests/test_conffiles.cpp diff --git a/tests/Makefile b/tests/Makefile index a924540f..56d7d95d 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,4 +1,4 @@ -CXXFLAGS+=-g3 -Wall -W -pedantic -DLINUX -I../include -I../projects/stargazer +CXXFLAGS+=-g3 -Wall -W -pedantic -DLINUX -I../include -I../projects/stargazer -I../stglibs/conffiles.lib LIBS=-lpthread PROG=tests @@ -6,7 +6,9 @@ SOURCES=main.cpp \ test_raw_ip.cpp \ test_admin_conf.cpp \ test_tariff.cpp \ - ../projects/stargazer/tariff.cpp + test_conffiles.cpp \ + ../projects/stargazer/tariff.cpp \ + ../stglibs/conffiles.lib/conffiles.cpp all: $(PROG) diff --git a/tests/test_conffiles.cpp b/tests/test_conffiles.cpp new file mode 100644 index 00000000..897148f5 --- /dev/null +++ b/tests/test_conffiles.cpp @@ -0,0 +1,94 @@ +#include // unlink + +#include +#include + +#include + +#include "conffiles.h" + +namespace tut +{ + struct conffile_data { + }; + + typedef test_group tg; + tg conffile_test_group("CONIGFILE tests group"); + + typedef tg::object testobject; + + template<> + template<> + void testobject::test<1>() + { + set_test_name("Check read/write"); + + { + CONFIGFILE cf("/tmp/test.cf", true); + + ensure_equals("Correct construction", cf.Error(), 0); + + ensure_equals("Correct writing 'a' string", cf.WriteString("a", "a-string"), 0); + ensure_equals("Correct writing 'b' integer (0)", cf.WriteInt("b", 0), 0); + ensure_equals("Correct writing 'e' double (2.718281828)", cf.WriteDouble("e", 2.718281828), 0); + } + + { + CONFIGFILE cf("/tmp/test.cf"); + + ensure_equals("Correct construction (part 2)", cf.Error(), 0); + + std::string svalue; + ensure_equals("Correct reading 'a' param as string", cf.ReadString("a", &svalue, "a-default"), 0); + int ivalue; + ensure_equals("Correct reading 'b' param as integer", cf.ReadInt("b", &ivalue, -1), 0); + double dvalue = 0; + ensure_equals("Correct reading 'e' param as double", cf.ReadDouble("e", &dvalue, 0), 0); + + ensure_equals("Correct 'a' value", svalue, "a-string"); + ensure_equals("Correct 'b' value", ivalue, 0); + ensure("Correct 'e' value", dvalue != 0); + } + + ensure_equals("Correct temporary file unlinking", unlink("/tmp/test.cf"), 0); + } + + template<> + template<> + void testobject::test<2>() + { + set_test_name("Check empty lines and comments"); + + { + ofstream f("/tmp/test.cf"); + + ensure("Correct construction (part 3)", f); + + f << "\n" + << "a=a-string# a string\n" + << " \n" + << "b=0\n" + << "#abc\n" + << "e=2.718281828\n"; + } + + { + CONFIGFILE cf("/tmp/test.cf"); + + ensure_equals("Correct construction (part 4)", cf.Error(), 0); + + std::string svalue; + ensure_equals("Correct reading 'a' param as string", cf.ReadString("a", &svalue, "a-default"), 0); + int ivalue; + ensure_equals("Correct reading 'b' param as integer", cf.ReadInt("b", &ivalue, -1), 0); + double dvalue = 0; + ensure_equals("Correct reading 'e' param as double", cf.ReadDouble("e", &dvalue, 0), 0); + + ensure_equals("Correct 'a' value", svalue, "a-string"); + ensure_equals("Correct 'b' value", ivalue, 0); + ensure("Correct 'e' value", dvalue != 0); + } + + ensure_equals("Correct temporary file unlinking", unlink("/tmp/test.cf"), 0); + } +} -- 2.44.2