Browse Source

Tests: PityTest11 - dirs ftw nr.2

LIB-11
heck 4 years ago
parent
commit
6fe42706e6
  1. 7
      test/pitytest11/src/PityUnit.hh
  2. 54
      test/pitytest11/src/PityUnit.hxx

7
test/pitytest11/src/PityUnit.hh

@ -58,6 +58,7 @@ namespace pEp {
// logging service
void log(const std::string& msg) const;
void logRaw(const std::string& msg) const;
// internal logging
static bool debug_log_enabled;
@ -88,14 +89,10 @@ namespace pEp {
std::string _normalizeName(std::string name) const;
std::string _status_string(const std::string& msg) const;
// TODO
// Dirs
void _ensureDir(const std::string& path) const;
void _recreateDir(const std::string& path ) const;
void _data_dir_delete();
void _data_dir_create();
void _data_dir_recreate();
// Fields
const std::string _name;
const PityUnit* _parent; //nullptr if RootUnit

54
test/pitytest11/src/PityUnit.hxx

@ -148,6 +148,14 @@ namespace pEp {
template<class T>
void PityUnit<T>::_init() const
{
logH1("PityTest Starting...");
logRaw("RootNode: " + getNodePathShort());
logRaw("GlobalRootDir: " + getGlobalRootDir());
logRaw("\nTestTree");
logRaw("--------");
logRaw(to_string());
logH3("INIT");
_ensureDir(getGlobalRootDir());
_recreateDir(processDir());
if (!_children.empty()) {
@ -155,17 +163,16 @@ namespace pEp {
_recreateDir(child.second.processDir());
}
}
logH3("INIT DONE");
}
template<class T>
void PityUnit<T>::run() const
{
pEpLogClass("called");
_init();
// caller is never nullptr if called by another PityUnit
if (_isRootNode()) {
logH1("Starting PityUnit from node: " + getNodePathShort());
std::cout << to_string() << std::endl;
_init();
}
// Execute in fork and wait here until process ends
@ -237,7 +244,6 @@ namespace pEp {
}
}
//Well, ok, lets just add some little convenience logging service in here, too
template<class T>
void PityUnit<T>::log(const std::string& msg) const
{
@ -249,9 +255,16 @@ namespace pEp {
builder << "] - ";
builder << msg;
builder << std::endl;
std::cout << builder.str();
logRaw(builder.str());
}
template<class T>
void PityUnit<T>::logRaw(const std::string& msg) const
{
std::cerr << msg << std::endl;
}
// PRIVATE ---------------------------------------------------------------------------------
template<class T>
@ -393,7 +406,7 @@ namespace pEp {
void PityUnit<T>::_ensureDir(const std::string& path) const
{
if (!Utils::path_exists(path)) {
log("creating dir:" + path);
logRaw("creating dir:" + path);
Utils::dir_create(path);
}
}
@ -403,40 +416,17 @@ namespace pEp {
{
if (Utils::path_exists(path)) {
try {
log("deleting dir:" + path);
logRaw("deleting dir:" + path);
Utils::path_delete_all(path);
} catch (const std::exception& e) {
log("PityUnit: - could not delete data dir: " + getGlobalRootDir());
logRaw("PityUnit: - could not delete data dir: " + getGlobalRootDir());
}
}
log("creating dir:" + path);
logRaw("creating dir:" + path);
Utils::dir_create(path);
}
template<class T>
void PityUnit<T>::_data_dir_create()
{
// Utils::dir_create(dataDir());
log("creating dir:" + getGlobalRootDir());
}
template<class T>
void PityUnit<T>::_data_dir_delete()
{
try {
// Utils::path_delete_all(getGlobalRootDir());
} catch (const std::exception& e) {
log("DistTest: - could not delete data dir: " + getGlobalRootDir());
}
}
template<class T>
void PityUnit<T>::_data_dir_recreate()
{
_data_dir_delete();
_data_dir_create();
};
} // namespace PityTest11
} // namespace pEp

Loading…
Cancel
Save