From 6faacc212ea17f98f3a1d26499d9a317208b9a0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Thu, 18 Aug 2022 02:19:24 +0200 Subject: 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. --- c/test.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'c/test.cpp') 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 +#include + #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)); -- cgit v1.2.3