mame/3rdparty/bx/tests/hash_test.cpp
Julian Sikorski 0837e7451a WIP: sync bgfx, bx and bimg with latest upstream (#5723)
* Sync with bgfx upstream revision b91d0b6

* Sync with bx upstream revision d60912b

* Sync with bimg upstream revision bd81f60

* Add astc-codec decoder

* Rename VertexDecl to VertexLayout

* Rename UniformType enum Int1 to Sampler.

* Add NVN stub

* Fix unused-const-variable error on macOS

* Drop redundant explicit language parameters
buildoptions_cpp are only applied to c++ files and buildoptions_objcpp are only
applied to objective c++ files. As such, hardcoding -x offers no benefit while
preventing overrides (such as one needed by 3rdparty/bgfx/src/renderer_vk.cpp on
macOS) from working.

* Re-introduce -x c++ in places where C code is compiled as C++ to prevent clang from throwing a warning

* Build bgfx as Objective-C++ on macOS
It is needed due to included headers

* Enable Direct3D12 and Vulkan bgfx rendering backends

* Enable building of spirv shaders

* Properly escape /c in cmd call

* Comment out dx12 bgfx renderer

* Honor VERBOSE setting during shaders build

* Only invert hlsl shader XYZ_TO_sRGB matrix for opengl

* Add spirv shaders

* OpenGL ES needs transposed matrix too

* Metal needs transposed matrix as well
2019-10-13 07:50:38 -04:00

80 lines
1.5 KiB
C++

/*
* Copyright 2010-2019 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bx#license-bsd-2-clause
*/
#include "test.h"
#include <bx/hash.h>
void makeCrcTable(uint32_t _poly)
{
for (uint32_t ii = 0; ii < 256; ++ii)
{
uint32_t crc = ii;
for (uint32_t jj = 0; jj < 8; ++jj)
{
if (1 == (crc & 1) )
{
crc = (crc >> 1) ^ _poly;
}
else
{
crc >>= 1;
}
}
printf("0x%08x,%c", crc, 7 == (ii & 7) ? '\n' : ' ');
}
}
struct HashTest
{
uint32_t crc32;
uint32_t adler32;
const char* input;
};
const HashTest s_hashTest[] =
{
{ 0, 1, "" },
{ 0xe8b7be43, 0x00620062, "a" },
{ 0x9e83486d, 0x012600c4, "ab" },
{ 0xc340daab, 0x06060205, "abvgd" },
{ 0x07642fe2, 0x020a00d6, "1389" },
{ 0x26d75737, 0x04530139, "555333" },
};
TEST_CASE("HashCrc32", "")
{
#if 0
makeCrcTable(0xedb88320);
printf("\n");
makeCrcTable(0x82f63b78);
printf("\n");
makeCrcTable(0xeb31d82e);
#endif // 0
for (uint32_t ii = 0; ii < BX_COUNTOF(s_hashTest); ++ii)
{
const HashTest& test = s_hashTest[ii];
bx::HashCrc32 hash;
hash.begin();
hash.add(test.input, bx::strLen(test.input) );
REQUIRE(test.crc32 == hash.end() );
}
}
TEST_CASE("HashAdler32", "")
{
for (uint32_t ii = 0; ii < BX_COUNTOF(s_hashTest); ++ii)
{
const HashTest& test = s_hashTest[ii];
bx::HashAdler32 hash;
hash.begin();
hash.add(test.input, bx::strLen(test.input) );
REQUIRE(test.adler32 == hash.end() );
}
}