From 023f6e88583b44d0b1722af63ae2c5319a509ac6 Mon Sep 17 00:00:00 2001 From: heck Date: Mon, 7 Jun 2021 12:57:37 +0200 Subject: [PATCH] Tests: PityUnit - Add termCol support --- src/PityUnit.hh | 16 +++++++--- src/PityUnit.hxx | 79 ++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 81 insertions(+), 14 deletions(-) diff --git a/src/PityUnit.hh b/src/PityUnit.hh index cc2f5b5..5e7bd33 100644 --- a/src/PityUnit.hh +++ b/src/PityUnit.hh @@ -7,6 +7,7 @@ #include #include #include "../../../src/pEpLog.hh" +#include "../../../src/std_utils.hh" // Yes, the mem mgmt is purely static on purpose (so far) @@ -45,7 +46,7 @@ namespace pEp { std::string processDir() const; // own process dir // Read-Write - void setExecutionMode(ExecutionMode mode); + // void setExecutionMode(ExecutionMode mode); static void setGlobalRootDir(const std::string& dir); static std::string getGlobalRootDir(); @@ -59,6 +60,9 @@ namespace pEp { // logging service void log(const std::string& msg) const; void logRaw(const std::string& msg) const; + void logH1(const std::string& msg) const; + void logH2(const std::string& msg) const; + void logH3(const std::string& msg) const; // internal logging static bool debug_log_enabled; @@ -88,10 +92,12 @@ namespace pEp { // Util std::string _normalizeName(std::string name) const; std::string _status_string(const std::string& msg) const; + Utils::Color colForProcNodeNr(int procNodeNr) const; + Utils::Color termColor() const; // Dirs void _ensureDir(const std::string& path) const; - void _recreateDir(const std::string& path ) const; + void _recreateDir(const std::string& path) const; // Fields const std::string _name; @@ -100,8 +106,10 @@ namespace pEp { const NodeFunc _test_func; ExecutionMode _exec_mode; static std::string _global_root_dir; - std::map _children; // map to guarantee uniqueness of sibling-names + int procNodeNr; + static int procNodesCount; // will be increased in everuy constructor + // internal logging Adapter::pEpLog::pEpLogger& m4gic_logger_n4me = logger_debug; @@ -118,7 +126,7 @@ namespace pEp { #define PTASSERT(condition) \ do { \ if (!(condition)) { \ - throw PityAssertException("AssertError"); \ + throw PityAssertException("AssertError"); \ } \ } while (0) #endif diff --git a/src/PityUnit.hxx b/src/PityUnit.hxx index a9086c3..370579e 100644 --- a/src/PityUnit.hxx +++ b/src/PityUnit.hxx @@ -15,7 +15,7 @@ #include #include -using namespace pEp::Adapter::pEpLog; +//using namespace pEp::Adapter::pEpLog; namespace pEp { namespace PityTest11 { @@ -23,6 +23,8 @@ namespace pEp { std::string PityUnit::_global_root_dir = "./pitytest_data/"; template bool PityUnit::debug_log_enabled = false; + template + int PityUnit::procNodesCount = 0; // CONCSTRUCTORS template @@ -38,6 +40,15 @@ namespace pEp { logger_debug.set_instancename(getNodePath()); if (!_isRootNode()) { parent->_addChildNode(*this); + // Inherit + procNodeNr = _parent->procNodeNr; + //Or update if procNode + if (_isProcessNode()) { + procNodesCount++; + procNodeNr = procNodesCount; + } + } else { + procNodeNr = procNodesCount; } } @@ -125,11 +136,11 @@ namespace pEp { } } - template - void PityUnit::setExecutionMode(ExecutionMode mode) - { - _exec_mode = mode; - } + // template + // void PityUnit::setExecutionMode(ExecutionMode mode) + // { + // _exec_mode = mode; + // } // static template<> @@ -254,14 +265,32 @@ namespace pEp { builder << getNodePathShort(); builder << "] - "; builder << msg; - builder << std::endl; + logRaw(builder.str()); } template void PityUnit::logRaw(const std::string& msg) const { - std::cerr << msg << std::endl; + Adapter::pEpLog::log(msg, termColor()); + } + + template + void PityUnit::logH1(const std::string& msg) const + { + Adapter::pEpLog::logH1(msg, termColor()); + } + + template + void PityUnit::logH2(const std::string& msg) const + { + Adapter::pEpLog::logH2(msg, termColor()); + } + + template + void PityUnit::logH3(const std::string& msg) const + { + Adapter::pEpLog::logH3(msg, termColor()); } @@ -282,11 +311,11 @@ namespace pEp { _test_func(*this); logH3(_status_string("SUCCESS")); } catch (const std::exception& e) { - log("reason: " + std::string(e.what())); + logRaw("reason: " + std::string(e.what())); logH3(_status_string("FAILED")); } } else { - log("No function to execute"); + logRaw("No function to execute"); } } @@ -402,6 +431,36 @@ namespace pEp { return ret; } + + template + Utils::Color PityUnit::colForProcNodeNr(int procNodeNr) const + { + switch (procNodeNr) { + case 0: + return Utils::Color::WHITE; + case 1: + return Utils::Color::CYAN; + case 2: + return Utils::Color::MAGENTA; + case 3: + return Utils::Color::BLUE; + case 4: + return Utils::Color::GREEN; + case 5: + return Utils::Color::YELLOW; + case 6: + return Utils::Color::RED; + default: + return Utils::Color::WHITE; + } + } + + template + Utils::Color PityUnit::termColor() const + { + return colForProcNodeNr(procNodeNr); + } + template void PityUnit::_ensureDir(const std::string& path) const {