2007-08-08 14:40:28 +00:00
|
|
|
#include "MessageDigestHelper.h"
|
2009-02-01 02:50:38 +00:00
|
|
|
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
2009-10-22 15:35:33 +00:00
|
|
|
#include "util.h"
|
2007-08-08 14:40:28 +00:00
|
|
|
#include "DefaultDiskWriter.h"
|
2010-11-11 02:56:24 +00:00
|
|
|
#include "MessageDigest.h"
|
2007-08-08 14:40:28 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
namespace aria2 {
|
2007-08-08 14:40:28 +00:00
|
|
|
|
|
|
|
class MessageDigestHelperTest:public CppUnit::TestFixture {
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(MessageDigestHelperTest);
|
2010-11-11 02:56:24 +00:00
|
|
|
CPPUNIT_TEST(testHexDigestDiskWriter);
|
|
|
|
CPPUNIT_TEST(testDigest);
|
2007-08-08 14:40:28 +00:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
private:
|
|
|
|
|
|
|
|
public:
|
|
|
|
void setUp() {
|
|
|
|
}
|
|
|
|
|
2010-11-11 02:56:24 +00:00
|
|
|
void testHexDigestDiskWriter();
|
|
|
|
void testDigest();
|
2007-08-08 14:40:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( MessageDigestHelperTest );
|
|
|
|
|
2010-11-11 02:56:24 +00:00
|
|
|
void MessageDigestHelperTest::testHexDigestDiskWriter() {
|
2009-05-04 07:50:38 +00:00
|
|
|
SharedHandle<DefaultDiskWriter> diskio
|
|
|
|
(new DefaultDiskWriter("4096chunk.txt"));
|
|
|
|
diskio->openExistingFile();
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("608cabc0f2fa18c260cafd974516865c772363d5"),
|
2010-11-11 02:56:24 +00:00
|
|
|
MessageDigestHelper::hexDigest
|
|
|
|
(MessageDigest::sha1(), diskio, 0, 4096));
|
2007-08-08 14:40:28 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("7a4a9ae537ebbbb826b1060e704490ad0f365ead"),
|
2010-11-11 02:56:24 +00:00
|
|
|
MessageDigestHelper::hexDigest
|
|
|
|
(MessageDigest::sha1(), diskio, 5, 100));
|
2007-08-08 14:40:28 +00:00
|
|
|
}
|
|
|
|
|
2010-11-11 02:56:24 +00:00
|
|
|
void MessageDigestHelperTest::testDigest()
|
2007-08-08 14:40:28 +00:00
|
|
|
{
|
2008-02-08 15:53:45 +00:00
|
|
|
std::string data = "aria2";
|
2010-11-11 02:56:24 +00:00
|
|
|
SharedHandle<MessageDigest> sha1 = MessageDigest::sha1();
|
|
|
|
sha1->update(data.data(), data.size());
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("f36003f22b462ffa184390533c500d8989e9f681"),
|
2010-11-11 02:56:24 +00:00
|
|
|
sha1->hexDigest());
|
2007-08-08 14:40:28 +00:00
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
|
|
|
|
} // namespace aria2
|