Browse Source

Includes for linux build.

Some windows compat ensured
LIB-11
heck 4 years ago
parent
commit
f95efdb92d
  1. 12
      src/pEpLog.hh
  2. 1
      src/pEpSQLite.cc
  3. 44
      src/std_utils.cc
  4. 8
      src/std_utils.hh
  5. 4
      test/Makefile
  6. 1
      test/framework/framework.cc
  7. 2
      test/framework/utils.hh
  8. 2
      test/pitytest11/src/PityUnit.hh
  9. 1
      test/pitytest11/src/PityUnit.hxx
  10. 1
      test/test_adapter.cc
  11. 1
      test/test_adapter_cxx.cc
  12. 12
      test/test_ensure_passphrase.cc
  13. 1
      test/test_leave_device_group.cc
  14. 3
      test/test_listmanager_dummy.cc
  15. 2
      test/test_message_cache.cc
  16. 1
      test/test_pEpSQLite.cc
  17. 1
      test/test_passphrase_cache.cc
  18. 5
      test/test_semaphore.cc

12
src/pEpLog.hh

@ -4,9 +4,19 @@
#ifndef LIBPEPADAPTER_PEPLOG_HH #ifndef LIBPEPADAPTER_PEPLOG_HH
#define LIBPEPADAPTER_PEPLOG_HH #define LIBPEPADAPTER_PEPLOG_HH
// getpid
// Linux - unistd.h
// macOS - unistd.h
// Android - unistd.h
// Win - process.h
#ifdef WIN32
#include <process.h>
#else
#include <unistd.h>
#endif
#include <sstream> #include <sstream>
#include <thread> #include <thread>
#include <unistd.h>
#include "std_utils.hh" #include "std_utils.hh"
// pEpLog // pEpLog

1
src/pEpSQLite.cc

@ -4,6 +4,7 @@
#include <cstdio> #include <cstdio>
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
#include <cstring>
using namespace std; using namespace std;

44
src/std_utils.cc

