mirror of
https://github.com/aria2/aria2.git
synced 2025-02-18 21:27:34 +00:00

Rewritten Exception class. Throw exception object, not its pointer and catch by reference, so that remove problematic delete operator for catched exception. * src/Exception.cc * src/Exception.h * test/ExceptionTest.cc * src/*: All files throwing/catching exception. * test/*: All files throwing/catching exception.
75 lines
1.7 KiB
C++
75 lines
1.7 KiB
C++
#include "MetaFileUtil.h"
|
|
#include "Data.h"
|
|
#include "Dictionary.h"
|
|
#include "List.h"
|
|
#include "DlAbortEx.h"
|
|
#include <string>
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
namespace aria2 {
|
|
|
|
class MetaFileUtilTest:public CppUnit::TestFixture {
|
|
|
|
CPPUNIT_TEST_SUITE(MetaFileUtilTest);
|
|
CPPUNIT_TEST(testParseMetaFile);
|
|
CPPUNIT_TEST(testBdecoding);
|
|
CPPUNIT_TEST_SUITE_END();
|
|
private:
|
|
|
|
public:
|
|
void setUp() {
|
|
}
|
|
|
|
void testParseMetaFile();
|
|
void testBdecoding();
|
|
};
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( MetaFileUtilTest );
|
|
|
|
void MetaFileUtilTest::testParseMetaFile() {
|
|
MetaEntry* entry = MetaFileUtil::parseMetaFile("test.torrent");
|
|
Dictionary* d = dynamic_cast<Dictionary*>(entry);
|
|
CPPUNIT_ASSERT(d != NULL);
|
|
}
|
|
|
|
void MetaFileUtilTest::testBdecoding() {
|
|
try {
|
|
std::string str = "5:abcd";
|
|
MetaFileUtil::bdecoding(str);
|
|
CPPUNIT_FAIL("DlAbortEx exception must be thrown.");
|
|
} catch(DlAbortEx& ex) {
|
|
} catch(...) {
|
|
CPPUNIT_FAIL("DlAbortEx exception must be thrown.");
|
|
}
|
|
|
|
try {
|
|
std::string str = "i1234";
|
|
MetaFileUtil::bdecoding(str);
|
|
CPPUNIT_FAIL("DlAbortEx exception must be thrown.");
|
|
} catch(DlAbortEx& ex) {
|
|
} catch(...) {
|
|
CPPUNIT_FAIL("DlAbortEx exception must be thrown.");
|
|
}
|
|
|
|
try {
|
|
const std::string str = "5abcd";
|
|
MetaFileUtil::bdecoding(str);
|
|
CPPUNIT_FAIL("DlAbortEx exception must be thrown.");
|
|
} catch(DlAbortEx& ex) {
|
|
} catch(...) {
|
|
CPPUNIT_FAIL("DlAbortEx exception must be thrown.");
|
|
}
|
|
|
|
try {
|
|
const std::string str = "d";
|
|
MetaFileUtil::bdecoding(str);
|
|
CPPUNIT_FAIL("DlAbortEx exception must be thrown.");
|
|
} catch(DlAbortEx& ex) {
|
|
} catch(...) {
|
|
CPPUNIT_FAIL("DlAbortEx exception must be thrown.");
|
|
}
|
|
}
|
|
|
|
} // namespace aria2
|