6#include <tdeaboutdata.h>
7#include <tdecmdlineargs.h>
8#include <tdeapplication.h>
20TestRetriever::TestRetriever()
25TestRetriever::~TestRetriever()
29void 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);
57static const TDECmdLineOptions options[] =
59 { "+url", I18N_NOOP( "URL of feed"), 0 },
63template< typename ActualType, typename ExpectedType>
64static 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;
75static 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.");
107static 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");
119static 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");
139static 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");
154static 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");
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>");
203void Tester::test( const TQString &url )
205 Loader *loader = Loader::create();
206 connect( loader, TQ_SIGNAL( loadingComplete( Loader *, Document, Status ) ),
207 this, TQ_SLOT( slotLoadingComplete( Loader *, Document, Status ) ) );
208 loader-> loadFrom( url, new TestRetriever );
211void 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;
260int 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.
TQString guid() const RSS 2.0 and upwards.
TQString title() const RSS 0.90 and upwards.
bool guidIsPermaLink() const RSS 2.0 and upwards.
TQString author() const a string desribing the author of the item.
const TQDateTime & pubDate() const RSS 2.0 and upwards.
const KURL & link() const RSS 0.90 and upwards.
TQString description() const RSS 0.91 and upwards.
|