Files

66 lines
2.2 KiB
C++

// native_bridge/debug/test_state_store.cpp
// G2.0 self-check: StateStore save/load/clear round-trip (not part of bridge).
// Build: cl /nologo /EHsc /std:c++17 /I native_bridge/include \
// debug/test_state_store.cpp native_bridge/src/StateStore.cpp
#include "StateStore.h"
#include <cassert>
#include <cstdio>
#include <string>
int main() {
const char* path = "state_roundtrip_test.json";
BridgeStateSnapshot snap;
snap.playing = true;
snap.playhead = 123.456789;
InstrumentStateEntry a;
a.channel = 0; a.type = 0; // VST3
a.path = "C:\\Program Files\\Common Files\\VST3\\Nexus.vst3";
a.presetBase64 = "AB+//w=="; // base64 chars incl + / =
a.bank = 0; a.program = 2;
InstrumentStateEntry b;
b.channel = 3; b.type = 2; // SF2/SF3
b.path = "C:\\sounds\\my bank.sf2";
b.presetBase64 = "line1\nline2\t\"quoted\"\\tail";
b.bank = 1; b.program = 5;
snap.instruments.push_back(a);
snap.instruments.push_back(b);
assert(StateStore::save(snap, path));
// Atomic write: no .tmp leftover after save.
FILE* tmp = std::fopen((std::string(path) + ".tmp").c_str(), "rb");
assert(tmp == nullptr);
if (tmp) std::fclose(tmp);
BridgeStateSnapshot out;
assert(StateStore::load(out, path));
assert(out.playing == true);
assert(out.playhead == 123.456789);
assert(out.instruments.size() == 2);
assert(out.instruments[0].channel == 0);
assert(out.instruments[0].type == 0);
assert(out.instruments[0].path == "C:\\Program Files\\Common Files\\VST3\\Nexus.vst3");
assert(out.instruments[0].presetBase64 == "AB+//w==");
assert(out.instruments[0].bank == 0 && out.instruments[0].program == 2);
assert(out.instruments[1].channel == 3);
assert(out.instruments[1].type == 2);
assert(out.instruments[1].path == "C:\\sounds\\my bank.sf2");
assert(out.instruments[1].presetBase64 == "line1\nline2\t\"quoted\"\\tail");
assert(out.instruments[1].bank == 1 && out.instruments[1].program == 5);
// Missing file -> load false, no crash.
assert(!StateStore::load(out, "no_such_file.json"));
// clear removes the file.
assert(StateStore::clear(path));
assert(!StateStore::load(out, path));
std::printf("state_store round-trip PASS\n");
return 0;
}