MetaFileUtilTest.cc 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include "MetaFileUtil.h"
  2. #include "Data.h"
  3. #include "Dictionary.h"
  4. #include "List.h"
  5. #include "DlAbortEx.h"
  6. #include <string>
  7. #include <cppunit/extensions/HelperMacros.h>
  8. namespace aria2 {
  9. class MetaFileUtilTest:public CppUnit::TestFixture {
  10. CPPUNIT_TEST_SUITE(MetaFileUtilTest);
  11. CPPUNIT_TEST(testParseMetaFile);
  12. CPPUNIT_TEST(testBdecoding);
  13. CPPUNIT_TEST_SUITE_END();
  14. private:
  15. public:
  16. void setUp() {
  17. }
  18. void testParseMetaFile();
  19. void testBdecoding();
  20. };
  21. CPPUNIT_TEST_SUITE_REGISTRATION( MetaFileUtilTest );
  22. void MetaFileUtilTest::testParseMetaFile() {
  23. SharedHandle<MetaEntry> entry(MetaFileUtil::parseMetaFile("test.torrent"));
  24. SharedHandle<Dictionary> d = dynamic_pointer_cast<Dictionary>(entry);
  25. CPPUNIT_ASSERT(!d.isNull());
  26. }
  27. void MetaFileUtilTest::testBdecoding() {
  28. try {
  29. std::string str = "5:abcd";
  30. MetaFileUtil::bdecoding(str);
  31. CPPUNIT_FAIL("DlAbortEx exception must be thrown.");
  32. } catch(DlAbortEx& ex) {
  33. } catch(...) {
  34. CPPUNIT_FAIL("DlAbortEx exception must be thrown.");
  35. }
  36. try {
  37. std::string str = "i1234";
  38. MetaFileUtil::bdecoding(str);
  39. CPPUNIT_FAIL("DlAbortEx exception must be thrown.");
  40. } catch(DlAbortEx& ex) {
  41. } catch(...) {
  42. CPPUNIT_FAIL("DlAbortEx exception must be thrown.");
  43. }
  44. try {
  45. const std::string str = "5abcd";
  46. MetaFileUtil::bdecoding(str);
  47. CPPUNIT_FAIL("DlAbortEx exception must be thrown.");
  48. } catch(DlAbortEx& ex) {
  49. } catch(...) {
  50. CPPUNIT_FAIL("DlAbortEx exception must be thrown.");
  51. }
  52. try {
  53. const std::string str = "d";
  54. MetaFileUtil::bdecoding(str);
  55. CPPUNIT_FAIL("DlAbortEx exception must be thrown.");
  56. } catch(DlAbortEx& ex) {
  57. } catch(...) {
  58. CPPUNIT_FAIL("DlAbortEx exception must be thrown.");
  59. }
  60. }
  61. } // namespace aria2