From 8d340992d61ae1649f5ae0b9374bb48a6ac38a8b Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Mon, 3 Jul 2006 14:19:59 +0000 Subject: [PATCH] --- test/MetalinkEntryTest.cc | 93 +++++++++++++++++++++++++++++++ test/MetalinkerTest.cc | 66 ++++++++++++++++++++++ test/Xml2MetalinkProcessorTest.cc | 66 ++++++++++++++++++++++ 3 files changed, 225 insertions(+) create mode 100644 test/MetalinkEntryTest.cc create mode 100644 test/MetalinkerTest.cc create mode 100644 test/Xml2MetalinkProcessorTest.cc diff --git a/test/MetalinkEntryTest.cc b/test/MetalinkEntryTest.cc new file mode 100644 index 00000000..99b47fc2 --- /dev/null +++ b/test/MetalinkEntryTest.cc @@ -0,0 +1,93 @@ +#include "MetalinkEntry.h" +#include + +using namespace std; + +class MetalinkEntryTest:public CppUnit::TestFixture { + + CPPUNIT_TEST_SUITE(MetalinkEntryTest); + CPPUNIT_TEST(testDropUnsupportedResource); + CPPUNIT_TEST(testReorderResourcesByPreference); + CPPUNIT_TEST(testCheck); + CPPUNIT_TEST_SUITE_END(); +private: + +public: + void setUp() { + } + void tearDown() { + } + + void testDropUnsupportedResource(); + void testReorderResourcesByPreference(); + void testCheck(); +}; + + +CPPUNIT_TEST_SUITE_REGISTRATION( MetalinkEntryTest ); + +MetalinkEntry* createTestEntry() { + MetalinkEntry* entry = new MetalinkEntry(); + MetalinkResource* res1 = new MetalinkResource(); + res1->url = "ftp://myhost/aria2.tar.bz2"; + res1->type = MetalinkResource::TYPE_FTP; + res1->location = "RO"; + res1->preference = 50; + MetalinkResource* res2 = new MetalinkResource(); + res2->url = "http://myhost/aria2.tar.bz2"; + res2->type = MetalinkResource::TYPE_HTTP; + res2->location = "AT"; + res2->preference = 100; + MetalinkResource* res3 = new MetalinkResource(); + res3->url = "http://myhost/aria2.torrent"; + res3->type = MetalinkResource::TYPE_BITTORRENT; + res3->location = "al"; + res3->preference = 60; + MetalinkResource* res4 = new MetalinkResource(); + res4->url = "http://myhost/aria2.ext"; + res4->type = MetalinkResource::TYPE_NOT_SUPPORTED; + res4->location = "ad"; + res4->preference = 10; + + entry->resources.push_back(res1); + entry->resources.push_back(res2); + entry->resources.push_back(res3); + entry->resources.push_back(res4); + return entry; +} + +void MetalinkEntryTest::testDropUnsupportedResource() { + MetalinkEntry* entry = createTestEntry(); + + entry->dropUnsupportedResource(); + + CPPUNIT_ASSERT_EQUAL(2, (int)entry->resources.size()); + + CPPUNIT_ASSERT_EQUAL((int)MetalinkResource::TYPE_FTP, + entry->resources.at(0)->type); + CPPUNIT_ASSERT_EQUAL((int)MetalinkResource::TYPE_HTTP, + entry->resources.at(1)->type); +} + +void MetalinkEntryTest::testReorderResourcesByPreference() { + MetalinkEntry* entry = createTestEntry(); + + entry->reorderResourcesByPreference(); + + CPPUNIT_ASSERT_EQUAL(100, entry->resources.at(0)->preference); + CPPUNIT_ASSERT_EQUAL(60, entry->resources.at(1)->preference); + CPPUNIT_ASSERT_EQUAL(50, entry->resources.at(2)->preference); + CPPUNIT_ASSERT_EQUAL(10, entry->resources.at(3)->preference); +} + +void MetalinkEntryTest::testCheck() { + MetalinkEntry entry; + string filename = "4096chunk.txt"; + CPPUNIT_ASSERT(entry.check(filename)); + entry.md5 = "82a7348c2e03731109d0cf45a7325b88"; + CPPUNIT_ASSERT(entry.check(filename)); + entry.md5 = "00000000000000000000000000000000"; + CPPUNIT_ASSERT(!entry.check(filename)); + entry.sha1 = "608cabc0f2fa18c260cafd974516865c772363d5"; + CPPUNIT_ASSERT(entry.check(filename)); +} diff --git a/test/MetalinkerTest.cc b/test/MetalinkerTest.cc new file mode 100644 index 00000000..897b3cea --- /dev/null +++ b/test/MetalinkerTest.cc @@ -0,0 +1,66 @@ +#include "Metalinker.h" +#include + +using namespace std; + +class MetalinkerTest:public CppUnit::TestFixture { + + CPPUNIT_TEST_SUITE(MetalinkerTest); + CPPUNIT_TEST(testQueryEntry); + CPPUNIT_TEST_SUITE_END(); +private: + +public: + void setUp() { + } + void tearDown() { + } + + void testQueryEntry(); +}; + + +CPPUNIT_TEST_SUITE_REGISTRATION( MetalinkerTest ); + +void MetalinkerTest::testQueryEntry() { + Metalinker* metalinker = new Metalinker(); + MetalinkEntry* entry1 = new MetalinkEntry(); + entry1->version = "0.5.2"; + entry1->language = "en-US"; + entry1->os = "Linux-x86"; + MetalinkEntry* entry2 = new MetalinkEntry(); + entry2->version = "0.5.1"; + entry2->language = "ja-JP"; + entry2->os = "Linux-m68k"; + metalinker->entries.push_back(entry1); + metalinker->entries.push_back(entry2); + + string version; + string language; + string os; + + version = "0.5.1"; + language = "ja-JP"; + os = "Linux-m68k"; + MetalinkEntry* entry = metalinker->queryEntry(version, + language, + os); + CPPUNIT_ASSERT_EQUAL(string("0.5.1"), entry->version); + CPPUNIT_ASSERT_EQUAL(string("ja-JP"), entry->language); + CPPUNIT_ASSERT_EQUAL(string("Linux-m68k"), entry->os); + + version = "0.6.0"; + language = ""; + os = ""; + CPPUNIT_ASSERT(!metalinker->queryEntry(version, language, os)); + + version = "0.5.2"; + language = ""; + os = ""; + entry = metalinker->queryEntry(version, language, os); + CPPUNIT_ASSERT_EQUAL(string("0.5.2"), entry->version); + CPPUNIT_ASSERT_EQUAL(string("en-US"), entry->language); + CPPUNIT_ASSERT_EQUAL(string("Linux-x86"), entry->os); + + delete metalinker; +} diff --git a/test/Xml2MetalinkProcessorTest.cc b/test/Xml2MetalinkProcessorTest.cc new file mode 100644 index 00000000..3886f90e --- /dev/null +++ b/test/Xml2MetalinkProcessorTest.cc @@ -0,0 +1,66 @@ +#include "Xml2MetalinkProcessor.h" +#include + +using namespace std; + +class Xml2MetalinkProcessorTest:public CppUnit::TestFixture { + + CPPUNIT_TEST_SUITE(Xml2MetalinkProcessorTest); + CPPUNIT_TEST(testParseFile); + CPPUNIT_TEST_SUITE_END(); +private: + +public: + void setUp() { + xmlInitParser(); + } + void tearDown() { + xmlCleanupParser(); + } + + void testParseFile(); +}; + + +CPPUNIT_TEST_SUITE_REGISTRATION( Xml2MetalinkProcessorTest ); + +void Xml2MetalinkProcessorTest::testParseFile() { + Xml2MetalinkProcessor proc; + Metalinker* metalinker = proc.parseFile("test.xml"); + + MetalinkEntries::iterator entryItr = metalinker->entries.begin(); + MetalinkEntry* entry1 = *entryItr; + CPPUNIT_ASSERT_EQUAL(string("0.5.2"), entry1->version); + CPPUNIT_ASSERT_EQUAL(string("en-US"), entry1->language); + CPPUNIT_ASSERT_EQUAL(string("Linux-x86"), entry1->os); + CPPUNIT_ASSERT_EQUAL(string("fc4d834e89c18c99b2615d902750948c"), + entry1->md5); + CPPUNIT_ASSERT_EQUAL(string("a96cf3f0266b91d87d5124cf94326422800b627d"), + entry1->sha1); + + MetalinkResources::iterator resourceItr1 = entry1->resources.begin(); + MetalinkResource* resource1 = *resourceItr1; + CPPUNIT_ASSERT_EQUAL((int)MetalinkResource::TYPE_FTP, resource1->type); + CPPUNIT_ASSERT_EQUAL(100, resource1->preference); + CPPUNIT_ASSERT_EQUAL(string("ftp://ftphost/aria2-0.5.2.tar.bz2"), + resource1->url); + resourceItr1++; + MetalinkResource* resource2 = *resourceItr1; + CPPUNIT_ASSERT_EQUAL((int)MetalinkResource::TYPE_HTTP, resource2->type); + CPPUNIT_ASSERT_EQUAL(100, resource2->preference); + CPPUNIT_ASSERT_EQUAL(string("http://httphost/aria2-0.5.2.tar.bz2"), + resource2->url); + + entryItr++; + + MetalinkEntry* entry2 = *entryItr; + CPPUNIT_ASSERT_EQUAL(string("0.5.1"), entry2->version); + CPPUNIT_ASSERT_EQUAL(string("ja-JP"), entry2->language); + CPPUNIT_ASSERT_EQUAL(string("Linux-m68k"), entry2->os); + CPPUNIT_ASSERT_EQUAL(string("92296e19c406d77d21bda0bb944eac46"), + entry2->md5); + CPPUNIT_ASSERT_EQUAL(string("4c255b0ed130f5ea880f0aa061c3da0487e251cc"), + entry2->sha1); + + delete metalinker; +}