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
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -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"); std::ofstream ofs("logtest.txt");
eo::log.redirect(ofs); eo::log.redirect(ofs);
eo::log << "In FILE" << std::endl; eo::log << "In FILE" << std::endl;
eo::log.redirect("logtest2.txt"); eo::log.redirect("logtest2.txt");
eo::log << "In FILE 2" << std::endl; 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; 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;