From ab621173afc918797a4ea68b5d6ceee7cc043f72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Tue, 16 Aug 2022 15:24:24 +0200 Subject: Add data migration test. --- c/test.cpp | 81 +++++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 64 insertions(+), 17 deletions(-) (limited to 'c/test.cpp') diff --git a/c/test.cpp b/c/test.cpp index abb03b3..9402eed 100644 --- a/c/test.cpp +++ b/c/test.cpp @@ -1,5 +1,6 @@ #include "data.h" #include "test.h" +#include "pl.h" #include "util.h" #include "win.h" @@ -26,8 +27,8 @@ TESTS TEST(EpisodeDataFromWeb) { - ElvData e; - DlvData d; + ElvDataA e; + DlvDataA d; FromWeb(10, e, d); if (wcscmp(e.title, L"Pro Soccer Player Blackmail Case") != 0) FAIL("title is not correct"); @@ -37,8 +38,8 @@ TESTS TEST(EpisodeDataFromProlog) { - ElvData e; - DlvData d; + ElvDataA e; + DlvDataA d; FromProlog(10, e); FromProlog(10, d); if (wcscmp(e.title, L"Pro Soccer Player Blackmail Case") != 0) @@ -49,28 +50,73 @@ TESTS TEST(IO) { - ElvData e1; - FromProlog(6, e1); + ElvDataA e1_0, e2_0; + FromProlog(6, e1_0); + FromProlog(10, e2_0); { - FileView fv{L"tmp.dat", sizeof(e1)}; - Write(fv, e1); + FileView fv{L"tmp.dat", sizeof(ElvDataA)*2}; + Write(fv, e1_0); + Write(fv+sizeof(ElvDataA), e2_0); } { - FileView fv{L"tmp.dat", sizeof(e1)}; - ElvData* e2 = Read(fv); - if (e1.rating != e2->rating) - FAIL("rating is different (%d/%d)", e1.rating, e2->rating); - if (e1.bWatched != e2->bWatched) + FileView fv{L"tmp.dat", sizeof(ElvDataA)}; + ElvDataA* e1 = Read(fv); + if (e1_0.rating != e1->rating) + FAIL("rating is different (%d/%d)", e1_0.rating, e1->rating); + if (e1_0.bWatched != e1->bWatched) FAIL("bWatched is different"); - if (e1.bTVOriginal != e2->bTVOriginal) + if (e1_0.bTVOriginal != e1->bTVOriginal) FAIL("bTVOriginal is different"); - if (wcscmp(e1.sRating, e2->sRating) != 0) + if (wcscmp(e1_0.sRating, e1->sRating) != 0) FAIL("sRating is different"); - if (wcscmp(e1.siEp, e2->siEp) != 0) + if (wcscmp(e1_0.siEp, e1->siEp) != 0) FAIL("siEp is different"); - if (wcscmp(e1.title, e2->title) != 0) + if (wcscmp(e1_0.title, e1->title) != 0) FAIL("title is different"); } + { + FileView fv{L"tmp.dat", sizeof(ElvDataA)*2}; + ElvDataA* e2 = Read(fv+sizeof(ElvDataA)); + if (e2_0.rating != e2->rating) + FAIL("rating is different (%d/%d)", e2_0.rating, e2->rating); + if (e2_0.bWatched != e2->bWatched) + FAIL("bWatched is different"); + if (e2_0.bTVOriginal != e2->bTVOriginal) + FAIL("bTVOriginal is different"); + if (wcscmp(e2_0.sRating, e2->sRating) != 0) + FAIL("sRating is different"); + if (wcscmp(e2_0.siEp, e2->siEp) != 0) + FAIL("siEp is different"); + if (wcscmp(e2_0.title, e2->title) != 0) + FAIL("title is different"); + } + //DeleteFile(L"tmp.dat"); + } + + TEST(MigrateElvDataFromPrologToDisk) + { + int cEp; + if (!Pl("episode_data","episode_count",&cEp)) + return; + + { + FileView fv{L"tmp.dat", sizeof(ElvDataA)*cEp}; + unsigned char* p = fv; + + for (int iEp = 1; iEp <= cEp; iEp++) { + ElvDataA e; + FromProlog(iEp, e); + Write(p, e); + p += sizeof(e); + } + } + { + FileView fv{L"tmp.dat", sizeof(ElvDataA)*cEp}; + ElvDataA* ve = reinterpret_cast(fv.view); + ElvDataA e = ve[9]; + if (wcscmp(e.title, L"Pro Soccer Player Blackmail Case") != 0) + FAIL("title is not correct"); + } //DeleteFile(L"tmp.dat"); } }; @@ -82,6 +128,7 @@ int RunTests() //EpisodeDataFromWeb{}, EpisodeDataFromProlog{}, IO{}, + MigrateElvDataFromPrologToDisk{}, }; printf("Results (%llu tests):\n", sizeof(tests)/sizeof(*tests)); -- cgit v1.2.3