Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(183)

Side by Side Diff: Source/core/css/CSSValueTest.cpp

Issue 1164573002: CSSValue Immediates: Change CSSValue to an object instead of a pointer (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Some small fixes to (hopefully) fix some broken tests Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium 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 "config.h"
6 #include "core/css/CSSValue.h"
7
8 #include "core/css/CSSPrimitiveValue.h"
9 #include "core/css/CSSValueTestHelper.h"
10 #include <gtest/gtest.h>
11
12 using namespace blink;
13
14 namespace {
15
16 // Helper functions since PassRefPtrWillBeRawPtr cannot be a member variable.
17 CSSValue makeCSSValueWithPassRefPtr(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> pr imitiveValue)
18 {
19 return CSSValue(primitiveValue);
20 }
21 CSSValue* makeCSSValuePtrWithPassRefPtr(PassRefPtrWillBeRawPtr<CSSPrimitiveValue > primitiveValue)
22 {
23 return new CSSValue(primitiveValue);
24 }
25 NullableCSSValue makeNullableCSSValueWithPassRefPtr(PassRefPtrWillBeRawPtr<CSSPr imitiveValue> primitiveValue)
26 {
27 return NullableCSSValue(primitiveValue);
28 }
29 NullableCSSValue* makeNullableCSSValuePtrWithPassRefPtr(PassRefPtrWillBeRawPtr<C SSPrimitiveValue> primitiveValue)
30 {
31 return new NullableCSSValue(primitiveValue);
32 }
33
34 TEST(CSSValueTest, CSSValueStackTest)
35 {
36 CSSPrimitiveValue* primitiveValuePtr = CSSPrimitiveValue::createIdentifier(C SSValueBold).leakRef();
37 RefPtrWillBeRawPtr<CSSPrimitiveValue> primitiveValueRef = CSSPrimitiveValue: :createIdentifier(CSSValueBold);
38
39 CSSValue rawPtrConstructor(primitiveValuePtr);
40 EXPECT_STREQ("bold", rawPtrConstructor.cssText().utf8().data());
41
42 CSSValue passRefPtrConstructor = makeCSSValueWithPassRefPtr(CSSPrimitiveValu e::createIdentifier(CSSValueBold));
43 EXPECT_STREQ("bold", passRefPtrConstructor.cssText().utf8().data());
44
45 CSSValue refPtrConstructor(primitiveValueRef);
46 EXPECT_STREQ("bold", refPtrConstructor.cssText().utf8().data());
47
48 CSSValue copyConstructor(rawPtrConstructor);
49 EXPECT_STREQ("bold", copyConstructor.cssText().utf8().data());
50
51 CSSValue constCopyConstructor(*const_cast<const CSSValue*>(&rawPtrConstructo r));
52 EXPECT_STREQ("bold", constCopyConstructor.cssText().utf8().data());
53
54 CSSValue newAssignmentOperator = rawPtrConstructor;
55 EXPECT_STREQ("bold", newAssignmentOperator.cssText().utf8().data());
56 EXPECT_STREQ("bold", rawPtrConstructor.cssText().utf8().data());
57
58 CSSValue existingAssignmentOperator(primitiveValuePtr);
59 existingAssignmentOperator = passRefPtrConstructor;
60 EXPECT_STREQ("bold", existingAssignmentOperator.cssText().utf8().data());
61 EXPECT_STREQ("bold", rawPtrConstructor.cssText().utf8().data());
62
63 CSSValue selfAssignmentOperator(primitiveValuePtr);
64 selfAssignmentOperator = rawPtrConstructor;
65 EXPECT_STREQ("bold", selfAssignmentOperator.cssText().utf8().data());
66 EXPECT_STREQ("bold", rawPtrConstructor.cssText().utf8().data());
67 }
68
69 TEST(CSSValueTest, CSSValueHeapTest)
70 {
71 CSSPrimitiveValue* primitiveValuePtr = CSSPrimitiveValue::createIdentifier(C SSValueBold).leakRef();
72 RefPtrWillBeRawPtr<CSSPrimitiveValue> primitiveValueRef = CSSPrimitiveValue: :createIdentifier(CSSValueBold);
73
74 CSSValue* rawPtrConstructor = new CSSValue(primitiveValuePtr);
75 EXPECT_STREQ("bold", rawPtrConstructor->cssText().utf8().data());
76
77 CSSValue* passRefPtrConstructor = makeCSSValuePtrWithPassRefPtr(CSSPrimitive Value::createIdentifier(CSSValueBold));
78 EXPECT_STREQ("bold", passRefPtrConstructor->cssText().utf8().data());
79
80 CSSValue* refPtrConstructor = new CSSValue(primitiveValueRef);
81 EXPECT_STREQ("bold", refPtrConstructor->cssText().utf8().data());
82
83 CSSValue* copyConstructor = new CSSValue(*rawPtrConstructor);
84 EXPECT_STREQ("bold", copyConstructor->cssText().utf8().data());
85
86 CSSValue* constCopyConstructor = new CSSValue(*const_cast<const CSSValue*>(r awPtrConstructor));
87 EXPECT_STREQ("bold", constCopyConstructor->cssText().utf8().data());
88
89 CSSValue* existingAssignmentOperator = new CSSValue(primitiveValuePtr);
90 *existingAssignmentOperator = *rawPtrConstructor;
91 EXPECT_STREQ("bold", existingAssignmentOperator->cssText().utf8().data());
92 EXPECT_STREQ("bold", rawPtrConstructor->cssText().utf8().data());
93
94 CSSValue* selfAssignmentOperator = new CSSValue(primitiveValuePtr);
95 *selfAssignmentOperator = *rawPtrConstructor;
96 EXPECT_STREQ("bold", selfAssignmentOperator->cssText().utf8().data());
97 EXPECT_STREQ("bold", rawPtrConstructor->cssText().utf8().data());
98
99 delete rawPtrConstructor;
100 delete passRefPtrConstructor;
101 delete refPtrConstructor;
102 delete copyConstructor;
103 delete constCopyConstructor;
104 delete existingAssignmentOperator;
105 delete selfAssignmentOperator;
106 }
107
108 TEST(CSSValueTest, NullableCSSValueStackTest)
109 {
110 CSSPrimitiveValue* primitiveValuePtr = CSSPrimitiveValue::createIdentifier(C SSValueBold).leakRef();
111 RefPtrWillBeRawPtr<CSSPrimitiveValue> primitiveValueRef = CSSPrimitiveValue: :createIdentifier(CSSValueBold);
112
113 NullableCSSValue defaultConstructor;
114 EXPECT_EQ(false, defaultConstructor);
115
116 NullableCSSValue nullPtrConstructor(nullptr);
117 EXPECT_EQ(false, nullPtrConstructor);
118
119 NullableCSSValue rawPtrConstructor(primitiveValuePtr);
120 EXPECT_STREQ("bold", rawPtrConstructor->cssText().utf8().data());
121
122 NullableCSSValue passRefPtrConstructor = makeNullableCSSValueWithPassRefPtr( CSSPrimitiveValue::createIdentifier(CSSValueBold));
123 EXPECT_STREQ("bold", passRefPtrConstructor->cssText().utf8().data());
124
125 NullableCSSValue refPtrConstructor(primitiveValueRef);
126 EXPECT_STREQ("bold", refPtrConstructor->cssText().utf8().data());
127
128 NullableCSSValue copyConstructor(rawPtrConstructor);
129 EXPECT_STREQ("bold", copyConstructor->cssText().utf8().data());
130
131 NullableCSSValue constCopyConstructor(*const_cast<const NullableCSSValue*>(& rawPtrConstructor));
132 EXPECT_STREQ("bold", constCopyConstructor->cssText().utf8().data());
133
134 NullableCSSValue nullCopyConstructor(nullPtrConstructor);
135 EXPECT_EQ(false, nullCopyConstructor);
136
137 NullableCSSValue nullConstCopyConstructor(*const_cast<const NullableCSSValue *>(&nullPtrConstructor));
138 EXPECT_EQ(false, nullConstCopyConstructor);
139
140 CSSValue cssValue(primitiveValuePtr);
141 NullableCSSValue cssValueCopyConstructor(cssValue);
142 EXPECT_STREQ("bold", cssValueCopyConstructor->cssText().utf8().data());
143
144 const CSSValue constCssValue(primitiveValuePtr);
145 NullableCSSValue constCssValueCopyConstructor(constCssValue);
146 EXPECT_STREQ("bold", constCssValueCopyConstructor->cssText().utf8().data());
147 }
148
149 TEST(CSSValueTest, NullableCSSValueHeapTest)
150 {
151 CSSPrimitiveValue* primitiveValuePtr = CSSPrimitiveValue::createIdentifier(C SSValueBold).leakRef();
152 RefPtrWillBeRawPtr<CSSPrimitiveValue> primitiveValueRef = CSSPrimitiveValue: :createIdentifier(CSSValueBold);
153
154 NullableCSSValue* defaultConstructor = new NullableCSSValue();
155 EXPECT_EQ(false, *defaultConstructor);
156
157 NullableCSSValue* nullPtrConstructor = new NullableCSSValue(nullptr);
158 EXPECT_EQ(false, *nullPtrConstructor);
159
160 NullableCSSValue* rawPtrConstructor = new NullableCSSValue(primitiveValuePtr );
161 EXPECT_STREQ("bold", (*rawPtrConstructor)->cssText().utf8().data());
162
163 NullableCSSValue* passRefPtrConstructor = makeNullableCSSValuePtrWithPassRef Ptr(CSSPrimitiveValue::createIdentifier(CSSValueBold));
164 EXPECT_STREQ("bold", (*passRefPtrConstructor)->cssText().utf8().data());
165
166 NullableCSSValue* refPtrConstructor = new NullableCSSValue(primitiveValueRef );
167 EXPECT_STREQ("bold", (*refPtrConstructor)->cssText().utf8().data());
168
169 NullableCSSValue* copyConstructor = new NullableCSSValue(*rawPtrConstructor) ;
170 EXPECT_STREQ("bold", (*copyConstructor)->cssText().utf8().data());
171
172 NullableCSSValue* constCopyConstructor = new NullableCSSValue(*const_cast<co nst NullableCSSValue*>(rawPtrConstructor));
173 EXPECT_STREQ("bold", (*constCopyConstructor)->cssText().utf8().data());
174
175 NullableCSSValue* nullCopyConstructor = new NullableCSSValue(*nullPtrConstru ctor);
176 EXPECT_EQ(false, *nullCopyConstructor);
177
178 NullableCSSValue* nullConstCopyConstructor = new NullableCSSValue(*const_cas t<const NullableCSSValue*>(nullPtrConstructor));
179 EXPECT_EQ(false, *nullConstCopyConstructor);
180
181 CSSValue* cssValue = new CSSValue(primitiveValuePtr);
182 NullableCSSValue* cssValueCopyConstructor = new NullableCSSValue(*cssValue);
183 EXPECT_STREQ("bold", (*cssValueCopyConstructor)->cssText().utf8().data());
184
185 const CSSValue* constCssValue = new CSSValue(primitiveValuePtr);
186 NullableCSSValue* constCssValueCopyConstructor = new NullableCSSValue(*const CssValue);
187 EXPECT_STREQ("bold", (*constCssValueCopyConstructor)->cssText().utf8().data( ));
188
189 delete defaultConstructor;
190 delete nullPtrConstructor;
191 delete rawPtrConstructor;
192 delete passRefPtrConstructor;
193 delete refPtrConstructor;
194 delete copyConstructor;
195 delete constCopyConstructor;
196 delete nullCopyConstructor;
197 delete nullConstCopyConstructor;
198 delete cssValueCopyConstructor;
199 delete constCssValueCopyConstructor;
200 }
201
202 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698