Title: [264163] trunk
Revision
264163
Author
calva...@igalia.com
Date
2020-07-09 02:36:52 -0700 (Thu, 09 Jul 2020)

Log Message

[WTF] Implement new BoxPtr alias
https://bugs.webkit.org/show_bug.cgi?id=212379

Reviewed by Darin Adler.

Source/WTF:

Added BoxPtr.h that includes BoxPtr<T> as alias of
Box<std::unique_ptr<T>>. We discussed about this class on bugzilla
and we agreed on this alias being the best idea. Apart from the
alias I'm adding a couple of helpers like a create function and
the operator== and operator!=.

Tests: BoxPtr API tests added.

* WTF.xcodeproj/project.pbxproj:
* wtf/BoxPtr.h: Added.
(WTF::createBoxPtr):
(WTF::operator==):
(WTF::operator!=):
* wtf/CMakeLists.txt:

Tools:

Tests for BoxPtr.

* TestWebKitAPI/CMakeLists.txt:
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WTF/BoxPtr.cpp: Added.
(TestWebKitAPI::BoxPtrLogger::create):
(TestWebKitAPI::BoxPtrLogger::BoxPtrLogger):
(TestWebKitAPI::boxPtrLoggerDeleter):
(TestWebKitAPI::TEST):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (264162 => 264163)


--- trunk/Source/WTF/ChangeLog	2020-07-09 09:24:58 UTC (rev 264162)
+++ trunk/Source/WTF/ChangeLog	2020-07-09 09:36:52 UTC (rev 264163)
@@ -1,3 +1,25 @@
+2020-07-09  Xabier Rodriguez Calvar  <calva...@igalia.com>
+
+        [WTF] Implement new BoxPtr alias
+        https://bugs.webkit.org/show_bug.cgi?id=212379
+
+        Reviewed by Darin Adler.
+
+        Added BoxPtr.h that includes BoxPtr<T> as alias of
+        Box<std::unique_ptr<T>>. We discussed about this class on bugzilla
+        and we agreed on this alias being the best idea. Apart from the
+        alias I'm adding a couple of helpers like a create function and
+        the operator== and operator!=.
+
+        Tests: BoxPtr API tests added.
+
+        * WTF.xcodeproj/project.pbxproj:
+        * wtf/BoxPtr.h: Added.
+        (WTF::createBoxPtr):
+        (WTF::operator==):
+        (WTF::operator!=):
+        * wtf/CMakeLists.txt:
+
 2020-07-08  Per Arne Vollan  <pvol...@apple.com>
 
         [Cocoa] Update Launch Services database in the WebContent process from the Network process

Modified: trunk/Source/WTF/WTF.xcodeproj/project.pbxproj (264162 => 264163)


--- trunk/Source/WTF/WTF.xcodeproj/project.pbxproj	2020-07-09 09:24:58 UTC (rev 264162)
+++ trunk/Source/WTF/WTF.xcodeproj/project.pbxproj	2020-07-09 09:36:52 UTC (rev 264163)
@@ -258,6 +258,7 @@
 		0F8F2B90172E00F0007DBDA5 /* CompilationThread.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CompilationThread.h; sourceTree = "<group>"; };
 		0F8F2B9B172F2594007DBDA5 /* ConversionMode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ConversionMode.h; sourceTree = "<group>"; };
 		0F93274A1C17F4B700CF6564 /* Box.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Box.h; sourceTree = "<group>"; };
+		0F93274A1C17F4B700CF6566 /* BoxPtr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BoxPtr.h; sourceTree = "<group>"; };
 		0F9495831C571CC900413A48 /* OrderMaker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OrderMaker.h; sourceTree = "<group>"; };
 		0F95B63120CB4B7700479635 /* DebugHeap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DebugHeap.h; sourceTree = "<group>"; };
 		0F95B63220CB4B7700479635 /* DebugHeap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DebugHeap.cpp; sourceTree = "<group>"; };
@@ -957,6 +958,7 @@
 				A8A47265151A825A004123FF /* BloomFilter.h */,
 				0FB399B820AF5A580017E213 /* BooleanLattice.h */,
 				0F93274A1C17F4B700CF6564 /* Box.h */,
