Diff
Modified: trunk/Tools/ChangeLog (157452 => 157453)
--- trunk/Tools/ChangeLog 2013-10-15 18:03:42 UTC (rev 157452)
+++ trunk/Tools/ChangeLog 2013-10-15 18:05:56 UTC (rev 157453)
@@ -1,3 +1,21 @@
+2013-10-15 Darin Adler <[email protected]>
+
+ Add some API tests for Vector, RefPtr, and Ref
+ https://bugs.webkit.org/show_bug.cgi?id=122840
+
+ Reviewed by Andreas Kling.
+
+ * TestWebKitAPI/CMakeLists.txt: Added new files.
+ * TestWebKitAPI/GNUmakefile.am: Ditto.
+ * TestWebKitAPI/TestWebKitAPI.vcxproj/TestWebKitAPI.vcxproj: Ditto.
+ * TestWebKitAPI/TestWebKitAPI.vcxproj/TestWebKitAPI.vcxproj.filters: Ditto.
+ * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: Ditto.
+
+ * TestWebKitAPI/Tests/WTF/Ref.cpp: Added.
+ * TestWebKitAPI/Tests/WTF/RefLogger.h: Added.
+ * TestWebKitAPI/Tests/WTF/RefPtr.cpp: Added.
+ * TestWebKitAPI/Tests/WTF/Vector.cpp: Added move-only insert tests.
+
2013-10-14 Roger Fong <[email protected]>
Adding myself to CC list for some components.
Modified: trunk/Tools/TestWebKitAPI/CMakeLists.txt (157452 => 157453)
--- trunk/Tools/TestWebKitAPI/CMakeLists.txt 2013-10-15 18:03:42 UTC (rev 157452)
+++ trunk/Tools/TestWebKitAPI/CMakeLists.txt 2013-10-15 18:05:56 UTC (rev 157453)
@@ -104,6 +104,8 @@
${TESTWEBKITAPI_DIR}/Tests/WTF/MathExtras.cpp
${TESTWEBKITAPI_DIR}/Tests/WTF/MetaAllocator.cpp
${TESTWEBKITAPI_DIR}/Tests/WTF/RedBlackTree.cpp
+ ${TESTWEBKITAPI_DIR}/Tests/WTF/Ref.cpp
+ ${TESTWEBKITAPI_DIR}/Tests/WTF/RefPtr.cpp
${TESTWEBKITAPI_DIR}/Tests/WTF/SHA1.cpp
${TESTWEBKITAPI_DIR}/Tests/WTF/SaturatedArithmeticOperations.cpp
${TESTWEBKITAPI_DIR}/Tests/WTF/StringBuilder.cpp
Modified: trunk/Tools/TestWebKitAPI/GNUmakefile.am (157452 => 157453)
--- trunk/Tools/TestWebKitAPI/GNUmakefile.am 2013-10-15 18:03:42 UTC (rev 157452)
+++ trunk/Tools/TestWebKitAPI/GNUmakefile.am 2013-10-15 18:05:56 UTC (rev 157453)
@@ -66,6 +66,9 @@
Tools/TestWebKitAPI/Tests/WTF/MetaAllocator.cpp \
Tools/TestWebKitAPI/Tests/WTF/MoveOnly.h \
Tools/TestWebKitAPI/Tests/WTF/RedBlackTree.cpp \
+ Tools/TestWebKitAPI/Tests/WTF/Ref.cpp \
+ Tools/TestWebKitAPI/Tests/WTF/RefLogger.h \
+ Tools/TestWebKitAPI/Tests/WTF/RefPtr.cpp \
Tools/TestWebKitAPI/Tests/WTF/SHA1.cpp \
Tools/TestWebKitAPI/Tests/WTF/SaturatedArithmeticOperations.cpp \
Tools/TestWebKitAPI/Tests/WTF/StringBuilder.cpp \
Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.vcxproj/TestWebKitAPI.vcxproj (157452 => 157453)
--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.vcxproj/TestWebKitAPI.vcxproj 2013-10-15 18:03:42 UTC (rev 157452)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.vcxproj/TestWebKitAPI.vcxproj 2013-10-15 18:05:56 UTC (rev 157453)
@@ -294,6 +294,8 @@
<ClCompile Include="..\Tests\WTF\MD5.cpp" />
<ClCompile Include="..\Tests\WTF\MathExtras.cpp" />
<ClCompile Include="..\Tests\WTF\MediaTime.cpp" />
+ <ClCompile Include="..\Tests\WTF\Ref.cpp" />
+ <ClCompile Include="..\Tests\WTF\RefPtr.cpp" />
<ClCompile Include="..\Tests\WTF\SHA1.cpp" />
<ClCompile Include="..\Tests\WTF\SaturatedArithmeticOperations.cpp" />
<ClCompile Include="..\Tests\WTF\StringHasher.cpp" />
Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.vcxproj/TestWebKitAPI.vcxproj.filters (157452 => 157453)
--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.vcxproj/TestWebKitAPI.vcxproj.filters 2013-10-15 18:03:42 UTC (rev 157452)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.vcxproj/TestWebKitAPI.vcxproj.filters 2013-10-15 18:05:56 UTC (rev 157453)
@@ -63,6 +63,12 @@
<ClCompile Include="..\Tests\WTF\MediaTime.cpp">
<Filter>Tests\WTF</Filter>
</ClCompile>
+ <ClCompile Include="..\Tests\WTF\Ref.cpp">
+ <Filter>Tests\WTF</Filter>
+ </ClCompile>
+ <ClCompile Include="..\Tests\WTF\RefPtr.cpp">
+ <Filter>Tests\WTF</Filter>
+ </ClCompile>
<ClCompile Include="..\Tests\WTF\SHA1.cpp">
<Filter>Tests\WTF</Filter>
</ClCompile>
Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (157452 => 157453)
--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2013-10-15 18:03:42 UTC (rev 157452)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2013-10-15 18:05:56 UTC (rev 157453)
@@ -113,6 +113,8 @@
9331407C17B4419000F083B1 /* DidNotHandleKeyDown.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9331407B17B4419000F083B1 /* DidNotHandleKeyDown.cpp */; };
9361002914DC95A70061379D /* lots-of-iframes.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9361002814DC957B0061379D /* lots-of-iframes.html */; };
939BA91714103412001A01BD /* DeviceScaleFactorOnBack.mm in Sources */ = {isa = PBXBuildFile; fileRef = 939BA91614103412001A01BD /* DeviceScaleFactorOnBack.mm */; };
+ 93A427A9180D9B0700CD24D7 /* RefPtr.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93A427A8180D9B0700CD24D7 /* RefPtr.cpp */; };
+ 93A427AB180DA26400CD24D7 /* Ref.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93A427AA180DA26400CD24D7 /* Ref.cpp */; };
93ABA80916DDAB91002DB2FA /* StringHasher.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93ABA80816DDAB91002DB2FA /* StringHasher.cpp */; };
93AF4ECE1506F064007FD57E /* NewFirstVisuallyNonEmptyLayoutForImages_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93AF4ECD1506F064007FD57E /* NewFirstVisuallyNonEmptyLayoutForImages_Bundle.cpp */; };
93AF4ED01506F123007FD57E /* lots-of-images.html in Resources */ = {isa = PBXBuildFile; fileRef = 93AF4ECF1506F123007FD57E /* lots-of-images.html */; };
@@ -419,6 +421,10 @@
9331407B17B4419000F083B1 /* DidNotHandleKeyDown.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DidNotHandleKeyDown.cpp; sourceTree = "<group>"; };
9361002814DC957B0061379D /* lots-of-iframes.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "lots-of-iframes.html"; sourceTree = "<group>"; };
939BA91614103412001A01BD /* DeviceScaleFactorOnBack.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DeviceScaleFactorOnBack.mm; sourceTree = "<group>"; };
+ 93A427A8180D9B0700CD24D7 /* RefPtr.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RefPtr.cpp; sourceTree = "<group>"; };
+ 93A427AA180DA26400CD24D7 /* Ref.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Ref.cpp; sourceTree = "<group>"; };
+ 93A427AC180DA60F00CD24D7 /* MoveOnly.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MoveOnly.h; sourceTree = "<group>"; };
+ 93A427AD180DA60F00CD24D7 /* RefLogger.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RefLogger.h; sourceTree = "<group>"; };
93ABA80816DDAB91002DB2FA /* StringHasher.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StringHasher.cpp; sourceTree = "<group>"; };
93AF4ECA1506F035007FD57E /* NewFirstVisuallyNonEmptyLayoutForImages.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NewFirstVisuallyNonEmptyLayoutForImages.cpp; sourceTree = "<group>"; };
93AF4ECD1506F064007FD57E /* NewFirstVisuallyNonEmptyLayoutForImages_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NewFirstVisuallyNonEmptyLayoutForImages_Bundle.cpp; sourceTree = "<group>"; };
@@ -808,7 +814,11 @@
B4039F9C15E6D8B3007255D6 /* MathExtras.cpp */,
CD5497B315857F0C00B5BC30 /* MediaTime.cpp */,
0FC6C4CE141034AD005B7F0C /* MetaAllocator.cpp */,
+ 93A427AC180DA60F00CD24D7 /* MoveOnly.h */,
0FC6C4CB141027E0005B7F0C /* RedBlackTree.cpp */,
+ 93A427AA180DA26400CD24D7 /* Ref.cpp */,
+ 93A427AD180DA60F00CD24D7 /* RefLogger.h */,
+ 93A427A8180D9B0700CD24D7 /* RefPtr.cpp */,
CD5393C91757BAC400C07123 /* SHA1.cpp */,
14F3B11215E45EAB00210069 /* SaturatedArithmeticOperations.cpp */,
81B50192140F232300D9EB58 /* StringBuilder.cpp */,
@@ -1111,6 +1121,7 @@
51393E201523944A005F39C5 /* DOMWindowExtensionBasic.cpp in Sources */,
F6F49C6915545C8E0007F39D /* DOMWindowExtensionNoCache.cpp in Sources */,
C045F9451385C2EA00C0F3CD /* DownloadDecideDestinationCrash.cpp in Sources */,
+ 93A427AB180DA26400CD24D7 /* Ref.cpp in Sources */,
C07E6CAF13FD67650038B22B /* DynamicDeviceScaleFactor.mm in Sources */,
BCAA485814A044D40088FAC4 /* EditorCommands.mm in Sources */,
4BB4160416815F9100824238 /* ElementAtPointInWebFrame.mm in Sources */,
@@ -1159,6 +1170,7 @@
93F1DB3114DA20760024C362 /* NewFirstVisuallyNonEmptyLayout.cpp in Sources */,
93F1DB5514DB1B730024C362 /* NewFirstVisuallyNonEmptyLayoutFails.cpp in Sources */,
9318778915EEC57700A9CCE3 /* NewFirstVisuallyNonEmptyLayoutForImages.cpp in Sources */,
+ 93A427A9180D9B0700CD24D7 /* RefPtr.cpp in Sources */,
7CFBCADF1743234F00B2BFCF /* WillLoad.cpp in Sources */,
93F7E86C14DC8E4D00C84A99 /* NewFirstVisuallyNonEmptyLayoutFrames.cpp in Sources */,
BC90977A125571AB00083756 /* PageLoadBasic.cpp in Sources */,
Added: trunk/Tools/TestWebKitAPI/Tests/WTF/Ref.cpp (0 => 157453)
--- trunk/Tools/TestWebKitAPI/Tests/WTF/Ref.cpp (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/Ref.cpp 2013-10-15 18:05:56 UTC (rev 157453)
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#include "RefLogger.h"
+#include <wtf/Ref.h>
+
+namespace TestWebKitAPI {
+
+TEST(WTF_Ref, Basic)
+{
+ DerivedRefLogger a("a");
+
+ {
+ Ref<RefLogger> ptr(a);
+ ASSERT_EQ(&a, &ptr.get());
+ ASSERT_EQ(&a.name, &ptr->name);
+ }
+ ASSERT_STREQ("ref(a) deref(a) ", takeLogStr().c_str());
+}
+
+TEST(WTF_Ref, Assignment)
+{
+ DerivedRefLogger a("a");
+ RefLogger b("b");
+ DerivedRefLogger c("c");
+
+ {
+ Ref<RefLogger> ptr(a);
+ ASSERT_EQ(&a, &ptr.get());
+ log() << "| ";
+ ptr = b;
+ ASSERT_EQ(&b, &ptr.get());
+ log() << "| ";
+ }
+ ASSERT_STREQ("ref(a) | ref(b) deref(a) | deref(b) ", takeLogStr().c_str());
+
+ {
+ Ref<RefLogger> ptr(a);
+ ASSERT_EQ(&a, &ptr.get());
+ log() << "| ";
+ ptr = c;
+ ASSERT_EQ(&c, &ptr.get());
+ log() << "| ";
+ }
+ ASSERT_STREQ("ref(a) | ref(c) deref(a) | deref(c) ", takeLogStr().c_str());
+}
+
+} // namespace TestWebKitAPI
Added: trunk/Tools/TestWebKitAPI/Tests/WTF/RefLogger.h (0 => 157453)
--- trunk/Tools/TestWebKitAPI/Tests/WTF/RefLogger.h (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/RefLogger.h 2013-10-15 18:05:56 UTC (rev 157453)
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef RefLogger_h
+
+namespace TestWebKitAPI {
+
+inline std::ostringstream& log()
+{
+ static std::ostringstream log;
+ return log;
+}
+
+inline std::string takeLogStr()
+{
+ std::string string = log().str();
+ log().str("");
+ return string;
+}
+
+struct RefLogger {
+ RefLogger(const char* name) : name(*name) { }
+ void ref() { log() << "ref(" << &name << ") "; }
+ void deref() { log() << "deref(" << &name << ") "; }
+ const char& name;
+};
+
+struct DerivedRefLogger : RefLogger {
+ DerivedRefLogger(const char* name) : RefLogger(name) { }
+};
+
+}
+
+#endif
Added: trunk/Tools/TestWebKitAPI/Tests/WTF/RefPtr.cpp (0 => 157453)
--- trunk/Tools/TestWebKitAPI/Tests/WTF/RefPtr.cpp (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/RefPtr.cpp 2013-10-15 18:05:56 UTC (rev 157453)
@@ -0,0 +1,355 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#include "RefLogger.h"
+#include <wtf/RefPtr.h>
+
+namespace TestWebKitAPI {
+
+TEST(WTF_RefPtr, Basic)
+{
+ DerivedRefLogger a("a");
+
+ RefPtr<RefLogger> empty;
+ ASSERT_EQ(nullptr, empty.get());
+
+ {
+ RefPtr<RefLogger> ptr(&a);
+ ASSERT_EQ(&a, ptr.get());
+ ASSERT_EQ(&a, &*ptr);
+ ASSERT_EQ(&a.name, &ptr->name);
+ }
+ ASSERT_STREQ("ref(a) deref(a) ", takeLogStr().c_str());
+
+ {
+ RefPtr<RefLogger> ptr = &a;
+ ASSERT_EQ(&a, ptr.get());
+ }
+ ASSERT_STREQ("ref(a) deref(a) ", takeLogStr().c_str());
+
+ {
+ RefPtr<RefLogger> p1 = &a;
+ RefPtr<RefLogger> p2(p1);
+ ASSERT_EQ(&a, p1.get());
+ ASSERT_EQ(&a, p2.get());
+ }
+ ASSERT_STREQ("ref(a) ref(a) deref(a) deref(a) ", takeLogStr().c_str());
+
+ {
+ RefPtr<RefLogger> p1 = &a;
+ RefPtr<RefLogger> p2 = p1;
+ ASSERT_EQ(&a, p1.get());
+ ASSERT_EQ(&a, p2.get());
+ }
+ ASSERT_STREQ("ref(a) ref(a) deref(a) deref(a) ", takeLogStr().c_str());
+
+ {
+ RefPtr<RefLogger> p1 = &a;
+ RefPtr<RefLogger> p2 = std::move(p1);
+ ASSERT_EQ(nullptr, p1.get());
+ ASSERT_EQ(&a, p2.get());
+ }
+ ASSERT_STREQ("ref(a) deref(a) ", takeLogStr().c_str());
+
+ {
+ RefPtr<RefLogger> p1 = &a;
+ RefPtr<RefLogger> p2(std::move(p1));
+ ASSERT_EQ(nullptr, p1.get());
+ ASSERT_EQ(&a, p2.get());
+ }
+ ASSERT_STREQ("ref(a) deref(a) ", takeLogStr().c_str());
+
+ {
+ RefPtr<DerivedRefLogger> p1 = &a;
+ RefPtr<RefLogger> p2 = p1;
+ ASSERT_EQ(&a, p1.get());
+ ASSERT_EQ(&a, p2.get());
+ }
+ ASSERT_STREQ("ref(a) ref(a) deref(a) deref(a) ", takeLogStr().c_str());
+
+ {
+ RefPtr<DerivedRefLogger> p1 = &a;
+ RefPtr<RefLogger> p2 = std::move(p1);
+ ASSERT_EQ(nullptr, p1.get());
+ ASSERT_EQ(&a, p2.get());
+ }
+ ASSERT_STREQ("ref(a) deref(a) ", takeLogStr().c_str());
+
+ {
+ RefPtr<RefLogger> ptr(&a);
+ ASSERT_EQ(&a, ptr.get());
+ ptr.clear();
+ ASSERT_EQ(nullptr, ptr.get());
+ }
+ ASSERT_STREQ("ref(a) deref(a) ", takeLogStr().c_str());
+
+ {
+ RefPtr<RefLogger> ptr(&a);
+ ASSERT_EQ(&a, ptr.get());
+ ptr.release();
+ ASSERT_EQ(nullptr, ptr.get());
+ }
+ ASSERT_STREQ("ref(a) deref(a) ", takeLogStr().c_str());
+}
+
+TEST(WTF_RefPtr, Adopt)
+{
+ DerivedRefLogger a("a");
+
+ RefPtr<RefLogger> empty;
+ ASSERT_EQ(nullptr, empty.get());
+
+ {
+ RefPtr<RefLogger> ptr(adoptRef(&a));
+ ASSERT_EQ(&a, ptr.get());
+ ASSERT_EQ(&a, &*ptr);
+ ASSERT_EQ(&a.name, &ptr->name);
+ }
+ ASSERT_STREQ("deref(a) ", takeLogStr().c_str());
+
+ {
+ RefPtr<RefLogger> ptr = adoptRef(&a);
+ ASSERT_EQ(&a, ptr.get());
+ }
+ ASSERT_STREQ("deref(a) ", takeLogStr().c_str());
+}
+
+TEST(WTF_RefPtr, Assignment)
+{
+ DerivedRefLogger a("a");
+ RefLogger b("b");
+ DerivedRefLogger c("c");
+
+ {
+ RefPtr<RefLogger> p1(&a);
+ RefPtr<RefLogger> p2(&b);
+ ASSERT_EQ(&a, p1.get());
+ ASSERT_EQ(&b, p2.get());
+ log() << "| ";
+ p1 = p2;
+ ASSERT_EQ(&b, p1.get());
+ ASSERT_EQ(&b, p2.get());
+ log() << "| ";
+ }
+ ASSERT_STREQ("ref(a) ref(b) | ref(b) deref(a) | deref(b) deref(b) ", takeLogStr().c_str());
+
+ {
+ RefPtr<RefLogger> ptr(&a);
+ ASSERT_EQ(&a, ptr.get());
+ log() << "| ";
+ ptr = &b;
+ ASSERT_EQ(&b, ptr.get());
+ log() << "| ";
+ }
+ ASSERT_STREQ("ref(a) | ref(b) deref(a) | deref(b) ", takeLogStr().c_str());
+
+ {
+ RefPtr<RefLogger> ptr(&a);
+ ASSERT_EQ(&a, ptr.get());
+ log() << "| ";
+ ptr = adoptRef(&b);
+ ASSERT_EQ(&b, ptr.get());
+ log() << "| ";
+ }
+ ASSERT_STREQ("ref(a) | deref(a) | deref(b) ", takeLogStr().c_str());
+
+ {
+ RefPtr<RefLogger> ptr(&a);
+ ASSERT_EQ(&a, ptr.get());
+ ptr = nullptr;
+ ASSERT_EQ(nullptr, ptr.get());
+ }
+ ASSERT_STREQ("ref(a) deref(a) ", takeLogStr().c_str());
+
+ {
+ RefPtr<RefLogger> p1(&a);
+ RefPtr<RefLogger> p2(&b);
+ ASSERT_EQ(&a, p1.get());
+ ASSERT_EQ(&b, p2.get());
+ log() << "| ";
+ p1 = std::move(p2);
+ ASSERT_EQ(&b, p1.get());
+ ASSERT_EQ(nullptr, p2.get());
+ log() << "| ";
+ }
+ ASSERT_STREQ("ref(a) ref(b) | deref(a) | deref(b) ", takeLogStr().c_str());
+
+ {
+ RefPtr<RefLogger> p1(&a);
+ RefPtr<DerivedRefLogger> p2(&c);
+ ASSERT_EQ(&a, p1.get());
+ ASSERT_EQ(&c, p2.get());
+ log() << "| ";
+ p1 = p2;
+ ASSERT_EQ(&c, p1.get());
+ ASSERT_EQ(&c, p2.get());
+ log() << "| ";
+ }
+ ASSERT_STREQ("ref(a) ref(c) | ref(c) deref(a) | deref(c) deref(c) ", takeLogStr().c_str());
+
+ {
+ RefPtr<RefLogger> ptr(&a);
+ ASSERT_EQ(&a, ptr.get());
+ log() << "| ";
+ ptr = &c;
+ ASSERT_EQ(&c, ptr.get());
+ log() << "| ";
+ }
+ ASSERT_STREQ("ref(a) | ref(c) deref(a) | deref(c) ", takeLogStr().c_str());
+
+ {
+ RefPtr<RefLogger> ptr(&a);
+ ASSERT_EQ(&a, ptr.get());
+ log() << "| ";
+ ptr = adoptRef(&c);
+ ASSERT_EQ(&c, ptr.get());
+ log() << "| ";
+ }
+ ASSERT_STREQ("ref(a) | deref(a) | deref(c) ", takeLogStr().c_str());
+
+ {
+ RefPtr<RefLogger> p1(&a);
+ RefPtr<DerivedRefLogger> p2(&c);
+ ASSERT_EQ(&a, p1.get());
+ ASSERT_EQ(&c, p2.get());
+ log() << "| ";
+ p1 = std::move(p2);
+ ASSERT_EQ(&c, p1.get());
+ ASSERT_EQ(nullptr, p2.get());
+ log() << "| ";
+ }
+ ASSERT_STREQ("ref(a) ref(c) | deref(a) | deref(c) ", takeLogStr().c_str());
+}
+
+TEST(WTF_RefPtr, Swap)
+{
+ RefLogger a("a");
+ RefLogger b("b");
+
+ {
+ RefPtr<RefLogger> p1(&a);
+ RefPtr<RefLogger> p2(&b);
+ ASSERT_EQ(&a, p1.get());
+ ASSERT_EQ(&b, p2.get());
+ p1.swap(p2);
+ ASSERT_EQ(&b, p1.get());
+ ASSERT_EQ(&a, p2.get());
+ log() << "| ";
+ }
+ ASSERT_STREQ("ref(a) ref(b) | deref(a) deref(b) ", takeLogStr().c_str());
+
+ {
+ RefPtr<RefLogger> p1(&a);
+ RefPtr<RefLogger> p2(&b);
+ ASSERT_EQ(&a, p1.get());
+ ASSERT_EQ(&b, p2.get());
+ std::swap(p1, p2);
+ ASSERT_EQ(&b, p1.get());
+ ASSERT_EQ(&a, p2.get());
+ log() << "| ";
+ }
+ ASSERT_STREQ("ref(a) ref(b) | deref(a) deref(b) ", takeLogStr().c_str());
+}
+
+TEST(WTF_RefPtr, Release)
+{
+ DerivedRefLogger a("a");
+ RefLogger b("b");
+ DerivedRefLogger c("c");
+
+ {
+ RefPtr<RefLogger> p1 = &a;
+ RefPtr<RefLogger> p2 = p1.release();
+ ASSERT_EQ(nullptr, p1.get());
+ ASSERT_EQ(&a, p2.get());
+ }
+ ASSERT_STREQ("ref(a) deref(a) ", takeLogStr().c_str());
+
+ {
+ RefPtr<RefLogger> p1 = &a;
+ RefPtr<RefLogger> p2(p1.release());
+ ASSERT_EQ(nullptr, p1.get());
+ ASSERT_EQ(&a, p2.get());
+ }
+ ASSERT_STREQ("ref(a) deref(a) ", takeLogStr().c_str());
+
+ {
+ RefPtr<DerivedRefLogger> p1 = &a;
+ RefPtr<RefLogger> p2 = p1.release();
+ ASSERT_EQ(nullptr, p1.get());
+ ASSERT_EQ(&a, p2.get());
+ }
+ ASSERT_STREQ("ref(a) deref(a) ", takeLogStr().c_str());
+
+ {
+ RefPtr<RefLogger> p1(&a);
+ RefPtr<RefLogger> p2(&b);
+ ASSERT_EQ(&a, p1.get());
+ ASSERT_EQ(&b, p2.get());
+ log() << "| ";
+ p1 = p2.release();
+ ASSERT_EQ(&b, p1.get());
+ ASSERT_EQ(nullptr, p2.get());
+ log() << "| ";
+ }
+ ASSERT_STREQ("ref(a) ref(b) | deref(a) | deref(b) ", takeLogStr().c_str());
+
+ {
+ RefPtr<RefLogger> p1(&a);
+ RefPtr<DerivedRefLogger> p2(&c);
+ ASSERT_EQ(&a, p1.get());
+ ASSERT_EQ(&c, p2.get());
+ log() << "| ";
+ p1 = p2.release();
+ ASSERT_EQ(&c, p1.get());
+ ASSERT_EQ(nullptr, p2.get());
+ log() << "| ";
+ }
+ ASSERT_STREQ("ref(a) ref(c) | deref(a) | deref(c) ", takeLogStr().c_str());
+}
+
+RefPtr<RefLogger> f1(RefLogger& logger)
+{
+ return RefPtr<RefLogger>(&logger);
+}
+
+TEST(WTF_RefPtr, ReturnValue)
+{
+ DerivedRefLogger a("a");
+
+ {
+ f1(a);
+ }
+ ASSERT_STREQ("ref(a) deref(a) ", takeLogStr().c_str());
+
+ {
+ auto ptr = f1(a);
+ }
+ ASSERT_STREQ("ref(a) deref(a) ", takeLogStr().c_str());
+}
+
+} // namespace TestWebKitAPI
Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/Vector.cpp (157452 => 157453)
--- trunk/Tools/TestWebKitAPI/Tests/WTF/Vector.cpp 2013-10-15 18:03:42 UTC (rev 157452)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/Vector.cpp 2013-10-15 18:05:56 UTC (rev 157453)
@@ -176,4 +176,33 @@
}
}
+TEST(WTF_Vector, MoveOnly_Insert)
+{
+ Vector<MoveOnly> vector;
+
+ for (size_t i = 0; i < 100; ++i) {
+ MoveOnly moveOnly(i);
+ vector.insert(0, std::move(moveOnly));
+ EXPECT_EQ(0U, moveOnly.value());
+ }
+
+ EXPECT_EQ(vector.size(), 100U);
+ for (size_t i = 0; i < 100; ++i)
+ EXPECT_EQ(99 - i, vector[i].value());
+
+ for (size_t i = 0; i < 200; i += 2) {
+ MoveOnly moveOnly(1000 + i);
+ vector.insert(i, std::move(moveOnly));
+ EXPECT_EQ(0U, moveOnly.value());
+ }
+
+ EXPECT_EQ(vector.size(), 200U);
+ for (size_t i = 0; i < 200; ++i) {
+ if (i % 2)
+ EXPECT_EQ(99 - i / 2, vector[i].value());
+ else
+ EXPECT_EQ(1000 + i, vector[i].value());
+ }
+}
+
} // namespace TestWebKitAPI