text/plain
•
2.15 KB
•
65 lines
#include <string.h>
#include "podcast_xml.h"
#include "test_harness.h"
#include "test_helpers.h"
static bool test_opml_parses_valid_feeds(void) {
ASSERT_TRUE(test_prepare_storage());
ASSERT_TRUE(test_copy_fixture_to_storage("opml/basic.opml",
".tests/opml/basic.opml"));
podcast_feed_t feeds[8];
memset(feeds, 0, sizeof(feeds));
int count = podcast_parse_opml("/.tests/opml/basic.opml", feeds, 8);
ASSERT_EQ_INT(2, count);
ASSERT_EQ_STR("Feed One", feeds[0].title);
ASSERT_EQ_STR("https://example.com/feed1.xml", feeds[0].url);
ASSERT_EQ_STR("Feed Two", feeds[1].title);
ASSERT_EQ_STR("https://example.com/feed2.xml", feeds[1].url);
return true;
}
static bool test_opml_respects_max_feeds(void) {
ASSERT_TRUE(test_prepare_storage());
ASSERT_TRUE(test_copy_fixture_to_storage("opml/basic.opml",
".tests/opml/basic.opml"));
podcast_feed_t feeds[1];
memset(feeds, 0, sizeof(feeds));
int count = podcast_parse_opml("/.tests/opml/basic.opml", feeds, 1);
ASSERT_EQ_INT(1, count);
ASSERT_EQ_STR("Feed One", feeds[0].title);
return true;
}
static bool test_opml_missing_file_returns_minus_one(void) {
ASSERT_TRUE(test_prepare_storage());
podcast_feed_t feeds[2];
memset(feeds, 0, sizeof(feeds));
ASSERT_EQ_INT(-1, podcast_parse_opml("/.tests/opml/missing.opml", feeds, 2));
return true;
}
static bool test_opml_malformed_returns_zero_feeds(void) {
ASSERT_TRUE(test_prepare_storage());
ASSERT_TRUE(test_copy_fixture_to_storage("opml/malformed.opml",
".tests/opml/malformed.opml"));
podcast_feed_t feeds[2];
memset(feeds, 0, sizeof(feeds));
ASSERT_EQ_INT(0, podcast_parse_opml("/.tests/opml/malformed.opml", feeds, 2));
return true;
}
void register_podcast_opml_tests(void) {
test_register("opml_parses_valid_feeds", test_opml_parses_valid_feeds);
test_register("opml_respects_max_feeds", test_opml_respects_max_feeds);
test_register("opml_missing_file_returns_minus_one",
test_opml_missing_file_returns_minus_one);
test_register("opml_malformed_returns_zero_feeds",
test_opml_malformed_returns_zero_feeds);
}