MetaFileUtilTest.cc 1.8 KB

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