Browse Source

Tests: PityUnit - Add termCol support

master
heck 4 years ago
parent
commit
023f6e8858
  1. 16
      src/PityUnit.hh
  2. 79
      src/PityUnit.hxx

16
src/PityUnit.hh

@ -7,6 +7,7 @@
#include <string> #include <string>
#include <map> #include <map>
#include "../../../src/pEpLog.hh" #include "../../../src/pEpLog.hh"
#include "../../../src/std_utils.hh"
// Yes, the mem mgmt is purely static on purpose (so far) // Yes, the mem mgmt is purely static on purpose (so far)
@ -45,7 +46,7 @@ namespace pEp {
std::string processDir() const; // own process dir std::string processDir() const; // own process dir
// Read-Write // Read-Write
void setExecutionMode(ExecutionMode mode); // void setExecutionMode(ExecutionMode mode);
static void setGlobalRootDir(const std::string& dir); static void setGlobalRootDir(const std::string& dir);
static std::string getGlobalRootDir(); static std::string getGlobalRootDir();
@ -59,6 +60,9 @@ namespace pEp {
// logging service // logging service
void log(const std::string& msg) const; void log(const std::string& msg) const;
void logRaw(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 // internal logging
static bool debug_log_enabled; static bool debug_log_enabled;
@ -88,10 +92,12 @@ namespace pEp {
// Util // Util
std::string _normalizeName(std::string name) const; std::string _normalizeName(std::string name) const;
std::string _status_string(const std::string& msg) const; std::string _status_string(const std::string& msg) const;
Utils::Color colForProcNodeNr(int procNodeNr) const;
Utils::Color termColor() const;
// Dirs // Dirs
void _ensureDir(const std::string& path) const; void _ensureDir(const std::string& path) const;
void _recreateDir(const std::string& path ) const; void _recreateDir(const std::string& path) const;
// Fields // Fields
const std::string _name; const std::string _name;
@ -100,8 +106,10 @@ namespace pEp {
const NodeFunc _test_func; const NodeFunc _test_func;
ExecutionMode _exec_mode; ExecutionMode _exec_mode;
static std::string _global_root_dir; static std::string _global_root_dir;
std::map<const std::string, PityUnit&> _children; // map to guarantee uniqueness of sibling-names std::map<const std::string, PityUnit&> _children; // map to guarantee uniqueness of sibling-names
int procNodeNr;
static int procNodesCount; // will be increased in everuy constructor
// internal logging // internal logging
Adapter::pEpLog::pEpLogger& m4gic_logger_n4me = logger_debug; Adapter::pEpLog::pEpLogger& m4gic_logger_n4me = logger_debug;
@ -118,7 +126,7 @@ namespace pEp {
#define PTASSERT(condition) \ #define PTASSERT(condition) \
do { \ do { \
if (!(condition)) { \ if (!(condition)) { \
throw PityAssertException("AssertError"); \ throw PityAssertException("AssertError"); \
} \ } \
} while (0) } while (0)
#endif #endif

79
src/PityUnit.hxx

@ -15,7 +15,7 @@
#include <sstream> #include <sstream>
#include <exception> #include <exception>
using namespace pEp::Adapter::pEpLog; //using namespace pEp::Adapter::pEpLog;
namespace pEp { namespace pEp {
namespace PityTest11 { namespace PityTest11 {
@ -23,6 +23,8 @@ namespace pEp {
std::string PityUnit<T>::_global_root_dir = "./pitytest_data/"; std::string PityUnit<T>::_global_root_dir = "./pitytest_data/";
template<class T> template<class T>
bool PityUnit<T>::debug_log_enabled = false; bool PityUnit<T>::debug_log_enabled = false;
template<class T>
int PityUnit<T>::procNodesCount = 0;
// CONCSTRUCTORS // CONCSTRUCTORS
template<class T> template<class T>
@ -38,6 +40,15 @@ namespace pEp {
logger_debug.set_instancename(getNodePath()); logger_debug.set_instancename(getNodePath());
if (!_isRootNode()) { if (!_isRootNode()) {
parent->_addChildNode(*this); 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<class T> // template<class T>
void PityUnit<T>::setExecutionMode(ExecutionMode mode) // void PityUnit<T>::setExecutionMode(ExecutionMode mode)
{ // {
_exec_mode = mode; // _exec_mode = mode;
} // }
// static // static
template<> template<>
@ -254,14 +265,32 @@ namespace pEp {
builder << getNodePathShort(); builder << getNodePathShort();
builder << "] - "; builder << "] - ";
builder << msg; builder << msg;
builder << std::endl;
logRaw(builder.str()); logRaw(builder.str());
} }
template<class T> template<class T>
void PityUnit<T>::logRaw(const std::string& msg) const void PityUnit<T>::logRaw(const std::string& msg) const
{ {
std::cerr << msg << std::endl; Adapter::pEpLog::log(msg, termColor());
}
template<class T>
void PityUnit<T>::logH1(const std::string& msg) const
{
Adapter::pEpLog::logH1(msg, termColor());
}
template<class T>
void PityUnit<T>::logH2(const std::string& msg) const
{
Adapter::pEpLog::logH2(msg, termColor());
}
template<class T>
void PityUnit<T>::logH3(const std::string& msg) const
{
Adapter::pEpLog::logH3(msg, termColor());
} }
@ -282,11 +311,11 @@ namespace pEp {
_test_func(*this); _test_func(*this);
logH3(_status_string("SUCCESS")); logH3(_status_string("SUCCESS"));
} catch (const std::exception& e) { } catch (const std::exception& e) {
log("reason: " + std::string(e.what())); logRaw("reason: " + std::string(e.what()));
logH3(_status_string("FAILED")); logH3(_status_string("FAILED"));
} }
} else { } else {
log("No function to execute"); logRaw("No function to execute");
} }
} }
@ -402,6 +431,36 @@ namespace pEp {
return ret; return ret;
} }
template<class T>
Utils::Color PityUnit<T>::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<class T>
Utils::Color PityUnit<T>::termColor() const
{
return colForProcNodeNr(procNodeNr);
}
template<class T> template<class T>
void PityUnit<T>::_ensureDir(const std::string& path) const void PityUnit<T>::_ensureDir(const std::string& path) const
{ {

Loading…
Cancel
Save