aria2/test/MessageDigestTest.cc

85 lines
2.3 KiB
C++
Raw Normal View History

2010-11-11 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net> Replaced MessageDigestContext with MessageDigest. Cleaned up unnecessary functions in MessageDigestHelper. * src/BtPieceMessage.cc * src/Checksum.h * src/DHTTokenTracker.cc * src/DownloadCommand.cc * src/DownloadCommand.h * src/HashFuncEntry.h * src/IteratableChecksumValidator.cc * src/IteratableChecksumValidator.h * src/IteratableChunkChecksumValidator.cc * src/IteratableChunkChecksumValidator.h * src/LibgcryptMessageDigestImpl.cc * src/LibgcryptMessageDigestImpl.h * src/LibsslMessageDigestImpl.cc * src/LibsslMessageDigestImpl.h * src/MSEHandshake.cc * src/MSEHandshake.h * src/Makefile.am * src/MessageDigest.cc * src/MessageDigest.h * src/MessageDigestHelper.cc * src/MessageDigestHelper.h * src/MessageDigestImpl.h * src/MetalinkParserController.cc * src/Piece.cc * src/Piece.h * src/UTMetadataDataExtensionMessage.cc * src/bittorrent_helper.cc * src/messageDigest.cc: Removed * src/messageDigest.h: Removed * src/util.cc * src/version_usage.cc * test/BittorrentHelperTest.cc * test/GZipDecoderTest.cc * test/GZipDecodingStreamFilterTest.cc * test/IteratableChecksumValidatorTest.cc * test/IteratableChunkChecksumValidatorTest.cc * test/Makefile.am * test/MessageDigestHelperTest.cc * test/MessageDigestTest.cc * test/Metalink2RequestGroupTest.cc * test/MetalinkProcessorTest.cc * test/PieceTest.cc * test/TestUtil.cc * test/TestUtil.h * test/UTMetadataDataExtensionMessageTest.cc * test/UTMetadataPostDownloadHandlerTest.cc
2010-11-11 02:56:24 +00:00
#include "MessageDigest.h"
#include <cppunit/extensions/HelperMacros.h>
#include "util.h"
namespace aria2 {
class MessageDigestTest:public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(MessageDigestTest);
CPPUNIT_TEST(testHexDigest);
CPPUNIT_TEST(testSupports);
CPPUNIT_TEST(testGetDigestLength);
CPPUNIT_TEST(testIsStronger);
CPPUNIT_TEST(testIsValidHash);
CPPUNIT_TEST(testGetCanonicalHashType);
CPPUNIT_TEST_SUITE_END();
SharedHandle<MessageDigest> sha1_;
public:
void setUp()
{
sha1_ = MessageDigest::sha1();
}
void testHexDigest();
void testSupports();
void testGetDigestLength();
void testIsStronger();
void testIsValidHash();
void testGetCanonicalHashType();
};
CPPUNIT_TEST_SUITE_REGISTRATION( MessageDigestTest );
void MessageDigestTest::testHexDigest()
{
sha1_->update("aria2", 5);
CPPUNIT_ASSERT_EQUAL(std::string("f36003f22b462ffa184390533c500d8989e9f681"),
sha1_->hexDigest());
}
void MessageDigestTest::testSupports()
{
CPPUNIT_ASSERT(MessageDigest::supports("sha-1"));
// Fails because sha1 is not valid name.
CPPUNIT_ASSERT(!MessageDigest::supports("sha1"));
}
void MessageDigestTest::testGetDigestLength()
{
CPPUNIT_ASSERT_EQUAL((size_t)20, MessageDigest::getDigestLength("sha-1"));
CPPUNIT_ASSERT_EQUAL((size_t)20, sha1_->getDigestLength());
}
void MessageDigestTest::testIsStronger()
{
CPPUNIT_ASSERT(MessageDigest::isStronger("sha-1", "md5"));
CPPUNIT_ASSERT(!MessageDigest::isStronger("md5", "sha-1"));
CPPUNIT_ASSERT(!MessageDigest::isStronger("unknown", "sha-1"));
CPPUNIT_ASSERT(!MessageDigest::isStronger("sha-1", "unknown"));
}
void MessageDigestTest::testIsValidHash()
{
CPPUNIT_ASSERT(MessageDigest::isValidHash
("sha-1", "f36003f22b462ffa184390533c500d8989e9f681"));
CPPUNIT_ASSERT(!MessageDigest::isValidHash
("sha-1", "f36003f22b462ffa184390533c500d89"));
}
void MessageDigestTest::testGetCanonicalHashType()
{
CPPUNIT_ASSERT_EQUAL(std::string("sha-1"),
MessageDigest::getCanonicalHashType("sha1"));
CPPUNIT_ASSERT_EQUAL(std::string("sha-256"),
MessageDigest::getCanonicalHashType("sha256"));
CPPUNIT_ASSERT_EQUAL(std::string("unknown"),
MessageDigest::getCanonicalHashType("unknown"));
}
} // namespace aria2