1 // Copyright 2018 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "xfa/fxfa/fxfa_basic.h"
6 
7 #include "core/fxcrt/bytestring.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 
10 namespace {
11 
HashTestCase(uint32_t hash,const char * str,uint32_t * so_far)12 void HashTestCase(uint32_t hash, const char* str, uint32_t* so_far) {
13   if (hash != 0xffffffffu) {
14     EXPECT_EQ(hash, FX_HashCode_GetAsIfW(str, false)) << str;
15     EXPECT_LT(*so_far, hash) << hash;
16   } else {
17     EXPECT_NE(hash, FX_HashCode_GetAsIfW(str, false)) << str;
18   }
19   *so_far = hash;
20 }
21 
22 }  // namespace
23 
TEST(FXFABasic,PacketHashTest)24 TEST(FXFABasic, PacketHashTest) {
25   uint32_t so_far = 0;
26 #undef PCKT____
27 #define PCKT____(a, b, c, d, e, f) HashTestCase(a, b, &so_far);
28 #include "xfa/fxfa/parser/packets.inc"
29 #undef PCKT____
30 }
31 
TEST(FXFABasic,AttributeHashTest)32 TEST(FXFABasic, AttributeHashTest) {
33   uint32_t so_far = 0;
34 #undef ATTR____
35 #define ATTR____(a, b, c, d) HashTestCase(a, b, &so_far);
36 #include "xfa/fxfa/parser/attributes.inc"
37 #undef ATTR____
38 }
39 
TEST(FXFABasic,ValueHashTest)40 TEST(FXFABasic, ValueHashTest) {
41   uint32_t so_far = 0;
42 #undef VALUE____
43 #define VALUE____(a, b, c) HashTestCase(a, b, &so_far);
44 #include "xfa/fxfa/parser/attribute_values.inc"
45 #undef VALUE____
46 }
47 
TEST(FXFABasic,ElementHashTest)48 TEST(FXFABasic, ElementHashTest) {
49   uint32_t so_far = 0;
50 #undef ELEM____
51 #define ELEM____(a, b, c, d) HashTestCase(a, b, &so_far);
52 #include "xfa/fxfa/parser/elements.inc"
53 #undef ELEM____
54 }
55