+				0F93274A1C17F4B700CF6566 /* BoxPtr.h */,
 				7C3F72391D78811900674E26 /* Brigand.h */,
 				0F4570441BE834410062A629 /* BubbleSort.h */,
 				A8A47267151A825A004123FF /* BumpPointerAllocator.h */,

Added: trunk/Source/WTF/wtf/BoxPtr.h (0 => 264163)


--- trunk/Source/WTF/wtf/BoxPtr.h	                        (rev 0)
+++ trunk/Source/WTF/wtf/BoxPtr.h	2020-07-09 09:36:52 UTC (rev 264163)
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2020 Metrological Group B.V.
+ * Copyright (C) 2020 Igalia S.L.
+ *
+ * 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. ``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
+ * 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.
+ */
+
+#pragma once
+
+#include <memory>
+#include <wtf/Box.h>
+
+namespace WTF {
+
+template<typename T> struct BoxPtrDeleter {
+    void operator()(T*) const = delete;
+};
+
+#define WTF_DEFINE_BOXPTR_DELETER(typeName, deleterFunction) \
+    template<> struct BoxPtrDeleter<typeName> \
+    { \
+        void operator() (typeName* ptr) const \
+        { \
+            deleterFunction(ptr); \
+        } \
+    };
+
+template<typename T> using BoxPtr = Box<std::unique_ptr<T, BoxPtrDeleter<T>>>;
+
+template<typename T> BoxPtr<T> createBoxPtr(T* ptr)
+{
+    return Box<std::unique_ptr<T, BoxPtrDeleter<T>>>::create(ptr);
+}
+
+template<typename T> bool operator==(const BoxPtr<T>& lhs, const BoxPtr<T>& rhs)
+{
+    if (!lhs && !rhs)
+        return true;
+
+    if (!lhs || !rhs)
+        return false;
+
+    if (!lhs->get() && !rhs->get())
+        return true;
+
+    if (!lhs->get() || !rhs->get())
+        return false;
+
+    return *lhs == *rhs;
+}
+
+template<typename T> bool operator!=(const BoxPtr<T>& lhs, const BoxPtr<T>& rhs)
+{
+    return !(lhs == rhs);
+}
+
+} // namespace WTF
+
+using WTF::createBoxPtr;
+using WTF::BoxPtr;

Modified: trunk/Source/WTF/wtf/CMakeLists.txt (264162 => 264163)


--- trunk/Source/WTF/wtf/CMakeLists.txt	2020-07-09 09:24:58 UTC (rev 264162)
+++ trunk/Source/WTF/wtf/CMakeLists.txt	2020-07-09 09:36:52 UTC (rev 264163)
@@ -17,6 +17,7 @@
     BloomFilter.h
     BooleanLattice.h
     Box.h
+    BoxPtr.h
     Brigand.h
     BubbleSort.h
     BumpPointerAllocator.h

Modified: trunk/Tools/ChangeLog (264162 => 264163)


--- trunk/Tools/ChangeLog	2020-07-09 09:24:58 UTC (rev 264162)
+++ trunk/Tools/ChangeLog	2020-07-09 09:36:52 UTC (rev 264163)
@@ -1,3 +1,20 @@
+2020-07-09  Xabier Rodriguez Calvar  <calva...@igalia.com>
+
+        [WTF] Implement new BoxPtr alias
+        https://bugs.webkit.org/show_bug.cgi?id=212379
+
+        Reviewed by Darin Adler.
+
+        Tests for BoxPtr.
+
+        * TestWebKitAPI/CMakeLists.txt:
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WTF/BoxPtr.cpp: Added.
+        (TestWebKitAPI::BoxPtrLogger::create):
+        (TestWebKitAPI::BoxPtrLogger::BoxPtrLogger):
+        (TestWebKitAPI::boxPtrLoggerDeleter):
+        (TestWebKitAPI::TEST):
+
 2020-07-09  Carlos Garcia Campos  <cgar...@igalia.com>
 
         [SOUP] Add support for HTTPCookieAcceptPolicy::OnlyFromMainDocumentDomain

