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

Unified 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, 7 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 side-by-side diff with in-line comments
Download patch
Index: Source/core/css/CSSValueTest.cpp
diff --git a/Source/core/css/CSSValueTest.cpp b/Source/core/css/CSSValueTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..f8964758e199a0ede400d48013e2ce552a968a17
--- /dev/null
+++ b/Source/core/css/CSSValueTest.cpp
@@ -0,0 +1,202 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "config.h"
+#include "core/css/CSSValue.h"
+
+#include "core/css/CSSPrimitiveValue.h"
+#include "core/css/CSSValueTestHelper.h"
+#include <gtest/gtest.h>
+
+using namespace blink;
+
+namespace {
+
+// Helper functions since PassRefPtrWillBeRawPtr cannot be a member variable.
+CSSValue makeCSSValueWithPassRefPtr(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> primitiveValue)
+{
+ return CSSValue(primitiveValue);
+}
+CSSValue* makeCSSValuePtrWithPassRefPtr(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> primitiveValue)
+{
+ return new CSSValue(primitiveValue);
+}
+NullableCSSValue makeNullableCSSValueWithPassRefPtr(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> primitiveValue)
+{
+ return NullableCSSValue(primitiveValue);
+}
+NullableCSSValue* makeNullableCSSValuePtrWithPassRefPtr(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> primitiveValue)
+{
+ return new NullableCSSValue(primitiveValue);
+}
+
+TEST(CSSValueTest, CSSValueStackTest)
+{
+ CSSPrimitiveValue* primitiveValuePtr = CSSPrimitiveValue::createIdentifier(CSSValueBold).leakRef();
+ RefPtrWillBeRawPtr<CSSPrimitiveValue> primitiveValueRef = CSSPrimitiveValue::createIdentifier(CSSValueBold);
+
+ CSSValue rawPtrConstructor(primitiveValuePtr);
+ EXPECT_STREQ("bold", rawPtrConstructor.cssText().utf8().data());
+
+ CSSValue passRefPtrConstructor = makeCSSValueWithPassRefPtr(CSSPrimitiveValue::createIdentifier(CSSValueBold));
+ EXPECT_STREQ("bold", passRefPtrConstructor.cssText().utf8().data());
+
+ CSSValue refPtrConstructor(primitiveValueRef);
+ EXPECT_STREQ("bold", refPtrConstructor.cssText().utf8().data());
+
+ CSSValue copyConstructor(rawPtrConstructor);
+ EXPECT_STREQ("bold", copyConstructor.cssText().utf8().data());
+
+ CSSValue constCopyConstructor(*const_cast<const CSSValue*>(&rawPtrConstructor));
+ EXPECT_STREQ("bold", constCopyConstructor.cssText().utf8().data());
+
+ CSSValue newAssignmentOperator = rawPtrConstructor;
+ EXPECT_STREQ("bold", newAssignmentOperator.cssText().utf8().data());
+ EXPECT_STREQ("bold", rawPtrConstructor.cssText().utf8().data());
+
+ CSSValue existingAssignmentOperator(primitiveValuePtr);
+ existingAssignmentOperator = passRefPtrConstructor;
+ EXPECT_STREQ("bold", existingAssignmentOperator.cssText().utf8().data());
+ EXPECT_STREQ("bold", rawPtrConstructor.cssText().utf8().data());
+
+ CSSValue selfAssignmentOperator(primitiveValuePtr);
+ selfAssignmentOperator = rawPtrConstructor;
+ EXPECT_STREQ("bold", selfAssignmentOperator.cssText().utf8().data());
+ EXPECT_STREQ("bold", rawPtrConstructor.cssText().utf8().data());
+}
+
+TEST(CSSValueTest, CSSValueHeapTest)
+{
+ CSSPrimitiveValue* primitiveValuePtr = CSSPrimitiveValue::createIdentifier(CSSValueBold).leakRef();
+ RefPtrWillBeRawPtr<CSSPrimitiveValue> primitiveValueRef = CSSPrimitiveValue::createIdentifier(CSSValueBold);
+
+ CSSValue* rawPtrConstructor = new CSSValue(primitiveValuePtr);
+ EXPECT_STREQ("bold", rawPtrConstructor->cssText().utf8().data());
+
+ CSSValue* passRefPtrConstructor = makeCSSValuePtrWithPassRefPtr(CSSPrimitiveValue::createIdentifier(CSSValueBold));
+ EXPECT_STREQ("bold", passRefPtrConstructor->cssText().utf8().data());
+
+ CSSValue* refPtrConstructor = new CSSValue(primitiveValueRef);
+ EXPECT_STREQ("bold", refPtrConstructor->cssText().utf8().data());
+
+ CSSValue* copyConstructor = new CSSValue(*rawPtrConstructor);
+ EXPECT_STREQ("bold", copyConstructor->cssText().utf8().data());
+
+ CSSValue* constCopyConstructor = new CSSValue(*const_cast<const CSSValue*>(rawPtrConstructor));
+ EXPECT_STREQ("bold", constCopyConstructor->cssText().utf8().data());
+
+ CSSValue* existingAssignmentOperator = new CSSValue(primitiveValuePtr);
+ *existingAssignmentOperator = *rawPtrConstructor;
+ EXPECT_STREQ("bold", existingAssignmentOperator->cssText().utf8().data());
+ EXPECT_STREQ("bold", rawPtrConstructor->cssText().utf8().data());
+
+ CSSValue* selfAssignmentOperator = new CSSValue(primitiveValuePtr);
+ *selfAssignmentOperator = *rawPtrConstructor;
+ EXPECT_STREQ("bold", selfAssignmentOperator->cssText().utf8().data());
+ EXPECT_STREQ("bold", rawPtrConstructor->cssText().utf8().data());
+
+ delete rawPtrConstructor;
+ delete passRefPtrConstructor;
+ delete refPtrConstructor;
+ delete copyConstructor;
+ delete constCopyConstructor;
+ delete existingAssignmentOperator;
+ delete selfAssignmentOperator;
+}
+
+TEST(CSSValueTest, NullableCSSValueStackTest)
+{
+ CSSPrimitiveValue* primitiveValuePtr = CSSPrimitiveValue::createIdentifier(CSSValueBold).leakRef();
+ RefPtrWillBeRawPtr<CSSPrimitiveValue> primitiveValueRef = CSSPrimitiveValue::createIdentifier(CSSValueBold);
+
+ NullableCSSValue defaultConstructor;
+ EXPECT_EQ(false, defaultConstructor);
+
+ NullableCSSValue nullPtrConstructor(nullptr);
+ EXPECT_EQ(false, nullPtrConstructor);
+
+ NullableCSSValue rawPtrConstructor(primitiveValuePtr);
+ EXPECT_STREQ("bold", rawPtrConstructor->cssText().utf8().data());
+
+ NullableCSSValue passRefPtrConstructor = makeNullableCSSValueWithPassRefPtr(CSSPrimitiveValue::createIdentifier(CSSValueBold));
+ EXPECT_STREQ("bold", passRefPtrConstructor->cssText().utf8().data());
+
+ NullableCSSValue refPtrConstructor(primitiveValueRef);
+ EXPECT_STREQ("bold", refPtrConstructor->cssText().utf8().data());
+
+ NullableCSSValue copyConstructor(rawPtrConstructor);
+ EXPECT_STREQ("bold", copyConstructor->cssText().utf8().data());
+
+ NullableCSSValue constCopyConstructor(*const_cast<const NullableCSSValue*>(&rawPtrConstructor));
+ EXPECT_STREQ("bold", constCopyConstructor->cssText().utf8().data());
+
+ NullableCSSValue nullCopyConstructor(nullPtrConstructor);
+ EXPECT_EQ(false, nullCopyConstructor);
+
+ NullableCSSValue nullConstCopyConstructor(*const_cast<const NullableCSSValue*>(&nullPtrConstructor));
+ EXPECT_EQ(false, nullConstCopyConstructor);
+
+ CSSValue cssValue(primitiveValuePtr);
+ NullableCSSValue cssValueCopyConstructor(cssValue);
+ EXPECT_STREQ("bold", cssValueCopyConstructor->cssText().utf8().data());
+
+ const CSSValue constCssValue(primitiveValuePtr);
+ NullableCSSValue constCssValueCopyConstructor(constCssValue);
+ EXPECT_STREQ("bold", constCssValueCopyConstructor->cssText().utf8().data());
+}
+
+TEST(CSSValueTest, NullableCSSValueHeapTest)
+{
+ CSSPrimitiveValue* primitiveValuePtr = CSSPrimitiveValue::createIdentifier(CSSValueBold).leakRef();
+ RefPtrWillBeRawPtr<CSSPrimitiveValue> primitiveValueRef = CSSPrimitiveValue::createIdentifier(CSSValueBold);
+
+ NullableCSSValue* defaultConstructor = new NullableCSSValue();
+ EXPECT_EQ(false, *defaultConstructor);
+
+ NullableCSSValue* nullPtrConstructor = new NullableCSSValue(nullptr);
+ EXPECT_EQ(false, *nullPtrConstructor);
+
+ NullableCSSValue* rawPtrConstructor = new NullableCSSValue(primitiveValuePtr);
+ EXPECT_STREQ("bold", (*rawPtrConstructor)->cssText().utf8().data());
+
+ NullableCSSValue* passRefPtrConstructor = makeNullableCSSValuePtrWithPassRefPtr(CSSPrimitiveValue::createIdentifier(CSSValueBold));
+ EXPECT_STREQ("bold", (*passRefPtrConstructor)->cssText().utf8().data());
+
+ NullableCSSValue* refPtrConstructor = new NullableCSSValue(primitiveValueRef);
+ EXPECT_STREQ("bold", (*refPtrConstructor)->cssText().utf8().data());
+
+ NullableCSSValue* copyConstructor = new NullableCSSValue(*rawPtrConstructor);
+ EXPECT_STREQ("bold", (*copyConstructor)->cssText().utf8().data());
+
+ NullableCSSValue* constCopyConstructor = new NullableCSSValue(*const_cast<const NullableCSSValue*>(rawPtrConstructor));
+ EXPECT_STREQ("bold", (*constCopyConstructor)->cssText().utf8().data());
+
+ NullableCSSValue* nullCopyConstructor = new NullableCSSValue(*nullPtrConstructor);
+ EXPECT_EQ(false, *nullCopyConstructor);
+
+ NullableCSSValue* nullConstCopyConstructor = new NullableCSSValue(*const_cast<const NullableCSSValue*>(nullPtrConstructor));
+ EXPECT_EQ(false, *nullConstCopyConstructor);
+
+ CSSValue* cssValue = new CSSValue(primitiveValuePtr);
+ NullableCSSValue* cssValueCopyConstructor = new NullableCSSValue(*cssValue);
+ EXPECT_STREQ("bold", (*cssValueCopyConstructor)->cssText().utf8().data());
+
+ const CSSValue* constCssValue = new CSSValue(primitiveValuePtr);
+ NullableCSSValue* constCssValueCopyConstructor = new NullableCSSValue(*constCssValue);
+ EXPECT_STREQ("bold", (*constCssValueCopyConstructor)->cssText().utf8().data());
+
+ delete defaultConstructor;
+ delete nullPtrConstructor;
+ delete rawPtrConstructor;
+ delete passRefPtrConstructor;
+ delete refPtrConstructor;
+ delete copyConstructor;
+ delete constCopyConstructor;
+ delete nullCopyConstructor;
+ delete nullConstCopyConstructor;
+ delete cssValueCopyConstructor;
+ delete constCssValueCopyConstructor;
+}
+
+} // namespace

Powered by Google App Engine
This is Rietveld 408576698