logger tests with assertions

This commit is contained in:
LPTK 2013-06-11 16:04:42 +02:00
commit b30a15b746

View file

@ -7,6 +7,9 @@
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <cassert>
// TODO test multiple redirection
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -15,10 +18,10 @@ int main(int ac, char** av)
eoParser parser(ac, av); eoParser parser(ac, av);
if (parser.userNeedsHelp()) if (parser.userNeedsHelp())
{ {
parser.printHelp(std::cout); parser.printHelp(std::cout);
exit(1); exit(1);
} }
make_help(parser); make_help(parser);
make_verbose(parser); make_verbose(parser);
@ -29,18 +32,37 @@ int main(int ac, char** av)
eo::log << "We are writing on the default output stream" << std::endl; eo::log << "We are writing on the default output stream" << std::endl;
std::ofstream ofs("logtest.txt"); {
eo::log.redirect(ofs); std::ofstream ofs("logtest.txt");
eo::log << "In FILE" << std::endl; eo::log.redirect(ofs);
eo::log << "In FILE" << std::endl;
eo::log.redirect("logtest2.txt");
eo::log << "In FILE 2" << std::endl;
}
eo::log.redirect("logtest2.txt"); std::ifstream ifs("logtest.txt");
eo::log << "In FILE 2" << std::endl; //ifs >> str;
std::string line;
assert(std::getline(ifs, line));
assert(line == "In FILE");
//std::cout << (line == "In FILE") << std::endl;
assert(!std::getline(ifs, line));
std::ostringstream oss; std::ostringstream oss;
eo::log.redirect(oss); eo::log.redirect(oss);
eo::log << oss << "In STRINGSTREAM"; //eo::log << oss << "In STRINGSTREAM";
eo::log << "In STRINGSTREAM";
std::cout << "Content of ostringstream: " << oss.str() << std::endl; std::cout << "Content of ostringstream: " << oss.str() << std::endl;
assert(oss.str() == "In STRINGSTREAM");
ifs.close();
ifs.open("logtest2.txt");
assert(std::getline(ifs, line));
assert(line == "In FILE 2");
assert(!std::getline(ifs, line));
//assert(false);
eo::log.redirect(std::cout); eo::log.redirect(std::cout);
eo::log << "on COUT" << std::endl; eo::log << "on COUT" << std::endl;
@ -59,7 +81,7 @@ int main(int ac, char** av)
eo::log << std::endl; eo::log << std::endl;
eo::log << eo::debug << 4 << ')' eo::log << eo::debug << 4 << ')'
<< "4) in debug mode\n"; << "4) in debug mode\n";
return 0; return 0;
} }