Modified: trunk/Tools/TestWebKitAPI/CMakeLists.txt (264162 => 264163)


--- trunk/Tools/TestWebKitAPI/CMakeLists.txt	2020-07-09 09:24:58 UTC (rev 264162)
+++ trunk/Tools/TestWebKitAPI/CMakeLists.txt	2020-07-09 09:36:52 UTC (rev 264163)
@@ -28,6 +28,7 @@
     Tests/WTF/AtomString.cpp
     Tests/WTF/Bitmap.cpp
     Tests/WTF/BloomFilter.cpp
+    Tests/WTF/BoxPtr.cpp
     Tests/WTF/BumpPointerAllocator.cpp
     Tests/WTF/CString.cpp
     Tests/WTF/CheckedArithmeticOperations.cpp

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (264162 => 264163)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2020-07-09 09:24:58 UTC (rev 264162)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2020-07-09 09:36:52 UTC (rev 264163)
@@ -559,6 +559,7 @@
 		7C83DF141D0A590C00FEBCF3 /* Ref.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93A427AA180DA26400CD24D7 /* Ref.cpp */; };
 		7C83DF151D0A590C00FEBCF3 /* RefCounter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 86BD19971A2DB05B006DCF0A /* RefCounter.cpp */; };
 		7C83DF161D0A590C00FEBCF3 /* RefPtr.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93A427A8180D9B0700CD24D7 /* RefPtr.cpp */; };
+		7C83DF181D0A590C00FEBCF3 /* BoxPtr.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93A427AE180DA60F00CD24D7 /* BoxPtr.cpp */; };
 		7C83DF1D1D0A590C00FEBCF3 /* Lock.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0FFC45A41B73EBE20085BD62 /* Lock.cpp */; };
 		7C83DF241D0A590C00FEBCF3 /* RetainPtr.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC029B1B1486B25900817DA9 /* RetainPtr.mm */; };
 		7C83DF261D0A590C00FEBCF3 /* SaturatedArithmeticOperations.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14F3B11215E45EAB00210069 /* SaturatedArithmeticOperations.cpp */; };
@@ -2348,6 +2349,7 @@
 		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>"; };
+		93A427AE180DA60F00CD24D7 /* BoxPtr.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BoxPtr.cpp; sourceTree = "<group>"; };
 		93A720E518F1A0E800A848E1 /* CalculationValue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CalculationValue.cpp; 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>"; };
@@ -4035,6 +4037,7 @@
 				26F1B44215CA434F00D1E4BF /* AtomString.cpp */,
 				FE2D9473245EB2DF00E48135 /* Bitmap.cpp */,
 				E40019301ACE9B5C001B0A2A /* BloomFilter.cpp */,
+				93A427AE180DA60F00CD24D7 /* BoxPtr.cpp */,
 				0451A5A6235E438E009DF945 /* BumpPointerAllocator.cpp */,
 				A7A966DA140ECCC8005EF9B4 /* CheckedArithmeticOperations.cpp */,
 				E302BDA92404B92300865277 /* CompactRefPtrTuple.cpp */,
@@ -4754,6 +4757,7 @@
 				FE2D9474245EB2F400E48135 /* Bitmap.cpp in Sources */,
 				1ADAD1501D77A9F600212586 /* BlockPtr.mm in Sources */,
 				7C83DE9C1D0A590C00FEBCF3 /* BloomFilter.cpp in Sources */,
+				7C83DF181D0A590C00FEBCF3 /* BoxPtr.cpp in Sources */,
 				04DB2396235E43EC00328F17 /* BumpPointerAllocator.cpp in Sources */,
 				7C83DEA01D0A590C00FEBCF3 /* CheckedArithmeticOperations.cpp in Sources */,
 				E302BDAA2404B92400865277 /* CompactRefPtrTuple.cpp in Sources */,

Added: trunk/Tools/TestWebKitAPI/Tests/WTF/BoxPtr.cpp (0 => 264163)


