1 #include "testlibrss.h" 3 #include <tqdatetime.h> 6 #include <tdeaboutdata.h> 7 #include <tdecmdlineargs.h> 8 #include <tdeapplication.h> 13 #include "enclosure.h" 20 TestRetriever::TestRetriever()
25 TestRetriever::~TestRetriever()
29 void TestRetriever::retrieveData(
const KURL &url)
32 TQFile file(url.path());
33 if (file.open(IO_ReadOnly))
36 TQTextStream stream(&file);
38 while (!stream.atEnd())
40 lines += stream.readLine();
44 TQCString content = lines.join(
"\n").local8Bit();
46 data.duplicate(content, content.length());
47 emit dataRetrieved(data,
true);
51 kdError() <<
"Failed to retrieveData: " << file.errorString() << endl;
52 m_errorCode = file.status();
53 emit dataRetrieved(TQByteArray{},
false);
57 static const TDECmdLineOptions options[] =
59 {
"+url", I18N_NOOP(
"URL of feed"), 0 },
63 template<
typename ActualType,
typename ExpectedType>
64 static void assertEquals(
const ActualType& actual,
const ExpectedType& expected)
66 if (actual != expected)
68 kdError() <<
"Assertion failed: actual == expected\n" 69 <<
" actual: " << actual <<
"\n" 70 <<
" expected: " << expected << endl;
75 static void checkRSS091(
const Document& document)
77 assertEquals(document.
title(),
"WriteTheWeb");
78 assertEquals(document.
link().url(),
"http://writetheweb.com");
79 assertEquals(document.
description(),
"News for web users that write back");
80 assertEquals(document.
language(), Language::en_us);
81 assertEquals(document.
copyright(),
"Copyright 2000, WriteTheWeb team.");
83 assertEquals(document.
webMaster(),
"webmaster@writetheweb.com");
88 kdError() <<
"Expected an <image> element to be found" << endl;
92 assertEquals(image->title(),
"WriteTheWeb");
93 assertEquals(image->url().url(),
"http://writetheweb.com/images/mynetscape88.gif");
94 assertEquals(image->link().url(),
"http://writetheweb.com");
95 assertEquals(image->description(),
"News for web users that write back");
96 assertEquals(image->width(), 88);
97 assertEquals(image->height(), 31);
99 assertEquals(document.
articles().count(), 6);
102 assertEquals(article.title(),
"Giving the world a pluggable Gnutella");
103 assertEquals(article.link().url(),
"http://writetheweb.com/read.php?item=24");
104 assertEquals(article.description(),
"WorldOS is a framework on which to build programs that work like Freenet or Gnutella -allowing distributed applications using peer-to-peer routing.");
107 static void checkWFW(
const Document& document)
109 assertEquals(document.
link().url(),
"http://wellformedweb.org/news/");
110 assertEquals(document.
description(),
"Exploring the limits of XML and HTTP");
112 assertEquals(document.
articles().count(), 5);
115 assertEquals(article.title(),
"Should you use Content Negotiation in your Web Services?");
116 assertEquals(article.commentsLink().url(),
"http://bitworking.org/news/comments/WebServicesAndContentNegotiation");
119 static void checkDC(
const Document& document)
122 assertEquals(document.
link().url(),
"https://www.theguardian.com/us");
124 TQDateTime expectedTime;
125 time_t time = KRFCDate::parseDateISO8601(
"2025-03-13T07:28:39Z");
126 expectedTime.setTime_t(time);
127 assertEquals(document.
pubDate(), expectedTime);
129 assertEquals(document.
articles().count(), 1);
132 time = KRFCDate::parseDateISO8601(
"2025-03-13T05:22:00Z");
133 expectedTime.setTime_t(time);
134 assertEquals(article.pubDate(), expectedTime);
136 assertEquals(article.author(),
"Hugo Lowell in Washington");
139 static void checkRDF(
const Document& document)
141 assertEquals(document.
title(),
"XML.com");
142 assertEquals(document.
link().url(),
"http://xml.com/pub");
144 assertEquals(document.
articles().count(), 2);
148 assertEquals(article.title(),
"Processing Inclusions with XSLT");
149 assertEquals(article.link().url(),
"http://xml.com/pub/2000/08/09/xslt/xslt.html");
150 assertEquals(article.guid(),
"http://xml.com/pub/2000/08/09/xslt/xslt.html");
151 assertEquals(article.guidIsPermaLink(),
false);
154 static void checkAtom10(
const Document& document)
156 assertEquals(document.
title(),
"dive into mark");
157 assertEquals(document.
description(),
"A <em>lot</em> of effort went into making this effortless");
158 kdWarning() <<
"Skipping check for Atom \"rights\" (Document::copyright) -- not implemented." << endl;
160 assertEquals(document.
language(), Language::en_us);
167 kdWarning() <<
"Skipping check for Atom \"updated\" (Document::pubDate/lastBuildDate) -- not implemented." << endl;
169 assertEquals(document.
link().url(),
"http://example.org/");
171 assertEquals(document.
articles().count(), 1);
175 assertEquals(article.title(),
"Atom draft-07 snapshot");
176 assertEquals(article.link().url(),
"http://example.org/2005/04/02/atom");
178 if (article.description().isNull())
180 kdError() <<
"Empty Atom article description." << endl;
188 kdWarning() <<
"Skipping check for Atom \"enclosure\" links -- not implemented." << endl;
190 assertEquals(article.guid(),
"tag:example.org,2003:3.2397");
195 TQDateTime articlePublishedDate;
196 time_t publishedTime = KRFCDate::parseDateISO8601(
"2005-07-31T12:29:29Z");
197 articlePublishedDate.setTime_t(publishedTime);
198 assertEquals(article.pubDate(), articlePublishedDate);
200 assertEquals(article.author(),
"<a href=\"mailto:f8dy@example.com\">Mark Pilgrim</a>");
203 void Tester::test(
const TQString &url )
207 this, TQ_SLOT( slotLoadingComplete(
Loader *,
Document, Status ) ) );
208 loader->
loadFrom( url,
new TestRetriever );
211 void Tester::slotLoadingComplete(
Loader *loader,
Document doc, Status status )
213 if (status != Success)
215 kdError() <<
"Failed to load Document: ec=" << loader->
errorCode() <<
" status=" << status << endl;
228 if (doc.
title() ==
"The Well-Formed Web")
233 else if (doc.
title() ==
"The Guardian")
238 else if (doc.
title() ==
"XML.com")
243 kdError() <<
"Unknown RSS 2.0 document '" << doc.
title() <<
"'" << endl;
260 int main(
int argc,
char **argv )
262 TDEAboutData aboutData(
"testlibrss",
"testlibrss",
"0.1" );
263 TDECmdLineArgs::init( argc, argv, &aboutData );
264 TDECmdLineArgs::addCmdLineOptions( options );
265 TDEApplication app(
false,
false);
267 TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();
268 if ( args->count() != 1 ) args->usage();
271 tester.test( args->arg( 0 ) );
276 #include "testlibrss.moc"
Represents an article as stored in a RSS file.