aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-08-18 02:19:24 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-08-18 02:19:24 +0200
commit6faacc212ea17f98f3a1d26499d9a317208b9a0a (patch)
treee2b1a1f9aa4eff88c638778c7ed9b2bc970e6168
parent5be94abdbb48cf0aeefe1e55048c90cd065c1486 (diff)
downloadEpisodeBrowser-6faacc212ea17f98f3a1d26499d9a317208b9a0a.tar.gz
Experiment with Wininet.
The plan is to fetch remote episode data in C++ instead of Prolog. Wininet seems to be sufficient for fetching the HTML, but I'm still not sure how the HTML is best parsed.
-rw-r--r--c/test.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/c/test.cpp b/c/test.cpp
index 4de5578..8d43a46 100644
--- a/c/test.cpp
+++ b/c/test.cpp
@@ -1,3 +1,6 @@
+#include <windows.h>
+#include <wininet.h>
+
#include "data.h"
#include "episodelistview.h"
#include "pl.h"
@@ -219,6 +222,32 @@ TESTS
extern CfgA& g_cfg;
g_cfg.cEp = i;
}
+
+ TEST(Internet)
+ {
+ HINTERNET hi, hiUrl;
+ unsigned char buf[2048];
+ DWORD cbRead;
+
+ hi = InternetOpen(L"Episode Browser",
+ INTERNET_OPEN_TYPE_DIRECT, nullptr, nullptr,
+ /*INTERNET_FLAG_ASYNC*/0);
+ if (!hi)
+ goto a;
+
+ hiUrl = InternetOpenUrl(hi, L"https://www.detectiveconanworld.com/wiki/Anime",
+ nullptr, 0, INTERNET_FLAG_NO_UI, 0);
+ if (!hiUrl)
+ goto b;
+
+ if (!InternetReadFile(hiUrl, &buf, sizeof(buf), &cbRead))
+ goto c;
+
+ return;
+ c: InternetCloseHandle(hiUrl);
+ b: InternetCloseHandle(hi);
+ a: FAIL(Win32Error{}.what());
+ }
};
int RunTests()
@@ -233,6 +262,7 @@ int RunTests()
//MigrateCfg{}
//MigrateDlvDataFromPrologToDisk{},
//DownloadData{},
+ Internet{},
};
printf("Results (%llu tests):\n", sizeof(tests)/sizeof(*tests));