From 2e8afa446f2444a8be5e6180bf90cfa48b6e02f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Wed, 17 Aug 2022 03:15:37 +0200 Subject: Add CfgA. --- c/test.cpp | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) (limited to 'c/test.cpp') diff --git a/c/test.cpp b/c/test.cpp index 84e0631..b8cf20a 100644 --- a/c/test.cpp +++ b/c/test.cpp @@ -1,10 +1,15 @@ #include "data.h" -#include "test.h" +#include "episodelistview.h" #include "pl.h" #include "util.h" #include "win.h" -Test::Test(const char* name_) : name(name_) {} +struct Test +{ + const char* name = {0}; + char error[64] = {0}; + Test(const char* name) : name(name) {} +}; #define CAT(a, b) a##b #define APPLY(a, ...) a(__VA_ARGS__) @@ -53,11 +58,16 @@ TESTS ElvDataA e1_0, e2_0; FromProlog(6, e1_0); FromProlog(10, e2_0); + + /* Write two ElvDataA structs to disk. */ { FileView fv{L"tmp.dat", 2}; memcpy(fv+0, &e1_0, sizeof(e1_0)); memcpy(fv+1, &e2_0, sizeof(e2_0)); } + + /* Read first ElvDataA struct from disk using + * ElvDataA-typed FileView. */ { FileView fv{L"tmp.dat", 2}; const ElvDataA& e1 = *fv; @@ -76,6 +86,9 @@ TESTS if (wcscmp(e1_0.title, e1.title) != 0) FAIL("title is different"); } + + /* Read second ElvDataA struct from disk using + * unsigned char-typed FileView. */ { FileView fv{L"tmp.dat", 2*sizeof(ElvDataA)}; ElvDataA& e2 = *reinterpret_cast(&fv.At(sizeof(ElvDataA))); @@ -102,7 +115,7 @@ TESTS return; { - FileView fv{L"tmp.dat", 8192}; + FileView fv{L"tmp.dat", ELVMAX}; ElvDataA* p = fv; for (int iEp = 1; iEp <= cEp; iEp++) { @@ -120,6 +133,25 @@ TESTS } //DeleteFile(L"tmp.dat"); } + + TEST(SampleConfigurationToDisk) + { + CfgA cfg_0; + { + FileView fv{L"tmp.dat", 1}; + Wcscpy(cfg_0.url, L"https://animixplay.to/v1/detective-conan/ep"); + memcpy(fv, &cfg_0, sizeof(cfg_0)); + } + { + FileView fv{L"tmp.dat", 1}; + const CfgA& cfg = fv.At(0); + if (cfg_0.bViewWatched != cfg.bViewWatched) + FAIL("bViewWatched is different"); + if (wcscmp(cfg_0.url, cfg.url) != 0) + FAIL("url is not correct"); + } + //DeleteFile(L"tmp.dat"); + } }; int RunTests() @@ -130,6 +162,7 @@ int RunTests() EpisodeDataFromProlog{}, IO{}, //MigrateElvDataFromPrologToDisk{}, + SampleConfigurationToDisk{}, }; printf("Results (%llu tests):\n", sizeof(tests)/sizeof(*tests)); -- cgit v1.2.3