SignatureTest.cc 984 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "Signature.h"
  2. #include <fstream>
  3. #include <cppunit/extensions/HelperMacros.h>
  4. #include "Exception.h"
  5. #include "File.h"
  6. namespace aria2 {
  7. class SignatureTest:public CppUnit::TestFixture {
  8. CPPUNIT_TEST_SUITE(SignatureTest);
  9. CPPUNIT_TEST(testSave);
  10. CPPUNIT_TEST_SUITE_END();
  11. public:
  12. void setUp() {}
  13. void tearDown() {}
  14. void testSave();
  15. };
  16. CPPUNIT_TEST_SUITE_REGISTRATION(SignatureTest);
  17. void SignatureTest::testSave()
  18. {
  19. Signature sig;
  20. sig.setBody("SIGNATURE");
  21. std::string filepath = A2_TEST_OUT_DIR"/aria2_SignatureTest_testSave";
  22. File outfile(filepath);
  23. if(outfile.exists()) {
  24. outfile.remove();
  25. }
  26. CPPUNIT_ASSERT(sig.save(filepath));
  27. {
  28. std::ifstream in(filepath.c_str(), std::ios::binary);
  29. std::string fileContent;
  30. in >> fileContent;
  31. CPPUNIT_ASSERT_EQUAL(sig.getBody(), fileContent);
  32. }
  33. // second attempt to save will fail because file already exists.
  34. CPPUNIT_ASSERT(!sig.save(filepath));
  35. }
  36. } // namespace aria2