- DucielPerf addon embedded in the DLL (always served, listed in the addon list): minimap button and /ducielperf (/dperf) open a window with Performance, Diagnostics, Features (module switches, world markers on me/target/clear, interact key bindings, loot all corpses) and Status tabs. - settings.cpp: one table of every ducielperf.cfg setting with live apply where possible; DucielPerf_SettingInfo / GetSetting / SetSetting. config_set_int writes ducielperf.cfg keeping comments and other keys. - Live switches: decompression, file cache, Lua strings, SavedVariables buffering, frame raising and clickthrough keep their hooks and call the client's code while off. New keys: inflate, filecache, luastrings, alloctrack, worldmarkers, interact, clickthrough, transmogfix, exitfix, minimap, minimap_angle. - Tests: test_config (cfg writing), test_addon (the addon on a mock WoW API in Lua 5.0). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
65 lines
2.5 KiB
C++
65 lines
2.5 KiB
C++
// Test for ducielperf.cfg writing (config_set_int in src/core/core.cpp).
|
|
// The config lives next to the running .exe, so this writes
|
|
// build/tests/ducielperf.cfg: comments, unknown keys and other settings must
|
|
// survive, duplicates collapse to one line, new keys are appended, and
|
|
// config_int reads back what was written.
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <windows.h>
|
|
|
|
#include "../src/core/core.h"
|
|
|
|
static int g_failures;
|
|
static void check(const char *what, bool ok) {
|
|
printf(" %-60s %s\n", what, ok ? "ok" : "FAIL");
|
|
if (!ok) g_failures++;
|
|
}
|
|
|
|
static char g_path[MAX_PATH];
|
|
|
|
static void writeFile(const char *text) {
|
|
FILE *f = fopen(g_path, "wb");
|
|
fputs(text, f);
|
|
fclose(f);
|
|
}
|
|
|
|
static void readFile(char *out, size_t n) {
|
|
FILE *f = fopen(g_path, "rb");
|
|
size_t len = f ? fread(out, 1, n - 1, f) : 0;
|
|
out[len] = 0;
|
|
if (f) fclose(f);
|
|
}
|
|
|
|
int main() {
|
|
printf("test_config\n");
|
|
GetModuleFileNameA(nullptr, g_path, MAX_PATH);
|
|
strcpy(strrchr(g_path, '\\') + 1, "ducielperf.cfg");
|
|
|
|
writeFile("# my settings\r\nframestats=1\r\n watchdog = 1\r\nwatchdog_ms=150\r\nwatchdog=0\r\nunknown_key=7\r\n"
|
|
"; another comment\r\ngcdefer_mb=128");
|
|
check("reads the last line for a key (as before)", config_int("watchdog", 5) == 0);
|
|
|
|
check("set watchdog=1", config_set_int("watchdog", 1));
|
|
char buf[1024];
|
|
readFile(buf, sizeof buf);
|
|
check("comments and other keys kept",
|
|
strstr(buf, "# my settings") && strstr(buf, "; another comment") && strstr(buf, "unknown_key=7") &&
|
|
strstr(buf, "framestats=1") && strstr(buf, "watchdog_ms=150"));
|
|
const char *first = strstr(buf, "watchdog=1");
|
|
check("one watchdog line, in place of the first", first && !strstr(first + 1, "watchdog=") &&
|
|
first < strstr(buf, "watchdog_ms"));
|
|
check("watchdog_ms not mistaken for watchdog", config_int("watchdog_ms", 0) == 150);
|
|
check("last line without newline kept", config_int("gcdefer_mb", 0) == 128);
|
|
check("read back", config_int("watchdog", 5) == 1);
|
|
|
|
check("new key appended", config_set_int("framelevel", 0) && config_int("framelevel", 1) == 0);
|
|
check("negative and large values", config_set_int("minimap_angle", 359) && config_int("minimap_angle", 0) == 359);
|
|
|
|
DeleteFileA(g_path);
|
|
check("works without a file", config_set_int("inflate", 0) && config_int("inflate", 1) == 0);
|
|
DeleteFileA(g_path);
|
|
|
|
printf(g_failures ? "test_config: %d FAILED\n" : "test_config: all passed\n", g_failures);
|
|
return g_failures ? 1 : 0;
|
|
}
|