Mercurial > code
view C++/Tests/Hash/TestHash.cpp @ 236:ff2db0ed78f1
* Import GoogleTest
* Start testing of OptionParser
author | David Demelier <markand@malikania.fr> |
---|---|
date | Fri, 04 Jul 2014 22:16:04 +0200 |
parents | 6a664378c5c4 |
children |
line wrap: on
line source
/* * TestHash.cpp -- test the hash cryptographic functions * * Copyright (c) 2013, 2014 David Demelier <markand@malikania.fr> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include <cppunit/TextTestRunner.h> #include <Hash.h> #include "TestHash.h" /* * We test the "Hello World" message in all cryptographic functions. */ void TestHash::md5() { std::string expected = "b10a8db164e0754105b7a99be72e3fe5"; std::string output = Hash::md5("Hello World"); CPPUNIT_ASSERT_EQUAL(output, expected); } void TestHash::sha1() { std::string expected = "0a4d55a8d778e5022fab701977c5d840bbc486d0"; std::string output = Hash::sha1("Hello World"); CPPUNIT_ASSERT_EQUAL(output, expected); } void TestHash::sha256() { std::string expected = "a591a6d40bf420404a011733cfb7b190d62c65bf0bcda32b57b277d9ad9f146e"; std::string output = Hash::sha256("Hello World"); CPPUNIT_ASSERT_EQUAL(output, expected); } void TestHash::sha512() { std::string expected = "2c74fd17edafd80e8447b0d46741ee243b7eb74dd2149a0ab1b9246fb30382f27e853d8585719e0e67cbda0daa8f51671064615d645ae27acb15bfb1447f459b"; std::string output = Hash::sha512("Hello World"); CPPUNIT_ASSERT_EQUAL(output, expected); } int main() { CppUnit::TextTestRunner runnerText; runnerText.addTest(TestHash::suite()); return runnerText.run("", false) == 1 ? 0 : 1; }