Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
cfxjse_mapmodule_unittest.cpp
Go to the documentation of this file.
1
// Copyright 2020 The PDFium Authors
2
// Use of this source code is governed by a BSD-style license that can be
3
// found in the LICENSE file.
4
5
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7
#
include
"fxjs/xfa/cfxjse_mapmodule.h"
8
9
#
include
<
optional
>
10
11
#
include
"core/fxcrt/fx_string.h"
12
#
include
"testing/gtest/include/gtest/gtest.h"
13
#
include
"xfa/fxfa/parser/cxfa_measurement.h"
14
15
TEST
(
CFXJSEMapModule
,
EmptyModule
) {
16
CFXJSE_MapModule
module;
17
EXPECT_FALSE(module
.
HasKey
(
1
)
);
18
EXPECT_FALSE(module
.
HasKey
(
2
)
);
19
EXPECT_FALSE(module
.
HasKey
(
3
)
);
20
EXPECT_FALSE(module
.
GetValue
(1).has_value());
21
EXPECT_FALSE(module
.
GetString
(2).has_value());
22
EXPECT_FALSE(module
.
GetMeasurement
(3).has_value());
23
}
24
25
TEST
(
CFXJSEMapModule
,
InsertDelete
) {
26
const
int
value = 101;
27
WideString
str
(
L"foo"
)
;
28
CXFA_Measurement
measure(L"1 pt");
29
CFXJSE_MapModule
module;
30
31
module
.
SetValue
(
100
,
value
)
;
32
module
.
SetString
(
200
,
str
)
;
33
module
.
SetMeasurement
(
300
,
measure
)
;
34
EXPECT_TRUE(module
.
HasKey
(
100
)
);
35
EXPECT_TRUE(module
.
HasKey
(
200
)
);
36
EXPECT_TRUE(module
.
HasKey
(
300
)
);
37
38
EXPECT_EQ(module
.
GetValue
(100).value(), value);
39
EXPECT_FALSE(module
.
GetString
(100).has_value());
40
EXPECT_FALSE(module
.
GetMeasurement
(100).has_value());
41
42
EXPECT_FALSE(module
.
GetValue
(200).has_value());
43
EXPECT_EQ(module
.
GetString
(200).value(), str);
44
EXPECT_FALSE(module
.
GetMeasurement
(200).has_value());
45
46
EXPECT_FALSE(module
.
GetValue
(300).has_value());
47
EXPECT_FALSE(module
.
GetString
(300).has_value());
48
EXPECT_EQ(module
.
GetMeasurement
(300).value().GetUnit(), measure
.
GetUnit
(
)
);
49
EXPECT_EQ(module
.
GetMeasurement
(300).value().GetValue(), measure
.
GetValue
(
)
);
50
51
module
.
RemoveKey
(
100
)
;
52
module
.
RemoveKey
(
200
)
;
53
module
.
RemoveKey
(
300
)
;
54
EXPECT_FALSE(module
.
HasKey
(
100
)
);
55
EXPECT_FALSE(module
.
HasKey
(
200
)
);
56
EXPECT_FALSE(module
.
HasKey
(
300
)
);
57
EXPECT_FALSE(module
.
GetValue
(100).has_value());
58
EXPECT_FALSE(module
.
GetString
(200).has_value());
59
EXPECT_FALSE(module
.
GetMeasurement
(200).has_value());
60
}
61
62
TEST
(
CFXJSEMapModule
,
KeyCollision
) {
63
const
int
value = 37;
64
WideString
str
(
L"foo"
)
;
65
CXFA_Measurement
measure(L"1 pt");
66
CFXJSE_MapModule
module;
67
68
module
.
SetValue
(
100
,
value
)
;
69
EXPECT_TRUE(module
.
HasKey
(
100
)
);
70
EXPECT_EQ(module
.
GetValue
(100).value(), value);
71
EXPECT_FALSE(module
.
GetString
(100).has_value());
72
EXPECT_FALSE(module
.
GetMeasurement
(100).has_value());
73
74
module
.
SetString
(
100
,
str
)
;
75
EXPECT_TRUE(module
.
HasKey
(
100
)
);
76
EXPECT_FALSE(module
.
GetValue
(100).has_value());
77
EXPECT_EQ(module
.
GetString
(100).value(), str);
78
EXPECT_FALSE(module
.
GetMeasurement
(100).has_value());
79
80
module
.
SetMeasurement
(
100
,
measure
)
;
81
EXPECT_FALSE(module
.
GetValue
(100).has_value());
82
EXPECT_FALSE(module
.
GetString
(100).has_value());
83
EXPECT_EQ(module
.
GetMeasurement
(100).value().GetUnit(), measure
.
GetUnit
(
)
);
84
85
module
.
SetValue
(
100
,
value
)
;
86
EXPECT_TRUE(module
.
HasKey
(
100
)
);
87
EXPECT_EQ(module
.
GetValue
(100).value(), value);
88
EXPECT_FALSE(module
.
GetString
(100).has_value());
89
EXPECT_FALSE(module
.
GetMeasurement
(100).has_value());
90
}
91
92
TEST
(
CFXJSEMapModule
,
MergeData
) {
93
const
int
value1 = 42;
94
const
int
value2 = -1999;
95
WideString
string1
(
L"foo"
)
;
96
WideString
string2
(
L"foo"
)
;
97
CXFA_Measurement
measure1(L"1 pt");
98
CXFA_Measurement
measure2(L"2 mm");
99
CFXJSE_MapModule
module1;
100
CFXJSE_MapModule
module2;
101
102
module1
.
SetValue
(
100
,
value1
)
;
103
module1
.
SetValue
(
101
,
value1
)
;
104
module1
.
SetString
(
200
,
string1
)
;
105
module1
.
SetString
(
201
,
string1
)
;
106
module1
.
SetMeasurement
(
300
,
measure1
)
;
107
module1
.
SetMeasurement
(
301
,
measure1
)
;
108
109
module2
.
SetString
(
100
,
string2
)
;
110
module2
.
SetMeasurement
(
200
,
measure2
)
;
111
module2
.
SetValue
(
300
,
value2
)
;
112
113
module1
.
MergeDataFrom
(
&module2
)
;
114
EXPECT_EQ(module1
.
GetString
(100).value(), string2);
115
EXPECT_EQ(module1
.
GetValue
(101).value(), value1);
116
EXPECT_EQ(module1
.
GetMeasurement
(200).value().GetUnit(), measure2
.
GetUnit
(
)
);
117
EXPECT_EQ(module1
.
GetString
(201).value(), string1);
118
EXPECT_EQ(module1
.
GetValue
(300).value(), value2);
119
EXPECT_EQ(module1
.
GetMeasurement
(301).value().GetUnit(), measure1
.
GetUnit
(
)
);
120
121
// module2 is undisturbed.
122
EXPECT_EQ(module2
.
GetString
(100).value(), string2);
123
EXPECT_EQ(module2
.
GetMeasurement
(200).value().GetUnit(), measure2
.
GetUnit
(
)
);
124
EXPECT_EQ(module2
.
GetValue
(300).value(), value2);
125
}
CFXJSE_MapModule
Definition
cfxjse_mapmodule.h:19
CFXJSE_MapModule::MergeDataFrom
void MergeDataFrom(const CFXJSE_MapModule *pSrc)
Definition
cfxjse_mapmodule.cpp:69
CFXJSE_MapModule::GetValue
std::optional< int32_t > GetValue(uint32_t key) const
Definition
cfxjse_mapmodule.cpp:35
CFXJSE_MapModule::SetValue
void SetValue(uint32_t key, int32_t value)
Definition
cfxjse_mapmodule.cpp:16
CFXJSE_MapModule::SetMeasurement
void SetMeasurement(uint32_t key, const CXFA_Measurement &measurement)
Definition
cfxjse_mapmodule.cpp:28
CFXJSE_MapModule::SetString
void SetString(uint32_t key, const WideString &wsString)
Definition
cfxjse_mapmodule.cpp:22
CFXJSE_MapModule::GetMeasurement
std::optional< CXFA_Measurement > GetMeasurement(uint32_t key) const
Definition
cfxjse_mapmodule.cpp:49
CFXJSE_MapModule::RemoveKey
void RemoveKey(uint32_t key)
Definition
cfxjse_mapmodule.cpp:63
CFXJSE_MapModule::HasKey
bool HasKey(uint32_t key) const
Definition
cfxjse_mapmodule.cpp:57
CFXJSE_MapModule::GetString
std::optional< WideString > GetString(uint32_t key) const
Definition
cfxjse_mapmodule.cpp:42
CXFA_Measurement
Definition
cxfa_measurement.h:13
CXFA_Measurement::GetValue
float GetValue() const
Definition
cxfa_measurement.h:27
CXFA_Measurement::GetUnit
XFA_Unit GetUnit() const
Definition
cxfa_measurement.h:26
fxcrt::WideString::WideString
WideString(const wchar_t *ptr)
Definition
widestring.cpp:407
TEST
TEST(FXCRYPT, MD5GenerateEmtpyData)
Definition
fx_crypt_unittest.cpp:50
WideString
fxcrt::WideString WideString
Definition
widestring.h:207
qtwebengine
src
3rdparty
chromium
third_party
pdfium
fxjs
xfa
cfxjse_mapmodule_unittest.cpp
Generated on
for Qt by
1.18.0