mirror of
https://github.com/ratspeak/microReticulum
synced 2026-11-27 13:52:14 +00:00
Replace string-concatenation logging with printf-style F-variants
Converted log calls across src/, examples/, and test/ to use DEBUGF/TRACEF/ERRORF/etc. macros instead of std::string + operator+. This eliminates temporary heap allocations on every log call, which matters on memory-constrained MCUs.
This commit is contained in:
1 parent
3babdc001d
commit
79b75bbd4e
35 files changed
+595
-604
No files matched your search
@@ -147,7 +147,7 @@ public:
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
ERROR("file_exists: failed to open file " + std::string(file_path));
|
||||
ERRORF("file_exists: failed to open file %s", file_path);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -181,9 +181,9 @@ public:
|
||||
//size_t read = fread(data.writable(size), size, 1, file);
|
||||
read = fread(data.writable(size), 1, size, file);
|
||||
#endif
|
||||
TRACE("read_file: read " + std::to_string(read) + " bytes from file " + std::string(file_path));
|
||||
TRACEF("read_file: read %zu bytes from file %s", read, file_path);
|
||||
if (read != size) {
|
||||
ERROR("read_file: failed to read file " + std::string(file_path));
|
||||
ERRORF("read_file: failed to read file %s", file_path);
|
||||
data.clear();
|
||||
}
|
||||
//TRACE("read_file: closing input file");
|
||||
@@ -199,7 +199,7 @@ public:
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
ERROR("read_file: failed to open input file " + std::string(file_path));
|
||||
ERRORF("read_file: failed to open input file %s", file_path);
|
||||
}
|
||||
return read;
|
||||
}
|
||||
@@ -227,9 +227,9 @@ public:
|
||||
//size_t wrote = fwrite(data.data(), data.size(), 1, file);
|
||||
wrote = fwrite(data.data(), 1, data.size(), file);
|
||||
#endif
|
||||
TRACE("write_file: wrote " + std::to_string(wrote) + " bytes to file " + std::string(file_path));
|
||||
TRACEF("write_file: wrote %zu bytes to file %s", wrote, file_path);
|
||||
if (wrote < data.size()) {
|
||||
WARNING("write_file: not all data was written to file " + std::string(file_path));
|
||||
WARNINGF("write_file: not all data was written to file %s", file_path);
|
||||
}
|
||||
//TRACE("write_file: closing output file");
|
||||
#ifdef ARDUINO
|
||||
@@ -244,7 +244,7 @@ public:
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
ERROR("write_file: failed to open output file " + std::string(file_path));
|
||||
ERRORF("write_file: failed to open output file %s", file_path);
|
||||
}
|
||||
return wrote;
|
||||
}
|
||||
@@ -374,7 +374,7 @@ public:
|
||||
}
|
||||
|
||||
/*virtua*/ bool directory_exists(const char* directory_path) {
|
||||
TRACE("directory_exists: checking for existence of directory " + std::string(directory_path));
|
||||
TRACEF("directory_exists: checking for existence of directory %s", directory_path);
|
||||
#ifdef ARDUINO
|
||||
#ifdef BOARD_ESP32
|
||||
File file = SPIFFS.open(directory_path, FILE_READ);
|
||||
@@ -409,13 +409,13 @@ public:
|
||||
#ifdef ARDUINO
|
||||
#ifdef BOARD_ESP32
|
||||
if (!SPIFFS.mkdir(directory_path)) {
|
||||
ERROR("create_directory: failed to create directorty " + std::string(directory_path));
|
||||
ERRORF("create_directory: failed to create directorty %s", directory_path);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
#elif BOARD_NRF52
|
||||
if (!InternalFS.mkdir(directory_path)) {
|
||||
ERROR("create_directory: failed to create directorty " + std::string(directory_path));
|
||||
ERRORF("create_directory: failed to create directorty %s", directory_path);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -433,18 +433,18 @@ public:
|
||||
}
|
||||
|
||||
/*virtua*/ bool remove_directory(const char* directory_path) {
|
||||
TRACE("remove_directory: removing directory " + std::string(directory_path));
|
||||
TRACEF("remove_directory: removing directory %s", directory_path);
|
||||
#ifdef ARDUINO
|
||||
#ifdef BOARD_ESP32
|
||||
//if (!LittleFS.rmdir_r(directory_path)) {
|
||||
if (!SPIFFS.rmdir(directory_path)) {
|
||||
ERROR("remove_directory: failed to remove directorty " + std::string(directory_path));
|
||||
ERRORF("remove_directory: failed to remove directorty %s", directory_path);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
#elif BOARD_NRF52
|
||||
if (!InternalFS.rmdir_r(directory_path)) {
|
||||
ERROR("remove_directory: failed to remove directory " + std::string(directory_path));
|
||||
ERRORF("remove_directory: failed to remove directory %s", directory_path);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -454,7 +454,7 @@ public:
|
||||
#else
|
||||
// Native
|
||||
if (rmdir(directory_path) == 0) {
|
||||
ERROR("remove_directory: failed to remove directory " + std::string(directory_path));
|
||||
ERRORF("remove_directory: failed to remove directory %s", directory_path);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -462,7 +462,7 @@ public:
|
||||
}
|
||||
|
||||
/*virtua*/ std::list<std::string> list_directory(const char* directory_path) {
|
||||
TRACE("list_directory: listing directory " + std::string(directory_path));
|
||||
TRACEF("list_directory: listing directory %s", directory_path);
|
||||
std::list<std::string> files;
|
||||
#ifdef ARDUINO
|
||||
#ifdef BOARD_ESP32
|
||||
@@ -471,7 +471,7 @@ public:
|
||||
File root = InternalFS.open(directory_path);
|
||||
#endif
|
||||
if (!root) {
|
||||
ERROR("list_directory: failed to open directory " + std::string(directory_path));
|
||||
ERRORF("list_directory: failed to open directory %s", directory_path);
|
||||
return files;
|
||||
}
|
||||
File file = root.openNextFile();
|
||||
@@ -491,7 +491,7 @@ public:
|
||||
// Native
|
||||
DIR *dir = opendir(directory_path);
|
||||
if (dir == NULL) {
|
||||
ERROR("list_directory: failed to open directory " + std::string(directory_path));
|
||||
ERRORF("list_directory: failed to open directory %s", directory_path);
|
||||
return files;
|
||||
}
|
||||
struct dirent *entry;
|
||||
@@ -503,7 +503,7 @@ public:
|
||||
files.push_back(name);
|
||||
}
|
||||
if (closedir(dir) == -1) {
|
||||
ERROR("list_directory: failed to close directory " + std::string(directory_path));
|
||||
ERRORF("list_directory: failed to close directory %s", directory_path);
|
||||
}
|
||||
|
||||
return files;
|
||||
|
||||
@@ -64,9 +64,9 @@ void testBytesMain() {
|
||||
bytes += prebuf + postbuf;
|
||||
TEST_ASSERT_EQUAL_size_t(14, bytes.size());
|
||||
TEST_ASSERT_EQUAL_MEMORY("FooHello World", bytes.data(), bytes.size());
|
||||
TRACE("assign bytes: " + bytes.toString());
|
||||
TRACE("assign prebuf: " + prebuf.toString());
|
||||
TRACE("assign postbuf: " + postbuf.toString());
|
||||
TRACEF("assign bytes: %s", bytes.toString().c_str());
|
||||
TRACEF("assign prebuf: %s", prebuf.toString().c_str());
|
||||
TRACEF("assign postbuf: %s", postbuf.toString().c_str());
|
||||
|
||||
// test string assignment with addition
|
||||
bytes = prebuf + postbuf;
|
||||
@@ -83,56 +83,56 @@ void testBytesMain() {
|
||||
// test left in range
|
||||
{
|
||||
RNS::Bytes left(bytes.left(5));
|
||||
TRACE("left: " + left.toString());
|
||||
TRACEF("left: %s", left.toString().c_str());
|
||||
TEST_ASSERT_EQUAL_size_t(5, left.size());
|
||||
TEST_ASSERT_EQUAL_MEMORY("Hello", left.data(), left.size());
|
||||
}
|
||||
// test left oob
|
||||
{
|
||||
RNS::Bytes left(bytes.left(20));
|
||||
TRACE("oob left: " + left.toString());
|
||||
TRACEF("oob left: %s", left.toString().c_str());
|
||||
TEST_ASSERT_EQUAL_size_t(11, left.size());
|
||||
TEST_ASSERT_EQUAL_MEMORY("Hello World", left.data(), left.size());
|
||||
}
|
||||
// test right in range
|
||||
{
|
||||
RNS::Bytes right(bytes.right(5));
|
||||
TRACE("right: " + right.toString());
|
||||
TRACEF("right: %s", right.toString().c_str());
|
||||
TEST_ASSERT_EQUAL_size_t(5, right.size());
|
||||
TEST_ASSERT_EQUAL_MEMORY("World", right.data(), right.size());
|
||||
}
|
||||
// test right oob
|
||||
{
|
||||
RNS::Bytes right(bytes.right(20));
|
||||
TRACE("oob right: " + right.toString());
|
||||
TRACEF("oob right: %s", right.toString().c_str());
|
||||
TEST_ASSERT_EQUAL_size_t(11, right.size());
|
||||
TEST_ASSERT_EQUAL_MEMORY("Hello World", right.data(), right.size());
|
||||
}
|
||||
// test mid in range
|
||||
{
|
||||
RNS::Bytes mid(bytes.mid(3, 5));
|
||||
TRACE("mid: " + mid.toString());
|
||||
TRACEF("mid: %s", mid.toString().c_str());
|
||||
TEST_ASSERT_EQUAL_size_t(5, mid.size());
|
||||
TEST_ASSERT_EQUAL_MEMORY("lo Wo", mid.data(), mid.size());
|
||||
}
|
||||
// test mid oob pos
|
||||
{
|
||||
RNS::Bytes mid(bytes.mid(20, 5));
|
||||
TRACE("oob pos mid: " + mid.toString());
|
||||
TRACEF("oob pos mid: %s", mid.toString().c_str());
|
||||
TEST_ASSERT_FALSE(mid);
|
||||
TEST_ASSERT_EQUAL_size_t(0, mid.size());
|
||||
}
|
||||
// test mid oob pos
|
||||
{
|
||||
RNS::Bytes mid(bytes.mid(3, 20));
|
||||
TRACE("oob len mid: " + mid.toString());
|
||||
TRACEF("oob len mid: %s", mid.toString().c_str());
|
||||
TEST_ASSERT_EQUAL_size_t(8, mid.size());
|
||||
TEST_ASSERT_EQUAL_MEMORY("lo World", mid.data(), mid.size());
|
||||
}
|
||||
// test mid to end variant
|
||||
{
|
||||
RNS::Bytes mid(bytes.mid(3));
|
||||
TRACE("end mid: " + mid.toString());
|
||||
TRACEF("end mid: %s", mid.toString().c_str());
|
||||
TEST_ASSERT_EQUAL_size_t(8, mid.size());
|
||||
TEST_ASSERT_EQUAL_MEMORY("lo World", mid.data(), mid.size());
|
||||
}
|
||||
@@ -142,7 +142,7 @@ void testBytesMain() {
|
||||
{
|
||||
RNS::Bytes shrink(bytes);
|
||||
shrink.resize(5);
|
||||
TRACE("shrink: " + shrink.toString());
|
||||
TRACEF("shrink: %s", shrink.toString().c_str());
|
||||
TEST_ASSERT_EQUAL_size_t(5, shrink.size());
|
||||
TEST_ASSERT_EQUAL_MEMORY("Hello", shrink.data(), shrink.size());
|
||||
}
|
||||
@@ -151,11 +151,11 @@ void testBytesMain() {
|
||||
HEAD("TestBytes: trim", RNS::LOG_TRACE);
|
||||
{
|
||||
RNS::Bytes bytes("Hello World");
|
||||
TRACE("orig: " + bytes.toString());
|
||||
TRACEF("orig: %s", bytes.toString().c_str());
|
||||
TEST_ASSERT_EQUAL_size_t(11, bytes.size());
|
||||
TEST_ASSERT_EQUAL_MEMORY("Hello World", bytes.data(), bytes.size());
|
||||
bytes = bytes.left(5);
|
||||
TRACE("trim: " + bytes.toString());
|
||||
TRACEF("trim: %s", bytes.toString().c_str());
|
||||
TEST_ASSERT_EQUAL_size_t(5, bytes.size());
|
||||
TEST_ASSERT_EQUAL_MEMORY("Hello", bytes.data(), bytes.size());
|
||||
}
|
||||
@@ -226,9 +226,9 @@ void testCowBytes() {
|
||||
TEST_ASSERT_EQUAL_MEMORY("1", bytes3.data(), bytes3.size());
|
||||
TEST_ASSERT_EQUAL_PTR(bytes2.data(), bytes3.data());
|
||||
|
||||
TRACE("pre bytes1 ptr: " + std::to_string((uintptr_t)bytes1.data()) + " data: " + bytes1.toString());
|
||||
TRACE("pre bytes2 ptr: " + std::to_string((uintptr_t)bytes2.data()) + " data: " + bytes2.toString());
|
||||
TRACE("pre bytes3 ptr: " + std::to_string((uintptr_t)bytes3.data()) + " data: " + bytes3.toString());
|
||||
TRACEF("pre bytes1 ptr: %p data: %s", (void*)bytes1.data(), bytes1.toString().c_str());
|
||||
TRACEF("pre bytes2 ptr: %p data: %s", (void*)bytes2.data(), bytes2.toString().c_str());
|
||||
TRACEF("pre bytes3 ptr: %p data: %s", (void*)bytes3.data(), bytes3.toString().c_str());
|
||||
|
||||
//bytes1.append("mississippi");
|
||||
//assert(bytes1.size() == 12);
|
||||
@@ -245,9 +245,9 @@ void testCowBytes() {
|
||||
TEST_ASSERT_EQUAL_MEMORY("mississippi", bytes3.data(), bytes3.size());
|
||||
TEST_ASSERT_NOT_EQUAL(bytes2.data(), bytes3.data());
|
||||
|
||||
TRACE("post bytes1 ptr: " + std::to_string((uintptr_t)bytes1.data()) + " data: " + bytes1.toString());
|
||||
TRACE("post bytes2 ptr: " + std::to_string((uintptr_t)bytes2.data()) + " data: " + bytes2.toString());
|
||||
TRACE("post bytes3 ptr: " + std::to_string((uintptr_t)bytes3.data()) + " data: " + bytes3.toString());
|
||||
TRACEF("post bytes1 ptr: %p data: %s", (void*)bytes1.data(), bytes1.toString().c_str());
|
||||
TRACEF("post bytes2 ptr: %p data: %s", (void*)bytes2.data(), bytes2.toString().c_str());
|
||||
TRACEF("post bytes3 ptr: %p data: %s", (void*)bytes3.data(), bytes3.toString().c_str());
|
||||
}
|
||||
|
||||
void testBytesConversion() {
|
||||
@@ -255,14 +255,14 @@ void testBytesConversion() {
|
||||
{
|
||||
RNS::Bytes bytes("Hello World");
|
||||
std::string hex = bytes.toHex(true);
|
||||
TRACE("text: \"" + bytes.toString() + "\" upper hex: \"" + hex + "\"");
|
||||
TRACEF("text: \"%s\" upper hex: \"%s\"", bytes.toString().c_str(), hex.c_str());
|
||||
TEST_ASSERT_EQUAL_size_t(22, hex.length());
|
||||
TEST_ASSERT_EQUAL_STRING("48656C6C6F20576F726C64", hex.c_str());
|
||||
}
|
||||
{
|
||||
RNS::Bytes bytes("Hello World");
|
||||
std::string hex = bytes.toHex(false);
|
||||
TRACE("text: \"" + bytes.toString() + "\" lower hex: \"" + hex + "\"");
|
||||
TRACEF("text: \"%s\" lower hex: \"%s\"", bytes.toString().c_str(), hex.c_str());
|
||||
TEST_ASSERT_EQUAL_size_t(22, hex.length());
|
||||
TEST_ASSERT_EQUAL_STRING("48656c6c6f20576f726c64", hex.c_str());
|
||||
}
|
||||
@@ -271,7 +271,7 @@ void testBytesConversion() {
|
||||
RNS::Bytes bytes;
|
||||
bytes.assignHex(hex.c_str());
|
||||
std::string text = bytes.toString();
|
||||
TRACE("hex: \"" + hex + "\" text: \"" + text + "\"");
|
||||
TRACEF("hex: \"%s\" text: \"%s\"", hex.c_str(), text.c_str());
|
||||
TEST_ASSERT_EQUAL_size_t(11, text.length());
|
||||
TEST_ASSERT_EQUAL_STRING("Hello World", text.c_str());
|
||||
}
|
||||
@@ -280,21 +280,21 @@ void testBytesConversion() {
|
||||
RNS::Bytes bytes;
|
||||
bytes.assignHex(hex.c_str());
|
||||
std::string text = bytes.toString();
|
||||
TRACE("hex: \"" + hex + "\" text: \"" + text + "\"");
|
||||
TRACEF("hex: \"%s\" text: \"%s\"", hex.c_str(), text.c_str());
|
||||
TEST_ASSERT_EQUAL_size_t(11, text.length());
|
||||
TEST_ASSERT_EQUAL_STRING("Hello World", text.c_str());
|
||||
|
||||
// overwrite
|
||||
bytes.assignHex(hex.c_str());
|
||||
text = bytes.toString();
|
||||
TRACE("hex: \"" + hex + "\" text: \"" + text + "\"");
|
||||
TRACEF("hex: \"%s\" text: \"%s\"", hex.c_str(), text.c_str());
|
||||
TEST_ASSERT_EQUAL_size_t(11, text.length());
|
||||
TEST_ASSERT_EQUAL_STRING("Hello World", text.c_str());
|
||||
|
||||
// apend
|
||||
bytes.appendHex(hex.c_str());
|
||||
text = bytes.toString();
|
||||
TRACE("hex: \"" + hex + "\" text: \"" + text + "\"");
|
||||
TRACEF("hex: \"%s\" text: \"%s\"", hex.c_str(), text.c_str());
|
||||
TEST_ASSERT_EQUAL_size_t(22, text.length());
|
||||
TEST_ASSERT_EQUAL_STRING("Hello WorldHello World", text.c_str());
|
||||
}
|
||||
|
||||
@@ -28,14 +28,14 @@ void testBytesMap()
|
||||
TEST_ASSERT_NOT_EQUAL(map.end(), preit);
|
||||
TEST_ASSERT_EQUAL_STRING("hello", (*preit).second.c_str());
|
||||
if (preit != map.end()) {
|
||||
TRACE(std::string("found prebuf: ") + (*preit).second);
|
||||
TRACEF("found prebuf: %s", (*preit).second.c_str());
|
||||
}
|
||||
|
||||
auto postit = map.find(postbuf);
|
||||
TEST_ASSERT_NOT_EQUAL(map.end(), postit);
|
||||
TEST_ASSERT_EQUAL_STRING("world", (*postit).second.c_str());
|
||||
if (postit != map.end()) {
|
||||
TRACE(std::string("found postbuf: ") + (*postit).second);
|
||||
TRACEF("found postbuf: %s", (*postit).second.c_str());
|
||||
}
|
||||
|
||||
const uint8_t newstr[] = "World";
|
||||
@@ -46,7 +46,7 @@ void testBytesMap()
|
||||
TEST_ASSERT_NOT_EQUAL(map.end(), newit);
|
||||
TEST_ASSERT_EQUAL_STRING("world", (*newit).second.c_str());
|
||||
if (newit != map.end()) {
|
||||
TRACE(std::string("found newbuf: ") + (*newit).second);
|
||||
TRACEF("found newbuf: %s", (*newit).second.c_str());
|
||||
}
|
||||
|
||||
std::string str = map["World"];
|
||||
@@ -85,7 +85,7 @@ void testOldMap() {
|
||||
}
|
||||
}
|
||||
for (auto& pair : entries) {
|
||||
TRACE("entries: " + pair.second._hash.toString());
|
||||
TRACEF("entries: %s", pair.second._hash.toString().c_str());
|
||||
}
|
||||
TEST_ASSERT_EQUAL_size_t(2, entries.size());
|
||||
TEST_ASSERT_EQUAL_size_t(2, other_entries.size());
|
||||
@@ -113,7 +113,7 @@ void testNewMap() {
|
||||
}
|
||||
}
|
||||
for (auto& [hash, entry] : entries) {
|
||||
TRACE("entries: " + entry._hash.toString());
|
||||
TRACEF("entries: %s", entry._hash.toString().c_str());
|
||||
}
|
||||
TEST_ASSERT_EQUAL_size_t(2, entries.size());
|
||||
TEST_ASSERT_EQUAL_size_t(2, other_entries.size());
|
||||
|
||||
@@ -165,22 +165,22 @@ void readFileStream(const char* file_path) {
|
||||
void testListDirectory() {
|
||||
|
||||
size_t pre_memory = RNS::Utilities::OS::heap_available();
|
||||
INFO("testListDirectory: pre-mem: " + std::to_string(pre_memory));
|
||||
INFOF("testListDirectory: pre-mem: %zu", pre_memory);
|
||||
|
||||
{
|
||||
for (int i = 0; i < 1; i++) {
|
||||
std::list<std::string> files;
|
||||
files = RNS::Utilities::OS::list_directory("/");
|
||||
for (auto& file : files) {
|
||||
INFO("FILE: " + file);
|
||||
INFOF("FILE: %s", file.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
size_t post_memory = RNS::Utilities::OS::heap_available();
|
||||
size_t diff_memory = (int)pre_memory - (int)post_memory;
|
||||
INFO("testListDirectory: post-mem: " + std::to_string(post_memory));
|
||||
INFO("testListDirectory: diff-mem: " + std::to_string(diff_memory));
|
||||
INFOF("testListDirectory: post-mem: %zu", post_memory);
|
||||
INFOF("testListDirectory: diff-mem: %zu", diff_memory);
|
||||
TEST_ASSERT_EQUAL_size_t(0, diff_memory);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,12 +20,12 @@ void testTime()
|
||||
double diff_time;
|
||||
|
||||
diff_time = (double)(end_ltime - start_ltime) / 1000.0;
|
||||
TRACE(std::string("ltime diff: ") + std::to_string(diff_time));
|
||||
TRACEF("ltime diff: %f", diff_time);
|
||||
TEST_ASSERT_TRUE(diff_time > sleep_time * 0.99);
|
||||
TEST_ASSERT_TRUE(diff_time < sleep_time * 1.01);
|
||||
|
||||
diff_time = end_dtime - start_dtime;
|
||||
TRACE(std::string("dtime diff: ") + std::to_string(diff_time));
|
||||
TRACEF("dtime diff: %f", diff_time);
|
||||
TEST_ASSERT_TRUE(diff_time > sleep_time * 0.99);
|
||||
TEST_ASSERT_TRUE(diff_time < sleep_time * 1.01);
|
||||
|
||||
|
||||
@@ -26,12 +26,12 @@ public:
|
||||
|
||||
private:
|
||||
virtual void send_outgoing(const RNS::Bytes& data) {
|
||||
DEBUG("TestInterface.send_outgoing: data: " + data.toHex());
|
||||
DEBUGF("TestInterface.send_outgoing: data: %s", data.toHex().c_str());
|
||||
// Perform post-send housekeeping
|
||||
InterfaceImpl::handle_outgoing(data);
|
||||
}
|
||||
void on_incoming(const RNS::Bytes& data) {
|
||||
DEBUG("TestInterface.on_incoming: data: " + data.toHex());
|
||||
DEBUGF("TestInterface.on_incoming: data: %s", data.toHex().c_str());
|
||||
// Pass received data on to transport
|
||||
InterfaceImpl::handle_incoming(data);
|
||||
}
|
||||
@@ -82,7 +82,7 @@ const char test_file_data[] = "test data";
|
||||
void testWrite() {
|
||||
RNS::Bytes data(test_file_data);
|
||||
if (RNS::Utilities::OS::write_file(test_file_path, data) == data.size()) {
|
||||
TRACE("wrote: " + std::to_string(data.size()) + " bytes");
|
||||
TRACEF("wrote: %zu bytes", data.size());
|
||||
}
|
||||
else {
|
||||
TRACE("write failed");
|
||||
@@ -93,8 +93,8 @@ void testWrite() {
|
||||
void testRead() {
|
||||
RNS::Bytes data;
|
||||
if (RNS::Utilities::OS::read_file(test_file_path, data) > 0) {
|
||||
TRACE("read: " + std::to_string(data.size()) + " bytes");
|
||||
TRACE("data: " + data.toString());
|
||||
TRACEF("read: %zu bytes", data.size());
|
||||
TRACEF("data: %s", data.toString().c_str());
|
||||
TEST_ASSERT_EQUAL_size_t(strlen(test_file_data), data.size());
|
||||
TEST_ASSERT_NOT_NULL(data.data());
|
||||
TEST_ASSERT_EQUAL_MEMORY(test_file_data, data.data(), strlen(test_file_data));
|
||||
@@ -132,10 +132,10 @@ void testSerializeObject() {
|
||||
if (length < size) {
|
||||
data.resize(length);
|
||||
}
|
||||
TRACE("serialized " + std::to_string(length) + " bytes");
|
||||
TRACEF("serialized %zu bytes", length);
|
||||
if (length > 0) {
|
||||
if (RNS::Utilities::OS::write_file(test_object_path, data) == data.size()) {
|
||||
TRACE("wrote: " + std::to_string(data.size()) + " bytes");
|
||||
TRACEF("wrote: %zu bytes", data.size());
|
||||
}
|
||||
else {
|
||||
TRACE("write failed");
|
||||
@@ -157,14 +157,14 @@ void testDeserializeObject() {
|
||||
RNS::Bytes data;
|
||||
if (RNS::Utilities::OS::read_file(test_object_path, data) > 0) {
|
||||
if (data) {
|
||||
TRACE("read: " + std::to_string(data.size()) + " bytes");
|
||||
//TRACE("data: " + data.toString());
|
||||
TRACEF("read: %zu bytes", data.size());
|
||||
//TRACEF("data: %s", data.toString().c_str());
|
||||
DeserializationError error = deserializeJson(doc, data.data());
|
||||
//DeserializationError error = deserializeMsgPack(doc, data.data());
|
||||
if (!error) {
|
||||
JsonObject root = doc.as<JsonObject>();
|
||||
for (JsonPair kv : root) {
|
||||
TRACE("key: " + std::string(kv.key().c_str()) + " value: " + kv.value().as<const char*>());
|
||||
TRACEF("key: %s value: %s", kv.key().c_str(), kv.value().as<const char*>());
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -184,7 +184,7 @@ void testSerializeObject() {
|
||||
|
||||
std::vector<std::string> vec({"one", "two"});
|
||||
TestObject test("test", vec);
|
||||
TRACE("testSerializeObject: test: " + test.toString());
|
||||
TRACEF("testSerializeObject: test: %s", test.toString().c_str());
|
||||
|
||||
JsonDocument doc;
|
||||
doc.set(test);
|
||||
@@ -196,10 +196,10 @@ void testSerializeObject() {
|
||||
if (length < size) {
|
||||
data.resize(length);
|
||||
}
|
||||
TRACE("testSerializeObject: serialized " + std::to_string(length) + " bytes");
|
||||
TRACEF("testSerializeObject: serialized %zu bytes", length);
|
||||
if (length > 0) {
|
||||
if (RNS::Utilities::OS::write_file(test_object_path, data) == data.size()) {
|
||||
TRACE("testSerializeObject: wrote: " + std::to_string(data.size()) + " bytes");
|
||||
TRACEF("testSerializeObject: wrote: %zu bytes", data.size());
|
||||
}
|
||||
else {
|
||||
TRACE("testSerializeObject: write failed");
|
||||
@@ -219,17 +219,17 @@ void testDeserializeObject() {
|
||||
|
||||
RNS::Bytes data;
|
||||
if (RNS::Utilities::OS::read_file(test_object_path, data) > 0) {
|
||||
TRACE("testDeserializeObject: read: " + std::to_string(data.size()) + " bytes");
|
||||
//TRACE("data: " + data.toString());
|
||||
TRACEF("testDeserializeObject: read: %zu bytes", data.size());
|
||||
//TRACEF("data: %s", data.toString().c_str());
|
||||
DeserializationError error = deserializeJson(doc, data.data());
|
||||
//DeserializationError error = deserializeMsgPack(doc, data.data());
|
||||
if (!error) {
|
||||
//JsonObject root = doc.as<JsonObject>();
|
||||
//for (JsonPair kv : root) {
|
||||
// TRACE("key: " + std::string(kv.key().c_str()) + " value: " + kv.value().as<const char*>());
|
||||
// TRACEF("key: %s value: %s", kv.key().c_str(), kv.value().as<const char*>());
|
||||
//}
|
||||
TestObject test = doc.as<TestObject>();
|
||||
TRACE("testDeserializeObject: test: " + test.toString());
|
||||
TRACEF("testDeserializeObject: test: %s", test.toString().c_str());
|
||||
}
|
||||
else {
|
||||
TRACE("testDeserializeObject: failed to deserialize");
|
||||
@@ -292,10 +292,10 @@ void testSerializeVector() {
|
||||
if (length < size) {
|
||||
data.resize(length);
|
||||
}
|
||||
TRACE("testSerializeVector: serialized " + std::to_string(length) + " bytes");
|
||||
TRACEF("testSerializeVector: serialized %zu bytes", length);
|
||||
if (length > 0) {
|
||||
if (RNS::Utilities::OS::write_file(test_vector_path, data) == data.size()) {
|
||||
TRACE("testSerializeVector: wrote: " + std::to_string(data.size()) + " bytes");
|
||||
TRACEF("testSerializeVector: wrote: %zu bytes", data.size());
|
||||
}
|
||||
else {
|
||||
TRACE("testSerializeVector: write failed");
|
||||
@@ -315,8 +315,8 @@ void testDeserializeVector() {
|
||||
|
||||
RNS::Bytes data;
|
||||
if (RNS::Utilities::OS::read_file(test_vector_path, data) > 0) {
|
||||
TRACE("testDeserializeVector: read: " + std::to_string(data.size()) + " bytes");
|
||||
//TRACE("testDeserializeVector: data: " + data.toString());
|
||||
TRACEF("testDeserializeVector: read: %zu bytes", data.size());
|
||||
//TRACEF("testDeserializeVector: data: %s", data.toString().c_str());
|
||||
DeserializationError error = deserializeJson(doc, data.data());
|
||||
//DeserializationError error = deserializeMsgPack(doc, data.data());
|
||||
if (!error) {
|
||||
@@ -324,12 +324,12 @@ void testDeserializeVector() {
|
||||
|
||||
std::vector<TestObject> vector = doc.as<std::vector<TestObject>>();
|
||||
for (auto& test : vector) {
|
||||
TRACE("testDeserializeVector: entry: " + test.toString());
|
||||
TRACEF("testDeserializeVector: entry: %s", test.toString().c_str());
|
||||
}
|
||||
|
||||
//JsonArray arr = doc.as<JsonArray>();
|
||||
//for (JsonVariant elem : arr) {
|
||||
// TRACE("testDeserializeVector: entry: " + elem.as<TestObject>().toString());
|
||||
// TRACEF("testDeserializeVector: entry: %s", elem.as<TestObject>().toString().c_str());
|
||||
//}
|
||||
}
|
||||
else {
|
||||
@@ -381,10 +381,10 @@ void testSerializeSet() {
|
||||
if (length < size) {
|
||||
data.resize(length);
|
||||
}
|
||||
TRACE("testSerializeSet: serialized " + std::to_string(length) + " bytes");
|
||||
TRACEF("testSerializeSet: serialized %zu bytes", length);
|
||||
if (length > 0) {
|
||||
if (RNS::Utilities::OS::write_file(test_set_path, data) == data.size()) {
|
||||
TRACE("testSerializeSet: wrote: " + std::to_string(data.size()) + " bytes");
|
||||
TRACEF("testSerializeSet: wrote: %zu bytes", data.size());
|
||||
}
|
||||
else {
|
||||
TRACE("testSerializeSet: write failed");
|
||||
@@ -404,8 +404,8 @@ void testDeserializeSet() {
|
||||
|
||||
RNS::Bytes data;
|
||||
if (RNS::Utilities::OS::read_file(test_set_path, data) > 0) {
|
||||
TRACE("testDeserializeSet: read: " + std::to_string(data.size()) + " bytes");
|
||||
//TRACE("testDeserializeSet: data: " + data.toString());
|
||||
TRACEF("testDeserializeSet: read: %zu bytes", data.size());
|
||||
//TRACEF("testDeserializeSet: data: %s", data.toString().c_str());
|
||||
DeserializationError error = deserializeJson(doc, data.data());
|
||||
//DeserializationError error = deserializeMsgPack(doc, data.data());
|
||||
if (!error) {
|
||||
@@ -413,12 +413,12 @@ void testDeserializeSet() {
|
||||
|
||||
std::set<TestObject> set = doc.as<std::set<TestObject>>();
|
||||
for (auto& test : set) {
|
||||
TRACE("testDeserializeSet: entry: " + test.toString());
|
||||
TRACEF("testDeserializeSet: entry: %s", test.toString().c_str());
|
||||
}
|
||||
|
||||
//JsonArray arr = doc.as<JsonArray>();
|
||||
//for (JsonVariant elem : arr) {
|
||||
// TRACE("testDeserializeSet: entry: " + elem.as<TestObject>().toString());
|
||||
// TRACEF("testDeserializeSet: entry: %s", elem.as<TestObject>().toString().c_str());
|
||||
//}
|
||||
}
|
||||
else {
|
||||
@@ -463,10 +463,10 @@ void testSerializeMap() {
|
||||
if (length < size) {
|
||||
data.resize(length);
|
||||
}
|
||||
TRACE("testSerializeMap: serialized " + std::to_string(length) + " bytes");
|
||||
TRACEF("testSerializeMap: serialized %zu bytes", length);
|
||||
if (length > 0) {
|
||||
if (RNS::Utilities::OS::write_file(test_map_path, data) == data.size()) {
|
||||
TRACE("testSerializeMap: wrote: " + std::to_string(data.size()) + " bytes");
|
||||
TRACEF("testSerializeMap: wrote: %zu bytes", data.size());
|
||||
}
|
||||
else {
|
||||
TRACE("testSerializeMap: write failed");
|
||||
@@ -486,8 +486,8 @@ void testDeserializeMap() {
|
||||
|
||||
RNS::Bytes data;
|
||||
if (RNS::Utilities::OS::read_file(test_map_path, data) > 0) {
|
||||
TRACE("testDeserializeMap: read: " + std::to_string(data.size()) + " bytes");
|
||||
//TRACE("testDeserializeMap: data: " + data.toString());
|
||||
TRACEF("testDeserializeMap: read: %zu bytes", data.size());
|
||||
//TRACEF("testDeserializeMap: data: %s", data.toString().c_str());
|
||||
DeserializationError error = deserializeJson(doc, data.data());
|
||||
//DeserializationError error = deserializeMsgPack(doc, data.data());
|
||||
if (!error) {
|
||||
@@ -495,12 +495,12 @@ void testDeserializeMap() {
|
||||
|
||||
std::map<std::string, TestObject> map(doc.as<std::map<std::string, TestObject>>());
|
||||
for (auto& [str, test] : map) {
|
||||
TRACE("testDeserializeMap: entry: " + str + " = " + test.toString());
|
||||
TRACEF("testDeserializeMap: entry: %s = %s", str.c_str(), test.toString().c_str());
|
||||
}
|
||||
|
||||
//JsonObject root = doc.as<JsonObject>();
|
||||
//for (JsonPair kv : root) {
|
||||
// TRACE("testDeserializeMap: entry: " + std::string(kv.key().c_str()) + " = " + kv.value().as<TestObject>().toString());
|
||||
// TRACEF("testDeserializeMap: entry: %s = %s", kv.key().c_str(), kv.value().as<TestObject>().toString().c_str());
|
||||
//}
|
||||
}
|
||||
else {
|
||||
@@ -569,27 +569,27 @@ void testSerializeDestinationTable() {
|
||||
}
|
||||
|
||||
for (auto& [hash, test] : map) {
|
||||
TRACE("testSerializeDestinationTable: entry: " + hash.toHex() + " = " + test.debugString());
|
||||
TRACEF("testSerializeDestinationTable: entry: %s = %s", hash.toHex().c_str(), test.debugString().c_str());
|
||||
}
|
||||
|
||||
JsonDocument doc;
|
||||
doc.set(map);
|
||||
TRACE("testSerializeDestinationTable: doc size " + std::to_string(doc.size()));
|
||||
TRACEF("testSerializeDestinationTable: doc size %zu", doc.size());
|
||||
|
||||
RNS::Bytes data;
|
||||
size_t size = 32768;
|
||||
//size_t size = BUFFER_SIZE;
|
||||
TRACE("testSerializeDestinationTable: buffer size " + std::to_string(size) + " bytes");
|
||||
TRACEF("testSerializeDestinationTable: buffer size %zu bytes", size);
|
||||
size_t length = serializeJson(doc, data.writable(size), size);
|
||||
//size_t length = serializeMsgPack(doc, data.writable(size), size);
|
||||
if (length < size) {
|
||||
data.resize(length);
|
||||
}
|
||||
TRACE("testSerializeDestinationTable: serialized " + std::to_string(length) + " bytes");
|
||||
TRACEF("testSerializeDestinationTable: serialized %zu bytes", length);
|
||||
if (length > 0) {
|
||||
TRACE("testSerializeDestinationTable: json: " + data.toString());
|
||||
TRACEF("testSerializeDestinationTable: json: %s", data.toString().c_str());
|
||||
if (RNS::Utilities::OS::write_file(test_destination_table_path, data) == data.size()) {
|
||||
TRACE("testSerializeDestinationTable: wrote: " + std::to_string(data.size()) + " bytes");
|
||||
TRACEF("testSerializeDestinationTable: wrote: %zu bytes", data.size());
|
||||
}
|
||||
else {
|
||||
TRACE("testSerializeDestinationTable: write failed");
|
||||
@@ -607,27 +607,27 @@ void testDeserializeDestinationTable() {
|
||||
|
||||
RNS::Bytes data;
|
||||
if (RNS::Utilities::OS::read_file(test_destination_table_path, data) > 0) {
|
||||
TRACE("testDeserializeDestinationTable: read: " + std::to_string(data.size()) + " bytes");
|
||||
TRACE("testDeserializeDestinationTable: json: " + data.toString());
|
||||
TRACEF("testDeserializeDestinationTable: read: %zu bytes", data.size());
|
||||
TRACEF("testDeserializeDestinationTable: json: %s", data.toString().c_str());
|
||||
JsonDocument doc;
|
||||
|
||||
//TRACE("testDeserializeVector: data: " + data.toString());
|
||||
//TRACEF("testDeserializeVector: data: %s", data.toString().c_str());
|
||||
DeserializationError error = deserializeJson(doc, data.data());
|
||||
//DeserializationError error = deserializeMsgPack(doc, data.data());
|
||||
TRACE("testDeserializeDestinationTable: doc size " + std::to_string(doc.size()));
|
||||
TRACEF("testDeserializeDestinationTable: doc size %zu", doc.size());
|
||||
if (!error) {
|
||||
TRACE("testDeserializeDestinationTable: successfully deserialized " + std::to_string(data.size()) + " bytes");
|
||||
//TRACE("testDeserializeDestinationTable: json: " + data.toString());
|
||||
TRACEF("testDeserializeDestinationTable: successfully deserialized %zu bytes", data.size());
|
||||
//TRACEF("testDeserializeDestinationTable: json: %s", data.toString().c_str());
|
||||
|
||||
static std::map<RNS::Bytes, RNS::Transport::DestinationEntry> map(doc.as<std::map<RNS::Bytes, RNS::Transport::DestinationEntry>>());
|
||||
TEST_ASSERT_EQUAL_size_t(22, map.size());
|
||||
for (auto& [hash, test] : map) {
|
||||
TRACE("testDeserializeDestinationTable: entry: " + hash.toHex() + " = " + test.debugString());
|
||||
TRACEF("testDeserializeDestinationTable: entry: %s = %s", hash.toHex().c_str(), test.debugString().c_str());
|
||||
}
|
||||
|
||||
//JsonObject root = doc.as<JsonObject>();
|
||||
//for (JsonPair kv : root) {
|
||||
// TRACE("testDeserializeDestinationTable: entry: " + std::string(kv.key().c_str()) + " = " + kv.value().as<TestObject>().toString());
|
||||
// TRACEF("testDeserializeDestinationTable: entry: %s = %s", kv.key().c_str(), kv.value().as<TestObject>().toString().c_str());
|
||||
//}
|
||||
}
|
||||
else {
|
||||
@@ -651,26 +651,26 @@ void testDeserializeEmptyDestinationTable() {
|
||||
|
||||
RNS::Bytes data;
|
||||
if (RNS::Utilities::OS::read_file(test_empty_destination_table_path, data) > 0) {
|
||||
TRACE("testDeserializeEmptyDestinationTable: read: " + std::to_string(data.size()) + " bytes");
|
||||
TRACEF("testDeserializeEmptyDestinationTable: read: %zu bytes", data.size());
|
||||
JsonDocument doc;
|
||||
|
||||
//TRACE("testDeserializeVector: data: " + data.toString());
|
||||
//TRACEF("testDeserializeVector: data: %s", data.toString().c_str());
|
||||
DeserializationError error = deserializeJson(doc, data.data());
|
||||
//DeserializationError error = deserializeMsgPack(doc, data.data());
|
||||
TRACE("testDeserializeEmptyDestinationTable: doc size " + std::to_string(doc.size()));
|
||||
TRACEF("testDeserializeEmptyDestinationTable: doc size %zu", doc.size());
|
||||
if (!error) {
|
||||
TRACE("testDeserializeEmptyDestinationTable: successfully deserialized " + std::to_string(data.size()) + " bytes");
|
||||
TRACE("testDeserializeEmptyDestinationTable: json: " + data.toString());
|
||||
TRACEF("testDeserializeEmptyDestinationTable: successfully deserialized %zu bytes", data.size());
|
||||
TRACEF("testDeserializeEmptyDestinationTable: json: %s", data.toString().c_str());
|
||||
|
||||
static std::map<RNS::Bytes, RNS::Transport::DestinationEntry> map(doc.as<std::map<RNS::Bytes, RNS::Transport::DestinationEntry>>());
|
||||
TEST_ASSERT_EQUAL_size_t(0, map.size());
|
||||
for (auto& [hash, test] : map) {
|
||||
TRACE("testDeserializeEmptyDestinationTable: entry: " + hash.toHex() + " = " + test.debugString());
|
||||
TRACEF("testDeserializeEmptyDestinationTable: entry: %s = %s", hash.toHex().c_str(), test.debugString().c_str());
|
||||
}
|
||||
|
||||
//JsonObject root = doc.as<JsonObject>();
|
||||
//for (JsonPair kv : root) {
|
||||
// TRACE("testDeserializeEmptyDestinationTable: entry: " + std::string(kv.key().c_str()) + " = " + kv.value().as<TestObject>().toString());
|
||||
// TRACEF("testDeserializeEmptyDestinationTable: entry: %s = %s", kv.key().c_str(), kv.value().as<TestObject>().toString().c_str());
|
||||
//}
|
||||
}
|
||||
else {
|
||||
@@ -715,7 +715,7 @@ void testJsonMsgpackSerializeObject() {
|
||||
|
||||
std::vector<std::string> vec({"one", "two"});
|
||||
TestObject test("test", vec);
|
||||
TRACE("testJsonMsgpackSerializeObject: test: " + test.toString());
|
||||
TRACEF("testJsonMsgpackSerializeObject: test: %s", test.toString().c_str());
|
||||
|
||||
JsonDocument doc;
|
||||
doc.set(test);
|
||||
@@ -726,10 +726,10 @@ void testJsonMsgpackSerializeObject() {
|
||||
if (length < size) {
|
||||
data.resize(length);
|
||||
}
|
||||
TRACE("testJsonMsgpackSerializeObject: serialized " + std::to_string(length) + " bytes");
|
||||
TRACEF("testJsonMsgpackSerializeObject: serialized %zu bytes", length);
|
||||
if (length > 0) {
|
||||
if (RNS::Utilities::OS::write_file(test_object_path, data) == data.size()) {
|
||||
TRACE("testJsonMsgpackSerializeObject: wrote: " + std::to_string(data.size()) + " bytes");
|
||||
TRACEF("testJsonMsgpackSerializeObject: wrote: %zu bytes", data.size());
|
||||
}
|
||||
else {
|
||||
TRACE("testJsonMsgpackSerializeObject: write failed");
|
||||
@@ -749,16 +749,16 @@ void testJsonMsgpackDeserializeObject() {
|
||||
|
||||
RNS::Bytes data;
|
||||
if (RNS::Utilities::OS::read_file(test_object_path, data) > 0) {
|
||||
TRACE("testJsonMsgpackDeserializeObject: read: " + std::to_string(data.size()) + " bytes");
|
||||
//TRACE("data: " + data.toString());
|
||||
TRACEF("testJsonMsgpackDeserializeObject: read: %zu bytes", data.size());
|
||||
//TRACEF("data: %s", data.toString().c_str());
|
||||
DeserializationError error = deserializeMsgPack(doc, data.data());
|
||||
if (!error) {
|
||||
//JsonObject root = doc.as<JsonObject>();
|
||||
//for (JsonPair kv : root) {
|
||||
// TRACE("key: " + std::string(kv.key().c_str()) + " value: " + kv.value().as<const char*>());
|
||||
// TRACEF("key: %s value: %s", kv.key().c_str(), kv.value().as<const char*>());
|
||||
//}
|
||||
TestObject test = doc.as<TestObject>();
|
||||
TRACE("testJsonMsgpackDeserializeObject: test: " + test.toString());
|
||||
TRACEF("testJsonMsgpackDeserializeObject: test: %s", test.toString().c_str());
|
||||
}
|
||||
else {
|
||||
TRACE("testJsonMsgpackDeserializeObject: failed to deserialize");
|
||||
@@ -809,10 +809,10 @@ void testJsonMsgpackSerializeArray() {
|
||||
if (length < size) {
|
||||
data.resize(length);
|
||||
}
|
||||
TRACE("testJsonMsgpackSerializeArray: serialized " + std::to_string(length) + " bytes");
|
||||
TRACEF("testJsonMsgpackSerializeArray: serialized %zu bytes", length);
|
||||
if (length > 0) {
|
||||
if (RNS::Utilities::OS::write_file(test_array_path, data) == data.size()) {
|
||||
TRACE("testJsonMsgpackSerializeArray: wrote: " + std::to_string(data.size()) + " bytes");
|
||||
TRACEF("testJsonMsgpackSerializeArray: wrote: %zu bytes", data.size());
|
||||
}
|
||||
else {
|
||||
TRACE("testJsonMsgpackSerializeArray: write failed");
|
||||
@@ -832,8 +832,8 @@ void testJsonMsgpackDeserializeArray() {
|
||||
|
||||
RNS::Bytes data;
|
||||
if (RNS::Utilities::OS::read_file(test_array_path, data) > 0) {
|
||||
TRACE("testJsonMsgpackDeserializeArray: read: " + std::to_string(data.size()) + " bytes");
|
||||
//TRACE("data: " + data.toString());
|
||||
TRACEF("testJsonMsgpackDeserializeArray: read: %zu bytes", data.size());
|
||||
//TRACEF("data: %s", data.toString().c_str());
|
||||
DeserializationError error = deserializeMsgPack(doc, data.data(), data.size());
|
||||
if (!error) {
|
||||
JsonArray array = doc.as<JsonArray>();
|
||||
@@ -869,7 +869,7 @@ void testMsgpackSerializeObject() {
|
||||
|
||||
std::vector<std::string> vec({"one", "two"});
|
||||
TestObject test("test", vec);
|
||||
TRACE("testMsgpackSerializeObject: test: " + test.toString());
|
||||
TRACEF("testMsgpackSerializeObject: test: %s", test.toString().c_str());
|
||||
|
||||
JsonDocument doc;
|
||||
|
||||
@@ -879,10 +879,10 @@ void testMsgpackSerializeObject() {
|
||||
if (length < size) {
|
||||
data.resize(length);
|
||||
}
|
||||
TRACE("testMsgpackSerializeObject: serialized " + std::to_string(length) + " bytes");
|
||||
TRACEF("testMsgpackSerializeObject: serialized %zu bytes", length);
|
||||
if (length > 0) {
|
||||
if (RNS::Utilities::OS::write_file(test_object_path, data) == data.size()) {
|
||||
TRACE("testMsgpackSerializeObject: wrote: " + std::to_string(data.size()) + " bytes");
|
||||
TRACEF("testMsgpackSerializeObject: wrote: %zu bytes", data.size());
|
||||
}
|
||||
else {
|
||||
TRACE("testMsgpackSerializeObject: write failed");
|
||||
@@ -902,16 +902,16 @@ void testMsgpackDeserializeObject() {
|
||||
|
||||
RNS::Bytes data;
|
||||
if (RNS::Utilities::OS::read_file(test_object_path, data) > 0) {
|
||||
TRACE("testMsgpackDeserializeObject: read: " + std::to_string(data.size()) + " bytes");
|
||||
//TRACE("data: " + data.toString());
|
||||
TRACEF("testMsgpackDeserializeObject: read: %zu bytes", data.size());
|
||||
//TRACEF("data: %s", data.toString().c_str());
|
||||
DeserializationError error = deserializeMsgPack(doc, data.data());
|
||||
if (!error) {
|
||||
//JsonObject root = doc.as<JsonObject>();
|
||||
//for (JsonPair kv : root) {
|
||||
// TRACE("key: " + std::string(kv.key().c_str()) + " value: " + kv.value().as<const char*>());
|
||||
// TRACEF("key: %s value: %s", kv.key().c_str(), kv.value().as<const char*>());
|
||||
//}
|
||||
TestObject test = doc.as<TestObject>();
|
||||
TRACE("testMsgpackDeserializeObject: test: " + test.toString());
|
||||
TRACEF("testMsgpackDeserializeObject: test: %s", test.toString().c_str());
|
||||
}
|
||||
else {
|
||||
TRACE("testMsgpackDeserializeObject: failed to deserialize");
|
||||
@@ -951,10 +951,10 @@ void testMsgpackSerializeArray() {
|
||||
//packer.to_array(time, one.collection(), two.collection());
|
||||
RNS::Bytes data(packer.data(), packer.size());
|
||||
|
||||
TRACE("testMsgpackSerializeArray: serialized " + std::to_string(data.size()) + " bytes");
|
||||
TRACEF("testMsgpackSerializeArray: serialized %zu bytes", data.size());
|
||||
if (packer.size() > 0) {
|
||||
if (RNS::Utilities::OS::write_file(test_array_path, data) == data.size()) {
|
||||
TRACE("testMsgpackSerializeArray: wrote: " + std::to_string(data.size()) + " bytes");
|
||||
TRACEF("testMsgpackSerializeArray: wrote: %zu bytes", data.size());
|
||||
}
|
||||
else {
|
||||
TRACE("testMsgpackSerializeArray: write failed");
|
||||
@@ -974,8 +974,8 @@ void testMsgpackDeserializeArray() {
|
||||
|
||||
RNS::Bytes data;
|
||||
if (RNS::Utilities::OS::read_file(test_array_path, data) > 0) {
|
||||
TRACE("testMsgpackDeserializeArray: read: " + std::to_string(data.size()) + " bytes");
|
||||
//TRACE("data: " + data.toString());
|
||||
TRACEF("testMsgpackDeserializeArray: read: %zu bytes", data.size());
|
||||
//TRACEF("data: %s", data.toString().c_str());
|
||||
MsgPack::Unpacker unpacker;
|
||||
unpacker.feed(data.data(), data.size());
|
||||
double time;
|
||||
@@ -1018,10 +1018,10 @@ void testMsgpackSerializeSeries() {
|
||||
//packer.serialize(time, one.collection(), two.collection());
|
||||
RNS::Bytes data(packer.data(), packer.size());
|
||||
|
||||
TRACE("testMsgpackSerializeSeries: serialized " + std::to_string(data.size()) + " bytes");
|
||||
TRACEF("testMsgpackSerializeSeries: serialized %zu bytes", data.size());
|
||||
if (packer.size() > 0) {
|
||||
if (RNS::Utilities::OS::write_file(test_series_path, data) == data.size()) {
|
||||
TRACE("testMsgpackSerializeSeries: wrote: " + std::to_string(data.size()) + " bytes");
|
||||
TRACEF("testMsgpackSerializeSeries: wrote: %zu bytes", data.size());
|
||||
}
|
||||
else {
|
||||
TRACE("testMsgpackSerializeSeries: write failed");
|
||||
@@ -1041,8 +1041,8 @@ void testMsgpackDeserializeSeries() {
|
||||
|
||||
RNS::Bytes data;
|
||||
if (RNS::Utilities::OS::read_file(test_series_path, data) > 0) {
|
||||
TRACE("testMsgpackDeserializeSeries: read: " + std::to_string(data.size()) + " bytes");
|
||||
//TRACE("data: " + data.toString());
|
||||
TRACEF("testMsgpackDeserializeSeries: read: %zu bytes", data.size());
|
||||
//TRACEF("data: %s", data.toString().c_str());
|
||||
MsgPack::Unpacker unpacker;
|
||||
unpacker.feed(data.data(), data.size());
|
||||
double time;
|
||||
|
||||
@@ -26,7 +26,7 @@ void testReference() {
|
||||
interfaces.insert(testinterface);
|
||||
for (auto iter = interfaces.begin(); iter != interfaces.end(); ++iter) {
|
||||
RNS::Interface& interface = (*iter);
|
||||
TRACE("Found interface: " + interface.toString());
|
||||
TRACEF("Found interface: %s", interface.toString().c_str());
|
||||
RNS::Bytes data;
|
||||
const_cast<RNS::Interface&>(interface).on_outgoing(data);
|
||||
}
|
||||
@@ -39,7 +39,7 @@ void testReference() {
|
||||
std::set<std::reference_wrapper<RNS::Interface>, std::less<RNS::Interface>> interfaces;
|
||||
interfaces.insert(testinterface);
|
||||
for (auto& interface : interfaces) {
|
||||
TRACE("Found interface: " + interface.toString());
|
||||
TRACEF("Found interface: %s", interface.toString().c_str());
|
||||
RNS::Bytes data;
|
||||
const_cast<RNS::Interface&>(interface).on_outgoing(data);
|
||||
}
|
||||
@@ -53,7 +53,7 @@ void testReference() {
|
||||
interfaces.push_back(testinterface);
|
||||
for (auto iter = interfaces.begin(); iter != interfaces.end(); ++iter) {
|
||||
RNS::Interface& interface = (*iter);
|
||||
TRACE("Found interface: " + interface.toString());
|
||||
TRACEF("Found interface: %s", interface.toString().c_str());
|
||||
RNS::Bytes data;
|
||||
const_cast<RNS::Interface&>(interface).on_outgoing(data);
|
||||
}
|
||||
@@ -67,7 +67,7 @@ void testReference() {
|
||||
interfaces.push_back(testinterface);
|
||||
//for (auto& interface : interfaces) {
|
||||
for (RNS::Interface& interface : interfaces) {
|
||||
TRACE("Found interface: " + interface.toString());
|
||||
TRACEF("Found interface: %s", interface.toString().c_str());
|
||||
RNS::Bytes data;
|
||||
const_cast<RNS::Interface&>(interface).on_outgoing(data);
|
||||
}
|
||||
@@ -81,14 +81,14 @@ void testReference() {
|
||||
interfaces.push_back(testinterface);
|
||||
for (auto iter = interfaces.begin(); iter != interfaces.end(); ++iter) {
|
||||
RNS::Interface& interface = (*iter);
|
||||
TRACE("1 Found interface: " + interface.toString());
|
||||
TRACEF("1 Found interface: %s", interface.toString().c_str());
|
||||
RNS::Bytes data;
|
||||
const_cast<RNS::Interface&>(interface).on_outgoing(data);
|
||||
}
|
||||
}
|
||||
for (auto iter = interfaces.begin(); iter != interfaces.end(); ++iter) {
|
||||
RNS::Interface& interface = (*iter);
|
||||
TRACE("2 Found interface: " + interface.toString());
|
||||
TRACEF("2 Found interface: %s", interface.toString().c_str());
|
||||
RNS::Bytes data;
|
||||
const_cast<RNS::Interface&>(interface).on_outgoing(data);
|
||||
}
|
||||
@@ -101,13 +101,13 @@ void testReference() {
|
||||
destinations.insert({destination.hash(), destination});
|
||||
//for (RNS::Destination& destination : destinations) {
|
||||
for (auto& [hash, destination] : destinations) {
|
||||
TRACE("Iterated destination: " + destination.toString());
|
||||
TRACEF("Iterated destination: %s", destination.toString().c_str());
|
||||
}
|
||||
RNS::Bytes hash = destination.hash();
|
||||
auto iter = destinations.find(hash);
|
||||
if (iter != destinations.end()) {
|
||||
RNS::Destination& destination = (*iter).second;
|
||||
TRACE("Found destination: " + destination.toString());
|
||||
TRACEF("Found destination: %s", destination.toString().c_str());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ public:
|
||||
_name = "(deleted)";
|
||||
}
|
||||
virtual void send_outgoing(const RNS::Bytes &data) {
|
||||
HEAD("OutInterface.send_outgoing: data: " + data.toHex(), RNS::LOG_TRACE);
|
||||
HEADF(RNS::LOG_TRACE, "OutInterface.send_outgoing: data: %s", data.toHex().c_str());
|
||||
|
||||
// Loop data back to InInterface for testing
|
||||
// NOTE: This sends the incoming data directory to RNS::Interface (which relays to Transport)
|
||||
@@ -57,13 +57,13 @@ public:
|
||||
virtual ~ExampleAnnounceHandler() {}
|
||||
virtual void received_announce(const RNS::Bytes& destination_hash, const RNS::Identity& announced_identity, const RNS::Bytes& app_data) {
|
||||
INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
INFO("ExampleAnnounceHandler: destination hash: " + destination_hash.toHex());
|
||||
INFOF("ExampleAnnounceHandler: destination hash: %s", destination_hash.toHex().c_str());
|
||||
if (announced_identity) {
|
||||
INFO("ExampleAnnounceHandler: announced identity hash: " + announced_identity.hash().toHex());
|
||||
INFO("ExampleAnnounceHandler: announced identity app data: " + announced_identity.app_data().toHex());
|
||||
INFOF("ExampleAnnounceHandler: announced identity hash: %s", announced_identity.hash().toHex().c_str());
|
||||
INFOF("ExampleAnnounceHandler: announced identity app data: %s", announced_identity.app_data().toHex().c_str());
|
||||
}
|
||||
if (app_data) {
|
||||
INFO("ExampleAnnounceHandler: app data text: \"" + app_data.toString() + "\"");
|
||||
INFOF("ExampleAnnounceHandler: app data text: \"%s\"", app_data.toString().c_str());
|
||||
}
|
||||
INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
}
|
||||
@@ -77,9 +77,9 @@ RNS::HAnnounceHandler announce_handler(new ExampleAnnounceHandler());
|
||||
//void(*)(const Bytes& data, const Packet& packet)
|
||||
void onPacket(const RNS::Bytes& data, const RNS::Packet& packet) {
|
||||
INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
INFO("onPacket: data: " + data.toHex());
|
||||
INFO("onPacket: text: \"" + data.toString() + "\"");
|
||||
//TRACE("onPacket: " + packet.debugString());
|
||||
INFOF("onPacket: data: %s", data.toHex().c_str());
|
||||
INFOF("onPacket: text: \"%s\"", data.toString().c_str());
|
||||
//TRACEF("onPacket: %s", packet.debugString().c_str());
|
||||
INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
}
|
||||
|
||||
@@ -87,9 +87,9 @@ void onPacket(const RNS::Bytes& data, const RNS::Packet& packet) {
|
||||
//void(*)(const Bytes& data, const Packet& packet)
|
||||
void onPingPacket(const RNS::Bytes& data, const RNS::Packet& packet) {
|
||||
INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
INFO("onPingPacket: data: " + data.toHex());
|
||||
INFO("onPingPacket: text: \"" + data.toString() + "\"");
|
||||
//TRACE("onPingPacket: " + packet.debugString());
|
||||
INFOF("onPingPacket: data: %s", data.toHex().c_str());
|
||||
INFOF("onPingPacket: text: \"%s\"", data.toString().c_str());
|
||||
//TRACEF("onPingPacket: %s", packet.debugString().c_str());
|
||||
INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
}
|
||||
|
||||
|
||||
@@ -23,12 +23,12 @@ public:
|
||||
|
||||
private:
|
||||
virtual void send_outgoing(const RNS::Bytes& data) {
|
||||
DEBUG("TestInterface.send_outgoing: data: " + data.toHex());
|
||||
DEBUGF("TestInterface.send_outgoing: data: %s", data.toHex().c_str());
|
||||
// Perform post-send housekeeping
|
||||
InterfaceImpl::handle_outgoing(data);
|
||||
}
|
||||
void on_incoming(const RNS::Bytes& data) {
|
||||
DEBUG("TestInterface.on_incoming: data: " + data.toHex());
|
||||
DEBUGF("TestInterface.on_incoming: data: %s", data.toHex().c_str());
|
||||
// Pass received data on to transport
|
||||
InterfaceImpl::handle_incoming(data);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ public:
|
||||
ERROR("handle_incoming: bad_alloc - out of memory");
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
ERROR(std::string("handle_incoming: exception: ") + e.what());
|
||||
ERRORF("handle_incoming: exception: %s", e.what());
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -55,7 +55,7 @@ public:
|
||||
ERROR("handle_outgoing: bad_alloc - out of memory");
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
ERROR(std::string("handle_outgoing: exception: ") + e.what());
|
||||
ERRORF("handle_outgoing: exception: %s", e.what());
|
||||
}
|
||||
}
|
||||
private:
|
||||
@@ -133,7 +133,7 @@ void initRNS() {
|
||||
ERROR("initRNS: bad_alloc - out of memory");
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
ERROR(std::string("initRNS: exception: ") + e.what());
|
||||
ERRORF("initRNS: exception: %s", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -538,7 +538,7 @@ void test_incoming_announce_stress() {
|
||||
break;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
ERROR(std::string("test_incoming_announce_stress: exception: ") + e.what());
|
||||
ERRORF("test_incoming_announce_stress: exception: %s", e.what());
|
||||
break;
|
||||
}
|
||||
RNS::Utilities::OS::sleep(0.1);
|
||||
|
||||
Reference in new issue
Block a user