Changeset View
Changeset View
Standalone View
Standalone View
source/ps/tests/test_Hashing.h
- This file was added.
/* Copyright (C) 2021 Wildfire Games. | |||||
* This file is part of 0 A.D. | |||||
* | |||||
* 0 A.D. is free software: you can redistribute it and/or modify | |||||
* it under the terms of the GNU General Public License as published by | |||||
* the Free Software Foundation, either version 2 of the License, or | |||||
* (at your option) any later version. | |||||
* | |||||
* 0 A.D. is distributed in the hope that it will be useful, | |||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||
* GNU General Public License for more details. | |||||
* | |||||
* You should have received a copy of the GNU General Public License | |||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#include "lib/self_test.h" | |||||
#include "ps/Hashing.h" | |||||
class TestHashing : public CxxTest::TestSuite | |||||
{ | |||||
public: | |||||
void test_fast_hash() | |||||
{ | |||||
// Simple test: these should be deterministic and no collision on these trivial cases | |||||
TS_ASSERT_EQUALS(FastHash("", ""), ""); | |||||
TS_ASSERT_EQUALS(FastHash("", "foo"), ""); | |||||
TS_ASSERT_EQUALS(FastHash("pass", ""), "EEB993F2F602DC4D8B189EADDAC6BDF3AE230EFD6342E92F01A96D0394F9E26B"); | |||||
TS_ASSERT_EQUALS(FastHash("pass", "foo"), "9592B1C615164F8681378AA2DB5D3AA3B96329DBBCE327CE5042507D6B0F7C08"); | |||||
TS_ASSERT_EQUALS(FastHash("pass", "foofoo"), "1E4C8A631497D0AD79E9CC890D73F8D32F79A71BDFDD87B7F94D2552BA88F886"); | |||||
TS_ASSERT_EQUALS(FastHash("pass", "bar"), "1E7C793F6B3E300A2597ECF9DEB6EB1D8D387817B8C9B239BAAD7758B52E3385"); | |||||
TS_ASSERT_EQUALS(FastHash("pass", "foobar"), "2C5F6B3193D2F1DEC39D0B307B430B00DF927DEB875A02CA52E9DFC637361D96"); | |||||
TS_ASSERT_EQUALS(FastHash("pass", ""), "EEB993F2F602DC4D8B189EADDAC6BDF3AE230EFD6342E92F01A96D0394F9E26B"); | |||||
TS_ASSERT_EQUALS(FastHash("passpass", ""), "92D7C426C51EECFC36D6DFBB76F28C29AD826A8D5A481C7424FB1760F5DCDD4C"); | |||||
TS_ASSERT_EQUALS(FastHash("passpass", "foo"), "B8C0FD8F03FBDFBCD06EE8459163D9547579DEF24127B9623BCB5C6438970578"); | |||||
TS_ASSERT_EQUALS(FastHash("passpass", "foofoo"), "7C921049C9BBF4C59BC8658F859C8C7D986EEC0FD38F6ABBF8402710BB65F6E5"); | |||||
TS_ASSERT_EQUALS(FastHash("passpass", "bar"), "77B925A32A4A7E70D764B205567611DDB7CEBF22D488D92A52D0AEEF21F49396"); | |||||
TS_ASSERT_EQUALS(FastHash("passpass", "foobar"), "80F83662E9865397BBE1D01037130F2D384129A4B480DB552A6BACB7F4740460"); | |||||
// Test that hashing hashes works. | |||||
TS_ASSERT_EQUALS(FastHash("A989A9C5BDB02DD91C038661424BE039E2AE727483A30D3F13F995D0AB6C3712", "foobar"), "D522D61243CCB7304DFC6E76AC39D16C1F360F771E721F6A4A72E75FB9A99F09"); | |||||
TS_ASSERT_EQUALS(FastHash("D9895FDEE287DBEE19907B7329207F388B1708AC4A123CA537603E953885B20F", "foobar"), "EBAF20776DBAB7C6B638FA878F79CB8432C8A6CBB6E9B760105F7C9286F3035B"); | |||||
} | |||||
}; |
Wildfire Games · Phabricator