diff --git a/TODO.txt b/TODO.txt index fa082d52..5338acb7 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,5 +1,3 @@ -* Re-structure so that top namespace in C++ is YggInterface -* Move C++ interface into src directory * Automated documentation using doxygen * Fill in missing docs * Fix handling of multiple connections in ZMQ socket (restricted to ZMQ_PAIR to simplify testing) diff --git a/src/YggInterface.h b/src/YggInterface.h index a3d6229f..f85bfada 100755 --- a/src/YggInterface.h +++ b/src/YggInterface.h @@ -7,7 +7,7 @@ #include "datatypes/dtype_t.h" // TODO: Allow use of ygglog_error as function in C -using namespace communication::utils; +using namespace YggInterface::utils; #ifdef __cplusplus /* If this is a C++ compiler, use C linkage */ extern "C" { diff --git a/src/YggInterface.hpp b/src/YggInterface.hpp index 5ff97928..ce21c59b 100644 --- a/src/YggInterface.hpp +++ b/src/YggInterface.hpp @@ -5,7 +5,7 @@ #define WITH_GLOBAL_SCOPE(COMM) global_scope_comm_on(); COMM; global_scope_comm_off() -using namespace communication::communicator; +using namespace YggInterface::communicator; /*! @brief Input communicator that can be used to receive messages from diff --git a/src/rapidjson b/src/rapidjson index 3dda647a..6ea654bc 160000 --- a/src/rapidjson +++ b/src/rapidjson @@ -1 +1 @@ -Subproject commit 3dda647a92829926c80a6195f6fa30286d9efddd +Subproject commit 6ea654bc77d5e2625e3c4d8e52497082cb85d060 diff --git a/src/utils/Address.cpp b/src/utils/Address.cpp index 862384e6..dc23a6aa 100644 --- a/src/utils/Address.cpp +++ b/src/utils/Address.cpp @@ -1,7 +1,7 @@ #include "Address.hpp" #include -using namespace communication::utils; +using namespace YggInterface::utils; Address::Address(const std::string &adr): _key(-1), _valid(false) { address(adr); diff --git a/src/utils/Address.hpp b/src/utils/Address.hpp index c41dead9..463a1b61 100644 --- a/src/utils/Address.hpp +++ b/src/utils/Address.hpp @@ -4,7 +4,7 @@ #define COMM_ADDRESS_SIZE 500 -namespace communication { +namespace YggInterface { namespace utils { static std::string blank; diff --git a/src/utils/logging.cpp b/src/utils/logging.cpp index 11e37dc1..b1ace933 100644 --- a/src/utils/logging.cpp +++ b/src/utils/logging.cpp @@ -1,7 +1,7 @@ #include "logging.hpp" #include "tools.hpp" -namespace communication { +namespace YggInterface { namespace utils { int YggdrasilLogger::_ygg_error_flag = 0; diff --git a/src/utils/logging.hpp b/src/utils/logging.hpp index ed3b7498..47c67c31 100644 --- a/src/utils/logging.hpp +++ b/src/utils/logging.hpp @@ -9,7 +9,7 @@ #endif #endif -namespace communication { +namespace YggInterface { namespace utils { class YggdrasilLogger { @@ -50,12 +50,12 @@ namespace utils { } } -#define ygglog_error communication::utils::YggdrasilLogger("ERROR", 40, true) -#define ygglog_info communication::utils::YggdrasilLogger("INFO", 20) -// #define ygglog_debug communication::utils::YggdrasilLogger("DEBUG", 10) -#define ygglog_debug communication::utils::YggdrasilLogger("DEBUG", 40) +#define ygglog_error YggInterface::utils::YggdrasilLogger("ERROR", 40, true) +#define ygglog_info YggInterface::utils::YggdrasilLogger("INFO", 20) +// #define ygglog_debug YggInterface::utils::YggdrasilLogger("DEBUG", 10) +#define ygglog_debug YggInterface::utils::YggdrasilLogger("DEBUG", 40) -#define ygglog_error_c(...) ygglog_error << communication::utils::string_format(__VA_ARGS__) << std::endl -#define ygglog_debug_c(...) ygglog_debug << communication::utils::string_format(__VA_ARGS__) << std::endl -#define ygglog_info_c(...) ygglog_info << communication::utils::string_format(__VA_ARGS__) << std::endl -#define ygglog_throw_error_c(...) communication::utils::ygglog_throw_error(communication::utils::string_format(__VA_ARGS__)) +#define ygglog_error_c(...) ygglog_error << YggInterface::utils::string_format(__VA_ARGS__) << std::endl +#define ygglog_debug_c(...) ygglog_debug << YggInterface::utils::string_format(__VA_ARGS__) << std::endl +#define ygglog_info_c(...) ygglog_info << YggInterface::utils::string_format(__VA_ARGS__) << std::endl +#define ygglog_throw_error_c(...) YggInterface::utils::ygglog_throw_error(YggInterface::utils::string_format(__VA_ARGS__)) diff --git a/src/utils/regex.cpp b/src/utils/regex.cpp index 4da91ddd..4ac2fc16 100644 --- a/src/utils/regex.cpp +++ b/src/utils/regex.cpp @@ -1,7 +1,7 @@ #include #include "regex.hpp" -namespace communication { +namespace YggInterface { namespace utils { /*! diff --git a/src/utils/regex.hpp b/src/utils/regex.hpp index 81bc6a35..1d0755bd 100644 --- a/src/utils/regex.hpp +++ b/src/utils/regex.hpp @@ -5,7 +5,7 @@ #include #define FMT_LEN 100 -namespace communication { +namespace YggInterface { namespace utils { size_t find_match(const std::regex ®ex, const std::string &to_match, diff --git a/src/utils/serialization.cpp b/src/utils/serialization.cpp index 885b97fd..f2437610 100644 --- a/src/utils/serialization.cpp +++ b/src/utils/serialization.cpp @@ -11,9 +11,9 @@ extern "C" { } #endif // RAPIDJSON_FORCE_IMPORT_ARRAY // #endif // RAPIDJSON_YGGDRASIL_PYTHON -using namespace communication::utils; +using namespace YggInterface::utils; -int communication::utils::split_head_body(const char *buf, +int YggInterface::utils::split_head_body(const char *buf, const char **head, size_t *headsiz) { // Split buffer into head and body @@ -63,7 +63,7 @@ int communication::utils::split_head_body(const char *buf, } template -std::string communication::utils::document2string(ValueT& rhs, +std::string YggInterface::utils::document2string(ValueT& rhs, const char* indent) { rapidjson::StringBuffer sb; rapidjson::PrettyWriter writer(sb, 0, strlen(indent)); @@ -72,7 +72,7 @@ std::string communication::utils::document2string(ValueT& rhs, return std::string(sb.GetString()); } -long communication::utils::copyData(char*& dst, const size_t dst_len, +long YggInterface::utils::copyData(char*& dst, const size_t dst_len, const char* src, const size_t src_len, bool allow_realloc) { if ((src_len + 1) > dst_len) { @@ -791,7 +791,7 @@ Header::Header(bool own_data) : } } Header::Header(const char* buf, const size_t &len, - communication::communicator::Comm_t* comm) : + YggInterface::communicator::Comm_t* comm) : Header() { Metadata* meta = NULL; int comm_flags = 0; @@ -935,7 +935,7 @@ long Header::copyData(const char* msg, const size_t msg_siz) { } else { bool allow_realloc = ((flags & HEAD_FLAG_ALLOW_REALLOC) && (offset == 0)); - ret = communication::utils::copyData(dst, size_buff - offset, + ret = YggInterface::utils::copyData(dst, size_buff - offset, msg, msg_siz, allow_realloc); if (allow_realloc && ((ret + 1) > static_cast(size_buff))) { data[0] = dst; diff --git a/src/utils/serialization.hpp b/src/utils/serialization.hpp index 5df81985..db16ed4f 100644 --- a/src/utils/serialization.hpp +++ b/src/utils/serialization.hpp @@ -25,14 +25,14 @@ static_cast(strlen(var)) -namespace communication { +namespace YggInterface { namespace communicator { class Comm_t; } } -namespace communication { +namespace YggInterface { namespace utils { /*! @@ -194,7 +194,7 @@ class Header : public Metadata { public: Header(bool own_data=false); Header(const char* buf, const size_t &len, - communication::communicator::Comm_t* comm); + YggInterface::communicator::Comm_t* comm); Header(char*& buf, const size_t &len, bool allow_realloc); ~Header() override; #if RAPIDJSON_HAS_CXX11_RVALUE_REFS diff --git a/src/utils/tools.cpp b/src/utils/tools.cpp index 739d59e6..a4d6135e 100644 --- a/src/utils/tools.cpp +++ b/src/utils/tools.cpp @@ -5,7 +5,7 @@ #include "tools.hpp" #define YGG_THREAD_MUTEX(name) \ - std::mutex communication::utils::name ## _mutex; + std::mutex YggInterface::utils::name ## _mutex; YGG_THREAD_MUTEX(init) YGG_THREAD_MUTEX(clean) YGG_THREAD_MUTEX(client) diff --git a/src/utils/tools.hpp b/src/utils/tools.hpp index 78b70729..1c04f937 100644 --- a/src/utils/tools.hpp +++ b/src/utils/tools.hpp @@ -91,7 +91,7 @@ #include "logging.hpp" -namespace communication { +namespace YggInterface { namespace utils { // template::value && @@ -290,11 +290,11 @@ static int global_thread_id = -1; #define YGG_THREADING_ACTIVE 1 #define YGG_THREAD_SAFE_BEGIN(name) \ _Pragma(STRINGIFY(omp critical (name))) { \ - const std::lock_guard name ## _lock(communication::utils::name ## _mutex); + const std::lock_guard name ## _lock(YggInterface::utils::name ## _mutex); #else // _OPENMP #define YGG_THREAD_SAFE_BEGIN(name) \ { \ - const std::lock_guard name ## _lock(communication::utils::name ## _mutex); + const std::lock_guard name ## _lock(YggInterface::utils::name ## _mutex); #endif // _OPENMP #define YGG_THREAD_SAFE_END \ } diff --git a/test/unittest/mock.cpp b/test/unittest/mock.cpp index 55630e69..d57bcae2 100644 --- a/test/unittest/mock.cpp +++ b/test/unittest/mock.cpp @@ -24,7 +24,7 @@ void init_sublib_contents() { void init_sublib_contents() {} #endif -namespace communication { +namespace YggInterface { namespace mock { #ifdef ELF_AVAILABLE diff --git a/test/unittest/mock.hpp b/test/unittest/mock.hpp index f78f0ba4..5c72307a 100644 --- a/test/unittest/mock.hpp +++ b/test/unittest/mock.hpp @@ -25,16 +25,16 @@ extern char sublib_contents[256]; #endif #define ELFHOOK(x) elf_hook(SUBLIB, LIBRARY_ADDRESS_BY_HANDLE(handle), #x, \ - (void*)communication::mock::x); + (void*)YggInterface::mock::x); #define ELFHOOK_ALT(x) elf_hook(SUBLIB, LIBRARY_ADDRESS_BY_HANDLE(handle), #x, \ - (void*)communication::mock::alt_ ## x); + (void*)YggInterface::mock::alt_ ## x); #define ELFHOOK_PARAM(x, y) elf_hook(SUBLIB, LIBRARY_ADDRESS_BY_HANDLE(handle), #x, \ - (void*)communication::mock::y); + (void*)YggInterface::mock::y); #define ELFREVERT(x,y) y = elf_hook(SUBLIB, LIBRARY_ADDRESS_BY_HANDLE(handle), #x, y); #define ELFHOOK_ARGS(x, a) elf_hook(SUBLIB, LIBRARY_ADDRESS_BY_HANDLE(handle), std::string(#x) + "|" + std::string(#a), \ - (void*)communication::mock::x); + (void*)YggInterface::mock::x); #define ELFREVERT_ARGS(x, a, y) y = elf_hook(SUBLIB, LIBRARY_ADDRESS_BY_HANDLE(handle), std::string(#x) + "|" + std::string(#a), \ y); @@ -74,7 +74,7 @@ extern char sublib_contents[256]; ELFREVERT(func ## _orig, dummy_func_ ## func); \ ELFREVERT(func, *original_func_ ## func) -namespace communication { +namespace YggInterface { namespace mock { #ifdef ELF_AVAILABLE diff --git a/test/unittest/tests/communicators/clientcommtest.cpp b/test/unittest/tests/communicators/clientcommtest.cpp index 66356610..fc60d672 100644 --- a/test/unittest/tests/communicators/clientcommtest.cpp +++ b/test/unittest/tests/communicators/clientcommtest.cpp @@ -8,11 +8,11 @@ #ifdef COMM_BASE -using namespace communication; -using namespace communication::communicator; -using namespace communication::mock; +using namespace YggInterface; +using namespace YggInterface::communicator; +using namespace YggInterface::mock; -namespace communication { +namespace YggInterface { namespace testing { class ClientComm_tester : public ClientComm { private: @@ -96,13 +96,13 @@ class ClientComm_tester : public ClientComm { TEST(ClientComm, constructor) { std::string name = "MyComm"; - communication::testing::ClientComm_tester cc(name); - communication::testing::ClientComm_tester cc1(""); + YggInterface::testing::ClientComm_tester cc(name); + YggInterface::testing::ClientComm_tester cc1(""); } TEST(ClientComm, send) { std::string name = "MyComm"; - communication::testing::ClientComm_tester cc(name); + YggInterface::testing::ClientComm_tester cc(name); std::string msg = "This is a test message"; EXPECT_TRUE(cc.addSignon()); EXPECT_GE(cc.send(msg.c_str(), msg.size()), 0); @@ -110,7 +110,7 @@ TEST(ClientComm, send) { TEST(ClientComm, sendLarge) { std::string name = "MyComm"; - communication::testing::ClientComm_tester cc(name); + YggInterface::testing::ClientComm_tester cc(name); cc.addWorkers(); std::string msg(cc.getMaxMsgSize(), 'A'); EXPECT_TRUE(cc.addSignon()); @@ -129,7 +129,7 @@ TEST(ClientComm, sendLarge) { TEST(ClientComm, recv) { std::string name = "MyComm"; - communication::testing::ClientComm_tester cc(name); + YggInterface::testing::ClientComm_tester cc(name); std::string req_send = "REQUEST"; std::string res_send = "RESPONSE"; std::string req_recv; @@ -204,7 +204,7 @@ TEST(ClientComm, async) { TEST(ClientComm, recvLarge) { std::string name = "MyComm"; - communication::testing::ClientComm_tester cc(name); + YggInterface::testing::ClientComm_tester cc(name); std::string bigMsg(cc.getMaxMsgSize(), 'A'); std::string req_send = "REQUEST" + bigMsg; std::string res_send = "RESPONSE" + bigMsg; @@ -225,7 +225,7 @@ TEST(ClientComm, recvLarge) { TEST(ClientComm, call) { std::string name = "MyComm"; - communication::testing::ClientComm_tester cc(name); + YggInterface::testing::ClientComm_tester cc(name); cc.addSchema("{\"type\": \"string\"}"); std::string req_send = "REQUEST1"; std::string res_send = "RESPONSE1"; diff --git a/test/unittest/tests/communicators/commbasetest.cpp b/test/unittest/tests/communicators/commbasetest.cpp index 3f390868..127beaaf 100644 --- a/test/unittest/tests/communicators/commbasetest.cpp +++ b/test/unittest/tests/communicators/commbasetest.cpp @@ -3,8 +3,8 @@ #include "communicators/CommBase.hpp" #include "rapidjson/document.h" -using namespace communication; -using namespace communication::communicator; +using namespace YggInterface; +using namespace YggInterface::communicator; class Comm_tTest: public Comm_t { public: diff --git a/test/unittest/tests/communicators/commheadtest.cpp b/test/unittest/tests/communicators/commheadtest.cpp index 516bad30..8b370f1f 100644 --- a/test/unittest/tests/communicators/commheadtest.cpp +++ b/test/unittest/tests/communicators/commheadtest.cpp @@ -1,7 +1,7 @@ #include "../../unittest.hpp" #include "utils/serialization.hpp" -using namespace communication::utils; +using namespace YggInterface::utils; // TODO: Add tests for HEADER diff --git a/test/unittest/tests/communicators/commtest.hpp b/test/unittest/tests/communicators/commtest.hpp index a80d848c..cf020a42 100644 --- a/test/unittest/tests/communicators/commtest.hpp +++ b/test/unittest/tests/communicators/commtest.hpp @@ -36,7 +36,7 @@ #define DO_RPC_SIGNON \ { \ std::string msg_cli = YGG_CLIENT_SIGNON; \ - communication::utils::Header header(msg_cli.c_str(), \ + YggInterface::utils::Header header(msg_cli.c_str(), \ msg_cli.size(), &sComm); \ EXPECT_TRUE(sComm.create_header_send(header)); \ size_t len = header.format(); \ diff --git a/test/unittest/tests/communicators/defaultcommtest.cpp b/test/unittest/tests/communicators/defaultcommtest.cpp index 90b40ef3..72eee2fb 100644 --- a/test/unittest/tests/communicators/defaultcommtest.cpp +++ b/test/unittest/tests/communicators/defaultcommtest.cpp @@ -6,9 +6,9 @@ #include "../../mock.hpp" #include "commtest.hpp" -using namespace communication; -using namespace communication::communicator; -using namespace communication::mock; +using namespace YggInterface; +using namespace YggInterface::communicator; +using namespace YggInterface::mock; TEST(DefaultCommu, checkTypeErrors) { DefaultComm x("", SEND); diff --git a/test/unittest/tests/communicators/interfacetest_c.cpp b/test/unittest/tests/communicators/interfacetest_c.cpp index 2cbb05aa..2798ffde 100644 --- a/test/unittest/tests/communicators/interfacetest_c.cpp +++ b/test/unittest/tests/communicators/interfacetest_c.cpp @@ -3,7 +3,7 @@ #include "communicators/comms.hpp" #include "commtest.hpp" -using namespace communication::communicator; +using namespace YggInterface::communicator; #define INIT_INPUT_BASE(cls, cls_args, alt, alt_args) \ alt sComm alt_args; \ diff --git a/test/unittest/tests/communicators/ipccommtest.cpp b/test/unittest/tests/communicators/ipccommtest.cpp index ab1216d7..43295163 100644 --- a/test/unittest/tests/communicators/ipccommtest.cpp +++ b/test/unittest/tests/communicators/ipccommtest.cpp @@ -6,9 +6,9 @@ #include "commtest.hpp" -using namespace communication; -using namespace communication::communicator; -using namespace communication::mock; +using namespace YggInterface; +using namespace YggInterface::communicator; +using namespace YggInterface::mock; class IPCComm_tester : public IPCComm { public: diff --git a/test/unittest/tests/communicators/mpicommtest.cpp b/test/unittest/tests/communicators/mpicommtest.cpp index 56a13ef6..6c308c0d 100644 --- a/test/unittest/tests/communicators/mpicommtest.cpp +++ b/test/unittest/tests/communicators/mpicommtest.cpp @@ -6,9 +6,9 @@ #include "../../mock.hpp" #include "commtest.hpp" -using namespace communication; -using namespace communication::communicator; -using namespace communication::mock; +using namespace YggInterface; +using namespace YggInterface::communicator; +using namespace YggInterface::mock; #if defined(MPIINSTALLED) && defined(MPI_COMM_WORLD) diff --git a/test/unittest/tests/communicators/requeststest.cpp b/test/unittest/tests/communicators/requeststest.cpp index d0a3451a..084ce1f7 100644 --- a/test/unittest/tests/communicators/requeststest.cpp +++ b/test/unittest/tests/communicators/requeststest.cpp @@ -4,8 +4,8 @@ #include "../../elf_hook.hpp" #include "../../mock.hpp" -using namespace communication::communicator; -using namespace communication::utils; +using namespace YggInterface::communicator; +using namespace YggInterface::utils; TEST(RequestList, Empty) { RequestList req(RECV); diff --git a/test/unittest/tests/communicators/servercommtest.cpp b/test/unittest/tests/communicators/servercommtest.cpp index 6a98bb55..e84b3a10 100644 --- a/test/unittest/tests/communicators/servercommtest.cpp +++ b/test/unittest/tests/communicators/servercommtest.cpp @@ -8,11 +8,11 @@ #ifdef COMM_BASE -using namespace communication; -using namespace communication::communicator; -using namespace communication::mock; +using namespace YggInterface; +using namespace YggInterface::communicator; +using namespace YggInterface::mock; -namespace communication { +namespace YggInterface { namespace testing { class ServerComm_tester : public ServerComm { public: @@ -48,7 +48,7 @@ TEST(ServerComm, constructor) { TEST(ServerComm, send) { std::string msg = "my message"; std::string name = "MyComm"; - communication::testing::ServerComm_tester sc(name); + YggInterface::testing::ServerComm_tester sc(name); EXPECT_EQ(sc.send(msg.c_str(), msg.size()), -1); sc.addRequest(); EXPECT_GE(sc.send(msg.c_str(), msg.size()), 0); @@ -68,7 +68,7 @@ TEST(ServerComm, recv) { char* data = (char*)malloc(sizeof(char)); size_t len = 1; - communication::testing::ServerComm_tester sc(name); + YggInterface::testing::ServerComm_tester sc(name); utils::Address addr(sc.getAddress()); ClientComm cc(name, addr); diff --git a/test/unittest/tests/communicators/zmqcommtest.cpp b/test/unittest/tests/communicators/zmqcommtest.cpp index 6943138d..e34ef627 100644 --- a/test/unittest/tests/communicators/zmqcommtest.cpp +++ b/test/unittest/tests/communicators/zmqcommtest.cpp @@ -6,13 +6,13 @@ #include "../../mock.hpp" #include "commtest.hpp" -using namespace communication; -using namespace communication::communicator; -using namespace communication::mock; +using namespace YggInterface; +using namespace YggInterface::communicator; +using namespace YggInterface::mock; #ifdef ZMQINSTALLED -namespace communication { +namespace YggInterface { namespace testing { class ZMQSocket_tester : public ZMQSocket { public: @@ -34,7 +34,7 @@ class ZMQComm_tester : public ZMQComm { std::string getAdr() { return address.address();} void setReply() { - // this->getReply()->addresses.push_back(new communication::utils::Address("ABCDE")); + // this->getReply()->addresses.push_back(new YggInterface::utils::Address("ABCDE")); std::string adr; this->getReply().create(adr); } @@ -46,22 +46,22 @@ COMM_SERI_TEST(ZMQComm) // TEST(yggSockT, yggSockTest) { // ZMQSocket ygs(ZMQ_REQ); -// EXPECT_EQ(communication::testing::ZMQSocket_tester::activeCount(), 1); +// EXPECT_EQ(YggInterface::testing::ZMQSocket_tester::activeCount(), 1); // ygs.close(); -// EXPECT_EQ(communication::testing::ZMQSocket_tester::activeCount(), 0); +// EXPECT_EQ(YggInterface::testing::ZMQSocket_tester::activeCount(), 0); // ZMQSocket::ctx_shutdown(); -// EXPECT_FALSE(communication::testing::ZMQSocket_tester::getValid()); +// EXPECT_FALSE(YggInterface::testing::ZMQSocket_tester::getValid()); // ZMQSocket::ctx_shutdown(); // ZMQSocket::get_context(); // //int x = 2; // ZMQSocket ygs1(ZMQ_REQ); // ZMQSocket ygs2(ZMQ_REQ); -// EXPECT_EQ(communication::testing::ZMQSocket_tester::activeCount(), 2); +// EXPECT_EQ(YggInterface::testing::ZMQSocket_tester::activeCount(), 2); // ZMQSocket::ctx_shutdown(); -// EXPECT_EQ(communication::testing::ZMQSocket_tester::activeCount(), 0); +// EXPECT_EQ(YggInterface::testing::ZMQSocket_tester::activeCount(), 0); -// //communication::testing::ZMQSocket_tester ygs2(ZMQ_REQ); +// //YggInterface::testing::ZMQSocket_tester ygs2(ZMQ_REQ); // //ygs2.setValid(false); diff --git a/test/unittest/tests/utils/testheader.cpp b/test/unittest/tests/utils/testheader.cpp index 70f2149c..f0b598b4 100644 --- a/test/unittest/tests/utils/testheader.cpp +++ b/test/unittest/tests/utils/testheader.cpp @@ -7,7 +7,7 @@ // #include TEST(Metadata, Utilities) { - communication::utils::Metadata metadata; + YggInterface::utils::Metadata metadata; EXPECT_TRUE(metadata.empty()); EXPECT_FALSE(metadata.hasType()); EXPECT_FALSE(metadata.hasSubtype()); @@ -21,7 +21,7 @@ TEST(Metadata, Utilities) { } TEST(Metadata, SetAndGet) { - communication::utils::Metadata metadata; + YggInterface::utils::Metadata metadata; EXPECT_THROW(metadata.getMeta(), std::exception); EXPECT_THROW(metadata.getSchema(), std::exception); EXPECT_THROW(metadata.SetSchemaMetadata("invalid", metadata), std::exception); @@ -139,9 +139,9 @@ TEST(Metadata, SetAndGet) { } TEST(Metadata, components) { - communication::utils::Metadata x; - communication::utils::Metadata y; - communication::utils::Metadata z; + YggInterface::utils::Metadata x; + YggInterface::utils::Metadata y; + YggInterface::utils::Metadata z; // Array z.fromSchema("{\"type\": \"array\", " "\"items\": [{\"type\": \"integer\"}]}", true); @@ -178,32 +178,32 @@ TEST(Metadata, components) { } TEST(Metadata, fromSchema) { - communication::utils::Metadata x; + YggInterface::utils::Metadata x; x.setGeneric(); EXPECT_TRUE(x.isGeneric()); x.fromSchema("{\"type\": \"integer\"}"); EXPECT_TRUE(x.isGeneric()); - communication::utils::Metadata y; + YggInterface::utils::Metadata y; y.fromSchema(x.metadata, true); EXPECT_EQ(x.metadata, y.metadata); y.fromSchema(x.getSchema()); - communication::utils::Metadata z; + YggInterface::utils::Metadata z; z.fromSchema("{\"type\": \"string\"}"); EXPECT_THROW(y.fromSchema(z.getSchema()), std::exception); - communication::utils::Metadata q; + YggInterface::utils::Metadata q; q.fromType("string"); EXPECT_EQ(z.metadata, q.metadata); } TEST(Metadata, fromScalar) { - communication::utils::Metadata x; + YggInterface::utils::Metadata x; x.fromSchema("{" " \"type\": \"scalar\"," " \"subtype\": \"float\"," " \"precision\": 4," " \"units\": \"cm\"" "}"); - communication::utils::Metadata y; + YggInterface::utils::Metadata y; y.fromScalar("float", 4, "cm"); EXPECT_EQ(x.metadata, y.metadata); std::cerr << x.metadata << std::endl; @@ -213,7 +213,7 @@ TEST(Metadata, fromScalar) { EXPECT_EQ(strcmp(y.subtypeName(), "float"), 0); } TEST(Metadata, fromNDArray) { - communication::utils::Metadata x; + YggInterface::utils::Metadata x; x.fromSchema("{" " \"type\": \"ndarray\"," " \"subtype\": \"float\"," @@ -221,7 +221,7 @@ TEST(Metadata, fromNDArray) { " \"shape\": [2, 3]," " \"units\": \"cm\"" "}"); - communication::utils::Metadata y; + YggInterface::utils::Metadata y; size_t shape[2] = { 2, 3 }; y.fromNDArray("float", 4, 2, shape, "cm"); EXPECT_EQ(x.metadata, y.metadata); @@ -272,7 +272,7 @@ TEST(Metadata, fromFormat) { std::string formatStr = "%f\t%d\t%5s\n"; { // Scalar - communication::utils::Metadata x; + YggInterface::utils::Metadata x; x.fromSchema("{" " \"type\": \"array\"," " \"items\": [" @@ -294,13 +294,13 @@ TEST(Metadata, fromFormat) { " ]" "}"); x.SetString("format_str", formatStr, x.metadata["serializer"]); - communication::utils::Metadata y; + YggInterface::utils::Metadata y; y.fromFormat(formatStr); EXPECT_EQ(x.metadata, y.metadata); } { // Arrays - communication::utils::Metadata x; + YggInterface::utils::Metadata x; x.fromSchema("{" " \"type\": \"array\"," " \"items\": [" @@ -322,7 +322,7 @@ TEST(Metadata, fromFormat) { " ]" "}"); x.SetString("format_str", formatStr, x.metadata["serializer"]); - communication::utils::Metadata y; + YggInterface::utils::Metadata y; y.fromFormat(formatStr, true); EXPECT_EQ(x.metadata, y.metadata); EXPECT_TRUE(y.isFormatArray()); @@ -330,7 +330,7 @@ TEST(Metadata, fromFormat) { { // Additional types std::string fmt = "%hhi\t%hi\t%lli\t%l64i\t%li\t%i\t%hhu\t%hu\t%llu\t%l64u\t%lu\t%u\t%f%+fj\n"; - communication::utils::Metadata x; + YggInterface::utils::Metadata x; #ifdef _MSC_VER x.fromSchema("{" " \"type\": \"array\"," @@ -475,14 +475,14 @@ TEST(Metadata, fromFormat) { "}"); #endif // _MSC_VER x.SetString("format_str", fmt, x.metadata["serializer"]); - communication::utils::Metadata y; + YggInterface::utils::Metadata y; y.fromFormat(fmt); EXPECT_EQ(x.metadata, y.metadata); } { // Singular std::string fmt = "%d\n"; - communication::utils::Metadata x; + YggInterface::utils::Metadata x; x.fromSchema("{" " \"type\": \"array\"," " \"allowSingular\": true," @@ -495,42 +495,42 @@ TEST(Metadata, fromFormat) { " ]" "}"); x.SetString("format_str", fmt, x.metadata["serializer"]); - communication::utils::Metadata y; + YggInterface::utils::Metadata y; y.fromFormat(fmt); EXPECT_EQ(x.metadata, y.metadata); } { // Error - communication::utils::Metadata x; + YggInterface::utils::Metadata x; EXPECT_THROW(x.fromFormat("%m"), std::exception); } } TEST(Metadata, fromMetadata) { - communication::utils::Metadata x; + YggInterface::utils::Metadata x; EXPECT_THROW(x.fromMetadata("{"), std::exception); EXPECT_THROW(x.fromMetadata("\"hello\""), std::exception); EXPECT_THROW(x.fromMetadata("{}"), std::exception); EXPECT_THROW(x.fromMetadata("{\"__meta__\": \"hello\"}"), std::exception); x.fromMetadata("{\"__meta__\": {}}"); - communication::utils::Metadata y; + YggInterface::utils::Metadata y; y.fromMetadata(x); EXPECT_EQ(x.metadata, y.metadata); } TEST(Metadata, fromEncode) { rapidjson::Value v(true); - communication::utils::Metadata x; + YggInterface::utils::Metadata x; x.fromSchema("{\"type\": \"boolean\"}"); - communication::utils::Metadata y; + YggInterface::utils::Metadata y; y.fromEncode(v); EXPECT_EQ(x.metadata, y.metadata); } TEST(Metadata, deserialize_errors) { rapidjson::VarArgList va; - communication::utils::Metadata x; + YggInterface::utils::Metadata x; EXPECT_THROW(x.deserialize("", va), std::exception); bool dst = false, dst2 = false; EXPECT_EQ(x.deserialize("true", 1, false, &dst), 1); @@ -547,7 +547,7 @@ TEST(Metadata, deserialize_errors) { TEST(Metadata, serialize_errors) { rapidjson::VarArgList va; - communication::utils::Metadata x; + YggInterface::utils::Metadata x; char* buf = (char*)(x.GetAllocator().Malloc(sizeof(char))); size_t len = 1; EXPECT_THROW(x.serialize(&buf, &len, va), std::exception); @@ -575,14 +575,14 @@ TEST(Metadata, serialize_errors) { } TEST(Header, Utilities) { - communication::utils::Header header; + YggInterface::utils::Header header; rapidjson::StringBuffer buf; header.formatBuffer(buf); EXPECT_EQ(buf.GetLength(), 0); EXPECT_EQ(header.format(), 0); EXPECT_TRUE(header == header); EXPECT_FALSE(header != header); - communication::utils::Header header2; + YggInterface::utils::Header header2; header2.fromType("integer", false, false); EXPECT_FALSE(header == header2); EXPECT_TRUE(header != header2); @@ -593,15 +593,15 @@ TEST(Header, Utilities) { } TEST(Header, for_send) { - communication::utils::Metadata schema; + YggInterface::utils::Metadata schema; schema.fromSchema("{\"type\": \"string\"}"); std::string msg = "This is a test message"; setenv("YGG_MODEL_NAME", "model", 1); setenv("YGG_MODEL_COPY", "1", 1); - communication::utils::Header header_send; + YggInterface::utils::Header header_send; header_send.for_send(&schema, msg.c_str(), msg.size(), 0); header_send.on_send(); - communication::utils::Header header_recv; + YggInterface::utils::Header header_recv; EXPECT_EQ(header_recv.on_recv(header_send.data[0], header_send.size_curr), -static_cast(header_send.size_curr)); @@ -613,11 +613,11 @@ TEST(Header, for_send) { EXPECT_EQ(header_recv.size_data, msg.size()); EXPECT_EQ(strcmp(header_recv.data[0], msg.c_str()), 0); // Header equality - communication::utils::Header header_send2; + YggInterface::utils::Header header_send2; header_send2.for_send(&schema, msg.c_str(), msg.size(), 0); header_send2.fromMetadata(header_send); header_send2.on_send(); - communication::utils::Header header_recv2(true); + YggInterface::utils::Header header_recv2(true); EXPECT_EQ(header_recv2.on_recv(header_send2.data[0], header_send2.size_curr), header_send2.size_curr); @@ -626,12 +626,12 @@ TEST(Header, for_send) { EXPECT_NE(header_recv, header_send); // Received message larger than buffer std::string msg3(2048, 'a'); - communication::utils::Header header_send3; + YggInterface::utils::Header header_send3; header_send3.for_send(&schema, msg3.c_str(), msg3.size(), 0); header_send3.on_send(); size_t size_buf3 = header_send3.size_curr - 1000; char* buf3 = (char*)malloc(size_buf3); - communication::utils::Header header_recv3(buf3, size_buf3, false); + YggInterface::utils::Header header_recv3(buf3, size_buf3, false); EXPECT_EQ(header_recv3.on_recv(header_send3.data[0], size_buf3 - 1), -1); free(buf3); buf3 = NULL; diff --git a/test/unittest/tests/utils/testutils.cpp b/test/unittest/tests/utils/testutils.cpp index 70333a9f..d3fc75d7 100644 --- a/test/unittest/tests/utils/testutils.cpp +++ b/test/unittest/tests/utils/testutils.cpp @@ -20,7 +20,7 @@ std::streambuf* prevbuf = std::cout.rdbuf(B.rdbuf()); EXPECT_DOUBLE_EQ(static_cast(lhs), static_cast(rhs)) #endif -using namespace communication::utils; +using namespace YggInterface::utils; namespace { #define COMPLEX_UNIT_TEST(type, typenm, comparator, real, img) { \ complex_ ## type ## _t cmplx; \ diff --git a/test/unittest/unittest.hpp b/test/unittest/unittest.hpp index 0c4123ce..c28ae2e3 100644 --- a/test/unittest/unittest.hpp +++ b/test/unittest/unittest.hpp @@ -103,7 +103,7 @@ class AssertException : public std::logic_error { // TODO: Perform destroy during exit automatically #ifdef ZMQINSTALLED #define INIT_ZMQ() \ - communication::communicator::ZMQContext ctx + YggInterface::communicator::ZMQContext ctx #define FINALIZE_ZMQ() \ ctx.destroy() #else // ZMQINSTALLED