mirror of
https://github.com/mikecarper/MeshCore.git
synced 2026-11-04 19:07:41 +00:00
Fix release size regressions and calibration test fixtures
This commit is contained in:
1 parent
ab6412e73c
commit
2d35a291fa
46 files changed
+1048
-373
No files matched your search
@@ -1,5 +1,6 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <array>
|
||||
#include <string>
|
||||
|
||||
#include <helpers/CLICommandUtils.h>
|
||||
@@ -27,6 +28,48 @@ TEST(CLICommandUtils, LabelsInboundDirectRouteAsRouted) {
|
||||
EXPECT_STREQ("FLOOD", mesh::cli::terminalInboundRouteLabel(false));
|
||||
}
|
||||
|
||||
TEST(CLICommandUtils, FormatErrorKeepsMessagePercentCharactersLiteral) {
|
||||
char reply[160];
|
||||
mesh::cli::formatError(reply, sizeof(reply), "use 50%-150%; literal %s %n %%");
|
||||
EXPECT_STREQ("Error: use 50%-150%; literal %s %n %%", reply);
|
||||
mesh::cli::formatError(reply, sizeof(reply), "");
|
||||
EXPECT_STREQ("Error: ", reply);
|
||||
}
|
||||
|
||||
TEST(CLICommandUtils, FormatErrorTruncatesAtEveryCapacityWithoutTouchingGuards) {
|
||||
const char* message = "reference 50%-150% of reading; retain %s literally";
|
||||
const std::string expected = std::string("Error: ") + message;
|
||||
std::array<char, 160> storage;
|
||||
for (size_t capacity = 0; capacity <= expected.size() + 2; ++capacity) {
|
||||
SCOPED_TRACE(capacity);
|
||||
storage.fill('@');
|
||||
char* reply = storage.data() + 1;
|
||||
mesh::cli::formatError(reply, capacity, message);
|
||||
EXPECT_EQ('@', storage.front());
|
||||
EXPECT_EQ(std::string(storage.size() - 1 - capacity, '@'),
|
||||
std::string(reply + capacity, storage.size() - 1 - capacity));
|
||||
if (capacity == 0) continue;
|
||||
const size_t length = expected.size() < capacity ? expected.size() : capacity - 1;
|
||||
EXPECT_EQ(expected.substr(0, length), std::string(reply));
|
||||
EXPECT_EQ('\0', reply[length]);
|
||||
}
|
||||
// snprintf also permits a null destination when the capacity is zero.
|
||||
mesh::cli::formatError(nullptr, 0, message);
|
||||
}
|
||||
|
||||
TEST(CLICommandUtils, FormatErrorHonorsFull160ByteReplyBoundary) {
|
||||
const std::string message = std::string(180, 'x') + "%n";
|
||||
const std::string expected = std::string("Error: ") + message;
|
||||
std::array<char, 162> storage;
|
||||
storage.fill('@');
|
||||
char* reply = storage.data() + 1;
|
||||
mesh::cli::formatError(reply, 160, message.c_str());
|
||||
EXPECT_EQ(expected.substr(0, 159), std::string(reply));
|
||||
EXPECT_EQ('\0', reply[159]);
|
||||
EXPECT_EQ('@', storage.front());
|
||||
EXPECT_EQ('@', storage.back());
|
||||
}
|
||||
|
||||
TEST(TerminalDisplayFilter, UsesQuietDefaultsWithEmergencyVisible) {
|
||||
mesh::TerminalDisplayFilter filter;
|
||||
|
||||
|
||||
Reference in new issue
Block a user