@ -7,11 +7,14 @@
#include <cstdio> #include <cstdio>
#include <cerrno> #include <cerrno>
#include <cmath> #include <cmath>
#include <dirent.h>
#include <sys/stat.h>
#include <algorithm> #include <algorithm>
#include <thread> #include <thread>
#include <random> #include <random>
#include <cstring>
#ifndef WIN32
#include <dirent.h>
#include <sys/stat.h>
#endif
using namespace std; using namespace std;
using namespace pEp; using namespace pEp;
@ -42,18 +45,6 @@ namespace pEp {
return src; 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 // File utils
bool path_exists(const string &filename) bool path_exists(const string &filename)
{ {
@ -61,6 +52,16 @@ namespace pEp {
return (bool)ifile; 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 path_is_dir(const string &path)
{ {
bool ret = false; bool ret = false;
@ -75,15 +76,6 @@ namespace pEp {
return ret; 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) void path_delete_all(const string &path)
{ {
try { try {
@ -106,6 +98,7 @@ namespace pEp {
throw_with_nested(e); throw_with_nested(e);
} }
} }
#endif
ofstream file_create(const string &filename) ofstream file_create(const string &filename)
{ {
@ -132,6 +125,7 @@ namespace pEp {
} }
} }
#ifndef WIN32
void dir_create(const string &dirname, const mode_t mode) void dir_create(const string &dirname, const mode_t mode)
{ {
if (mkdir(dirname.c_str(), mode) != 0) { if (mkdir(dirname.c_str(), mode) != 0) {
@ -140,7 +134,6 @@ namespace pEp {
} }
} }
void dir_ensure(const std::string &path) void dir_ensure(const std::string &path)
{ {
if (!Utils::path_exists(path)) { if (!Utils::path_exists(path)) {
@ -217,6 +210,7 @@ namespace pEp {
ret.end()); ret.end());
return ret; return ret;
} }
#endif
// Attention, it pads left... // Attention, it pads left...
string padTo(const string &str, const size_t num, const char paddingChar) string padTo(const string &str, const size_t num, const char paddingChar)
@ -237,6 +231,8 @@ namespace pEp {
return ret; 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 tldr(const std::string &str, const size_t len)
{ {
std::string decoration = "..."; std::string decoration = "...";

8
src/std_utils.hh

@ -28,9 +28,13 @@ namespace pEp {
// ---------- // ----------
// path (file & dir) // path (file & dir)
bool path_exists(const std::string &filename); bool path_exists(const std::string &filename);
bool path_is_dir(const std::string &path);
void path_delete(const std::string &filename); 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); void path_delete_all(const std::string &path);
#endif
void path_ensure_not_existing(const std::string &path); void path_ensure_not_existing(const std::string &path);
// file // file
@ -38,6 +42,7 @@ namespace pEp {
std::string file_read(const std::string &filename); std::string file_read(const std::string &filename);
// dir // dir
#ifndef WIN32
void dir_create(const std::string &dirname, const mode_t mode = 0775); void dir_create(const std::string &dirname, const mode_t mode = 0775);
void dir_ensure(const std::string &path); void dir_ensure(const std::string &path);
void dir_recreate(const std::string &path); void dir_recreate(const std::string &path);
@ -51,6 +56,7 @@ namespace pEp {
const bool incl_dot_and_dotdot = false); const bool incl_dot_and_dotdot = false);
std::vector<std::string> dir_list_files(const std::string &dirname); std::vector<std::string> dir_list_files(const std::string &dirname);
#endif
//String formatting //String formatting
std::string padTo(const std::string &str, const size_t num, const char paddingChar); std::string padTo(const std::string &str, const size_t num, const char paddingChar);

4
test/Makefile

@ -1,7 +1,7 @@
include ../Makefile.conf include ../Makefile.conf
LDFLAGS:=-L../src $(LDFLAGS) -L./pitytest11/src 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) CXXFLAGS:=-I../src -DENGINE_TEST=$(ENGINE_TEST) $(CXXFLAGS)
# Test # Test
@ -25,7 +25,7 @@ OBJ_FRAMEWORK=$(subst .cc,.o,$(SRC_FRAMEWORK))
.PHONY: all clean rmtestdata pitytest pitytest-clean .PHONY: all clean rmtestdata pitytest pitytest-clean
.DEFAULT_GOAL := all .DEFAULT_GOAL := all
all: $(BIN_TEST) all: pitytest $(BIN_TEST)
$(BIN_TEST): $(OBJ_FRAMEWORK) $(BIN_TEST): $(OBJ_FRAMEWORK)

1
test/framework/framework.cc

@ -8,7 +8,6 @@
#include <utility> #include <utility>
#include <exception> #include <exception>
#include <thread> #include <thread>
#include <unistd.h>
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>

2
test/framework/utils.hh

@ -9,7 +9,7 @@
#include <exception> #include <exception>
#include <chrono> #include <chrono>
#include <thread> #include <thread>
#include <unistd.h> #include <cstring>
#include <tuple> #include <tuple>
#include <pEp/pEpEngine.h> #include <pEp/pEpEngine.h>
#include <pEp/identity_list.h> #include <pEp/identity_list.h>

2
test/pitytest11/src/PityUnit.hh

@ -8,11 +8,11 @@
#include "../../../src/std_utils.hh" #include "../../../src/std_utils.hh"
#include "fs_mutex.hh" #include "fs_mutex.hh"
#include "PityTransport.hh" #include "PityTransport.hh"
//#include "PityPerspective.hh"
#include <string> #include <string>
#include <map> #include <map>
#include <memory> #include <memory>
#include <unordered_map> #include <unordered_map>
#include <functional>
// Yes, the mem mgmt is purely static on purpose (so far) // Yes, the mem mgmt is purely static on purpose (so far)

1
test/pitytest11/src/PityUnit.hxx

@ -15,6 +15,7 @@
#include <exception> #include <exception>
#include <memory> #include <memory>
#include <unordered_map> #include <unordered_map>
#include <sys/wait.h>
namespace pEp { namespace pEp {

1
test/test_adapter.cc

@ -5,7 +5,6 @@
#include "framework/utils.hh" #include "framework/utils.hh"
#include <iostream> #include <iostream>
#include <assert.h> #include <assert.h>
#include <unistd.h>
#include <pEp/sync_api.h> #include <pEp/sync_api.h>
#include <pEp/keymanagement.h> #include <pEp/keymanagement.h>

1
test/test_adapter_cxx.cc

@ -5,7 +5,6 @@
#include "framework/utils.hh" #include "framework/utils.hh"
#include <iostream> #include <iostream>
#include <assert.h> #include <assert.h>
#include <unistd.h>
#include <pEp/keymanagement.h> #include <pEp/keymanagement.h>
#include <pEp/sync_api.h> #include <pEp/sync_api.h>

12
test/test_ensure_passphrase.cc

@ -3,21 +3,11 @@
#include "framework/framework.hh" #include "framework/framework.hh"
//#include <iostream> #include <cassert>
//#include <fstream>
//#include <sstream>
//#include <unistd.h>
#include <assert.h>
//#include <stdlib.h>
//#include <string.h>
//#include <sys/param.h>
//#include <pEp/message_api.h>
#include <pEp/keymanagement.h> #include <pEp/keymanagement.h>
#include <pEp/key_reset.h> #include <pEp/key_reset.h>
#include "../src/passphrase_cache.hh" #include "../src/passphrase_cache.hh"
//#include "../src/status_to_string.hh"
#include "../src/Adapter.hh" #include "../src/Adapter.hh"
using namespace pEp; using namespace pEp;

1
test/test_leave_device_group.cc

@ -5,7 +5,6 @@
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#include <unistd.h>
#include <pEp/sync_api.h> #include <pEp/sync_api.h>

3
test/test_listmanager_dummy.cc

@ -1,10 +1,9 @@
#include "../src/listmanager_dummy.hh" #include "../src/listmanager_dummy.hh"
#include "../src/utils.hh" #include "../src/utils.hh"
#include "../src/std_utils.hh"
#include "framework/utils.hh" #include "framework/utils.hh"
#include <iostream>
#include <exception> #include <exception>
#include <map> #include <map>
#include <cassert>
using namespace std; using namespace std;

2
test/test_message_cache.cc

@ -6,7 +6,7 @@
#include <iostream> #include <iostream>
#include <cassert> #include <cassert>
#include <sys/param.h> #include <sys/param.h>
#include <unistd.h> #include <cstring>
#include "../src/message_cache.hh" #include "../src/message_cache.hh"
#include "../src/Adapter.hh" #include "../src/Adapter.hh"

1
test/test_pEpSQLite.cc

@ -5,6 +5,7 @@
#include "framework/utils.hh" #include "framework/utils.hh"
#include <fstream> #include <fstream>
#include <cassert>
using namespace std; using namespace std;
using namespace pEp; using namespace pEp;

1
test/test_passphrase_cache.cc

@ -4,7 +4,6 @@
#include "framework/framework.hh" #include "framework/framework.hh"
#include <iostream> #include <iostream>
#include <unistd.h>
#include <assert.h> #include <assert.h>
#include <sys/param.h> #include <sys/param.h>

5
test/test_semaphore.cc

@ -3,8 +3,7 @@
#include <iostream> #include <iostream>
#include <thread> #include <thread>
#include <unistd.h> #include "../src/std_utils.hh"
#include "../src/Semaphore.hh" #include "../src/Semaphore.hh"
using namespace std; using namespace std;
@ -24,7 +23,7 @@ int main()
cout << "1: keep going\n"; cout << "1: keep going\n";
}); });
sleep(1); Utils::sleep_millis(1000);
thread thread2([&]() { thread thread2([&]() {
cout << "2: setting go\n"; cout << "2: setting go\n";

Loading…
Cancel
Save