MetaFileUtilTest.cc 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. using namespace std;
  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. MetaEntry* entry = MetaFileUtil::parseMetaFile("test.torrent");
  24. Dictionary* d = dynamic_cast<Dictionary*>(entry);
  25. CPPUNIT_ASSERT(d != NULL);
  26. }
  27. void MetaFileUtilTest::testBdecoding() {
  28. try {
  29. char* str = "5:abcd";
  30. MetaEntry* entry = MetaFileUtil::bdecoding(str, strlen(str));
  31. CPPUNIT_FAIL("DlAbortEx exception must be throwed.");
  32. } catch(DlAbortEx* ex) {
  33. delete ex;
  34. } catch(...) {
  35. CPPUNIT_FAIL("DlAbortEx exception must be throwed.");
  36. }
  37. try {
  38. char* str = "i1234";
  39. MetaEntry* entry = MetaFileUtil::bdecoding(str, strlen(str));
  40. CPPUNIT_FAIL("DlAbortEx exception must be throwed.");
  41. } catch(DlAbortEx* ex) {
  42. delete ex;
  43. } catch(...) {
  44. CPPUNIT_FAIL("DlAbortEx exception must be throwed.");
  45. }
  46. try {
  47. char* str = "5abcd";
  48. MetaEntry* entry = MetaFileUtil::bdecoding(str, strlen(str));
  49. CPPUNIT_FAIL("DlAbortEx exception must be throwed.");
  50. } catch(DlAbortEx* ex) {
  51. delete ex;
  52. } catch(...) {
  53. CPPUNIT_FAIL("DlAbortEx exception must be throwed.");
  54. }
  55. try {
  56. char* str = "d";
  57. MetaEntry* entry = MetaFileUtil::bdecoding(str, strlen(str));
  58. CPPUNIT_FAIL("DlAbortEx exception must be throwed.");
  59. } catch(DlAbortEx* ex) {
  60. delete ex;
  61. } catch(...) {
  62. CPPUNIT_FAIL("DlAbortEx exception must be throwed.");
  63. }
  64. }