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
cfx_globaldata_unittest.cpp
Go to the documentation of this file.
1
// Copyright 2018 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
#
include
"fxjs/cfx_globaldata.h"
6
7
#
include
<
stdint
.
h
>
8
9
#
include
<
utility
>
10
#
include
<
vector
>
11
12
#
include
"core/fxcrt/data_vector.h"
13
#
include
"testing/gtest/include/gtest/gtest.h"
14
15
namespace
{
16
17
class
TestDelegate :
public
CFX_GlobalData
::
Delegate
{
18
public
:
19
TestDelegate() =
default
;
20
~TestDelegate()
override
=
default
;
21
22
bool
StoreBuffer(pdfium::span<
const
uint8_t> buffer)
override
{
23
last_buffer_ = DataVector<uint8_t>(buffer.begin(), buffer.end());
24
return
true
;
25
}
26
std::optional<pdfium::span<uint8_t>> LoadBuffer()
override
{
27
return
pdfium::span<uint8_t>(last_buffer_);
28
}
29
void
BufferDone()
override
{
30
// Catch misuse after done.
31
last_buffer_ = DataVector<uint8_t>();
32
}
33
34
DataVector<uint8_t> last_buffer_;
35
};
36
37
}
// namespace
38
39
TEST
(
CFXGlobalData
,
GetSafety
) {
40
CFX_GlobalData
* pInstance =
CFX_GlobalData
::
GetRetainedInstance
(
nullptr
)
;
41
EXPECT_FALSE(pInstance
->
GetGlobalVariable
(
"nonesuch"
)
);
42
EXPECT_FALSE(pInstance
->
GetAt
(
-1
)
);
43
EXPECT_FALSE(pInstance
->
GetAt
(
0
)
);
44
EXPECT_FALSE(pInstance
->
GetAt
(
1
)
);
45
46
pInstance
->
SetGlobalVariableNumber
(
"double"
,
2.0
)
;
47
pInstance
->
SetGlobalVariableString
(
"string"
,
"clams"
)
;
48
49
EXPECT_FALSE(pInstance
->
GetGlobalVariable
(
"nonesuch"
)
);
50
EXPECT_FALSE(pInstance
->
GetAt
(
-1
)
);
51
EXPECT_EQ(pInstance
->
GetGlobalVariable
(
"double"
)
, pInstance
->
GetAt
(
0
)
);
52
EXPECT_EQ(pInstance
->
GetGlobalVariable
(
"string"
)
, pInstance
->
GetAt
(
1
)
);
53
EXPECT_FALSE(pInstance
->
GetAt
(
2
)
);
54
55
ASSERT_TRUE(pInstance
->
Release
(
)
);
56
}
57
58
TEST
(
CFXGlobalData
,
StoreReload
) {
59
TestDelegate delegate;
60
std::vector<std::unique_ptr<CFX_KeyValue>> array;
61
CFX_GlobalData
* pInstance =
CFX_GlobalData
::
GetRetainedInstance
(&delegate);
62
pInstance
->
SetGlobalVariableNumber
(
"double"
,
2.0
)
;
63
pInstance
->
SetGlobalVariableString
(
"string"
,
"clams"
)
;
64
pInstance
->
SetGlobalVariableBoolean
(
"boolean"
,
true
)
;
65
pInstance
->
SetGlobalVariableNull
(
"null"
)
;
66
pInstance->SetGlobalVariableObject(
"array"
,
std
::move(array));
67
pInstance
->
SetGlobalVariablePersistent
(
"double"
,
true
)
;
68
pInstance
->
SetGlobalVariablePersistent
(
"string"
,
true
)
;
69
pInstance
->
SetGlobalVariablePersistent
(
"boolean"
,
true
)
;
70
pInstance
->
SetGlobalVariablePersistent
(
"null"
,
true
)
;
71
pInstance
->
SetGlobalVariablePersistent
(
"array"
,
true
)
;
72
ASSERT_TRUE(pInstance
->
Release
(
)
);
73
74
pInstance =
CFX_GlobalData
::
GetRetainedInstance
(&delegate);
75
auto
* element = pInstance
->
GetAt
(
0
)
;
76
ASSERT_TRUE(element);
77
EXPECT_EQ(
"double"
, element->data.sKey);
78
EXPECT_EQ(
CFX_Value
::
DataType
::
kNumber
, element->data.nType);
79
EXPECT_EQ(2.0, element->data.dData);
80
81
element = pInstance
->
GetAt
(
1
)
;
82
ASSERT_TRUE(element);
83
EXPECT_EQ(
"string"
, element->data.sKey);
84
EXPECT_EQ(
CFX_Value
::
DataType
::
kString
, element->data.nType);
85
EXPECT_EQ(
"clams"
, element->data.sData);
86
87
element = pInstance
->
GetAt
(
2
)
;
88
ASSERT_TRUE(element);
89
EXPECT_EQ(
"boolean"
, element->data.sKey);
90
EXPECT_EQ(
CFX_Value
::
DataType
::
kBoolean
, element->data.nType);
91
EXPECT_EQ(
true
, element->data.bData);
92
93
element = pInstance
->
GetAt
(
3
)
;
94
ASSERT_TRUE(element);
95
EXPECT_EQ(
"null"
, element->data.sKey);
96
EXPECT_EQ(
CFX_Value
::
DataType
::
kNull
, element->data.nType);
97
98
// Arrays don't get persisted.
99
element = pInstance
->
GetAt
(
4
)
;
100
ASSERT_FALSE(element);
101
102
ASSERT_TRUE(pInstance
->
Release
(
)
);
103
}
104
105
TEST
(
CFXGlobalData
,
ResetValues
) {
106
CFX_GlobalData
* pInstance =
CFX_GlobalData
::
GetRetainedInstance
(
nullptr
)
;
107
pInstance
->
SetGlobalVariableString
(
"double"
,
"bogus!!!"
)
;
108
pInstance
->
SetGlobalVariableString
(
"string"
,
"bogus!!!"
)
;
109
pInstance
->
SetGlobalVariableString
(
"boolean"
,
"bogus!!!"
)
;
110
pInstance
->
SetGlobalVariableString
(
"null"
,
"bogus!!!"
)
;
111
112
pInstance
->
SetGlobalVariableNumber
(
"double"
,
2.0
)
;
113
pInstance
->
SetGlobalVariableString
(
"string"
,
"clams"
)
;
114
pInstance
->
SetGlobalVariableBoolean
(
"boolean"
,
true
)
;
115
pInstance
->
SetGlobalVariableNull
(
"null"
)
;
116
117
auto
* element = pInstance
->
GetAt
(
0
)
;
118
ASSERT_TRUE(element);
119
EXPECT_EQ(
"double"
, element->data.sKey);
120
EXPECT_EQ(
CFX_Value
::
DataType
::
kNumber
, element->data.nType);
121
EXPECT_EQ(2.0, element->data.dData);
122
123
element = pInstance
->
GetAt
(
1
)
;
124
ASSERT_TRUE(element);
125
EXPECT_EQ(
"string"
, element->data.sKey);
126
EXPECT_EQ(
CFX_Value
::
DataType
::
kString
, element->data.nType);
127
EXPECT_EQ(
"clams"
, element->data.sData);
128
129
element = pInstance
->
GetAt
(
2
)
;
130
ASSERT_TRUE(element);
131
EXPECT_EQ(
"boolean"
, element->data.sKey);
132
EXPECT_EQ(
CFX_Value
::
DataType
::
kBoolean
, element->data.nType);
133
EXPECT_EQ(
true
, element->data.bData);
134
135
element = pInstance
->
GetAt
(
3
)
;
136
ASSERT_TRUE(element);
137
EXPECT_EQ(
"null"
, element->data.sKey);
138
EXPECT_EQ(
CFX_Value
::
DataType
::
kNull
, element->data.nType);
139
140
ASSERT_TRUE(pInstance
->
Release
(
)
);
141
}
142
143
TEST
(
CFXGlobalData
,
DeleteValues
) {
144
CFX_GlobalData
* pInstance =
CFX_GlobalData
::
GetRetainedInstance
(
nullptr
)
;
145
pInstance
->
SetGlobalVariableNumber
(
"double"
,
2.0
)
;
146
pInstance
->
SetGlobalVariableString
(
"string"
,
"clams"
)
;
147
pInstance
->
SetGlobalVariableBoolean
(
"boolean"
,
true
)
;
148
pInstance
->
SetGlobalVariableNull
(
"null"
)
;
149
EXPECT_EQ(4, pInstance
->
GetSize
(
)
);
150
151
pInstance
->
DeleteGlobalVariable
(
"nonesuch"
)
;
152
EXPECT_EQ(4, pInstance
->
GetSize
(
)
);
153
154
pInstance
->
DeleteGlobalVariable
(
"boolean"
)
;
155
EXPECT_EQ(3, pInstance
->
GetSize
(
)
);
156
157
pInstance
->
DeleteGlobalVariable
(
"string"
)
;
158
EXPECT_EQ(2, pInstance
->
GetSize
(
)
);
159
160
pInstance
->
DeleteGlobalVariable
(
"double"
)
;
161
EXPECT_EQ(1, pInstance
->
GetSize
(
)
);
162
163
pInstance
->
DeleteGlobalVariable
(
"null"
)
;
164
EXPECT_EQ(0, pInstance
->
GetSize
(
)
);
165
166
ASSERT_TRUE(pInstance
->
Release
(
)
);
167
}
CFX_GlobalData::Delegate
Definition
cfx_globaldata.h:21
CFX_GlobalData
Definition
cfx_globaldata.h:19
CFX_GlobalData::Release
bool Release()
Definition
cfx_globaldata.cpp:95
CFX_GlobalData::SetGlobalVariablePersistent
bool SetGlobalVariablePersistent(ByteString propname, bool bPersistent)
Definition
cfx_globaldata.cpp:216
CFX_GlobalData::GetAt
Element * GetAt(int index)
Definition
cfx_globaldata.cpp:245
CFX_GlobalData::SetGlobalVariableNull
void SetGlobalVariableNull(ByteString propname)
Definition
cfx_globaldata.cpp:201
CFX_GlobalData::SetGlobalVariableNumber
void SetGlobalVariableNumber(ByteString propname, double dData)
Definition
cfx_globaldata.cpp:128
CFX_GlobalData::DeleteGlobalVariable
bool DeleteGlobalVariable(ByteString propname)
Definition
cfx_globaldata.cpp:229
CFX_GlobalData::GetRetainedInstance
static CFX_GlobalData * GetRetainedInstance(Delegate *pDelegate)
Definition
cfx_globaldata.cpp:87
CFX_GlobalData::SetGlobalVariableBoolean
void SetGlobalVariableBoolean(ByteString propname, bool bData)
Definition
cfx_globaldata.cpp:146
CFX_GlobalData::GetGlobalVariable
Element * GetGlobalVariable(const ByteString &sPropname)
Definition
cfx_globaldata.cpp:122
CFX_GlobalData::SetGlobalVariableString
void SetGlobalVariableString(ByteString propname, const ByteString &sData)
Definition
cfx_globaldata.cpp:164
CFX_GlobalData::GetSize
int32_t GetSize() const
Definition
cfx_globaldata.cpp:241
CFX_Value
Definition
cfx_keyvalue.h:17
CFX_Value::DataType
DataType
Definition
cfx_keyvalue.h:19
CFX_Value::DataType::kString
@ kString
Definition
cfx_keyvalue.h:22
CFX_Value::DataType::kBoolean
@ kBoolean
Definition
cfx_keyvalue.h:21
CFX_Value::DataType::kNumber
@ kNumber
Definition
cfx_keyvalue.h:20
CFX_Value::DataType::kNull
@ kNull
Definition
cfx_keyvalue.h:24
TEST
TEST(FXCRYPT, MD5GenerateEmtpyData)
Definition
fx_crypt_unittest.cpp:50
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
qtwebengine
src
3rdparty
chromium
third_party
pdfium
fxjs
cfx_globaldata_unittest.cpp
Generated on
for Qt by
1.18.0