aboutsummaryrefslogtreecommitdiff
path: root/c/test.cpp
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-08-17 03:15:37 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-08-17 03:15:37 +0200
commit2e8afa446f2444a8be5e6180bf90cfa48b6e02f0 (patch)
tree2ad81de172861419f16da8d4dd53074f80bd455d /c/test.cpp
parentbd857d24443b8c8f5d2f58047c3f8ac5f058acea (diff)
downloadEpisodeBrowser-2e8afa446f2444a8be5e6180bf90cfa48b6e02f0.tar.gz
Add CfgA.
Diffstat (limited to 'c/test.cpp')
-rw-r--r--c/test.cpp39
1 files changed, 36 insertions, 3 deletions
diff --git a/c/test.cpp b/c/test.cpp
index 84e0631..b8cf20a 100644
--- a/c/test.cpp
+++ b/c/test.cpp
@@ -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));