Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:17:43

0001 
0002 #include <catch.hpp>
0003 #include <iostream>
0004 #include <JANA/JLogger.h>
0005 
0006 
0007 TEST_CASE("JLogMessage_DestructorOrdering") {
0008 
0009     {
0010         JLogMessage m("JANA: ");
0011         // This will destruct immediately, but only because it's in its own scope
0012         m << "1. This is a test";
0013         REQUIRE(m.str() == "1. This is a test");
0014 
0015         m << std::endl << "   which continues on the second line";
0016         REQUIRE(m.str() == "1. This is a test\n   which continues on the second line");
0017     }
0018 
0019     std::cout << std::endl;
0020 
0021     JLogger logger {JLogger::Level::WARN, &std::cout, "jana"};
0022     logger.show_group = true;
0023     if (logger.level >= JLogger::Level::WARN) {
0024         JLogMessage msg(logger, JLogger::Level::INFO);
0025         msg << "2. This will print at level INFO and include" << std::endl;
0026         msg << "   multiple lines and the group name 'jana'" << std::endl;
0027         msg << "   It will destruct immediately because it is inside an if-block";
0028     }
0029 
0030     std::cout << std::endl;
0031 
0032     if (logger.level >= JLogger::Level::WARN) JLogMessage("jaanaa >> ") << "3. This destructs immediately even without enclosing braces";
0033 
0034     std::cout << std::endl;
0035 
0036     JLogMessage("Silly: ") << "4. This message will destruct immediately because it is an rvalue";
0037 
0038     std::cout << std::endl;
0039 
0040     std::cout << "6. This should be the last thing printed, assuming our destructors behave" << std::endl;
0041 
0042 }
0043 
0044 TEST_CASE("JLogMessage_Newlines") {
0045 
0046     JLogMessage("jaanaa> ") << "1. This message has a trailing newline in the code but shouldn't in the output" << std::endl;
0047     JLogMessage("jaanaa> ") << "2. This message has no trailing newline in either the code or the output";
0048 
0049     std::cout << "--------" << std::endl;
0050     std::cout << "The following line should just be log metadata with no log message" << std::endl;
0051     JLogMessage("jaanaa> ") << std::endl;
0052     std::cout << "--------" << std::endl;
0053 
0054     JLogMessage("jaanaa> ") << "There should be a line of just log metadata below this one" << std::endl << std::endl;
0055     JLogMessage("jaanaa> ") << "This should be the last line prefixed with 'jaanaa'.";
0056 
0057     JLogger logger {JLogger::Level::DEBUG, &std::cout, "jana"};
0058 
0059     LOG_INFO(logger) << "This message has a trailing newline in the code but shouldn't in the output" << std::endl;
0060     LOG_INFO(logger) << "This message has a trailing newline in the code but shouldn't in the output" << LOG_END;
0061 
0062     LOG_INFO(logger) << "This message has a trailing newline containing log metadata" << std::endl << std::endl;
0063     LOG_INFO(logger) << "This message has a trailing newline containing log metadata" << LOG_END << LOG_END;
0064     LOG_INFO(logger) << "This message has a trailing newline containing log metadata " << std::endl << LOG_END;
0065 }
0066 
0067 
0068 TEST_CASE("JLogMessage_StreamIntoLogger") {
0069     JLogger logger {JLogger::Level::ERROR, &std::cout, "jana"};
0070     logger.ShowGroup(true);
0071     logger << "This is a test. x = " << 22 << std::endl;
0072     logger << "This should be the next line" << std::endl << "And another" << std::endl;
0073     logger << std::endl << "There should be a blank line above this";
0074 }
0075 
0076 
0077