314 lines
7.9 KiB
C++
314 lines
7.9 KiB
C++
/*
|
|
* Copyright (c) 2011 Juli Mallett. All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions
|
|
* are met:
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
* notice, this list of conditions and the following disclaimer.
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
* documentation and/or other materials provided with the distribution.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
* SUCH DAMAGE.
|
|
*/
|
|
|
|
#include <common/test.h>
|
|
|
|
#include <xcodec/xcodec.h>
|
|
#include <xcodec/xcodec_hash.h>
|
|
|
|
/*
|
|
* Single-character run known-answer tests.
|
|
*/
|
|
static uint64_t char_kats[] = {
|
|
0x0000000080200400ull,
|
|
0x8200400000400800ull,
|
|
0x0400800080600c00ull,
|
|
0x8200400000801000ull,
|
|
0x8600c00080a01400ull,
|
|
0x8200400000c01800ull,
|
|
0x0400800080e01c00ull,
|
|
0x8200400001002000ull,
|
|
0x0801000081202400ull,
|
|
0x8200400001402800ull,
|
|
0x0400800081602c00ull,
|
|
0x8200400001803000ull,
|
|
0x8600c00081a03400ull,
|
|
0x8200400001c03800ull,
|
|
0x0400800081e03c00ull,
|
|
0x8200400002004000ull,
|
|
0x8a01400082204400ull,
|
|
0x8200400002404800ull,
|
|
0x0400800082604c00ull,
|
|
0x8200400002805000ull,
|
|
0x8600c00082a05400ull,
|
|
0x8200400002c05800ull,
|
|
0x0400800082e05c00ull,
|
|
0x8200400003006000ull,
|
|
0x0801000083206400ull,
|
|
0x8200400003406800ull,
|
|
0x0400800083606c00ull,
|
|
0x8200400003807000ull,
|
|
0x8600c00083a07400ull,
|
|
0x8200400003c07800ull,
|
|
0x0400800083e07c00ull,
|
|
0x8200400004008000ull,
|
|
0x0c01800084208400ull,
|
|
0x8200400004408800ull,
|
|
0x0400800084608c00ull,
|
|
0x8200400004809000ull,
|
|
0x8600c00084a09400ull,
|
|
0x8200400004c09800ull,
|
|
0x0400800084e09c00ull,
|
|
0x820040000500a000ull,
|
|
0x080100008520a400ull,
|
|
0x820040000540a800ull,
|
|
0x040080008560ac00ull,
|
|
0x820040000580b000ull,
|
|
0x8600c00085a0b400ull,
|
|
0x8200400005c0b800ull,
|
|
0x0400800085e0bc00ull,
|
|
0x820040000600c000ull,
|
|
0x8a0140008620c400ull,
|
|
0x820040000640c800ull,
|
|
0x040080008660cc00ull,
|
|
0x820040000680d000ull,
|
|
0x8600c00086a0d400ull,
|
|
0x8200400006c0d800ull,
|
|
0x0400800086e0dc00ull,
|
|
0x820040000700e000ull,
|
|
0x080100008720e400ull,
|
|
0x820040000740e800ull,
|
|
0x040080008760ec00ull,
|
|
0x820040000780f000ull,
|
|
0x8600c00087a0f400ull,
|
|
0x8200400007c0f800ull,
|
|
0x0400800087e0fc00ull,
|
|
0x8200400008010000ull,
|
|
0x8e01c00088210400ull,
|
|
0x8200400008410800ull,
|
|
0x0400800088610c00ull,
|
|
0x8200400008811000ull,
|
|
0x8600c00088a11400ull,
|
|
0x8200400008c11800ull,
|
|
0x0400800088e11c00ull,
|
|
0x8200400009012000ull,
|
|
0x0801000089212400ull,
|
|
0x8200400009412800ull,
|
|
0x0400800089612c00ull,
|
|
0x8200400009813000ull,
|
|
0x8600c00089a13400ull,
|
|
0x8200400009c13800ull,
|
|
0x0400800089e13c00ull,
|
|
0x820040000a014000ull,
|
|
0x8a0140008a214400ull,
|
|
0x820040000a414800ull,
|
|
0x040080008a614c00ull,
|
|
0x820040000a815000ull,
|
|
0x8600c0008aa15400ull,
|
|
0x820040000ac15800ull,
|
|
0x040080008ae15c00ull,
|
|
0x820040000b016000ull,
|
|
0x080100008b216400ull,
|
|
0x820040000b416800ull,
|
|
0x040080008b616c00ull,
|
|
0x820040000b817000ull,
|
|
0x8600c0008ba17400ull,
|
|
0x820040000bc17800ull,
|
|
0x040080008be17c00ull,
|
|
0x820040000c018000ull,
|
|
0x0c0180008c218400ull,
|
|
0x820040000c418800ull,
|
|
0x040080008c618c00ull,
|
|
0x820040000c819000ull,
|
|
0x8600c0008ca19400ull,
|
|
0x820040000cc19800ull,
|
|
0x040080008ce19c00ull,
|
|
0x820040000d01a000ull,
|
|
0x080100008d21a400ull,
|
|
0x820040000d41a800ull,
|
|
0x040080008d61ac00ull,
|
|
0x820040000d81b000ull,
|
|
0x8600c0008da1b400ull,
|
|
0x820040000dc1b800ull,
|
|
0x040080008de1bc00ull,
|
|
0x820040000e01c000ull,
|
|
0x8a0140008e21c400ull,
|
|
0x820040000e41c800ull,
|
|
0x040080008e61cc00ull,
|
|
0x820040000e81d000ull,
|
|
0x8600c0008ea1d400ull,
|
|
0x820040000ec1d800ull,
|
|
0x040080008ee1dc00ull,
|
|
0x820040000f01e000ull,
|
|
0x080100008f21e400ull,
|
|
0x820040000f41e800ull,
|
|
0x040080008f61ec00ull,
|
|
0x820040000f81f000ull,
|
|
0x8600c0008fa1f400ull,
|
|
0x820040000fc1f800ull,
|
|
0x040080008fe1fc00ull,
|
|
0x8200400010020000ull,
|
|
0x1002000090220400ull,
|
|
0x8200400010420800ull,
|
|
0x0400800090620c00ull,
|
|
0x8200400010821000ull,
|
|
0x8600c00090a21400ull,
|
|
0x8200400010c21800ull,
|
|
0x0400800090e21c00ull,
|
|
0x8200400011022000ull,
|
|
0x0801000091222400ull,
|
|
0x8200400011422800ull,
|
|
0x0400800091622c00ull,
|
|
0x8200400011823000ull,
|
|
0x8600c00091a23400ull,
|
|
0x8200400011c23800ull,
|
|
0x0400800091e23c00ull,
|
|
0x8200400012024000ull,
|
|
0x8a01400092224400ull,
|
|
0x8200400012424800ull,
|
|
0x0400800092624c00ull,
|
|
0x8200400012825000ull,
|
|
0x8600c00092a25400ull,
|
|
0x8200400012c25800ull,
|
|
0x0400800092e25c00ull,
|
|
0x8200400013026000ull,
|
|
0x0801000093226400ull,
|
|
0x8200400013426800ull,
|
|
0x0400800093626c00ull,
|
|
0x8200400013827000ull,
|
|
0x8600c00093a27400ull,
|
|
0x8200400013c27800ull,
|
|
0x0400800093e27c00ull,
|
|
0x8200400014028000ull,
|
|
0x0c01800094228400ull,
|
|
0x8200400014428800ull,
|
|
0x0400800094628c00ull,
|
|
0x8200400014829000ull,
|
|
0x8600c00094a29400ull,
|
|
0x8200400014c29800ull,
|
|
0x0400800094e29c00ull,
|
|
0x820040001502a000ull,
|
|
0x080100009522a400ull,
|
|
0x820040001542a800ull,
|
|
0x040080009562ac00ull,
|
|
0x820040001582b000ull,
|
|
0x8600c00095a2b400ull,
|
|
0x8200400015c2b800ull,
|
|
0x0400800095e2bc00ull,
|
|
0x820040001602c000ull,
|
|
0x8a0140009622c400ull,
|
|
0x820040001642c800ull,
|
|
0x040080009662cc00ull,
|
|
0x820040001682d000ull,
|
|
0x8600c00096a2d400ull,
|
|
0x8200400016c2d800ull,
|
|
0x0400800096e2dc00ull,
|
|
0x820040001702e000ull,
|
|
0x080100009722e400ull,
|
|
0x820040001742e800ull,
|
|
0x040080009762ec00ull,
|
|
0x820040001782f000ull,
|
|
0x8600c00097a2f400ull,
|
|
0x8200400017c2f800ull,
|
|
0x0400800097e2fc00ull,
|
|
0x8200400018030000ull,
|
|
0x8e01c00098230400ull,
|
|
0x8200400018430800ull,
|
|
0x0400800098630c00ull,
|
|
0x8200400018831000ull,
|
|
0x8600c00098a31400ull,
|
|
0x8200400018c31800ull,
|
|
0x0400800098e31c00ull,
|
|
0x8200400019032000ull,
|
|
0x0801000099232400ull,
|
|
0x8200400019432800ull,
|
|
0x0400800099632c00ull,
|
|
0x8200400019833000ull,
|
|
0x8600c00099a33400ull,
|
|
0x8200400019c33800ull,
|
|
0x0400800099e33c00ull,
|
|
0x820040001a034000ull,
|
|
0x8a0140009a234400ull,
|
|
0x820040001a434800ull,
|
|
0x040080009a634c00ull,
|
|
0x820040001a835000ull,
|
|
0x8600c0009aa35400ull,
|
|
0x820040001ac35800ull,
|
|
0x040080009ae35c00ull,
|
|
0x820040001b036000ull,
|
|
0x080100009b236400ull,
|
|
0x820040001b436800ull,
|
|
0x040080009b636c00ull,
|
|
0x820040001b837000ull,
|
|
0x8600c0009ba37400ull,
|
|
0x820040001bc37800ull,
|
|
0x040080009be37c00ull,
|
|
0x820040001c038000ull,
|
|
0x0c0180009c238400ull,
|
|
0x820040001c438800ull,
|
|
0x040080009c638c00ull,
|
|
0x820040001c839000ull,
|
|
0x8600c0009ca39400ull,
|
|
0x820040001cc39800ull,
|
|
0x040080009ce39c00ull,
|
|
0x820040001d03a000ull,
|
|
0x080100009d23a400ull,
|
|
0x820040001d43a800ull,
|
|
0x040080009d63ac00ull,
|
|
0x820040001d83b000ull,
|
|
0x8600c0009da3b400ull,
|
|
0x820040001dc3b800ull,
|
|
0x040080009de3bc00ull,
|
|
0x820040001e03c000ull,
|
|
0x8a0140009e23c400ull,
|
|
0x820040001e43c800ull,
|
|
0x040080009e63cc00ull,
|
|
0x820040001e83d000ull,
|
|
0x8600c0009ea3d400ull,
|
|
0x820040001ec3d800ull,
|
|
0x040080009ee3dc00ull,
|
|
0x820040001f03e000ull,
|
|
0x080100009f23e400ull,
|
|
0x820040001f43e800ull,
|
|
0x040080009f63ec00ull,
|
|
0x820040001f83f000ull,
|
|
0x8600c0009fa3f400ull,
|
|
0x820040001fc3f800ull,
|
|
0x040080009fe3fc00ull,
|
|
0x8200400020040000ull
|
|
};
|
|
|
|
int
|
|
main(void)
|
|
{
|
|
{
|
|
TestGroup g("/test/xcodec/hash1/char_kat", "XCodecHash #1 / Single-character KATs");
|
|
|
|
unsigned i;
|
|
for (i = 0; i < sizeof char_kats / sizeof char_kats[0]; i++) {
|
|
XCodecHash hash;
|
|
unsigned j;
|
|
for (j = 0; j < XCODEC_SEGMENT_LENGTH; j++)
|
|
hash.add((uint8_t)i);
|
|
|
|
std::ostringstream os;
|
|
os << "KAT #" << i;
|
|
|
|
Test _(g, os.str(), char_kats[i] == hash.mix());
|
|
}
|
|
}
|
|
|
|
return (0);
|
|
}
|