#include "3rd-party/catch.hpp" #include #include #include #include #include #include TEST_CASE("Throws exception if file doesn't exist", "[rsspp::parser]") { rsspp::parser p; try { rsspp::feed f = p.parse_file("data/non-existent.xml"); } catch (rsspp::exception e) { REQUIRE(e.what() == std::string("could not parse file")); } } TEST_CASE("Throws exception if file can't be parsed", "[rsspp::parser]") { rsspp::parser p; try { rsspp::feed f = p.parse_file("data/empty.xml"); } catch (rsspp::exception e) { REQUIRE(e.what() == std::string("could not parse file")); } } TEST_CASE("Extracts data from RSS 0.91", "[rsspp::parser]") { rsspp::parser p; rsspp::feed f; REQUIRE_NOTHROW(f = p.parse_file("data/rss091_1.xml")); REQUIRE(f.rss_version == rsspp::RSS_0_91); REQUIRE(f.title == "Example Channel"); REQUIRE(f.description == "an example feed"); REQUIRE(f.link == "http://example.com/"); REQUIRE(f.language == "en"); REQUIRE(f.items.size() == 1u); REQUIRE(f.items[0].title == "1 < 2"); REQUIRE(f.items[0].link == "http://example.com/1_less_than_2.html"); REQUIRE(f.items[0].description == "1 < 2, 3 < 4.\nIn HTML, starts a bold phrase\nand you start a link with is empty, try to deduce it from the URL", "[rss::rss_parser]") { configcontainer cfg; cache rsscache(":memory:", &cfg); rss_parser p( "file://data/items_without_titles.xml", &rsscache, &cfg, nullptr, nullptr); auto feed = p.parse(); REQUIRE(feed->items()[0]->title() == "A gentle introduction to testing"); REQUIRE(feed->items()[1]->title() == "A missing rel attribute"); REQUIRE(feed->items()[2]->title() == "Alternate link isnt first"); REQUIRE(feed->items()[3]->title() == "A test for htm extension"); REQUIRE(feed->items()[4]->title() == "Alternate link isn't first"); } }