nrtb-core team mailing list archive
-
nrtb-core team
-
Mailing list archive
-
Message #00062
[Branch ~fpstovall/nrtb/cpp_common] Rev 24: Updated the Makefile and unit test to automatically run and test confreader on a library build. T...
------------------------------------------------------------
revno: 24
committer: fpstovall@xxxxxxxxx
branch nick: dev
timestamp: Fri 2010-12-31 09:37:14 -0500
message:
Updated the Makefile and unit test to automatically run and test confreader on a library build. The build will now fail if any unit test does not suceed.
modified:
common/confreader/Makefile
common/confreader/conftest.cpp
common/confreader/test.config
--
lp:~fpstovall/nrtb/cpp_common
https://code.launchpad.net/~fpstovall/nrtb/cpp_common
Your team NRTB Core is subscribed to branch lp:~fpstovall/nrtb/cpp_common.
To unsubscribe from this branch go to https://code.launchpad.net/~fpstovall/nrtb/cpp_common/+edit-subscription
=== modified file 'common/confreader/Makefile'
--- common/confreader/Makefile 2010-12-29 14:40:32 +0000
+++ common/confreader/Makefile 2010-12-31 14:37:14 +0000
@@ -17,6 +17,9 @@
#***********************************************
lib: conftest
+ @rm -f conf_test.log
+ @./conftest test=1 test2-2 test2=71.837486 test3="jack danials" --doit
+ @grep "Run Complete" conf_test.log
@cp -v confreader.h ../include
@cp -v confreader.o ../obj
@echo build complete
=== modified file 'common/confreader/conftest.cpp'
--- common/confreader/conftest.cpp 2010-12-27 04:09:19 +0000
+++ common/confreader/conftest.cpp 2010-12-31 14:37:14 +0000
@@ -30,12 +30,29 @@
int main(int argc, char* argv[])
{
- setup_global_logging("conf_test.log");
- Poco::Logger & log = Poco::Logger::get("log_test");
- log.information("=-=-=-=-=-= conftest Init =-=-=-=-=-=-=");
- conf_reader & config = conf_reader::get_instance();
+ bool set_if_failed = false;
+ setup_global_logging("conf_test.log");
+ Poco::Logger & log = Poco::Logger::get("conftest");
+ log.information("=-=-=-=-=-= conftest Init =-=-=-=-=-=-=");
+ conf_reader & config = conf_reader::get_instance();
+ try
+ {
log.information("Starting read");
config.read(argc,argv,"test.config");
+ }
+ catch (...)
+ {
+ set_if_failed = true;
+ cerr << "Failed reading the configuration." << endl;
+ };
+ if (config.size() != 12)
+ {
+ set_if_failed = true;
+ cerr << "Did not find 12 parameters." << endl;
+ };
+ // iterator test
+ try
+ {
conf_reader::iterator c = config.begin();
conf_reader::iterator e = config.end();
while (c != e)
@@ -44,32 +61,69 @@
<< "\"" << endl;
c++;
};
- // template test.
- int test = config.get<int>("test",-1);
- int test2 = config.get<int>("test2",-1);
- string test3 = config.get<string>("test3","not specified");
- cout << "(int) test = " << test
- << "\n(int) test2 = " << test2
- << "\n(string) test3 = " << test3 << endl;
- double test4 = config.get<double>("test",-1);
- double test5 = config.get<double>("test2",-1);
- cout << "(double) test = " << test4
- << "\n(double) test2 = " << test5
- << endl;
- cout << "?var \"--doit\" exists? "
- << (config.exists("--doit") ? "Yes" : "No")
- << endl;
- vector<int> intlist = config.getall<int>("test");
- cout << "valid int \"test\" values:" << endl;
- for (unsigned int i=0; i < intlist.size(); i++)
- {
- cout << "\t" << i << ": " << intlist[i] << endl;
- };
- strlist strings = config.getall<string>("test");
- cout << "valid string \"test\" values:" << endl;
- for (unsigned int i=0; i < strings.size(); i++)
- {
- cout << "\t" << i << ": " << strings[i] << endl;
- };
- log.information("Run Complete");
+ }
+ catch (...)
+ {
+ set_if_failed = true;
+ cerr << "Iterator test failed." << endl;
+ };
+ // template test.
+ int test = config.get<int>("test",-1);
+ int test2 = config.get<int>("test2",-1);
+ string test3 = config.get<string>("test3","not specified");
+ double test4 = config.get<double>("test",-1);
+ double test5 = config.get<double>("test2",-1);
+ cout << "(int) test = " << test
+ << "\n(int) test2 = " << test2
+ << "\n(string) test3 = \"" << test3 << "\""
+ << "\n(double) test = " << test4
+ << "\n(double) test2 = " << test5
+ << endl;
+ if (
+ (test != 1) or (test2 != 0)
+ or (test3 != "jack danials")
+ or (test4 != 1.0) or (test5 != 71.837486)
+ )
+ {
+ set_if_failed = true;
+ cerr << "** Template test failed." << endl;
+ };
+ // exists test.
+ cout << "?var \"--doit\" exists? "
+ << (config.exists("--doit") ? "Yes" : "No")
+ << endl;
+ if (!config.exists("--doit"))
+ {
+ set_if_failed = true;
+ cerr << "exists() test failed." << endl;
+ };
+ vector<int> intlist = config.getall<int>("test");
+ cout << "valid int \"test\" values:" << endl;
+ for (unsigned int i=0; i < intlist.size(); i++)
+ {
+ cout << "\t" << i << ": " << intlist[i] << endl;
+ };
+ if (intlist.size() != 2)
+ {
+ set_if_failed = true;
+ cerr << "getall<int>() did not find 2 parameters." << endl;
+ };
+ strlist strings = config.getall<string>("test");
+ cout << "valid string \"test\" values:" << endl;
+ for (unsigned int i=0; i < strings.size(); i++)
+ {
+ cout << "\t" << i << ": " << strings[i] << endl;
+ };
+ if (strings.size() != 3)
+ {
+ set_if_failed = true;
+ cerr << "getall<string>() did not find 3 parameters." << endl;
+ };
+ if (set_if_failed)
+ {
+ cerr << "** ntrb::conf_reader UNIT TEST FAILED. **" << endl;
+ log.fatal("UNIT TEST FAILED");
+ };
+ log.information("Run Complete");
+ return set_if_failed;
};
=== modified file 'common/confreader/test.config'
--- common/confreader/test.config 2010-12-25 22:44:22 +0000
+++ common/confreader/test.config 2010-12-31 14:37:14 +0000
@@ -1,9 +1,9 @@
###### config reader test file ######
# use this command line to properly test this:
#
-# ./conftest test=1 test2=71.837486 test2=2 test3="jack danials" --doit
+# ./conftest test=1 test2=2 test2=71.837486 test3="jack danials" --doit
#
-# You should get a warning about problems reading dummyfile, and 10
+# You should get a warning about problems reading dummyfile, and 12
# variables listed. "test" should be 2 overridden by the command line.
# You can test the ability to override the config file name with the
# command: