Diff
Modified: trunk/Source/WTF/ChangeLog (279338 => 279339)
--- trunk/Source/WTF/ChangeLog 2021-06-28 13:57:15 UTC (rev 279338)
+++ trunk/Source/WTF/ChangeLog 2021-06-28 15:34:32 UTC (rev 279339)
@@ -1,3 +1,22 @@
+2021-06-28 Sam Weinig <wei...@apple.com>
+
+ Add helpers to create Spans from CFDataRef and NSData
+ https://bugs.webkit.org/show_bug.cgi?id=227217
+
+ Reviewed by Chris Dumez.
+
+ Add overloads of asBytes() for CFDataRef and NSData. This is going to
+ be a common enough pattern to warrent these helpers.
+
+ * WTF.xcodeproj/project.pbxproj:
+ * wtf/PlatformFTW.cmake:
+ * wtf/PlatformMac.cmake:
+ * wtf/PlatformWin.cmake:
+ * wtf/cf/SpanCF.h: Added.
+ (WTF::asBytes):
+ * wtf/cocoa/SpanCocoa.h: Added.
+ (WTF::asBytes):
+
2021-06-27 Antoine Quint <grao...@webkit.org>
[Model] [iOS] Add support for rendering model resources
Modified: trunk/Source/WTF/WTF.xcodeproj/project.pbxproj (279338 => 279339)
--- trunk/Source/WTF/WTF.xcodeproj/project.pbxproj 2021-06-28 13:57:15 UTC (rev 279338)
+++ trunk/Source/WTF/WTF.xcodeproj/project.pbxproj 2021-06-28 15:34:32 UTC (rev 279339)
@@ -692,6 +692,8 @@
AD89B6B91E64150F0090707F /* MemoryPressureHandlerCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MemoryPressureHandlerCocoa.mm; sourceTree = "<group>"; };
ADF2CE641E39F106006889DB /* MemoryFootprint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MemoryFootprint.h; sourceTree = "<group>"; };
ADF2CE651E39F106006889DB /* MemoryFootprintCocoa.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MemoryFootprintCocoa.cpp; sourceTree = "<group>"; };
+ BC3FEB5D267FCD340054006A /* SpanCF.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SpanCF.h; sourceTree = "<group>"; };
+ BC3FEB5E267FCD460054006A /* SpanCocoa.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SpanCocoa.h; sourceTree = "<group>"; };
BCA30C7F266D3034000D230C /* Span.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Span.h; sourceTree = "<group>"; };
C2BCFC3E1F61D13000C9222C /* Language.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Language.cpp; sourceTree = "<group>"; };
C2BCFC3F1F61D13000C9222C /* Language.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Language.h; sourceTree = "<group>"; };
@@ -840,6 +842,7 @@
C2BCFC411F61D61600C9222C /* LanguageCF.cpp */,
2CDED0EE18115C38004DBA70 /* RunLoopCF.cpp */,
A3EE5C3B21FFAC7C00FABD61 /* SchedulePairCF.cpp */,
+ BC3FEB5D267FCD340054006A /* SpanCF.h */,
1AFDE647195201C300C48FFA /* TypeCastsCF.h */,
5C1F0594216437B30039302C /* URLCF.cpp */,
);
@@ -1581,6 +1584,7 @@
1CA85CA8241B0B260071C2F5 /* RuntimeApplicationChecksCocoa.cpp */,
1CA85CA7241B0B110071C2F5 /* RuntimeApplicationChecksCocoa.h */,
A30D412C1F0DE0BA00B71954 /* SoftLinking.h */,
+ BC3FEB5E267FCD460054006A /* SpanCocoa.h */,
EB61EDC62409CCC0001EFE36 /* SystemTracingCocoa.cpp */,
5CC0EE862162BC2200A1A842 /* URLCocoa.mm */,
93241657243BC2E50032FAAE /* VectorCocoa.h */,
Modified: trunk/Source/WTF/wtf/PlatformFTW.cmake (279338 => 279339)
--- trunk/Source/WTF/wtf/PlatformFTW.cmake 2021-06-28 13:57:15 UTC (rev 279338)
+++ trunk/Source/WTF/wtf/PlatformFTW.cmake 2021-06-28 15:34:32 UTC (rev 279339)
@@ -37,6 +37,7 @@
if (USE_CF)
list(APPEND WTF_PUBLIC_HEADERS
cf/CFURLExtras.h
+ cf/SpanCF.h
cf/TypeCastsCF.h
text/cf/StringConcatenateCF.h
Modified: trunk/Source/WTF/wtf/PlatformMac.cmake (279338 => 279339)
--- trunk/Source/WTF/wtf/PlatformMac.cmake 2021-06-28 13:57:15 UTC (rev 279338)
+++ trunk/Source/WTF/wtf/PlatformMac.cmake 2021-06-28 15:34:32 UTC (rev 279339)
@@ -11,6 +11,7 @@
WeakObjCPtr.h
cf/CFURLExtras.h
+ cf/SpanCF.h
cf/TypeCastsCF.h
cocoa/CrashReporter.h
@@ -18,6 +19,7 @@
cocoa/NSURLExtras.h
cocoa/RuntimeApplicationChecksCocoa.h
cocoa/SoftLinking.h
+ cocoa/SpanCocoa.h
cocoa/VectorCocoa.h
darwin/WeakLinking.h
Modified: trunk/Source/WTF/wtf/PlatformWin.cmake (279338 => 279339)
--- trunk/Source/WTF/wtf/PlatformWin.cmake 2021-06-28 13:57:15 UTC (rev 279338)
+++ trunk/Source/WTF/wtf/PlatformWin.cmake 2021-06-28 15:34:32 UTC (rev 279339)
@@ -35,6 +35,7 @@
if (USE_CF)
list(APPEND WTF_PUBLIC_HEADERS
cf/CFURLExtras.h
+ cf/SpanCF.h
cf/TypeCastsCF.h
text/cf/StringConcatenateCF.h
Added: trunk/Source/WTF/wtf/cf/SpanCF.h (0 => 279339)
--- trunk/Source/WTF/wtf/cf/SpanCF.h (rev 0)
+++ trunk/Source/WTF/wtf/cf/SpanCF.h 2021-06-28 15:34:32 UTC (rev 279339)
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2021 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.
+ */
+
+#pragma once
+
+#include <CoreFoundation/CoreFoundation.h>
+#include <wtf/RetainPtr.h>
+#include <wtf/Span.h>
+
+namespace WTF {
+
+inline Span<const std::byte> asBytes(CFDataRef data)
+{
+ return { reinterpret_cast<const std::byte*>(CFDataGetBytePtr(data)), static_cast<size_t>(CFDataGetLength(data)) };
+}
+
+inline Span<const std::byte> asBytes(const RetainPtr<CFDataRef>& data)
+{
+ return asBytes(data.get());
+}
+
+}
+
+using WTF::asBytes;
Added: trunk/Source/WTF/wtf/cocoa/SpanCocoa.h (0 => 279339)
--- trunk/Source/WTF/wtf/cocoa/SpanCocoa.h (rev 0)
+++ trunk/Source/WTF/wtf/cocoa/SpanCocoa.h 2021-06-28 15:34:32 UTC (rev 279339)
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2021 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.
+ */
+
+#pragma once
+
+#include <Foundation/Foundation.h>
+#include <wtf/RetainPtr.h>
+#include <wtf/Span.h>
+
+namespace WTF {
+
+inline Span<const std::byte> asBytes(NSData *data)
+{
+ return { reinterpret_cast<const std::byte*>(data.bytes), data.length };
+}
+
+inline Span<const std::byte> asBytes(const RetainPtr<NSData>& data)
+{
+ return asBytes(data.get());
+}
+
+}
+
+using WTF::asBytes;
Modified: trunk/Tools/ChangeLog (279338 => 279339)
--- trunk/Tools/ChangeLog 2021-06-28 13:57:15 UTC (rev 279338)
+++ trunk/Tools/ChangeLog 2021-06-28 15:34:32 UTC (rev 279339)
@@ -1,3 +1,15 @@
+2021-06-28 Sam Weinig <wei...@apple.com>
+
+ Add helpers to create Spans from CFDataRef and NSData
+ https://bugs.webkit.org/show_bug.cgi?id=227217
+
+ Reviewed by Chris Dumez.
+
+ * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+ * TestWebKitAPI/Tests/WTF/cf/SpanCF.cpp: Added.
+ * TestWebKitAPI/Tests/WTF/cocoa/SpanCocoa.mm: Added.
+ Add tests for new asBytes() overloads.
+
2021-06-28 Philippe Normand <pnorm...@igalia.com>
[webkitpy] Test timeouts not properly detected when running layout tests with Python 3
Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (279338 => 279339)
--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2021-06-28 13:57:15 UTC (rev 279338)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2021-06-28 15:34:32 UTC (rev 279339)
@@ -979,6 +979,8 @@
BC22D31914DC68B900FFB1DD /* UserMessage_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC22D31714DC68B800FFB1DD /* UserMessage_Bundle.cpp */; };
BC246D9C132F1FF000B56D7C /* CanHandleRequest_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC246D97132F1FE100B56D7C /* CanHandleRequest_Bundle.cpp */; };
BC2D006412AA04CE00E732A3 /* file-with-anchor.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = BC2D004A12A9FEB300E732A3 /* file-with-anchor.html */; };
+ BC3FEB61267FCDB00054006A /* SpanCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC3FEB60267FCDB00054006A /* SpanCF.cpp */; };
+ BC3FEB64267FCF740054006A /* SpanCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC3FEB63267FCF740054006A /* SpanCocoa.mm */; };
BC575A97126E74F1006F0F12 /* InjectedBundleMain.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC575946126E7351006F0F12 /* InjectedBundleMain.cpp */; };
BC575AA2126E7660006F0F12 /* InjectedBundleController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC575AA0126E7657006F0F12 /* InjectedBundleController.cpp */; };
BC575AB0126E83C8006F0F12 /* InjectedBundleBasic_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC575AAF126E83C8006F0F12 /* InjectedBundleBasic_Bundle.cpp */; };
@@ -2735,6 +2737,8 @@
BC2D004A12A9FEB300E732A3 /* file-with-anchor.html */ = {isa = PBXFileReference; explicitFileType = text.html; fileEncoding = 4; path = "file-with-anchor.html"; sourceTree = "<group>"; };
BC3C4C7014575B6A0025FB62 /* WKBrowsingContextLoadDelegateTest.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WKBrowsingContextLoadDelegateTest.mm; path = WebKitObjC/WKBrowsingContextLoadDelegateTest.mm; sourceTree = "<group>"; };
BC3C4C7D14587AA60025FB62 /* WKBrowsingContextGroupTest.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WKBrowsingContextGroupTest.mm; path = WebKitObjC/WKBrowsingContextGroupTest.mm; sourceTree = "<group>"; };
+ BC3FEB60267FCDB00054006A /* SpanCF.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = SpanCF.cpp; sourceTree = "<group>"; };
+ BC3FEB63267FCF740054006A /* SpanCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = SpanCocoa.mm; sourceTree = "<group>"; };
BC55F5F814AD78EE00484BE1 /* Vector.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Vector.cpp; sourceTree = "<group>"; };
BC575946126E7351006F0F12 /* InjectedBundleMain.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InjectedBundleMain.cpp; sourceTree = "<group>"; };
BC575980126E74AF006F0F12 /* InjectedBundleTestWebKitAPI.bundle */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = InjectedBundleTestWebKitAPI.bundle; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -4850,6 +4854,7 @@
children = (
BC029B161486AD6400817DA9 /* RetainPtr.cpp */,
C0991C50143C7D68007998F2 /* RetainPtrHashing.cpp */,
+ BC3FEB60267FCDB00054006A /* SpanCF.cpp */,
);
path = cf;
sourceTree = "<group>";
@@ -4944,6 +4949,7 @@
E3C21A7821B25C82003B31A3 /* cocoa */ = {
isa = PBXGroup;
children = (
+ BC3FEB63267FCF740054006A /* SpanCocoa.mm */,
E3C21A7B21B25CA2003B31A3 /* URLExtras.mm */,
);
path = cocoa;
@@ -5757,6 +5763,8 @@
510A91F824D3622100BFD89C /* SonyDualShock3.mm in Sources */,
51EB126424CA6B66000CB030 /* SonyDualShock4.mm in Sources */,
7CCE7F151A411AE600447C4C /* SpacebarScrolling.cpp in Sources */,
+ BC3FEB61267FCDB00054006A /* SpanCF.cpp in Sources */,
+ BC3FEB64267FCF740054006A /* SpanCocoa.mm in Sources */,
9342589C255B609B0059EEDD /* SpeechRecognition.mm in Sources */,
57F4AAA0208FAEF000A68E9E /* SSLKeyGenerator.mm in Sources */,
83BC5AC020E6C0DF00F5879F /* StartLoadInDidFailProvisionalLoad.mm in Sources */,
Added: trunk/Tools/TestWebKitAPI/Tests/WTF/cf/SpanCF.cpp (0 => 279339)
--- trunk/Tools/TestWebKitAPI/Tests/WTF/cf/SpanCF.cpp (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/cf/SpanCF.cpp 2021-06-28 15:34:32 UTC (rev 279339)
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2021 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/cf/SpanCF.h>
+
+namespace TestWebKitAPI {
+
+TEST(WTFSpanCF, Empty)
+{
+ auto data = "" nullptr, 0));
+
+ {
+ auto span = asBytes(data.get());
+ EXPECT_EQ(span.size(), 0u);
+ EXPECT_EQ(span.data(), nullptr);
+ }
+
+ {
+ auto span = asBytes(data);
+ EXPECT_EQ(span.size(), 0u);
+ EXPECT_EQ(span.data(), nullptr);
+ }
+}
+
+TEST(WTFSpanCF, Bytes)
+{
+ const uint8_t input[4] = { 1, 2, 3, 4 };
+ auto data = "" input, 4, kCFAllocatorNull));
+
+ {
+ auto span = asBytes(data.get());
+ EXPECT_EQ(span.size(), 4u);
+ EXPECT_EQ(reinterpret_cast<const uint8_t*>(span.data()), input);
+ }
+
+ {
+ auto span = asBytes(data);
+ EXPECT_EQ(span.size(), 4u);
+ EXPECT_EQ(reinterpret_cast<const uint8_t*>(span.data()), input);
+ }
+}
+
+}
Added: trunk/Tools/TestWebKitAPI/Tests/WTF/cocoa/SpanCocoa.mm (0 => 279339)
--- trunk/Tools/TestWebKitAPI/Tests/WTF/cocoa/SpanCocoa.mm (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/cocoa/SpanCocoa.mm 2021-06-28 15:34:32 UTC (rev 279339)
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2021 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/cocoa/SpanCocoa.h>
+
+namespace TestWebKitAPI {
+
+TEST(WTFSpanCocoa, Empty)
+{
+ auto data = "" alloc] init]);
+
+ {
+ auto span = asBytes(data.get());
+ EXPECT_EQ(span.size(), 0u);
+ EXPECT_EQ(span.data(), nullptr);
+ }
+
+ {
+ auto span = asBytes(data);
+ EXPECT_EQ(span.size(), 0u);
+ EXPECT_EQ(span.data(), nullptr);
+ }
+}
+
+TEST(WTFSpanCocoa, Bytes)
+{
+ uint8_t input[4] = { 1, 2, 3, 4 };
+ auto data = "" alloc] initWithBytesNoCopy:input length:4 deallocator:^(void*, NSUInteger) { }]);
+
+ {
+ auto span = asBytes(data.get());
+ EXPECT_EQ(span.size(), 4u);
+ EXPECT_EQ(reinterpret_cast<const uint8_t*>(span.data()), input);
+ }
+
+ {
+ auto span = asBytes(data);
+ EXPECT_EQ(span.size(), 4u);
+ EXPECT_EQ(reinterpret_cast<const uint8_t*>(span.data()), input);
+ }
+}
+
+}