aboutsummaryrefslogtreecommitdiff
path: root/c/test.cpp
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-08-16 13:42:11 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-08-16 13:42:11 +0200
commit1cb00589065fd05b8d7cf0030eed84c488e9634d (patch)
treef6054ff80e8c87d8a4b7a53dbfced30f05dd6dd2 /c/test.cpp
parent5095c2e2ba9aadf468514804fb3a872d10fdc17d (diff)
downloadEpisodeBrowser-1cb00589065fd05b8d7cf0030eed84c488e9634d.tar.gz
Avoid serialization.
A great benefit of this is that the program doesn't need to COPY the data from the file view to the struct.
Diffstat (limited to 'c/test.cpp')
-rw-r--r--c/test.cpp57
1 files changed, 14 insertions, 43 deletions
diff --git a/c/test.cpp b/c/test.cpp
index fb5d44d..abb03b3 100644
--- a/c/test.cpp
+++ b/c/test.cpp
@@ -47,59 +47,31 @@ TESTS
FAIL("date is not correct");
}
- TEST(Serialization)
- {
- ElvData e1;
- FromProlog(6, e1);
-
- unsigned char buf[CB_SERIALIZE_ELVDATA];
- Serialize(e1, buf);
-
- ElvData e2;
- if (!Unserialize(e2, buf))
- FAIL("invalid serialization version");
- if (e1.rating != e2.rating)
- FAIL("rating is different");
- if (e1.bWatched != e2.bWatched)
- FAIL("bWatched is different");
- if (e1.bTVOriginal != e2.bTVOriginal)
- FAIL("bTVOriginal is different");
- if (wcscmp(e1.sRating, e2.sRating) != 0)
- FAIL("sRating is different");
- if (wcscmp(e1.siEp, e2.siEp) != 0)
- FAIL("siEp is different");
- if (wcscmp(e1.title, e2.title) != 0)
- FAIL("title is different");
- }
-
- TEST(SerializationPlusIO)
+ TEST(IO)
{
ElvData e1;
FromProlog(6, e1);
{
- DatView dv{L"tmp.dat", CB_SERIALIZE_ELVDATA};
- Serialize(e1, static_cast<unsigned char*>(dv.view));
+ FileView fv{L"tmp.dat", sizeof(e1)};
+ Write(fv, e1);
}
{
- DatView dv{L"tmp.dat", CB_SERIALIZE_ELVDATA};
-
- ElvData e2;
- if (!Unserialize(e2, static_cast<unsigned char*>(dv.view)))
- FAIL("invalid serialization version");
- if (e1.rating != e2.rating)
- FAIL("rating is different");
- if (e1.bWatched != e2.bWatched)
+ 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)
FAIL("bWatched is different");
- if (e1.bTVOriginal != e2.bTVOriginal)
+ if (e1.bTVOriginal != e2->bTVOriginal)
FAIL("bTVOriginal is different");
- if (wcscmp(e1.sRating, e2.sRating) != 0)
+ if (wcscmp(e1.sRating, e2->sRating) != 0)
FAIL("sRating is different");
- if (wcscmp(e1.siEp, e2.siEp) != 0)
+ if (wcscmp(e1.siEp, e2->siEp) != 0)
FAIL("siEp is different");
- if (wcscmp(e1.title, e2.title) != 0)
+ if (wcscmp(e1.title, e2->title) != 0)
FAIL("title is different");
}
- DeleteFile(L"tmp.dat");
+ //DeleteFile(L"tmp.dat");
}
};
@@ -109,8 +81,7 @@ int RunTests()
StrcpyWithSmallerDestination{},
//EpisodeDataFromWeb{},
EpisodeDataFromProlog{},
- Serialization{},
- SerializationPlusIO{},
+ IO{},
};
printf("Results (%llu tests):\n", sizeof(tests)/sizeof(*tests));