--- trunk/Tools/TestWebKitAPI/Tests/WTF/BoxPtr.cpp	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/BoxPtr.cpp	2020-07-09 09:36:52 UTC (rev 264163)
@@ -0,0 +1,213 @@
+/*
+ * Copyright (C) 2013-2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2020 Metrological Group B.V.
+ * Copyright (C) 2020 Igalia S.L.
+ *
+ * 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. ``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
+ * 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 "Logger.h"
+#include <wtf/BoxPtr.h>
+
+namespace TestWebKitAPI {
+
+struct BoxPtrLogger {
+    BoxPtrLogger(const char* name);
+    static BoxPtrLogger* create(const char* name) { return new BoxPtrLogger(name); }
+    const char& name;
+};
+
+BoxPtrLogger::BoxPtrLogger(const char* name)
+    : name { *name }
+{
+    log() << "create(" << name << ") ";
+}
+
+void boxPtrLoggerDeleter(BoxPtrLogger* logger)
+{
+    log() << "delete(" << &logger->name << ") ";
+    delete logger;
+}
+
+};
+
+namespace WTF {
+
+WTF_DEFINE_BOXPTR_DELETER(TestWebKitAPI::BoxPtrLogger, TestWebKitAPI::boxPtrLoggerDeleter);
+
+}
+
+namespace TestWebKitAPI {
+
+TEST(WTF_BoxPtr, Basic)
+{
+    {
+        BoxPtr<BoxPtrLogger> empty;
+        EXPECT_EQ(false, static_cast<bool>(empty));
+    }
+    EXPECT_STREQ("", takeLogStr().c_str());
+
+    {
+        BoxPtrLogger* a = BoxPtrLogger::create("a");
+        BoxPtr<BoxPtrLogger> ptr = createBoxPtr(a);
+        EXPECT_EQ(true, static_cast<bool>(ptr));
+        EXPECT_EQ(a, ptr->get());
+        EXPECT_EQ(a->name, (*ptr)->name);
+    }
+    EXPECT_STREQ("create(a) delete(a) ", takeLogStr().c_str());
+
+    {
+        BoxPtrLogger* a = BoxPtrLogger::create("a");
+        BoxPtr<BoxPtrLogger> p1 = createBoxPtr(a);
+        BoxPtr<BoxPtrLogger> p2(p1);
+        EXPECT_EQ(a, p1->get());
+        EXPECT_EQ(a, p2->get());
+    }
+    EXPECT_STREQ("create(a) delete(a) ", takeLogStr().c_str());
+
+    {
+        BoxPtrLogger* a = BoxPtrLogger::create("a");
+        BoxPtr<BoxPtrLogger> p1 = createBoxPtr(a);
+        BoxPtr<BoxPtrLogger> p2 = p1;
+        EXPECT_EQ(a, p1->get());
+        EXPECT_EQ(a, p2->get());
+    }
+    EXPECT_STREQ("create(a) delete(a) ", takeLogStr().c_str());
+
+    {
+        BoxPtrLogger* a = BoxPtrLogger::create("a");
+        BoxPtr<BoxPtrLogger> p1 = createBoxPtr(a);
+        BoxPtr<BoxPtrLogger> p2 = WTFMove(p1);
+        EXPECT_EQ(false, static_cast<bool>(p1));
+        EXPECT_EQ(a, p2->get());
+    }
+    EXPECT_STREQ("create(a) delete(a) ", takeLogStr().c_str());
+
+    {
+        BoxPtrLogger* a = BoxPtrLogger::create("a");
+        BoxPtr<BoxPtrLogger> p1 = createBoxPtr(a);
+        BoxPtr<BoxPtrLogger> p2(WTFMove(p1));
+        EXPECT_EQ(false, static_cast<bool>(p1));
+        EXPECT_EQ(a, p2->get());
+    }
+    EXPECT_STREQ("create(a) delete(a) ", takeLogStr().c_str());
+
+    {
+        BoxPtrLogger* a = BoxPtrLogger::create("a");
+        BoxPtr<BoxPtrLogger> ptr = createBoxPtr(a);
+        EXPECT_EQ(a, ptr->get());
+        ptr = nullptr;
+        EXPECT_EQ(false, static_cast<bool>(ptr));
+    }
+    EXPECT_STREQ("create(a) delete(a) ", takeLogStr().c_str());
+}
+
+TEST(WTF_BoxPtr, Assignment)
+{
+    {
+        BoxPtrLogger* a = BoxPtrLogger::create("a");
+        BoxPtrLogger* b = BoxPtrLogger::create("b");
+        BoxPtr<BoxPtrLogger> p1 = createBoxPtr(a);
+        BoxPtr<BoxPtrLogger> p2 = createBoxPtr(b);
+        EXPECT_EQ(a, p1->get());
+        EXPECT_EQ(b, p2->get());
+        log() << "| ";
+        p1 = p2;
+        EXPECT_EQ(b, p1->get());
+        EXPECT_EQ(b, p2->get());
+        log() << "| ";
+    }
+    EXPECT_STREQ("create(a) create(b) | delete(a) | delete(b) ", takeLogStr().c_str());
+
+    {
+        BoxPtrLogger* a = BoxPtrLogger::create("a");
+        BoxPtrLogger* b = BoxPtrLogger::create("b");
+        BoxPtr<BoxPtrLogger> p1 = createBoxPtr(a);
+        BoxPtr<BoxPtrLogger> p2 = createBoxPtr(b);
+        EXPECT_EQ(a, p1->get());
+        EXPECT_EQ(b, p2->get());
+        log() << "| ";
+        p1 = WTFMove(p2);
+        EXPECT_EQ(b, p1->get());
+        EXPECT_EQ(false, static_cast<bool>(p2));
+        log() << "| ";
+    }
+    EXPECT_STREQ("create(a) create(b) | delete(a) | delete(b) ", takeLogStr().c_str());
+
+    {
+        BoxPtrLogger* a = BoxPtrLogger::create("a");
+        BoxPtr<BoxPtrLogger> ptr = createBoxPtr(a);
+        EXPECT_EQ(a, ptr->get());
+        log() << "| ";
+        IGNORE_CLANG_WARNINGS_BEGIN("self-assign-overloaded")
+        ptr = ptr;
+        IGNORE_CLANG_WARNINGS_END
+        EXPECT_EQ(a, ptr->get());
+        log() << "| ";
+    }
+    EXPECT_STREQ("create(a) | | delete(a) ", takeLogStr().c_str());
+
+    {
+        BoxPtrLogger* a = BoxPtrLogger::create("a");
+        BoxPtr<BoxPtrLogger> ptr = createBoxPtr(a);
+        EXPECT_EQ(a, ptr->get());
+        IGNORE_CLANG_WARNINGS_BEGIN("self-move")
+        ptr = WTFMove(ptr);
+        IGNORE_CLANG_WARNINGS_END
+        EXPECT_EQ(a, ptr->get());
+    }
+    EXPECT_STREQ("create(a) delete(a) ", takeLogStr().c_str());
+}
+
+TEST(WTF_BoxPtr, Operators)
+{
+    {
+        BoxPtrLogger* a = BoxPtrLogger::create("a");
+        BoxPtrLogger* b = BoxPtrLogger::create("b");
+        BoxPtr<BoxPtrLogger> p1 = createBoxPtr(a);
+        BoxPtr<BoxPtrLogger> p2 = createBoxPtr(b);
+        EXPECT_EQ(p1, p1);
+        EXPECT_NE(p1, p2);
+    }
+    EXPECT_STREQ("create(a) create(b) delete(b) delete(a) ", takeLogStr().c_str());
+
+    {
+        BoxPtrLogger* a = BoxPtrLogger::create("a");
+        BoxPtr<BoxPtrLogger> p1 = createBoxPtr(a);
+        EXPECT_EQ(static_cast<bool>(p1), true);
+        EXPECT_EQ(!p1, false);
+    }
+    EXPECT_STREQ("create(a) delete(a) ", takeLogStr().c_str());
+
+    {
+        BoxPtr<BoxPtrLogger> empty;
+        BoxPtrLogger* a = BoxPtrLogger::create("a");
+        BoxPtr<BoxPtrLogger> p1 = createBoxPtr(a);
+        EXPECT_NE(empty, p1);
+        EXPECT_EQ(empty, empty);
+    }
+    EXPECT_STREQ("create(a) delete(a) ", takeLogStr().c_str());
+}
+
+};
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to