aboutsummaryrefslogtreecommitdiff
path: root/c/test.cpp
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-08-17 02:33:26 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-08-17 02:33:26 +0200
commitbd857d24443b8c8f5d2f58047c3f8ac5f058acea (patch)
tree0ef5f3c9abf5ccd6ee6a9e376ceac985de2409fd /c/test.cpp
parent8351d4c42c76584415e02a40d41f497a8f042c72 (diff)
downloadEpisodeBrowser-bd857d24443b8c8f5d2f58047c3f8ac5f058acea.tar.gz
Make FileView more type-safe.
Diffstat (limited to 'c/test.cpp')
-rw-r--r--c/test.cpp59
1 files changed, 30 insertions, 29 deletions
diff --git a/c/test.cpp b/c/test.cpp
index cecc408..84e0631 100644
--- a/c/test.cpp
+++ b/c/test.cpp
@@ -54,40 +54,42 @@ TESTS
FromProlog(6, e1_0);
FromProlog(10, e2_0);
{
- FileView fv{L"tmp.dat", sizeof(ElvDataA)*2};
- Write(fv, e1_0);
- Write(reinterpret_cast<unsigned char*>(static_cast<ElvDataA*>(fv)+1), e2_0);
+ FileView<ElvDataA> fv{L"tmp.dat", 2};
+ memcpy(fv+0, &e1_0, sizeof(e1_0));
+ memcpy(fv+1, &e2_0, sizeof(e2_0));
}
{
- 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)
+ FileView<ElvDataA> fv{L"tmp.dat", 2};
+ const ElvDataA& e1 = *fv;
+ if (e1.version != 'a')
+ FAIL("version is different");
+ 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_0.bTVOriginal != e1->bTVOriginal)
+ if (e1_0.bTVOriginal != e1.bTVOriginal)
FAIL("bTVOriginal is different");
- if (wcscmp(e1_0.sRating, e1->sRating) != 0)
+ if (wcscmp(e1_0.sRating, e1.sRating) != 0)
FAIL("sRating is different");
- if (wcscmp(e1_0.siEp, e1->siEp) != 0)
+ if (wcscmp(e1_0.siEp, e1.siEp) != 0)
FAIL("siEp is different");
- if (wcscmp(e1_0.title, e1->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(reinterpret_cast<unsigned char*>(static_cast<ElvDataA*>(fv)+1));
- if (e2_0.rating != e2->rating)
- FAIL("rating is different (%d/%d)", e2_0.rating, e2->rating);
- if (e2_0.bWatched != e2->bWatched)
+ FileView<unsigned char> fv{L"tmp.dat", 2*sizeof(ElvDataA)};
+ ElvDataA& e2 = *reinterpret_cast<ElvDataA*>(&fv.At(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)
+ if (e2_0.bTVOriginal != e2.bTVOriginal)
FAIL("bTVOriginal is different");
- if (wcscmp(e2_0.sRating, e2->sRating) != 0)
+ if (wcscmp(e2_0.sRating, e2.sRating) != 0)
FAIL("sRating is different");
- if (wcscmp(e2_0.siEp, e2->siEp) != 0)
+ if (wcscmp(e2_0.siEp, e2.siEp) != 0)
FAIL("siEp is different");
- if (wcscmp(e2_0.title, e2->title) != 0)
+ if (wcscmp(e2_0.title, e2.title) != 0)
FAIL("title is different");
}
//DeleteFile(L"tmp.dat");
@@ -100,20 +102,19 @@ TESTS
return;
{
- FileView fv{L"tmp.dat", sizeof(ElvDataA)*8192};
- unsigned char* p = fv;
+ FileView<ElvDataA> fv{L"tmp.dat", 8192};
+ ElvDataA* p = fv;
for (int iEp = 1; iEp <= cEp; iEp++) {
ElvDataA e;
FromProlog(iEp, e);
- Write(p, e);
- p += sizeof(e);
+ memcpy(p, &e, sizeof(e));
+ p++;
}
}
{
- FileView fv{L"tmp.dat", sizeof(ElvDataA)*8192};
- ElvDataA* ve = reinterpret_cast<ElvDataA*>(fv.view);
- ElvDataA& e = ve[9];
+ FileView<ElvDataA> fv{L"tmp.dat", 8192};
+ ElvDataA& e = fv.At(9);
if (wcscmp(e.title, L"Pro Soccer Player Blackmail Case") != 0)
FAIL("title is not correct");
}
@@ -128,7 +129,7 @@ int RunTests()
//EpisodeDataFromWeb{},
EpisodeDataFromProlog{},
IO{},
- MigrateElvDataFromPrologToDisk{},
+ //MigrateElvDataFromPrologToDisk{},
};
printf("Results (%llu tests):\n", sizeof(tests)/sizeof(*tests));