Diff
Modified: trunk/Source/WTF/ChangeLog (124610 => 124611)
--- trunk/Source/WTF/ChangeLog 2012-08-03 14:15:37 UTC (rev 124610)
+++ trunk/Source/WTF/ChangeLog 2012-08-03 14:37:37 UTC (rev 124611)
@@ -1,3 +1,23 @@
+2012-08-03 Benjamin Poulain <[email protected]>
+
+ StringImpl created from literal should be BufferInternal
+ https://bugs.webkit.org/show_bug.cgi?id=92940
+
+ Reviewed by Anders Carlsson.
+
+ The ownership of string created from literal should be BufferInternal so that
+ StringImpl never tries to delete the characters.
+
+ The ownership was accidentaly set to BufferOwned in r123689.
+
+ * wtf/text/StringImpl.cpp:
+ (WTF::StringImpl::createFromLiteral): Update to use the new constructor.
+ * wtf/text/StringImpl.h:
+ (WTF::StringImpl::StringImpl):
+ Add a new constructor making the construction from literal explicit.
+ Add the flag s_hashFlagHasTerminatingNullCharacter since the data has the terminating
+ null character.
+
2012-08-02 Patrick Gansterer <[email protected]>
Move getLocalTime() as static inline function to DateMath
Modified: trunk/Source/WTF/wtf/text/StringImpl.cpp (124610 => 124611)
--- trunk/Source/WTF/wtf/text/StringImpl.cpp 2012-08-03 14:15:37 UTC (rev 124610)
+++ trunk/Source/WTF/wtf/text/StringImpl.cpp 2012-08-03 14:37:37 UTC (rev 124611)
@@ -85,7 +85,7 @@
PassRefPtr<StringImpl> StringImpl::createFromLiteral(const LChar* characters, unsigned length)
{
ASSERT(charactersAreAllASCII<LChar>(characters, length));
- return adoptRef(new StringImpl(characters, length));
+ return adoptRef(new StringImpl(characters, length, ConstructFromLiteral));
}
PassRefPtr<StringImpl> StringImpl::createUninitialized(unsigned length, LChar*& data)
Modified: trunk/Source/WTF/wtf/text/StringImpl.h (124610 => 124611)
--- trunk/Source/WTF/wtf/text/StringImpl.h 2012-08-03 14:15:37 UTC (rev 124610)
+++ trunk/Source/WTF/wtf/text/StringImpl.h 2012-08-03 14:37:37 UTC (rev 124611)
@@ -165,6 +165,19 @@
ASSERT(m_length);
}
+ enum ConstructFromLiteralTag { ConstructFromLiteral };
+ StringImpl(const LChar* characters, unsigned length, ConstructFromLiteralTag)
+ : m_refCount(s_refCountIncrement)
+ , m_length(length)
+ , m_data8(characters)
+ , m_buffer(0)
+ , m_hashAndFlags(s_hashFlag8BitBuffer | BufferInternal | s_hashFlagHasTerminatingNullCharacter)
+ {
+ ASSERT(m_data8);
+ ASSERT(m_length);
+ ASSERT(!characters[length]);
+ }
+
// Create a StringImpl adopting ownership of the provided buffer (BufferOwned)
StringImpl(const UChar* characters, unsigned length)
: m_refCount(s_refCountIncrement)
Modified: trunk/Tools/ChangeLog (124610 => 124611)
--- trunk/Tools/ChangeLog 2012-08-03 14:15:37 UTC (rev 124610)
+++ trunk/Tools/ChangeLog 2012-08-03 14:37:37 UTC (rev 124611)
@@ -1,3 +1,20 @@
+2012-08-03 Benjamin Poulain <[email protected]>
+
+ StringImpl created from literal should be BufferInternal
+ https://bugs.webkit.org/show_bug.cgi?id=92940
+
+ Reviewed by Anders Carlsson.
+
+ Add tests for the contruction of strings from literal.
+
+ * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+ * TestWebKitAPI/Tests/WTF/AtomicString.cpp: Added.
+ (TestWebKitAPI):
+ (TestWebKitAPI::TEST):
+ * TestWebKitAPI/Tests/WTF/StringImpl.cpp: Added.
+ (TestWebKitAPI):
+ (TestWebKitAPI::TEST):
+
2012-08-03 Balazs Kelemen <[email protected]>
[nrwt] fix unit tests after turned pixel testing to be a per test setting
Modified: trunk/Tools/TestWebKitAPI/CMakeLists.txt (124610 => 124611)
--- trunk/Tools/TestWebKitAPI/CMakeLists.txt 2012-08-03 14:15:37 UTC (rev 124610)
+++ trunk/Tools/TestWebKitAPI/CMakeLists.txt 2012-08-03 14:37:37 UTC (rev 124611)
@@ -66,12 +66,14 @@
ADD_EXECUTABLE(test_wtf
${test_main_SOURCES}
${TESTWEBKITAPI_DIR}/TestsController.cpp
+ ${TESTWEBKITAPI_DIR}/Tests/WTF/AtomicString.cpp
${TESTWEBKITAPI_DIR}/Tests/WTF/CheckedArithmeticOperations.cpp
${TESTWEBKITAPI_DIR}/Tests/WTF/Functional.cpp
${TESTWEBKITAPI_DIR}/Tests/WTF/HashMap.cpp
${TESTWEBKITAPI_DIR}/Tests/WTF/MetaAllocator.cpp
${TESTWEBKITAPI_DIR}/Tests/WTF/RedBlackTree.cpp
${TESTWEBKITAPI_DIR}/Tests/WTF/StringBuilder.cpp
+ ${TESTWEBKITAPI_DIR}/Tests/WTF/StringImpl.cpp
${TESTWEBKITAPI_DIR}/Tests/WTF/StringOperators.cpp
${TESTWEBKITAPI_DIR}/Tests/WTF/TemporaryChange.cpp
${TESTWEBKITAPI_DIR}/Tests/WTF/Vector.cpp
Modified: trunk/Tools/TestWebKitAPI/GNUmakefile.am (124610 => 124611)
--- trunk/Tools/TestWebKitAPI/GNUmakefile.am 2012-08-03 14:15:37 UTC (rev 124610)
+++ trunk/Tools/TestWebKitAPI/GNUmakefile.am 2012-08-03 14:37:37 UTC (rev 124611)
@@ -50,12 +50,14 @@
-no-fast-install
Programs_TestWebKitAPI_TestWTF_SOURCES = \
+ Tools/TestWebKitAPI/Tests/WTF/AtomicString.cpp \
Tools/TestWebKitAPI/Tests/WTF/CheckedArithmeticOperations.cpp \
Tools/TestWebKitAPI/Tests/WTF/Functional.cpp \
Tools/TestWebKitAPI/Tests/WTF/HashMap.cpp \
Tools/TestWebKitAPI/Tests/WTF/MediaTime.cpp \
Tools/TestWebKitAPI/Tests/WTF/RedBlackTree.cpp \
Tools/TestWebKitAPI/Tests/WTF/StringBuilder.cpp \
+ Tools/TestWebKitAPI/Tests/WTF/StringImpl.cpp \
Tools/TestWebKitAPI/Tests/WTF/StringOperators.cpp \
Tools/TestWebKitAPI/Tests/WTF/TemporaryChange.cpp \
Tools/TestWebKitAPI/Tests/WTF/VectorBasic.cpp \
Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (124610 => 124611)
--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2012-08-03 14:15:37 UTC (rev 124610)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2012-08-03 14:37:37 UTC (rev 124611)
@@ -25,6 +25,8 @@
26B2DFF915BDE599004F691D /* HashSet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26B2DFF815BDE599004F691D /* HashSet.cpp */; };
26DF5A5E15A29BAA003689C2 /* CancelLoadFromResourceLoadDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 26DF5A5D15A29BAA003689C2 /* CancelLoadFromResourceLoadDelegate.mm */; };
26DF5A6315A2A27E003689C2 /* CancelLoadFromResourceLoadDelegate.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 26DF5A6115A2A22B003689C2 /* CancelLoadFromResourceLoadDelegate.html */; };
+ 26F1B44415CA434F00D1E4BF /* AtomicString.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26F1B44215CA434F00D1E4BF /* AtomicString.cpp */; };
+ 26F1B44515CA434F00D1E4BF /* StringImpl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26F1B44315CA434F00D1E4BF /* StringImpl.cpp */; };
333B9CE21277F23100FEFCE3 /* PreventEmptyUserAgent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 333B9CE11277F23100FEFCE3 /* PreventEmptyUserAgent.cpp */; };
33BE5AF5137B5A6C00705813 /* MouseMoveAfterCrash.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 33BE5AF4137B5A6C00705813 /* MouseMoveAfterCrash.cpp */; };
33BE5AF9137B5AAE00705813 /* MouseMoveAfterCrash_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 33BE5AF8137B5AAE00705813 /* MouseMoveAfterCrash_Bundle.cpp */; };
@@ -156,9 +158,9 @@
C507E8A714C6545B005D6B3B /* InspectorBar.mm in Sources */ = {isa = PBXBuildFile; fileRef = C507E8A614C6545B005D6B3B /* InspectorBar.mm */; };
C540F776152E4DA000A40C8C /* SimplifyMarkup.mm in Sources */ = {isa = PBXBuildFile; fileRef = C540F775152E4DA000A40C8C /* SimplifyMarkup.mm */; };
C540F784152E5A9A00A40C8C /* verboseMarkup.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C540F783152E5A7800A40C8C /* verboseMarkup.html */; };
+ CD5497B415857F0C00B5BC30 /* MediaTime.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD5497B315857F0C00B5BC30 /* MediaTime.cpp */; };
E1220DA0155B25480013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = E1220D9F155B25480013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.mm */; };
E1220DCA155B28AA0013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = E1220DC9155B287D0013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.html */; };
- CD5497B415857F0C00B5BC30 /* MediaTime.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD5497B315857F0C00B5BC30 /* MediaTime.cpp */; };
E490296814E2E3A4002BEDD1 /* TypingStyleCrash.mm in Sources */ = {isa = PBXBuildFile; fileRef = E490296714E2E3A4002BEDD1 /* TypingStyleCrash.mm */; };
F3FC3EE313678B7300126A65 /* libgtest.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F3FC3EE213678B7300126A65 /* libgtest.a */; };
F660AA0D15A5F061003A1243 /* GetInjectedBundleInitializationUserDataCallback.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F660AA0C15A5F061003A1243 /* GetInjectedBundleInitializationUserDataCallback.cpp */; };
@@ -252,6 +254,8 @@
26B2DFF815BDE599004F691D /* HashSet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = HashSet.cpp; path = WTF/HashSet.cpp; sourceTree = "<group>"; };
26DF5A5D15A29BAA003689C2 /* CancelLoadFromResourceLoadDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CancelLoadFromResourceLoadDelegate.mm; sourceTree = "<group>"; };
26DF5A6115A2A22B003689C2 /* CancelLoadFromResourceLoadDelegate.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = CancelLoadFromResourceLoadDelegate.html; sourceTree = "<group>"; };
+ 26F1B44215CA434F00D1E4BF /* AtomicString.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = AtomicString.cpp; path = WTF/AtomicString.cpp; sourceTree = "<group>"; };
+ 26F1B44315CA434F00D1E4BF /* StringImpl.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = StringImpl.cpp; path = WTF/StringImpl.cpp; sourceTree = "<group>"; };
333B9CE11277F23100FEFCE3 /* PreventEmptyUserAgent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PreventEmptyUserAgent.cpp; sourceTree = "<group>"; };
33BE5AF4137B5A6C00705813 /* MouseMoveAfterCrash.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MouseMoveAfterCrash.cpp; sourceTree = "<group>"; };
33BE5AF8137B5AAE00705813 /* MouseMoveAfterCrash_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MouseMoveAfterCrash_Bundle.cpp; sourceTree = "<group>"; };
@@ -399,9 +403,9 @@
C507E8A614C6545B005D6B3B /* InspectorBar.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = InspectorBar.mm; sourceTree = "<group>"; };
C540F775152E4DA000A40C8C /* SimplifyMarkup.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SimplifyMarkup.mm; sourceTree = "<group>"; };
C540F783152E5A7800A40C8C /* verboseMarkup.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = verboseMarkup.html; sourceTree = "<group>"; };
+ CD5497B315857F0C00B5BC30 /* MediaTime.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = MediaTime.cpp; path = WTF/MediaTime.cpp; sourceTree = "<group>"; };
E1220D9F155B25480013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MemoryCacheDisableWithinResourceLoadDelegate.mm; sourceTree = "<group>"; };
E1220DC9155B287D0013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = MemoryCacheDisableWithinResourceLoadDelegate.html; sourceTree = "<group>"; };
- CD5497B315857F0C00B5BC30 /* MediaTime.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = MediaTime.cpp; path = WTF/MediaTime.cpp; sourceTree = "<group>"; };
E490296714E2E3A4002BEDD1 /* TypingStyleCrash.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = TypingStyleCrash.mm; sourceTree = "<group>"; };
F3FC3EE213678B7300126A65 /* libgtest.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libgtest.a; sourceTree = BUILT_PRODUCTS_DIR; };
F660AA0C15A5F061003A1243 /* GetInjectedBundleInitializationUserDataCallback.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GetInjectedBundleInitializationUserDataCallback.cpp; sourceTree = "<group>"; };
@@ -621,6 +625,7 @@
children = (
BC029B1A1486B23800817DA9 /* ns */,
C0991C4F143C7D68007998F2 /* cf */,
+ 26F1B44215CA434F00D1E4BF /* AtomicString.cpp */,
CD5497B315857F0C00B5BC30 /* MediaTime.cpp */,
0FC6C4CE141034AD005B7F0C /* MetaAllocator.cpp */,
0FC6C4CB141027E0005B7F0C /* RedBlackTree.cpp */,
@@ -629,6 +634,7 @@
0BCD833414857CE400EA2003 /* HashMap.cpp */,
26B2DFF815BDE599004F691D /* HashSet.cpp */,
81B50192140F232300D9EB58 /* StringBuilder.cpp */,
+ 26F1B44315CA434F00D1E4BF /* StringImpl.cpp */,
C01363C713C3997300EF3964 /* StringOperators.cpp */,
0BCD85691485C98B00EA2003 /* TemporaryChange.cpp */,
BC55F5F814AD78EE00484BE1 /* Vector.cpp */,
@@ -861,6 +867,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
+ 26F1B44415CA434F00D1E4BF /* AtomicString.cpp in Sources */,
BC131885117114B600B69727 /* PlatformUtilitiesMac.mm in Sources */,
BC131A9B1171316900B69727 /* main.mm in Sources */,
BC131AA9117131FC00B69727 /* TestsController.cpp in Sources */,
@@ -901,6 +908,7 @@
C085880013FEC3A6001EF4E5 /* InstanceMethodSwizzler.mm in Sources */,
37DC678D140D7C5000ABCCDB /* DOMRangeOfString.mm in Sources */,
81B50193140F232300D9EB58 /* StringBuilder.cpp in Sources */,
+ 26F1B44515CA434F00D1E4BF /* StringImpl.cpp in Sources */,
0FC6C4CC141027E0005B7F0C /* RedBlackTree.cpp in Sources */,
0FC6C4CF141034AD005B7F0C /* MetaAllocator.cpp in Sources */,
A7A966DB140ECCC8005EF9B4 /* CheckedArithmeticOperations.cpp in Sources */,
Added: trunk/Tools/TestWebKitAPI/Tests/WTF/AtomicString.cpp (0 => 124611)
--- trunk/Tools/TestWebKitAPI/Tests/WTF/AtomicString.cpp (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/AtomicString.cpp 2012-08-03 14:37:37 UTC (rev 124611)
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2012 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/text/AtomicString.h>
+
+namespace TestWebKitAPI {
+
+TEST(WTF, AtomicStringCreationFromLiteral)
+{
+ AtomicString stringWithTemplate("Template Literal", AtomicString::ConstructFromLiteral);
+ ASSERT_EQ(strlen("Template Literal"), stringWithTemplate.length());
+ ASSERT_TRUE(stringWithTemplate == "Template Literal");
+ ASSERT_TRUE(stringWithTemplate.string().is8Bit());
+ ASSERT_TRUE(stringWithTemplate.impl()->hasTerminatingNullCharacter());
+
+ const char* programmaticStringData = "Explicit Size Literal";
+ AtomicString programmaticString(programmaticStringData, strlen(programmaticStringData), AtomicString::ConstructFromLiteral);
+ ASSERT_EQ(strlen(programmaticStringData), programmaticString.length());
+ ASSERT_TRUE(programmaticStringData == programmaticStringData);
+ ASSERT_TRUE(programmaticString.string().is8Bit());
+ ASSERT_TRUE(programmaticString.impl()->hasTerminatingNullCharacter());
+ ASSERT_EQ(programmaticStringData, reinterpret_cast<const char*>(programmaticString.string().characters8()));
+}
+
+TEST(WTF, AtomicStringCreationFromLiteralUniqueness)
+{
+ AtomicString string1("Template Literal", AtomicString::ConstructFromLiteral);
+ AtomicString string2("Template Literal", AtomicString::ConstructFromLiteral);
+ ASSERT_EQ(string1.impl(), string2.impl());
+
+ AtomicString string3("Template Literal");
+ ASSERT_EQ(string1.impl(), string3.impl());
+}
+
+} // namespace TestWebKitAPI
Added: trunk/Tools/TestWebKitAPI/Tests/WTF/StringImpl.cpp (0 => 124611)
--- trunk/Tools/TestWebKitAPI/Tests/WTF/StringImpl.cpp (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/StringImpl.cpp 2012-08-03 14:37:37 UTC (rev 124611)
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2012 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/text/StringImpl.h>
+
+namespace TestWebKitAPI {
+
+TEST(WTF, StringImplCreationFromLiteral)
+{
+ RefPtr<StringImpl> stringWithTemplate = StringImpl::createFromLiteral("Template Literal");
+ ASSERT_EQ(strlen("Template Literal"), stringWithTemplate->length());
+ ASSERT_TRUE(equal(stringWithTemplate.get(), "Template Literal"));
+ ASSERT_TRUE(stringWithTemplate->is8Bit());
+ ASSERT_TRUE(stringWithTemplate->hasTerminatingNullCharacter());
+
+ const char* programmaticStringData = "Explicit Size Literal";
+ RefPtr<StringImpl> programmaticString = StringImpl::createFromLiteral(reinterpret_cast<const LChar*>(programmaticStringData), strlen(programmaticStringData));
+ ASSERT_EQ(strlen(programmaticStringData), programmaticString->length());
+ ASSERT_TRUE(equal(programmaticString.get(), programmaticStringData));
+ ASSERT_EQ(programmaticStringData, reinterpret_cast<const char*>(programmaticString->characters8()));
+ ASSERT_TRUE(programmaticString->is8Bit());
+ ASSERT_TRUE(programmaticString->hasTerminatingNullCharacter());
+}
+
+TEST(WTF, StringImplFromLiteralLoop16BitConversion)
+{
+ RefPtr<StringImpl> controlString = StringImpl::create("Template Literal");
+ for (size_t i = 0; i < 10; ++i) {
+ RefPtr<StringImpl> string = StringImpl::createFromLiteral("Template Literal");
+
+ ASSERT_EQ(0, memcmp(controlString->characters(), string->characters(), controlString->length() * sizeof(UChar)));
+ ASSERT_TRUE(string->has16BitShadow());
+ }
+}
+
+} // namespace TestWebKitAPI