<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[197788] trunk</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/197788">197788</a></dd>
<dt>Author</dt> <dd>dbates@webkit.org</dd>
<dt>Date</dt> <dd>2016-03-08 11:33:10 -0800 (Tue, 08 Mar 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>Support iterating over an OptionSet and checking if it is empty
https://bugs.webkit.org/show_bug.cgi?id=154941
<rdar://problem/24964187>
Reviewed by Darin Adler.
Source/WTF:
Implements support for iterating over the enumerators in an OptionSet as well as
determining if the set is empty.
Iterating over an OptionSet is in Big Theta(N) where N is the number of items in
the set. More precisely, it is in Big Theta(log M) where M is the bitmask represented
by the bitwise OR-ing of all enumerators in the set.
* wtf/OptionSet.h: Added comment to describe the purpose of this class and its invariant -
the enumerators must be positive powers of two.
(WTF::OptionSet::Iterator::operator*): Returns the enumerator pointed to by the iterator.
(WTF::OptionSet::Iterator::operator++): Advance to the next smallest enumerator in the set.
(WTF::OptionSet::Iterator::operator==): Returns whether the iterator is equal to the specified iterator.
(WTF::OptionSet::Iterator::operator!=): Returns whether the iterator is not equal to the specified iterator.
(WTF::OptionSet::Iterator::Iterator): Added.
(WTF::OptionSet::fromRaw): Instantiate using specialized private constructor to allow
instantiation with a raw value of 0.
(WTF::OptionSet::OptionSet): Specialized constructor that asserts that the specified value
is a positive power of two. This variant is only compiled when assertions are enabled (i.e. !ASSERT_DISABLED).
(WTF::OptionSet::isEmpty): Returns whether the set is empty.
(WTF::OptionSet::begin): Returns an iterator to the enumerator with the smallest value in the set.
(WTF::OptionSet::end): Returns an iterator that represents the end sentinel of the set.
Tools:
Add tests to ensure that we do not regression both iteration of an OptionSet and
determining whether an OptionSet is empty.
* TestWebKitAPI/Test.h:
(TestWebKitAPI::Util::assertStrongEnum): Helper function to assert two strong enum type for equality.
* TestWebKitAPI/Tests/WTF/OptionSet.cpp:
(TestWebKitAPI::TEST):</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWTFChangeLog">trunk/Source/WTF/ChangeLog</a></li>
<li><a href="#trunkSourceWTFwtfOptionSeth">trunk/Source/WTF/wtf/OptionSet.h</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITesth">trunk/Tools/TestWebKitAPI/Test.h</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWTFOptionSetcpp">trunk/Tools/TestWebKitAPI/Tests/WTF/OptionSet.cpp</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWTFChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/ChangeLog (197787 => 197788)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/ChangeLog        2016-03-08 19:32:58 UTC (rev 197787)
+++ trunk/Source/WTF/ChangeLog        2016-03-08 19:33:10 UTC (rev 197788)
</span><span class="lines">@@ -1,3 +1,33 @@
</span><ins>+2016-03-08 Daniel Bates <dabates@apple.com>
+
+ Support iterating over an OptionSet and checking if it is empty
+ https://bugs.webkit.org/show_bug.cgi?id=154941
+ <rdar://problem/24964187>
+
+ Reviewed by Darin Adler.
+
+ Implements support for iterating over the enumerators in an OptionSet as well as
+ determining if the set is empty.
+
+ Iterating over an OptionSet is in Big Theta(N) where N is the number of items in
+ the set. More precisely, it is in Big Theta(log M) where M is the bitmask represented
+ by the bitwise OR-ing of all enumerators in the set.
+
+ * wtf/OptionSet.h: Added comment to describe the purpose of this class and its invariant -
+ the enumerators must be positive powers of two.
+ (WTF::OptionSet::Iterator::operator*): Returns the enumerator pointed to by the iterator.
+ (WTF::OptionSet::Iterator::operator++): Advance to the next smallest enumerator in the set.
+ (WTF::OptionSet::Iterator::operator==): Returns whether the iterator is equal to the specified iterator.
+ (WTF::OptionSet::Iterator::operator!=): Returns whether the iterator is not equal to the specified iterator.
+ (WTF::OptionSet::Iterator::Iterator): Added.
+ (WTF::OptionSet::fromRaw): Instantiate using specialized private constructor to allow
+ instantiation with a raw value of 0.
+ (WTF::OptionSet::OptionSet): Specialized constructor that asserts that the specified value
+ is a positive power of two. This variant is only compiled when assertions are enabled (i.e. !ASSERT_DISABLED).
+ (WTF::OptionSet::isEmpty): Returns whether the set is empty.
+ (WTF::OptionSet::begin): Returns an iterator to the enumerator with the smallest value in the set.
+ (WTF::OptionSet::end): Returns an iterator that represents the end sentinel of the set.
+
</ins><span class="cx"> 2016-03-07 Keith Rollin <krollin@apple.com>
</span><span class="cx">
</span><span class="cx"> Enhance logging: Use "always on" macros
</span></span></pre></div>
<a id="trunkSourceWTFwtfOptionSeth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/OptionSet.h (197787 => 197788)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/OptionSet.h        2016-03-08 19:32:58 UTC (rev 197787)
+++ trunk/Source/WTF/wtf/OptionSet.h        2016-03-08 19:33:10 UTC (rev 197788)
</span><span class="lines">@@ -27,37 +27,83 @@
</span><span class="cx"> #define OptionSet_h
</span><span class="cx">
</span><span class="cx"> #include <initializer_list>
</span><ins>+#include <iterator>
</ins><span class="cx"> #include <type_traits>
</span><ins>+#include <wtf/Assertions.h>
+#include <wtf/MathExtras.h>
</ins><span class="cx">
</span><span class="cx"> namespace WTF {
</span><span class="cx">
</span><ins>+// OptionSet is a class that represents a set of enumerators in a space-efficient manner. The enumerators
+// must be powers of two greater than 0. This class is useful as a replacement for passing a bitmask of
+// enumerators around.
</ins><span class="cx"> template<typename T> class OptionSet {
</span><span class="cx"> static_assert(std::is_enum<T>::value, "T is not an enum type");
</span><span class="cx"> typedef typename std::make_unsigned<typename std::underlying_type<T>::type>::type StorageType;
</span><span class="cx">
</span><span class="cx"> public:
</span><ins>+ template<typename StorageType> class Iterator {
+ public:
+ // Isolate the rightmost set bit.
+ T operator*() const { return static_cast<T>(m_value & -m_value); }
+
+ // Iterates from smallest to largest enum value by turning off the rightmost set bit.
+ Iterator& operator++()
+ {
+ m_value &= m_value - 1;
+ return *this;
+ }
+
+ Iterator& operator++(int) = delete;
+
+ bool operator==(const Iterator& other) const { return m_value == other.m_value; }
+ bool operator!=(const Iterator& other) const { return m_value != other.m_value; }
+
+ private:
+ Iterator(StorageType value) : m_value(value) { }
+ friend OptionSet;
+
+ StorageType m_value;
+ };
+ using iterator = Iterator<StorageType>;
+
</ins><span class="cx"> static OptionSet fromRaw(StorageType storageType)
</span><span class="cx"> {
</span><del>- return static_cast<T>(storageType);
</del><ins>+ return OptionSet(static_cast<T>(storageType), FromRawValue);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> constexpr OptionSet() = default;
</span><span class="cx">
</span><ins>+#if ASSERT_DISABLED
</ins><span class="cx"> constexpr OptionSet(T t)
</span><span class="cx"> : m_storage(static_cast<StorageType>(t))
</span><span class="cx"> {
</span><span class="cx"> }
</span><ins>+#else
+ OptionSet(T t)
+ : m_storage(static_cast<StorageType>(t))
+ {
+ ASSERT_WITH_MESSAGE(hasOneBitSet(static_cast<StorageType>(t)), "Enumerator is not a positive power of two.");
+ }
+#endif
</ins><span class="cx">
</span><span class="cx"> // FIXME: Make this constexpr once we adopt C++14 as C++11 does not support for-loops
</span><span class="cx"> // in a constexpr function.
</span><span class="cx"> OptionSet(std::initializer_list<T> initializerList)
</span><span class="cx"> {
</span><del>- for (auto& option : initializerList)
</del><ins>+ for (auto& option : initializerList) {
+ ASSERT_WITH_MESSAGE(hasOneBitSet(static_cast<StorageType>(option)), "Enumerator is not a positive power of two.");
</ins><span class="cx"> m_storage |= static_cast<StorageType>(option);
</span><ins>+ }
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> constexpr StorageType toRaw() const { return m_storage; }
</span><span class="cx">
</span><ins>+ constexpr bool isEmpty() const { return !m_storage; }
+
+ constexpr iterator begin() const { return m_storage; }
+ constexpr iterator end() const { return 0; }
+
</ins><span class="cx"> constexpr bool contains(OptionSet optionSet) const
</span><span class="cx"> {
</span><span class="cx"> return m_storage & optionSet.m_storage;
</span><span class="lines">@@ -71,6 +117,11 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> private:
</span><ins>+ enum InitializationTag { FromRawValue };
+ constexpr OptionSet(T t, InitializationTag)
+ : m_storage(static_cast<StorageType>(t))
+ {
+ }
</ins><span class="cx"> StorageType m_storage { 0 };
</span><span class="cx"> };
</span><span class="cx">
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (197787 => 197788)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2016-03-08 19:32:58 UTC (rev 197787)
+++ trunk/Tools/ChangeLog        2016-03-08 19:33:10 UTC (rev 197788)
</span><span class="lines">@@ -1,3 +1,19 @@
</span><ins>+2016-03-08 Daniel Bates <dabates@apple.com>
+
+ Support iterating over an OptionSet and checking if it is empty
+ https://bugs.webkit.org/show_bug.cgi?id=154941
+ <rdar://problem/24964187>
+
+ Reviewed by Darin Adler.
+
+ Add tests to ensure that we do not regression both iteration of an OptionSet and
+ determining whether an OptionSet is empty.
+
+ * TestWebKitAPI/Test.h:
+ (TestWebKitAPI::Util::assertStrongEnum): Helper function to assert two strong enum type for equality.
+ * TestWebKitAPI/Tests/WTF/OptionSet.cpp:
+ (TestWebKitAPI::TEST):
+
</ins><span class="cx"> 2016-03-08 Alexey Proskuryakov <ap@apple.com>
</span><span class="cx">
</span><span class="cx"> Add debug iOS Simulator bots to the dashboard
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITesth"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Test.h (197787 => 197788)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Test.h        2016-03-08 19:32:58 UTC (rev 197787)
+++ trunk/Tools/TestWebKitAPI/Test.h        2016-03-08 19:33:10 UTC (rev 197788)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2010 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2010, 2016 Apple Inc. All rights reserved.
</ins><span class="cx"> *
</span><span class="cx"> * Redistribution and use in source and binary forms, with or without
</span><span class="cx"> * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -26,6 +26,8 @@
</span><span class="cx"> #ifndef Test_h
</span><span class="cx"> #define Test_h
</span><span class="cx">
</span><ins>+#include <type_traits>
+
</ins><span class="cx"> namespace TestWebKitAPI {
</span><span class="cx">
</span><span class="cx"> #define EXPECT_NOT_NULL(expression) \
</span><span class="lines">@@ -40,6 +42,18 @@
</span><span class="cx"> #define ASSERT_NULL(expression) \
</span><span class="cx"> ASSERT_TRUE(!(expression))
</span><span class="cx">
</span><ins>+template<typename T>
+static inline ::testing::AssertionResult assertStrongEnum(const char* expected_expression, const char* actual_expression, T expected, T actual)
+{
+ static_assert(std::is_enum<T>::value, "T is not an enum type");
+ typedef typename std::underlying_type<T>::type UnderlyingStorageType;
+ return ::testing::internal::CmpHelperEQ(expected_expression, actual_expression, static_cast<UnderlyingStorageType>(expected), static_cast<UnderlyingStorageType>(actual));
+}
+
+#define EXPECT_STRONG_ENUM_EQ(expected, actual) \
+ EXPECT_PRED_FORMAT2(TestWebKitAPI::assertStrongEnum, expected, actual)
+
+
</ins><span class="cx"> } // namespace TestWebKitAPI
</span><span class="cx">
</span><span class="cx"> #endif // Test_h
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWTFOptionSetcpp"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/OptionSet.cpp (197787 => 197788)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WTF/OptionSet.cpp        2016-03-08 19:32:58 UTC (rev 197787)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/OptionSet.cpp        2016-03-08 19:33:10 UTC (rev 197788)
</span><span class="lines">@@ -25,40 +25,74 @@
</span><span class="cx">
</span><span class="cx"> #include "config.h"
</span><span class="cx">
</span><ins>+#include "Test.h"
</ins><span class="cx"> #include <wtf/OptionSet.h>
</span><span class="cx">
</span><span class="cx"> namespace TestWebKitAPI {
</span><span class="cx">
</span><del>-enum class ExampleFlags {
</del><ins>+enum class ExampleFlags : uint64_t {
</ins><span class="cx"> A = 1 << 0,
</span><span class="cx"> B = 1 << 1,
</span><span class="cx"> C = 1 << 2,
</span><ins>+ D = 1ULL << 31,
+ E = 1ULL << 63,
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> TEST(WTF_OptionSet, EmptySet)
</span><span class="cx"> {
</span><span class="cx"> OptionSet<ExampleFlags> set;
</span><ins>+ EXPECT_TRUE(set.isEmpty());
</ins><span class="cx"> EXPECT_FALSE(set.contains(ExampleFlags::A));
</span><span class="cx"> EXPECT_FALSE(set.contains(ExampleFlags::B));
</span><span class="cx"> EXPECT_FALSE(set.contains(ExampleFlags::C));
</span><ins>+ EXPECT_FALSE(set.contains(ExampleFlags::D));
+ EXPECT_FALSE(set.contains(ExampleFlags::E));
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> TEST(WTF_OptionSet, ContainsOneFlag)
</span><span class="cx"> {
</span><span class="cx"> OptionSet<ExampleFlags> set = ExampleFlags::A;
</span><ins>+ EXPECT_FALSE(set.isEmpty());
</ins><span class="cx"> EXPECT_TRUE(set.contains(ExampleFlags::A));
</span><span class="cx"> EXPECT_FALSE(set.contains(ExampleFlags::B));
</span><span class="cx"> EXPECT_FALSE(set.contains(ExampleFlags::C));
</span><ins>+ EXPECT_FALSE(set.contains(ExampleFlags::D));
+ EXPECT_FALSE(set.contains(ExampleFlags::E));
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> TEST(WTF_OptionSet, ContainsTwoFlags)
</span><span class="cx"> {
</span><span class="cx"> OptionSet<ExampleFlags> set { ExampleFlags::A, ExampleFlags::B };
</span><ins>+ EXPECT_FALSE(set.isEmpty());
</ins><span class="cx"> EXPECT_TRUE(set.contains(ExampleFlags::A));
</span><span class="cx"> EXPECT_TRUE(set.contains(ExampleFlags::B));
</span><span class="cx"> EXPECT_FALSE(set.contains(ExampleFlags::C));
</span><ins>+ EXPECT_FALSE(set.contains(ExampleFlags::D));
+ EXPECT_FALSE(set.contains(ExampleFlags::E));
</ins><span class="cx"> }
</span><span class="cx">
</span><ins>+TEST(WTF_OptionSet, ContainsTwoFlags2)
+{
+ OptionSet<ExampleFlags> set { ExampleFlags::A, ExampleFlags::D };
+ EXPECT_FALSE(set.isEmpty());
+ EXPECT_TRUE(set.contains(ExampleFlags::A));
+ EXPECT_TRUE(set.contains(ExampleFlags::D));
+ EXPECT_FALSE(set.contains(ExampleFlags::B));
+ EXPECT_FALSE(set.contains(ExampleFlags::C));
+ EXPECT_FALSE(set.contains(ExampleFlags::E));
+}
+
+TEST(WTF_OptionSet, ContainsTwoFlags3)
+{
+ OptionSet<ExampleFlags> set { ExampleFlags::D, ExampleFlags::E };
+ EXPECT_FALSE(set.isEmpty());
+ EXPECT_TRUE(set.contains(ExampleFlags::D));
+ EXPECT_TRUE(set.contains(ExampleFlags::E));
+ EXPECT_FALSE(set.contains(ExampleFlags::A));
+ EXPECT_FALSE(set.contains(ExampleFlags::B));
+ EXPECT_FALSE(set.contains(ExampleFlags::C));
+}
+
</ins><span class="cx"> TEST(WTF_OptionSet, OperatorBitwiseOr)
</span><span class="cx"> {
</span><span class="cx"> OptionSet<ExampleFlags> set = ExampleFlags::A;
</span><span class="lines">@@ -71,11 +105,13 @@
</span><span class="cx"> TEST(WTF_OptionSet, EmptyOptionSetToRawValueToOptionSet)
</span><span class="cx"> {
</span><span class="cx"> OptionSet<ExampleFlags> set;
</span><ins>+ EXPECT_TRUE(set.isEmpty());
</ins><span class="cx"> EXPECT_FALSE(set.contains(ExampleFlags::A));
</span><span class="cx"> EXPECT_FALSE(set.contains(ExampleFlags::B));
</span><span class="cx"> EXPECT_FALSE(set.contains(ExampleFlags::C));
</span><span class="cx">
</span><span class="cx"> auto set2 = OptionSet<ExampleFlags>::fromRaw(set.toRaw());
</span><ins>+ EXPECT_TRUE(set2.isEmpty());
</ins><span class="cx"> EXPECT_FALSE(set2.contains(ExampleFlags::A));
</span><span class="cx"> EXPECT_FALSE(set2.contains(ExampleFlags::B));
</span><span class="cx"> EXPECT_FALSE(set2.contains(ExampleFlags::C));
</span><span class="lines">@@ -84,27 +120,152 @@
</span><span class="cx"> TEST(WTF_OptionSet, OptionSetThatContainsOneFlagToRawValueToOptionSet)
</span><span class="cx"> {
</span><span class="cx"> OptionSet<ExampleFlags> set = ExampleFlags::A;
</span><ins>+ EXPECT_FALSE(set.isEmpty());
</ins><span class="cx"> EXPECT_TRUE(set.contains(ExampleFlags::A));
</span><span class="cx"> EXPECT_FALSE(set.contains(ExampleFlags::B));
</span><span class="cx"> EXPECT_FALSE(set.contains(ExampleFlags::C));
</span><ins>+ EXPECT_FALSE(set.contains(ExampleFlags::D));
+ EXPECT_FALSE(set.contains(ExampleFlags::E));
</ins><span class="cx">
</span><span class="cx"> auto set2 = OptionSet<ExampleFlags>::fromRaw(set.toRaw());
</span><ins>+ EXPECT_FALSE(set2.isEmpty());
</ins><span class="cx"> EXPECT_TRUE(set2.contains(ExampleFlags::A));
</span><span class="cx"> EXPECT_FALSE(set2.contains(ExampleFlags::B));
</span><span class="cx"> EXPECT_FALSE(set2.contains(ExampleFlags::C));
</span><ins>+ EXPECT_FALSE(set2.contains(ExampleFlags::D));
+ EXPECT_FALSE(set2.contains(ExampleFlags::E));
</ins><span class="cx"> }
</span><span class="cx">
</span><ins>+TEST(WTF_OptionSet, OptionSetThatContainsOneFlagToRawValueToOptionSet2)
+{
+ OptionSet<ExampleFlags> set = ExampleFlags::E;
+ EXPECT_FALSE(set.isEmpty());
+ EXPECT_TRUE(set.contains(ExampleFlags::E));
+ EXPECT_FALSE(set.contains(ExampleFlags::A));
+ EXPECT_FALSE(set.contains(ExampleFlags::B));
+ EXPECT_FALSE(set.contains(ExampleFlags::C));
+ EXPECT_FALSE(set.contains(ExampleFlags::D));
+
+ auto set2 = OptionSet<ExampleFlags>::fromRaw(set.toRaw());
+ EXPECT_FALSE(set2.isEmpty());
+ EXPECT_TRUE(set2.contains(ExampleFlags::E));
+ EXPECT_FALSE(set2.contains(ExampleFlags::A));
+ EXPECT_FALSE(set2.contains(ExampleFlags::B));
+ EXPECT_FALSE(set2.contains(ExampleFlags::C));
+ EXPECT_FALSE(set2.contains(ExampleFlags::D));
+}
+
</ins><span class="cx"> TEST(WTF_OptionSet, OptionSetThatContainsTwoFlagsToRawValueToOptionSet)
</span><span class="cx"> {
</span><span class="cx"> OptionSet<ExampleFlags> set { ExampleFlags::A, ExampleFlags::C };
</span><ins>+ EXPECT_FALSE(set.isEmpty());
</ins><span class="cx"> EXPECT_TRUE(set.contains(ExampleFlags::A));
</span><span class="cx"> EXPECT_TRUE(set.contains(ExampleFlags::C));
</span><span class="cx"> EXPECT_FALSE(set.contains(ExampleFlags::B));
</span><span class="cx">
</span><span class="cx"> auto set2 = OptionSet<ExampleFlags>::fromRaw(set.toRaw());
</span><ins>+ EXPECT_FALSE(set2.isEmpty());
</ins><span class="cx"> EXPECT_TRUE(set2.contains(ExampleFlags::A));
</span><span class="cx"> EXPECT_TRUE(set2.contains(ExampleFlags::C));
</span><span class="cx"> EXPECT_FALSE(set2.contains(ExampleFlags::B));
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+TEST(WTF_OptionSet, OptionSetThatContainsTwoFlagsToRawValueToOptionSet2)
+{
+ OptionSet<ExampleFlags> set { ExampleFlags::D, ExampleFlags::E };
+ EXPECT_FALSE(set.isEmpty());
+ EXPECT_TRUE(set.contains(ExampleFlags::D));
+ EXPECT_TRUE(set.contains(ExampleFlags::E));
+ 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.isEmpty());
+ EXPECT_TRUE(set2.contains(ExampleFlags::D));
+ EXPECT_TRUE(set2.contains(ExampleFlags::E));
+ EXPECT_FALSE(set2.contains(ExampleFlags::A));
+ EXPECT_FALSE(set2.contains(ExampleFlags::B));
+ EXPECT_FALSE(set2.contains(ExampleFlags::C));
+}
+
+TEST(WTF_OptionSet, TwoIteratorsIntoSameOptionSet)
+{
+ OptionSet<ExampleFlags> set { ExampleFlags::C, ExampleFlags::B };
+ OptionSet<ExampleFlags>::iterator it1 = set.begin();
+ OptionSet<ExampleFlags>::iterator it2 = it1;
+ ++it1;
+ EXPECT_STRONG_ENUM_EQ(ExampleFlags::C, *it1);
+ EXPECT_STRONG_ENUM_EQ(ExampleFlags::B, *it2);
+}
+
+TEST(WTF_OptionSet, IterateOverOptionSetThatContainsTwoFlags)
+{
+ OptionSet<ExampleFlags> set { ExampleFlags::A, ExampleFlags::C };
+ OptionSet<ExampleFlags>::iterator it = set.begin();
+ OptionSet<ExampleFlags>::iterator end = set.end();
+ EXPECT_TRUE(it != end);
+ EXPECT_STRONG_ENUM_EQ(ExampleFlags::A, *it);
+ ++it;
+ EXPECT_STRONG_ENUM_EQ(ExampleFlags::C, *it);
+ ++it;
+ EXPECT_TRUE(it == end);
+}
+
+TEST(WTF_OptionSet, IterateOverOptionSetThatContainsFlags2)
+{
+ OptionSet<ExampleFlags> set { ExampleFlags::D, ExampleFlags::E };
+ OptionSet<ExampleFlags>::iterator it = set.begin();
+ OptionSet<ExampleFlags>::iterator end = set.end();
+ EXPECT_TRUE(it != end);
+ EXPECT_STRONG_ENUM_EQ(ExampleFlags::D, *it);
+ ++it;
+ EXPECT_STRONG_ENUM_EQ(ExampleFlags::E, *it);
+ ++it;
+ EXPECT_TRUE(it == end);
+}
+
+TEST(WTF_OptionSet, NextItemAfterLargestIn32BitFlagSet)
+{
+ enum class ThirtyTwoBitFlags : uint32_t {
+ A = 1UL << 31,
+ };
+ OptionSet<ThirtyTwoBitFlags> set { ThirtyTwoBitFlags::A };
+ OptionSet<ThirtyTwoBitFlags>::iterator it = set.begin();
+ OptionSet<ThirtyTwoBitFlags>::iterator end = set.end();
+ EXPECT_TRUE(it != end);
+ ++it;
+ EXPECT_TRUE(it == end);
+}
+
+TEST(WTF_OptionSet, NextItemAfterLargestIn64BitFlagSet)
+{
+ enum class SixtyFourBitFlags : uint64_t {
+ A = 1ULL << 63,
+ };
+ OptionSet<SixtyFourBitFlags> set { SixtyFourBitFlags::A };
+ OptionSet<SixtyFourBitFlags>::iterator it = set.begin();
+ OptionSet<SixtyFourBitFlags>::iterator end = set.end();
+ EXPECT_TRUE(it != end);
+ ++it;
+ EXPECT_TRUE(it == end);
+}
+
+TEST(WTF_OptionSet, IterationOrderTheSameRegardlessOfInsertionOrder)
+{
+ OptionSet<ExampleFlags> set1 = ExampleFlags::C;
+ set1 |= ExampleFlags::A;
+
+ OptionSet<ExampleFlags> set2 = ExampleFlags::A;
+ set2 |= ExampleFlags::C;
+
+ OptionSet<ExampleFlags>::iterator it1 = set1.begin();
+ OptionSet<ExampleFlags>::iterator it2 = set2.begin();
+
+ EXPECT_TRUE(*it1 == *it2);
+ ++it1;
+ ++it2;
+ EXPECT_TRUE(*it1 == *it2);
+}
+
</ins><span class="cx"> } // namespace TestWebKitAPI
</span></span></pre>
</div>
</div>
</body>
</html>