logger tests with assertions
This commit is contained in:
parent
de9af0ba21
commit
b30a15b746
1 changed files with 34 additions and 12 deletions
|
|
@ -7,6 +7,9 @@
|
|||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
// TODO test multiple redirection
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
|
@ -15,10 +18,10 @@ int main(int ac, char** av)
|
|||
eoParser parser(ac, av);
|
||||
|
||||
if (parser.userNeedsHelp())
|
||||
{
|
||||
parser.printHelp(std::cout);
|
||||
exit(1);
|
||||
}
|
||||
{
|
||||
parser.printHelp(std::cout);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
make_help(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;
|
||||
|
||||
std::ofstream ofs("logtest.txt");
|
||||
eo::log.redirect(ofs);
|
||||
eo::log << "In FILE" << std::endl;
|
||||
|
||||
eo::log.redirect("logtest2.txt");
|
||||
eo::log << "In FILE 2" << std::endl;
|
||||
{
|
||||
std::ofstream ofs("logtest.txt");
|
||||
eo::log.redirect(ofs);
|
||||
eo::log << "In FILE" << std::endl;
|
||||
eo::log.redirect("logtest2.txt");
|
||||
eo::log << "In FILE 2" << std::endl;
|
||||
}
|
||||
|
||||
std::ifstream ifs("logtest.txt");
|
||||
//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;
|
||||
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;
|
||||
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 << "on COUT" << std::endl;
|
||||
|
|
@ -59,7 +81,7 @@ int main(int ac, char** av)
|
|||
eo::log << std::endl;
|
||||
|
||||
eo::log << eo::debug << 4 << ')'
|
||||
<< "4) in debug mode\n";
|
||||
<< "4) in debug mode\n";
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue