Tests: Added Series Tests
This will be the last set of tests added for now. Seasons don't have easily testable functions.
This commit is contained in:
parent
274ddc5cc9
commit
750f250545
|
@ -27,7 +27,18 @@ namespace dropout_dl {
|
|||
}
|
||||
}
|
||||
|
||||
#if defined(__WIN32__)
|
||||
|
||||
std::string remove_leading_and_following_whitespace(const std::string& str) {
|
||||
int start = 0;
|
||||
int end = str.length() - 1;
|
||||
|
||||
for (; str[start] == ' ' || str[start] == '\t' || str[start] == '\n'; start++);
|
||||
for (; str[end] == ' ' || str[end] == '\t' || str[end] == '\n'; end--);
|
||||
|
||||
return str.substr(start, end - start + 1);
|
||||
}
|
||||
|
||||
#if defined(__WIN32__)
|
||||
#include <windows.h>
|
||||
msec_t time_ms(void)
|
||||
{
|
||||
|
|
|
@ -162,6 +162,15 @@ namespace dropout_dl {
|
|||
*/
|
||||
void replace_all(std::string& str, const std::string& from, const std::string& to);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param str - A string
|
||||
* @return <b>str</b> with any leading or following whitespace
|
||||
*
|
||||
* Removes leading and following whitespace from a string and returns the modified string
|
||||
*/
|
||||
std::string remove_leading_and_following_whitespace(const std::string& str);
|
||||
|
||||
#if defined(__WIN32__)
|
||||
#include <windows.h>
|
||||
msec_t time_ms(void);
|
||||
|
|
|
@ -8,36 +8,24 @@ namespace dropout_dl {
|
|||
|
||||
std::string series::get_series_name(const std::string& html_data) {
|
||||
std::string collection_title("collection-title");
|
||||
std::string open_a_tag("<h1");
|
||||
std::string close_tag(">");
|
||||
std::string close_a("</h1>");
|
||||
|
||||
int series_name_start = -1;
|
||||
|
||||
for (int i = 0; i < html_data.size(); i++) {
|
||||
if (substr_is(html_data, i, collection_title)) {
|
||||
for (int j = i + collection_title.size(); j < html_data.size(); j++) {
|
||||
if (html_data[j] == '\n' || html_data[j] == ' ' || html_data[j] == '\t') continue;
|
||||
if (substr_is(html_data, j, close_tag)) {
|
||||
for (int l = 0; l < html_data.size() - j; l++) {
|
||||
char c = html_data[j + l];
|
||||
if (series_name_start == -1) {
|
||||
if (html_data[j + l + 1] == '\n' || html_data[j + l + 1] == ' ' ||
|
||||
html_data[j + l + 1] == '\t') {
|
||||
continue;
|
||||
} else {
|
||||
series_name_start = j + l + 1;
|
||||
}
|
||||
}
|
||||
if (substr_is(html_data, j + l, close_a) || (series_name_start != -1 && html_data[j + l] == '\n')) {
|
||||
return html_data.substr(series_name_start, l - (series_name_start - j));
|
||||
if (substr_is(html_data, j + l, close_a)) {
|
||||
return remove_leading_and_following_whitespace(html_data.substr(j + 1, l - 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return "-1";
|
||||
return "ERROR";
|
||||
}
|
||||
|
||||
std::vector<season> series::get_seasons(const std::string &html_data, const std::vector<cookie>& cookies) {
|
||||
|
|
|
@ -76,7 +76,7 @@ namespace dropout_dl {
|
|||
this->url = url;
|
||||
this->page_data = get_generic_page(url);
|
||||
this->name = get_series_name(page_data);
|
||||
if (name == "-1") {
|
||||
if (name == "ERROR") {
|
||||
std::cerr << "SERIES PARSE ERROR: Could not parse series name\n";
|
||||
exit(10);
|
||||
}
|
||||
|
|
|
@ -3,10 +3,8 @@ project(dropout-dl-tests)
|
|||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
add_executable(test test.cpp episode_tests.cpp ../src/episode.cpp)
|
||||
add_executable(test test.cpp episode_tests.cpp ../src/episode.cpp ../src/season.cpp series_tests.cpp ../src/series.cpp)
|
||||
|
||||
target_link_libraries(test curl sqlite3 gcrypt)
|
||||
|
||||
message(STATUS "Building Tests")
|
||||
|
||||
include_directories(episode ../src)
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
namespace dropout_dl {
|
||||
tests test_episode_name_parsing() {
|
||||
bool success;
|
||||
std::vector<dropout_dl::test<std::string>> out;
|
||||
|
||||
std::string (*test_function)(const std::string&) = episode::get_episode_name;
|
||||
|
||||
|
@ -14,7 +14,7 @@ namespace dropout_dl {
|
|||
" <strong>" + base_test_solution + "</strong>\n"
|
||||
" </h1>";
|
||||
|
||||
test base("Basic Episode Name Parsing", test_function, base_test, base_test_solution);
|
||||
out.emplace_back("Basic Episode Name Parsing", test_function, base_test, base_test_solution);
|
||||
|
||||
|
||||
std::string multiple_header_test_solution = "Multi Header Test Title";
|
||||
|
@ -35,7 +35,7 @@ namespace dropout_dl {
|
|||
"</h1>";
|
||||
|
||||
|
||||
test multiple_header("Multiple Header Episode Name Parsing", test_function, multiple_header_test, multiple_header_test_solution);
|
||||
out.emplace_back("Multiple Header Episode Name Parsing", test_function, multiple_header_test, multiple_header_test_solution);
|
||||
|
||||
std::string no_valid_header_test_solution = "ERROR";
|
||||
std::string no_valid_header_test = "<h1>\n"
|
||||
|
@ -48,7 +48,7 @@ namespace dropout_dl {
|
|||
"<strong>Header with strong</strong>"
|
||||
"</h1>\n";
|
||||
|
||||
test no_valid_header("No Valid Header Episode Name Parsing", test_function, no_valid_header_test, no_valid_header_test_solution);
|
||||
out.emplace_back("No Valid Header Episode Name Parsing", test_function, no_valid_header_test, no_valid_header_test_solution);
|
||||
|
||||
|
||||
std::string html_character_test_solution = "'&;";
|
||||
|
@ -56,14 +56,14 @@ namespace dropout_dl {
|
|||
" <strong>'&;</strong>\n"
|
||||
"</h1>";
|
||||
|
||||
test html_character_code("Html Character Code Episode Name Parsing", test_function, html_character_test, html_character_test_solution);
|
||||
out.emplace_back("Html Character Code Episode Name Parsing", test_function, html_character_test, html_character_test_solution);
|
||||
|
||||
|
||||
return tests("Episode Name Parsing", {base, multiple_header, no_valid_header, html_character_code});
|
||||
return {"Episode Name Parsing", out};
|
||||
}
|
||||
|
||||
tests test_episode_number_parsing() {
|
||||
bool success;
|
||||
std::vector<dropout_dl::test<std::string>> out;
|
||||
|
||||
std::string (*test_function)(const std::string&) = episode::get_episode_number;
|
||||
|
||||
|
@ -72,7 +72,7 @@ namespace dropout_dl {
|
|||
" Season 1, Episode 1\n"
|
||||
"</a>";
|
||||
|
||||
test base("Basic Episode Number Parsing", test_function, base_test, base_test_solution);
|
||||
out.emplace_back("Basic Episode Number Parsing", test_function, base_test, base_test_solution);
|
||||
|
||||
|
||||
std::string multiple_link_test_solution = "1";
|
||||
|
@ -86,7 +86,7 @@ namespace dropout_dl {
|
|||
" Season 1, Episode 2\n";
|
||||
|
||||
|
||||
test multiple_link("Multiple Link Episode Number Parsing", test_function, multiple_link_test, multiple_link_test_solution);
|
||||
out.emplace_back("Multiple Link Episode Number Parsing", test_function, multiple_link_test, multiple_link_test_solution);
|
||||
|
||||
std::string no_valid_number_test_solution = "-1";
|
||||
std::string no_valid_number_test = "<a>\n"
|
||||
|
@ -99,7 +99,7 @@ namespace dropout_dl {
|
|||
"Episode"
|
||||
"</a>\n";
|
||||
|
||||
test no_valid_number("No Valid Episode Number Parsing", test_function, no_valid_number_test, no_valid_number_test_solution);
|
||||
out.emplace_back("No Valid Episode Number Parsing", test_function, no_valid_number_test, no_valid_number_test_solution);
|
||||
|
||||
|
||||
std::string earlier_episode_text_test_solution = "15";
|
||||
|
@ -110,13 +110,13 @@ namespace dropout_dl {
|
|||
" Season 1, Episode 15\n"
|
||||
"</a>";
|
||||
|
||||
test earlier_episode_text("Earlier Episode Text Number Parsing", test_function, earlier_episode_text_test, earlier_episode_text_test_solution);
|
||||
out.emplace_back("Earlier Episode Text Number Parsing", test_function, earlier_episode_text_test, earlier_episode_text_test_solution);
|
||||
|
||||
return tests("Episode Name Parsing", {base, multiple_link, no_valid_number, earlier_episode_text});
|
||||
return {"Episode Name Parsing", out};
|
||||
}
|
||||
|
||||
tests test_episode_series_name_parsing() {
|
||||
bool success;
|
||||
std::vector<dropout_dl::test<std::string>> out;
|
||||
|
||||
std::string (*test_function)(const std::string&) = episode::get_series_name;
|
||||
|
||||
|
@ -127,7 +127,7 @@ namespace dropout_dl {
|
|||
" </a>\n"
|
||||
"</h3>";
|
||||
|
||||
test base("Basic Episode Series Name Parsing", test_function, base_test, base_test_solution);
|
||||
out.emplace_back("Basic Episode Series Name Parsing", test_function, base_test, base_test_solution);
|
||||
|
||||
|
||||
std::string multiple_header_test_solution = "Multi Header Test Title";
|
||||
|
@ -148,7 +148,7 @@ namespace dropout_dl {
|
|||
"</h3>";
|
||||
|
||||
|
||||
test multiple_header("Multiple Header Episode Series Name Parsing", test_function, multiple_header_test, multiple_header_test_solution);
|
||||
out.emplace_back("Multiple Header Episode Series Name Parsing", test_function, multiple_header_test, multiple_header_test_solution);
|
||||
|
||||
std::string no_valid_header_test_solution = "ERROR";
|
||||
std::string no_valid_header_test = "<h3>\n"
|
||||
|
@ -161,7 +161,7 @@ namespace dropout_dl {
|
|||
"<a>Header with strong</a>"
|
||||
"</h3>\n";
|
||||
|
||||
test no_valid_header("No Valid Header Episode Series Name Parsing", test_function, no_valid_header_test, no_valid_header_test_solution);
|
||||
out.emplace_back("No Valid Header Episode Series Name Parsing", test_function, no_valid_header_test, no_valid_header_test_solution);
|
||||
|
||||
|
||||
std::string html_character_test_solution = "'&;";
|
||||
|
@ -169,13 +169,13 @@ namespace dropout_dl {
|
|||
" <a>'&;</a>\n"
|
||||
"</h3>";
|
||||
|
||||
test html_character("Html Character Code Episode Series Name Parsing", test_function, html_character_test, html_character_test_solution);
|
||||
out.emplace_back("Html Character Code Episode Series Name Parsing", test_function, html_character_test, html_character_test_solution);
|
||||
|
||||
return tests("Episode Name Parsing", {base, multiple_header, no_valid_header, html_character});
|
||||
return {"Episode Name Parsing", out};
|
||||
}
|
||||
|
||||
tests test_episode_embedded_url_parsing() {
|
||||
bool success;
|
||||
std::vector<dropout_dl::test<std::string>> out;
|
||||
|
||||
std::string (*test_function)(const std::string&) = episode::get_embed_url;
|
||||
|
||||
|
@ -184,7 +184,7 @@ namespace dropout_dl {
|
|||
" embed_url: \"" + base_test_solution + "\"\n"
|
||||
" };";
|
||||
|
||||
test base("Basic Episode Embedded URL Parsing", test_function, base_test, base_test_solution);
|
||||
out.emplace_back("Basic Episode Embedded URL Parsing", test_function, base_test, base_test_solution);
|
||||
|
||||
|
||||
std::string multiple_script_test_solution = "Multi Header Test Title";
|
||||
|
@ -247,7 +247,7 @@ namespace dropout_dl {
|
|||
" </script>";
|
||||
|
||||
|
||||
test multiple_script("Multiple Script Embedded URL Parsing", test_function, multiple_script_test, multiple_script_test_solution);
|
||||
out.emplace_back("Multiple Script Embedded URL Parsing", test_function, multiple_script_test, multiple_script_test_solution);
|
||||
|
||||
std::string no_valid_URL_test_solution = "";
|
||||
std::string no_valid_URL_test = " <script>\n"
|
||||
|
@ -260,28 +260,28 @@ namespace dropout_dl {
|
|||
" };\n"
|
||||
" </script>";
|
||||
|
||||
test no_valid_URL("No Valid Embedded URL Parsing", test_function, no_valid_URL_test, no_valid_URL_test_solution);
|
||||
out.emplace_back("No Valid Embedded URL Parsing", test_function, no_valid_URL_test, no_valid_URL_test_solution);
|
||||
|
||||
return tests("Episode Name Parsing", {base, multiple_script, no_valid_URL});
|
||||
return {"Episode Name Parsing", out};
|
||||
}
|
||||
|
||||
tests test_episode_config_url_parsing() {
|
||||
bool success;
|
||||
std::vector<dropout_dl::test<std::string>> out;
|
||||
|
||||
std::string (*test_function)(const std::string&) = episode::get_config_url;
|
||||
|
||||
std::string base_test_solution = "Base Test URL";
|
||||
std::string base_test = R"(window.OTTData = {"config_url":")" + base_test_solution + "\"};";
|
||||
|
||||
test base("Basic Episode Config URL Parsing", test_function, base_test, base_test_solution);
|
||||
out.emplace_back("Basic Episode Config URL Parsing", test_function, base_test, base_test_solution);
|
||||
|
||||
|
||||
std::string no_valid_URL_test_solution = "";
|
||||
std::string no_valid_URL_test = R"(window.OTTData = {"api_data":{"api_host":"","api_token":"","user_auth_token":{"auth_user_token":"","embed_referrer_host":""}},"buy_button":{"label":null,"url":null},"collection":{"id":null},"product":{"id":null},"":{"label":"","url":""},"site":{"id":null,"subdomain":"","twitter_name":""},"video":{"duration":null,"id":null,"is_trailer":"","title":"","is_live_video":false,"live_event_id":null},"google_cast_app_id":"","hide_chrome":null,"initial_time":null,"js_api_enabled":null,"locale":"","show_share_actions":null,"user":{"id":,"email":""},"analytics_url":""})";
|
||||
|
||||
test no_valid_URL("No Valid Config URL Parsing", test_function, no_valid_URL_test, no_valid_URL_test_solution);
|
||||
out.emplace_back("No Valid Config URL Parsing", test_function, no_valid_URL_test, no_valid_URL_test_solution);
|
||||
|
||||
return tests("Episode Name Parsing", {base, no_valid_URL});
|
||||
return {"Episode Name Parsing", out};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#pragma once
|
||||
|
||||
|
||||
#include "episode.h"
|
||||
#include "../src/episode.h"
|
||||
#include "test.h"
|
||||
|
||||
std::vector<dropout_dl::tests> test_episode();
|
|
@ -2,6 +2,7 @@
|
|||
// Created by moss on 9/30/22.
|
||||
//
|
||||
#include "test.h"
|
||||
#include "series_tests.h"
|
||||
#include "episode_tests.h"
|
||||
|
||||
template<typename t>
|
||||
|
@ -28,6 +29,7 @@ void dropout_dl::tests::display() {
|
|||
|
||||
|
||||
int main() {
|
||||
std::string episode_tests_name = "Episode Tests";
|
||||
std::vector<dropout_dl::tests> episode_tests = test_episode();
|
||||
|
||||
bool episode_tests_success = true;
|
||||
|
@ -36,13 +38,36 @@ int main() {
|
|||
}
|
||||
|
||||
if (episode_tests_success) {
|
||||
std::cout << TESTNAME << BOLDGREEN << "Episode Tests" << std::endl;
|
||||
std::cout << TESTNAME << BOLDGREEN << episode_tests_name << std::endl;
|
||||
}
|
||||
else {
|
||||
std::cout << TESTNAME << BOLDRED << "Episode Tests" << std::endl;
|
||||
std::cout << TESTNAME << BOLDRED << episode_tests_name << std::endl;
|
||||
}
|
||||
|
||||
for (auto& test : episode_tests) {
|
||||
test.display();
|
||||
}
|
||||
|
||||
|
||||
std::cout << "\n\n";
|
||||
|
||||
|
||||
std::string series_tests_name = "Series Tests";
|
||||
std::vector<dropout_dl::tests> series_tests = test_series();
|
||||
|
||||
bool series_tests_success = true;
|
||||
for (const auto& test : episode_tests) {
|
||||
series_tests_success &= test.success;
|
||||
}
|
||||
|
||||
if (series_tests_success) {
|
||||
std::cout << TESTNAME << BOLDGREEN << series_tests_name << std::endl;
|
||||
}
|
||||
else {
|
||||
std::cout << TESTNAME << BOLDRED << series_tests_name << std::endl;
|
||||
}
|
||||
|
||||
for (auto& test : series_tests) {
|
||||
test.display();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue