Files
onionHEN/source/util/tests/test_platform_log.c
T
Hexwell 2c455c1eb6 test: expand host unit coverage for platform, ready flags, and IPC
Add suites for liborion_platform (fs/log/notify), richer settings and ready
flag cases, and msg.hpp protocol ordinals. Link real platform sources under
ORION_HOST_TEST; fix DaemonCommands to unsigned so high-bit opcodes are
well-formed. Rename host binary to orion-host-tests.
2026-07-10 15:42:32 +08:00

49 lines
1.2 KiB
C

/* Host tests for liborion_platform OrionHEN_log / configure. */
#include "test_harness.h"
#include <orion/log.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
static int test_log_file_sink(void) {
char tmpl[] = "/tmp/orion-log-XXXXXX";
int fd = mkstemp(tmpl);
TEST_ASSERT_TRUE(fd >= 0);
close(fd);
unlink(tmpl); /* log open will create */
orion_log_configure("HostTest", tmpl);
OrionHEN_log("hello %d", 42);
FILE *f = fopen(tmpl, "r");
TEST_ASSERT_TRUE(f != NULL);
char buf[256];
size_t n = fread(buf, 1, sizeof(buf) - 1, f);
fclose(f);
buf[n] = '\0';
TEST_ASSERT_TRUE(strstr(buf, "hello 42") != NULL);
TEST_ASSERT_TRUE(strchr(buf, '\n') != NULL);
unlink(tmpl);
/* disable file sink for later suites */
orion_log_configure("OrionHEN", NULL);
return 0;
}
static int test_log_configure_tag_only(void) {
orion_log_configure("TagOnly", NULL);
/* no file sink — should not crash */
OrionHEN_log("silent-ish");
orion_log_configure("OrionHEN", NULL);
return 0;
}
int test_platform_log_suite(void) {
int failures = 0;
failures += orion_test_run("log_file_sink", test_log_file_sink);
failures += orion_test_run("log_configure_tag_only", test_log_configure_tag_only);
return failures;
}