Diff
Modified: trunk/Source/WTF/ChangeLog (197522 => 197523)
--- trunk/Source/WTF/ChangeLog 2016-03-03 23:42:55 UTC (rev 197522)
+++ trunk/Source/WTF/ChangeLog 2016-03-03 23:49:18 UTC (rev 197523)
@@ -1,3 +1,17 @@
+2016-03-03 Daniel Bates <[email protected]>
+
+ Add unit tests for WTF::OptionSet
+ https://bugs.webkit.org/show_bug.cgi?id=154925
+ <rdar://problem/24964211>
+
+ Reviewed by Darin Adler.
+
+ * wtf/CMakeLists.txt: Add header OptionSet.h to the list of WTF headers.
+ * wtf/OptionSet.h: Use in-class initialization to initialize m_storage and declare
+ the trivial constexpr constructor as default.
+ (WTF::OptionSet::OptionSet): For convenience add a constructor that takes a std::initializer_list.
+ This code was written by Anders Carlsson.
+
2016-03-03 Andy Estes <[email protected]>
Adopt CFNetwork storage partitioning SPI
Modified: trunk/Source/WTF/wtf/CMakeLists.txt (197522 => 197523)
--- trunk/Source/WTF/wtf/CMakeLists.txt 2016-03-03 23:42:55 UTC (rev 197522)
+++ trunk/Source/WTF/wtf/CMakeLists.txt 2016-03-03 23:49:18 UTC (rev 197523)
@@ -60,6 +60,7 @@
NumberOfCores.h
OSAllocator.h
OSRandomSource.h
+ OptionSet.h
OrderMaker.h
PageAllocation.h
PageBlock.h
Modified: trunk/Source/WTF/wtf/OptionSet.h (197522 => 197523)
--- trunk/Source/WTF/wtf/OptionSet.h 2016-03-03 23:42:55 UTC (rev 197522)
+++ trunk/Source/WTF/wtf/OptionSet.h 2016-03-03 23:49:18 UTC (rev 197523)
@@ -26,6 +26,7 @@
#ifndef OptionSet_h
#define OptionSet_h
+#include <initializer_list>
#include <type_traits>
namespace WTF {
@@ -40,16 +41,21 @@
return static_cast<T>(storageType);
}
- constexpr OptionSet()
- : m_storage(0)
- {
- }
+ constexpr OptionSet() = default;
constexpr OptionSet(T t)
: m_storage(static_cast<StorageType>(t))
{
}
+ // FIXME: Make this constexpr once we adopt C++14 as C++11 does not support for-loops
+ // in a constexpr function.
+ OptionSet(std::initializer_list<T> initializerList)
+ {
+ for (auto& option : initializerList)
+ m_storage |= static_cast<StorageType>(option);
+ }
+
constexpr StorageType toRaw() const { return m_storage; }
constexpr bool contains(OptionSet optionSet) const
@@ -65,7 +71,7 @@
}
private:
- StorageType m_storage;
+ StorageType m_storage { 0 };
};
}
Modified: trunk/Tools/ChangeLog (197522 => 197523)
--- trunk/Tools/ChangeLog 2016-03-03 23:42:55 UTC (rev 197522)
+++ trunk/Tools/ChangeLog 2016-03-03 23:49:18 UTC (rev 197523)
@@ -1,3 +1,18 @@
+2016-03-03 Daniel Bates <[email protected]>
+
+ Add unit tests for WTF::OptionSet
+ https://bugs.webkit.org/show_bug.cgi?id=154925
+ <rdar://problem/24964211>
+
+ Reviewed by Darin Adler.
+
+ Add tests to ensure that we do not regress the behavior of WTF::OptionSet.
+
+ * TestWebKitAPI/CMakeLists.txt: Add file TestWebKitAPI/Tests/WTF/OptionSet.cpp.
+ * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: Ditto.
+ * TestWebKitAPI/Tests/WTF/OptionSet.cpp: Added.
+ (TestWebKitAPI::TEST):
+
2016-03-03 Commit Queue <[email protected]>
Unreviewed, rolling out r197442.
Modified: trunk/Tools/TestWebKitAPI/CMakeLists.txt (197522 => 197523)
--- trunk/Tools/TestWebKitAPI/CMakeLists.txt 2016-03-03 23:42:55 UTC (rev 197522)
+++ trunk/Tools/TestWebKitAPI/CMakeLists.txt 2016-03-03 23:49:18 UTC (rev 197523)
@@ -58,6 +58,7 @@
${TESTWEBKITAPI_DIR}/Tests/WTF/MediaTime.cpp
${TESTWEBKITAPI_DIR}/Tests/WTF/MetaAllocator.cpp
${TESTWEBKITAPI_DIR}/Tests/WTF/NakedPtr.cpp
+ ${TESTWEBKITAPI_DIR}/Tests/WTF/OptionSet.cpp
${TESTWEBKITAPI_DIR}/Tests/WTF/ParkingLot.cpp
${TESTWEBKITAPI_DIR}/Tests/WTF/RedBlackTree.cpp
${TESTWEBKITAPI_DIR}/Tests/WTF/Ref.cpp
Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (197522 => 197523)
--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2016-03-03 23:42:55 UTC (rev 197522)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2016-03-03 23:49:18 UTC (rev 197523)
@@ -342,6 +342,7 @@
CE3524F81B1431F60028A7C5 /* TextFieldDidBeginAndEndEditing_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CE3524F21B142B8D0028A7C5 /* TextFieldDidBeginAndEndEditing_Bundle.cpp */; };
CE3524F91B1441C40028A7C5 /* TextFieldDidBeginAndEndEditing.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CE3524F11B142B8D0028A7C5 /* TextFieldDidBeginAndEndEditing.cpp */; };
CE3524FA1B1443890028A7C5 /* input-focus-blur.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CE3524F51B142BBB0028A7C5 /* input-focus-blur.html */; };
+ CE50D8CA1C8665CE0072EA5A /* OptionSet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CE50D8C81C8665CE0072EA5A /* OptionSet.cpp */; };
CEA6CF2819CCF69D0064F5A7 /* open-and-close-window.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CEA6CF2719CCF69D0064F5A7 /* open-and-close-window.html */; };
CEBABD491B71687C0051210A /* should-open-external-schemes.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CEBABD481B71687C0051210A /* should-open-external-schemes.html */; };
E1220DCA155B28AA0013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = E1220DC9155B287D0013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.html */; };
@@ -841,6 +842,7 @@
CE3524F11B142B8D0028A7C5 /* TextFieldDidBeginAndEndEditing.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TextFieldDidBeginAndEndEditing.cpp; sourceTree = "<group>"; };
CE3524F21B142B8D0028A7C5 /* TextFieldDidBeginAndEndEditing_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TextFieldDidBeginAndEndEditing_Bundle.cpp; sourceTree = "<group>"; };
CE3524F51B142BBB0028A7C5 /* input-focus-blur.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "input-focus-blur.html"; sourceTree = "<group>"; };
+ CE50D8C81C8665CE0072EA5A /* OptionSet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = OptionSet.cpp; sourceTree = "<group>"; };
CEA6CF2219CCF5BD0064F5A7 /* OpenAndCloseWindow.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = OpenAndCloseWindow.mm; sourceTree = "<group>"; };
CEA6CF2719CCF69D0064F5A7 /* open-and-close-window.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "open-and-close-window.html"; sourceTree = "<group>"; };
CEBABD481B71687C0051210A /* should-open-external-schemes.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "should-open-external-schemes.html"; sourceTree = "<group>"; };
@@ -1286,6 +1288,7 @@
0FC6C4CE141034AD005B7F0C /* MetaAllocator.cpp */,
93A427AC180DA60F00CD24D7 /* MoveOnly.h */,
FEB6F74E1B2BA44E009E4922 /* NakedPtr.cpp */,
+ CE50D8C81C8665CE0072EA5A /* OptionSet.cpp */,
1AFDE6541953B2C000C48FFA /* Optional.cpp */,
0FE447971B76F1E3009498EB /* ParkingLot.cpp */,
0FC6C4CB141027E0005B7F0C /* RedBlackTree.cpp */,
@@ -1898,6 +1901,7 @@
2D9A53AF1B31FA8D0074D5AA /* ShrinkToFit.mm in Sources */,
51B454EC1B4E236B0085EAA6 /* WebViewCloseInsideDidFinishLoadForFrame.mm in Sources */,
7AA021BB1AB09EA70052953F /* DateMath.cpp in Sources */,
+ CE50D8CA1C8665CE0072EA5A /* OptionSet.cpp in Sources */,
2D1FE0B01AD465C1006CD9E6 /* FixedLayoutSize.mm in Sources */,
1CB9BC381A67482300FE5678 /* WeakPtr.cpp in Sources */,
2E7765CD16C4D80A00BA2BB1 /* mainIOS.mm in Sources */,
Added: trunk/Tools/TestWebKitAPI/Tests/WTF/OptionSet.cpp (0 => 197523)
--- trunk/Tools/TestWebKitAPI/Tests/WTF/OptionSet.cpp (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/OptionSet.cpp 2016-03-03 23:49:18 UTC (rev 197523)
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2016 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 <wtf/OptionSet.h>
+
+namespace TestWebKitAPI {
+
+enum class ExampleFlags {
+ A = 1 << 0,
+ B = 1 << 1,
+ C = 1 << 2,
+};
+
+TEST(WTF_OptionSet, EmptySet)
+{
+ OptionSet<ExampleFlags> set;
+ EXPECT_FALSE(set.contains(ExampleFlags::A));
+ EXPECT_FALSE(set.contains(ExampleFlags::B));
+ EXPECT_FALSE(set.contains(ExampleFlags::C));
+}
+
+TEST(WTF_OptionSet, ContainsOneFlag)
+{
+ OptionSet<ExampleFlags> set = ExampleFlags::A;
+ EXPECT_TRUE(set.contains(ExampleFlags::A));
+ EXPECT_FALSE(set.contains(ExampleFlags::B));
+ EXPECT_FALSE(set.contains(ExampleFlags::C));
+}
+
+TEST(WTF_OptionSet, ContainsTwoFlags)
+{
+ OptionSet<ExampleFlags> set { ExampleFlags::A, ExampleFlags::B };
+ EXPECT_TRUE(set.contains(ExampleFlags::A));
+ EXPECT_TRUE(set.contains(ExampleFlags::B));
+ EXPECT_FALSE(set.contains(ExampleFlags::C));
+}
+
+TEST(WTF_OptionSet, OperatorBitwiseOr)
+{
+ OptionSet<ExampleFlags> set = ExampleFlags::A;
+ set |= ExampleFlags::C;
+ EXPECT_TRUE(set.contains(ExampleFlags::A));
+ EXPECT_FALSE(set.contains(ExampleFlags::B));
+ EXPECT_TRUE(set.contains(ExampleFlags::C));
+}
+
+TEST(WTF_OptionSet, EmptyOptionSetToRawValueToOptionSet)
+{
+ OptionSet<ExampleFlags> set;
+ EXPECT_FALSE(set.contains(ExampleFlags::A));
+ EXPECT_FALSE(set.contains(ExampleFlags::B));
+ EXPECT_FALSE(set.contains(ExampleFlags::C));
+
+ auto set2 = OptionSet<ExampleFlags>::fromRaw(set.toRaw());
+ EXPECT_FALSE(set2.contains(ExampleFlags::A));
+ EXPECT_FALSE(set2.contains(ExampleFlags::B));
+ EXPECT_FALSE(set2.contains(ExampleFlags::C));
+}
+
+TEST(WTF_OptionSet, OptionSetThatContainsOneFlagToRawValueToOptionSet)
+{
+ OptionSet<ExampleFlags> set = ExampleFlags::A;
+ EXPECT_TRUE(set.contains(ExampleFlags::A));
+ EXPECT_FALSE(set.contains(ExampleFlags::B));
+ EXPECT_FALSE(set.contains(ExampleFlags::C));
+
+ auto set2 = OptionSet<ExampleFlags>::fromRaw(set.toRaw());
+ EXPECT_TRUE(set2.contains(ExampleFlags::A));
+ EXPECT_FALSE(set2.contains(ExampleFlags::B));
+ EXPECT_FALSE(set2.contains(ExampleFlags::C));
+}
+
+TEST(WTF_OptionSet, OptionSetThatContainsTwoFlagsToRawValueToOptionSet)
+{
+ OptionSet<ExampleFlags> set { ExampleFlags::A, ExampleFlags::C };
+ EXPECT_TRUE(set.contains(ExampleFlags::A));
+ EXPECT_TRUE(set.contains(ExampleFlags::C));
+ EXPECT_FALSE(set.contains(ExampleFlags::B));
+
+ auto set2 = OptionSet<ExampleFlags>::fromRaw(set.toRaw());
+ EXPECT_TRUE(set2.contains(ExampleFlags::A));
+ EXPECT_TRUE(set2.contains(ExampleFlags::C));
+ EXPECT_FALSE(set2.contains(ExampleFlags::B));
+}
+
+} // namespace TestWebKitAPI
Property changes on: trunk/Tools/TestWebKitAPI/Tests/WTF/OptionSet.cpp
___________________________________________________________________
Added: svn:eol-style