diff options
Diffstat (limited to 'c/test.cpp')
-rw-r--r-- | c/test.cpp | 39 |
1 files changed, 36 insertions, 3 deletions
@@ -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<ElvDataA> 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<ElvDataA> 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<unsigned char> fv{L"tmp.dat", 2*sizeof(ElvDataA)}; ElvDataA& e2 = *reinterpret_cast<ElvDataA*>(&fv.At(sizeof(ElvDataA))); @@ -102,7 +115,7 @@ TESTS return; { - FileView<ElvDataA> fv{L"tmp.dat", 8192}; + FileView<ElvDataA> 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<CfgA> 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<CfgA> 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)); |