2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2010 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
2010-12-22 21:39:39 +00:00
|
|
|
*/
|
|
|
|
|
2013-11-28 08:24:29 +00:00
|
|
|
// This is a GPU-backend specific test
|
|
|
|
#if SK_SUPPORT_GPU
|
2010-12-22 21:39:39 +00:00
|
|
|
|
2014-08-28 16:54:34 +00:00
|
|
|
#include "GrMurmur3HashKey.h"
|
2014-01-31 21:48:52 +00:00
|
|
|
#include "GrBinHashKey.h"
|
2013-11-28 08:24:29 +00:00
|
|
|
|
2014-01-31 21:48:52 +00:00
|
|
|
#include "Test.h"
|
2010-12-22 21:39:39 +00:00
|
|
|
|
2014-11-21 14:48:43 +00:00
|
|
|
struct AlignedKey {
|
|
|
|
uint32_t align;
|
|
|
|
char key[8];
|
|
|
|
};
|
|
|
|
|
2014-07-20 16:40:00 +00:00
|
|
|
template<typename KeyType> static void TestHash(skiatest::Reporter* reporter) {
|
2014-11-21 14:48:43 +00:00
|
|
|
AlignedKey a, b;
|
|
|
|
memcpy(&a.key, "abcdABCD", 8);
|
|
|
|
memcpy(&b.key, "abcdBBCD", 8);
|
|
|
|
const uint32_t* testStringA = reinterpret_cast<const uint32_t*>(&a.key);
|
|
|
|
const uint32_t* testStringB = reinterpret_cast<const uint32_t*>(&b.key);
|
2011-03-31 21:26:24 +00:00
|
|
|
|
2014-07-20 16:40:00 +00:00
|
|
|
KeyType keyA;
|
2011-08-18 18:15:16 +00:00
|
|
|
keyA.setKeyData(testStringA);
|
|
|
|
// test copy constructor and comparison
|
2014-07-20 16:40:00 +00:00
|
|
|
KeyType keyA2(keyA);
|
2013-11-28 08:24:29 +00:00
|
|
|
REPORTER_ASSERT(reporter, keyA == keyA2);
|
|
|
|
REPORTER_ASSERT(reporter, keyA.getHash() == keyA2.getHash());
|
2011-08-18 18:15:16 +00:00
|
|
|
// test re-init
|
|
|
|
keyA2.setKeyData(testStringA);
|
2013-11-28 08:24:29 +00:00
|
|
|
REPORTER_ASSERT(reporter, keyA == keyA2);
|
|
|
|
REPORTER_ASSERT(reporter, keyA.getHash() == keyA2.getHash());
|
2011-08-18 18:15:16 +00:00
|
|
|
// test sorting
|
2014-07-20 16:40:00 +00:00
|
|
|
KeyType keyB;
|
2011-08-18 18:15:16 +00:00
|
|
|
keyB.setKeyData(testStringB);
|
2013-11-28 08:24:29 +00:00
|
|
|
REPORTER_ASSERT(reporter, keyA.getHash() != keyB.getHash());
|
2011-03-31 21:26:24 +00:00
|
|
|
}
|
|
|
|
|
2014-07-20 16:40:00 +00:00
|
|
|
|
|
|
|
DEF_TEST(GrBinHashKey, reporter) {
|
|
|
|
enum {
|
|
|
|
kDataLenUsedForKey = 8
|
|
|
|
};
|
|
|
|
|
|
|
|
TestHash<GrBinHashKey<kDataLenUsedForKey> >(reporter);
|
|
|
|
TestHash<GrMurmur3HashKey<kDataLenUsedForKey> >(reporter);
|
|
|
|
}
|
|
|
|
|
2013-11-28 08:24:29 +00:00
|
|
|
#endif
|