diff options
author | John Ankarström <john@ankarstrom.se> | 2022-08-16 15:24:24 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2022-08-16 15:24:24 +0200 |
commit | ab621173afc918797a4ea68b5d6ceee7cc043f72 (patch) | |
tree | e347f9ff7b8139851e69a84b58717a93e957ab92 /c/test.cpp | |
parent | 1cb00589065fd05b8d7cf0030eed84c488e9634d (diff) | |
download | EpisodeBrowser-ab621173afc918797a4ea68b5d6ceee7cc043f72.tar.gz |
Add data migration test.
Diffstat (limited to 'c/test.cpp')
-rw-r--r-- | c/test.cpp | 81 |
1 files changed, 64 insertions, 17 deletions
@@ -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<ElvDataA*>(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)); |