2008-07-12 15:09:03 +00:00
|
|
|
#include "Signature.h"
|
2009-02-09 12:45:07 +00:00
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
2008-07-12 15:09:03 +00:00
|
|
|
#include "Exception.h"
|
|
|
|
#include "File.h"
|
|
|
|
|
|
|
|
namespace aria2 {
|
|
|
|
|
|
|
|
class SignatureTest:public CppUnit::TestFixture {
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(SignatureTest);
|
|
|
|
CPPUNIT_TEST(testSave);
|
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
public:
|
|
|
|
void setUp() {}
|
|
|
|
|
|
|
|
void tearDown() {}
|
|
|
|
|
|
|
|
void testSave();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(SignatureTest);
|
|
|
|
|
|
|
|
void SignatureTest::testSave()
|
|
|
|
{
|
|
|
|
Signature sig;
|
|
|
|
sig.setBody("SIGNATURE");
|
2010-12-02 13:38:36 +00:00
|
|
|
std::string filepath = A2_TEST_OUT_DIR"/aria2_SignatureTest_testSave";
|
2008-07-12 15:09:03 +00:00
|
|
|
File outfile(filepath);
|
|
|
|
if(outfile.exists()) {
|
|
|
|
outfile.remove();
|
2012-10-01 14:52:22 +00:00
|
|
|
}
|
2008-07-12 15:09:03 +00:00
|
|
|
CPPUNIT_ASSERT(sig.save(filepath));
|
|
|
|
{
|
2009-02-13 11:28:42 +00:00
|
|
|
std::ifstream in(filepath.c_str(), std::ios::binary);
|
2008-07-12 15:09:03 +00:00
|
|
|
std::string fileContent;
|
|
|
|
in >> fileContent;
|
|
|
|
CPPUNIT_ASSERT_EQUAL(sig.getBody(), fileContent);
|
|
|
|
}
|
|
|
|
// second attempt to save will fail because file already exists.
|
|
|
|
CPPUNIT_ASSERT(!sig.save(filepath));
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace aria2
|