diff --git a/src/pEpLog.hh b/src/pEpLog.hh index 33eb6e6..ecff7ed 100644 --- a/src/pEpLog.hh +++ b/src/pEpLog.hh @@ -4,9 +4,19 @@ #ifndef LIBPEPADAPTER_PEPLOG_HH #define LIBPEPADAPTER_PEPLOG_HH +// getpid +// Linux - unistd.h +// macOS - unistd.h +// Android - unistd.h +// Win - process.h +#ifdef WIN32 + #include +#else + #include +#endif + #include #include -#include #include "std_utils.hh" // pEpLog @@ -137,7 +147,7 @@ namespace pEp { void log(const std::string& msg, Utils::Color col = Utils::Color::WHITE); void logH1(const std::string& msg, Utils::Color col = Utils::Color::WHITE); void logH2(const std::string& msg, Utils::Color col = Utils::Color::WHITE); - void logH3(const std::string&msg, Utils::Color col = Utils::Color::WHITE); + void logH3(const std::string& msg, Utils::Color col = Utils::Color::WHITE); std::string decorate_three_lines(const std::string& msg, char decoration = '-'); std::string decorate_centered(const std::string& msg, char decoration = '-'); } // namespace pEpLog @@ -200,7 +210,7 @@ namespace pEp { // Print a logging message in the format "thread - classname[instancename] - " void log(const std::string& msg, Utils::Color col = Utils::Color::WHITE) const; // Prints just "" - void logRaw(const std::string& msg, Utils::Color col = Utils::Color::WHITE) const; + void logRaw(const std::string& msg, Utils::Color col = Utils::Color::WHITE) const; void set_enabled(const bool& enabled); bool get_enabled() const; std::string get_classname() const; diff --git a/src/pEpSQLite.cc b/src/pEpSQLite.cc index dddc13c..219cfef 100644 --- a/src/pEpSQLite.cc +++ b/src/pEpSQLite.cc @@ -4,6 +4,7 @@ #include #include #include +#include using namespace std; diff --git a/src/std_utils.cc b/src/std_utils.cc index c357a5b..fd57ebc 100644 --- a/src/std_utils.cc +++ b/src/std_utils.cc @@ -7,11 +7,14 @@ #include #include #include -#include -#include #include #include #include +#include +#ifndef WIN32 + #include + #include +#endif using namespace std; using namespace pEp; @@ -42,18 +45,6 @@ namespace pEp { return src; } - // void print_exception(const exception &e, int level) - // { - // cerr << string(level, ' ') << "exception: " << e.what() << endl; - // try { - // rethrow_if_nested(e); - // } catch (const exception &e) { - // print_exception(e, level + 1); - // } catch (...) { - // } - // } - - // File utils bool path_exists(const string &filename) { @@ -61,6 +52,16 @@ namespace pEp { return (bool)ifile; } + void path_delete(const string &filename) + { + int status = remove(filename.c_str()); + if (status) { + runtime_error e{ string("path_delete(\"" + filename + "\") - " + strerror(errno)) }; + throw(e); + } + } + +#ifndef WIN32 bool path_is_dir(const string &path) { bool ret = false; @@ -75,15 +76,6 @@ namespace pEp { return ret; } - void path_delete(const string &filename) - { - int status = remove(filename.c_str()); - if (status) { - runtime_error e{ string("path_delete(\"" + filename + "\") - " + strerror(errno)) }; - throw(e); - } - } - void path_delete_all(const string &path) { try { @@ -106,6 +98,7 @@ namespace pEp { throw_with_nested(e); } } +#endif ofstream file_create(const string &filename) { @@ -132,6 +125,7 @@ namespace pEp { } } +#ifndef WIN32 void dir_create(const string &dirname, const mode_t mode) { if (mkdir(dirname.c_str(), mode) != 0) { @@ -140,7 +134,6 @@ namespace pEp { } } - void dir_ensure(const std::string &path) { if (!Utils::path_exists(path)) { @@ -217,6 +210,7 @@ namespace pEp { ret.end()); return ret; } +#endif // Attention, it pads left... string padTo(const string &str, const size_t num, const char paddingChar) @@ -237,6 +231,8 @@ namespace pEp { return ret; } + // prints the beginning and the end of the string and clips out + // content in the middle replaced by "... tldr ..." std::string tldr(const std::string &str, const size_t len) { std::string decoration = "..."; diff --git a/src/std_utils.hh b/src/std_utils.hh index 654b365..4c15ef4 100644 --- a/src/std_utils.hh +++ b/src/std_utils.hh @@ -26,11 +26,15 @@ namespace pEp { // File utils // ---------- - // path (file&dir) + // path (file & dir) bool path_exists(const std::string &filename); - bool path_is_dir(const std::string &path); void path_delete(const std::string &filename); + bool path_is_dir(const std::string &path); + +#ifndef WIN32 void path_delete_all(const std::string &path); +#endif + void path_ensure_not_existing(const std::string &path); // file @@ -38,9 +42,10 @@ namespace pEp { std::string file_read(const std::string &filename); // dir +#ifndef WIN32 void dir_create(const std::string &dirname, const mode_t mode = 0775); - void dir_ensure(const std::string& path); - void dir_recreate(const std::string& path); + void dir_ensure(const std::string &path); + void dir_recreate(const std::string &path); std::vector dir_list_all( const std::string &path, @@ -51,6 +56,7 @@ namespace pEp { const bool incl_dot_and_dotdot = false); std::vector dir_list_files(const std::string &dirname); +#endif //String formatting std::string padTo(const std::string &str, const size_t num, const char paddingChar); @@ -70,7 +76,7 @@ namespace pEp { WHITE, }; - std::string to_termcol(const Color& col); + std::string to_termcol(const Color &col); // Time diff --git a/test/Makefile b/test/Makefile index 2368717..7fbcb4c 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,7 +1,7 @@ include ../Makefile.conf LDFLAGS:=-L../src $(LDFLAGS) -L./pitytest11/src -LDLIBS=-lstdc++ -lpEpEngine -lpEpAdapter -lPityTest +LDLIBS=-lstdc++ -lpEpEngine -lpEpAdapter -lPityTest -lpthread -ldl CXXFLAGS:=-I../src -DENGINE_TEST=$(ENGINE_TEST) $(CXXFLAGS) # Test @@ -25,7 +25,7 @@ OBJ_FRAMEWORK=$(subst .cc,.o,$(SRC_FRAMEWORK)) .PHONY: all clean rmtestdata pitytest pitytest-clean .DEFAULT_GOAL := all -all: $(BIN_TEST) +all: pitytest $(BIN_TEST) $(BIN_TEST): $(OBJ_FRAMEWORK) diff --git a/test/framework/framework.cc b/test/framework/framework.cc index 322b102..0dfd407 100644 --- a/test/framework/framework.cc +++ b/test/framework/framework.cc @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include diff --git a/test/framework/utils.hh b/test/framework/utils.hh index 3accc37..7685a2e 100644 --- a/test/framework/utils.hh +++ b/test/framework/utils.hh @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/test/pitytest11/src/PityUnit.hh b/test/pitytest11/src/PityUnit.hh index 50d880d..7877a7b 100644 --- a/test/pitytest11/src/PityUnit.hh +++ b/test/pitytest11/src/PityUnit.hh @@ -8,11 +8,11 @@ #include "../../../src/std_utils.hh" #include "fs_mutex.hh" #include "PityTransport.hh" -//#include "PityPerspective.hh" #include #include #include #include +#include // Yes, the mem mgmt is purely static on purpose (so far) diff --git a/test/pitytest11/src/PityUnit.hxx b/test/pitytest11/src/PityUnit.hxx index 4d9dfd3..2c51375 100644 --- a/test/pitytest11/src/PityUnit.hxx +++ b/test/pitytest11/src/PityUnit.hxx @@ -15,6 +15,7 @@ #include #include #include +#include namespace pEp { diff --git a/test/test_adapter.cc b/test/test_adapter.cc index abde388..dacc996 100644 --- a/test/test_adapter.cc +++ b/test/test_adapter.cc @@ -5,7 +5,6 @@ #include "framework/utils.hh" #include #include -#include #include #include diff --git a/test/test_adapter_cxx.cc b/test/test_adapter_cxx.cc index bf620c3..6cbed24 100644 --- a/test/test_adapter_cxx.cc +++ b/test/test_adapter_cxx.cc @@ -5,7 +5,6 @@ #include "framework/utils.hh" #include #include -#include #include #include diff --git a/test/test_ensure_passphrase.cc b/test/test_ensure_passphrase.cc index 4f26fe8..f9d2fc8 100644 --- a/test/test_ensure_passphrase.cc +++ b/test/test_ensure_passphrase.cc @@ -3,21 +3,11 @@ #include "framework/framework.hh" -//#include -//#include -//#include -//#include -#include -//#include -//#include -//#include - -//#include +#include #include #include #include "../src/passphrase_cache.hh" -//#include "../src/status_to_string.hh" #include "../src/Adapter.hh" using namespace pEp; diff --git a/test/test_leave_device_group.cc b/test/test_leave_device_group.cc index 6cfcf71..b5ca810 100644 --- a/test/test_leave_device_group.cc +++ b/test/test_leave_device_group.cc @@ -5,7 +5,6 @@ #include #include -#include #include diff --git a/test/test_listmanager_dummy.cc b/test/test_listmanager_dummy.cc index 6985166..b229c2a 100644 --- a/test/test_listmanager_dummy.cc +++ b/test/test_listmanager_dummy.cc @@ -1,10 +1,9 @@ #include "../src/listmanager_dummy.hh" #include "../src/utils.hh" -#include "../src/std_utils.hh" #include "framework/utils.hh" -#include #include #include +#include using namespace std; diff --git a/test/test_message_cache.cc b/test/test_message_cache.cc index fc240f9..a344f24 100644 --- a/test/test_message_cache.cc +++ b/test/test_message_cache.cc @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include "../src/message_cache.hh" #include "../src/Adapter.hh" diff --git a/test/test_pEpSQLite.cc b/test/test_pEpSQLite.cc index a68ccde..88a5e66 100644 --- a/test/test_pEpSQLite.cc +++ b/test/test_pEpSQLite.cc @@ -5,6 +5,7 @@ #include "framework/utils.hh" #include +#include using namespace std; using namespace pEp; diff --git a/test/test_passphrase_cache.cc b/test/test_passphrase_cache.cc index 016ea84..305df36 100644 --- a/test/test_passphrase_cache.cc +++ b/test/test_passphrase_cache.cc @@ -4,7 +4,6 @@ #include "framework/framework.hh" #include -#include #include #include diff --git a/test/test_semaphore.cc b/test/test_semaphore.cc index 1a5eafb..083c544 100644 --- a/test/test_semaphore.cc +++ b/test/test_semaphore.cc @@ -3,8 +3,7 @@ #include #include -#include - +#include "../src/std_utils.hh" #include "../src/Semaphore.hh" using namespace std; @@ -24,7 +23,7 @@ int main() cout << "1: keep going\n"; }); - sleep(1); + Utils::sleep_millis(1000); thread thread2([&]() { cout << "2: setting go\n";