upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/tests/unit/test_display.c
diff options
context:
space:
mode:
authorYour Name <you@example.com>2026-05-19 04:10:12 +0530
committerYour Name <you@example.com>2026-05-19 04:10:12 +0530
commit2d78aadfd603fab9a9342b1281ad1d46ad82cf1d (patch)
tree3e8875b7e0301ac6634548e186542e2d67a68f34 /tests/unit/test_display.c
parentabee221b0f0e5a4513ab126afbdfddc2728df6be (diff)
feat: relay hardening — restore build, add tests, negentropy adapter
Restores build broken by eeb9d2d (cvm-relay-stability removed deps): - CMakeLists.txt: restore display.c, font.c, local_relay.c, relay_selector.c, sync_manager.c, axs15231b, qrcode, wisp_relay - tollgate_main.c: restore display.h, local_relay.h, relay_selector.h, sync_manager.h includes and display calls - cvm_server.c: kept master's keepalive/timeout/ping-pong fixes New test infrastructure: - test-local-relay, test-relay-nip11, test-cvm-roundtrip, test-cvm-mcp, test-cross-board make targets - test-cvm-roundtrip.mjs: MCP get_config + get_balance via public relay - test-cross-board.mjs: cross-board payment test - test-cvm-mcp-relay.mjs: kept from master New unit tests (35 tests): - test_display.c: 22 tests for escape_wifi_field - test_negentropy_adapter.c: 13 tests for negentropy adapter New modules: - negentropy_adapter.c/h: NIP-77 adapter skeleton Docs: - AGENTS.md: display module docs, new test commands - RELAY_HARDENING_PLAN.md: hardening checklist - RELAY_HARDENING_MERGE.md: merge plan and checklist Cleanup: - Removed CHECKLIST-CVM-RELAY.md, PLAN-SQUASH-MERGE.md (stale planning docs) - Removed components/esp-miner submodule Host unit tests: 63/63 pass
Diffstat (limited to 'tests/unit/test_display.c')
-rw-r--r--tests/unit/test_display.c128
1 files changed, 128 insertions, 0 deletions
diff --git a/tests/unit/test_display.c b/tests/unit/test_display.c
new file mode 100644
index 0000000..81f67a7
--- /dev/null
+++ b/tests/unit/test_display.c
@@ -0,0 +1,128 @@
1#include "test_framework.h"
2#include <string.h>
3#include <stdio.h>
4
5static int escape_wifi_field(const char *src, char *dst, int dst_size) {
6 int si = 0, di = 0;
7 while (src[si] && di < dst_size - 2) {
8 char c = src[si];
9 if (c == '\\' || c == ';' || c == ':' || c == ',' || c == '"') {
10 if (di + 2 >= dst_size) break;
11 dst[di++] = '\\';
12 dst[di++] = c;
13 } else {
14 dst[di++] = c;
15 }
16 si++;
17 }
18 dst[di] = '\0';
19 return di;
20}
21
22static int test_escape_no_special(void) {
23 char dst[64];
24 int len = escape_wifi_field("HelloWorld", dst, sizeof(dst));
25 ASSERT(strcmp(dst, "HelloWorld") == 0, "no special chars unchanged");
26 ASSERT(len == 10, "no special chars length correct");
27 return 0;
28}
29
30static int test_escape_semicolon(void) {
31 char dst[64];
32 int len = escape_wifi_field("Hello;World", dst, sizeof(dst));
33 ASSERT(strcmp(dst, "Hello\\;World") == 0, "semicolon escaped");
34 ASSERT(len == 12, "semicolon escaped length correct");
35 return 0;
36}
37
38static int test_escape_colon(void) {
39 char dst[64];
40 int len = escape_wifi_field("Hello:World", dst, sizeof(dst));
41 ASSERT(strcmp(dst, "Hello\\:World") == 0, "colon escaped");
42 ASSERT(len == 12, "colon escaped length correct");
43 return 0;
44}
45
46static int test_escape_backslash(void) {
47 char dst[64];
48 int len = escape_wifi_field("Hello\\World", dst, sizeof(dst));
49 ASSERT(strcmp(dst, "Hello\\\\World") == 0, "backslash escaped");
50 ASSERT(len == 12, "backslash escaped length correct");
51 return 0;
52}
53
54static int test_escape_comma(void) {
55 char dst[64];
56 int len = escape_wifi_field("Hello,World", dst, sizeof(dst));
57 ASSERT(strcmp(dst, "Hello\\,World") == 0, "comma escaped");
58 ASSERT(len == 12, "comma escaped length correct");
59 return 0;
60}
61
62static int test_escape_quote(void) {
63 char dst[64];
64 int len = escape_wifi_field("Hello\"World", dst, sizeof(dst));
65 ASSERT(strcmp(dst, "Hello\\\"World") == 0, "quote escaped");
66 ASSERT(len == 12, "quote escaped length correct");
67 return 0;
68}
69
70static int test_escape_multiple(void) {
71 char dst[64];
72 int len = escape_wifi_field("a;b:c\\d", dst, sizeof(dst));
73 ASSERT(strcmp(dst, "a\\;b\\:c\\\\d") == 0, "multiple special chars escaped");
74 ASSERT(len == 10, "multiple special chars length correct");
75 return 0;
76}
77
78static int test_escape_empty(void) {
79 char dst[64];
80 int len = escape_wifi_field("", dst, sizeof(dst));
81 ASSERT(strcmp(dst, "") == 0, "empty string stays empty");
82 ASSERT(len == 0, "empty string length is 0");
83 return 0;
84}
85
86static int test_escape_overflow(void) {
87 char dst[5];
88 int len = escape_wifi_field("Hello;World", dst, sizeof(dst));
89 ASSERT(len < (int)sizeof(dst), "output truncated on overflow");
90 ASSERT(dst[len] == '\0', "still null-terminated after truncation");
91 return 0;
92}
93
94static int test_escape_ssid_like(void) {
95 char dst[64];
96 int len = escape_wifi_field("TollGate-C0E9CA", dst, sizeof(dst));
97 ASSERT(strcmp(dst, "TollGate-C0E9CA") == 0, "TollGate SSID no escaping needed");
98 ASSERT(len == 15, "TollGate SSID length correct");
99 return 0;
100}
101
102static int test_escape_all_special_in_one(void) {
103 char dst[64];
104 int len = escape_wifi_field("\\;:,\"", dst, sizeof(dst));
105 ASSERT(strcmp(dst, "\\\\\\;\\:\\,\\\"") == 0, "all special chars in sequence");
106 ASSERT(len == 10, "all special chars length correct");
107 return 0;
108}
109
110int main(void) {
111 int failed = 0;
112 failed += test_escape_no_special();
113 failed += test_escape_semicolon();
114 failed += test_escape_colon();
115 failed += test_escape_backslash();
116 failed += test_escape_comma();
117 failed += test_escape_quote();
118 failed += test_escape_multiple();
119 failed += test_escape_empty();
120 failed += test_escape_overflow();
121 failed += test_escape_ssid_like();
122 failed += test_escape_all_special_in_one();
123
124 if (failed == 0) {
125 printf("\n=== ALL DISPLAY TESTS PASSED ===\n");
126 }
127 return failed;
128}