Changeset 255125 in webkit


Ignore:
Timestamp:
Jan 25, 2020, 12:13:34 PM (5 years ago)
Author:
mark.lam@apple.com
Message:

Add some tests for dynamically allocated StaticStringImpls.
https://bugs.webkit.org/show_bug.cgi?id=206802

Reviewed by Darin Adler.

Source/WTF:

Removed some unnecessary explicit specialization of the charactersAreAllASCII()
template function.

  • wtf/text/StringImpl.cpp:

(WTF::StringImpl::createFromLiteral):
(WTF::StringImpl::createStaticStringImpl):

Tools:

  • TestWebKitAPI/Tests/WTF/StringImpl.cpp:

(TestWebKitAPI::doStaticStringImplTests):
(TestWebKitAPI::TEST):

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/Source/WTF/ChangeLog

    r255120 r255125  
     12020-01-25  Mark Lam  <mark.lam@apple.com>
     2
     3        Add some tests for dynamically allocated StaticStringImpls.
     4        https://bugs.webkit.org/show_bug.cgi?id=206802
     5
     6        Reviewed by Darin Adler.
     7
     8        Removed some unnecessary explicit specialization of the charactersAreAllASCII()
     9        template function.
     10
     11        * wtf/text/StringImpl.cpp:
     12        (WTF::StringImpl::createFromLiteral):
     13        (WTF::StringImpl::createStaticStringImpl):
     14
    1152020-01-24  Mark Lam  <mark.lam@apple.com>
    216
  • TabularUnified trunk/Source/WTF/wtf/text/StringImpl.cpp

    r255120 r255125  
    157157{
    158158    ASSERT_WITH_MESSAGE(length, "Use StringImpl::empty() to create an empty string");
    159     ASSERT(charactersAreAllASCII<LChar>(reinterpret_cast<const LChar*>(characters), length));
     159    ASSERT(charactersAreAllASCII(reinterpret_cast<const LChar*>(characters), length));
    160160    return adoptRef(*new StringImpl(reinterpret_cast<const LChar*>(characters), length, ConstructWithoutCopying));
    161161}
     
    285285{
    286286    const LChar* lcharCharacters = reinterpret_cast<const LChar*>(characters);
    287     ASSERT(charactersAreAllASCII<LChar>(lcharCharacters, length));
     287    ASSERT(charactersAreAllASCII(lcharCharacters, length));
    288288    Ref<StringImpl> result = createInternal(lcharCharacters, length);
    289289    result->setHash(StringHasher::computeHashAndMaskTop8Bits(lcharCharacters, length));
  • TabularUnified trunk/Tools/ChangeLog

    r255123 r255125  
     12020-01-25  Mark Lam  <mark.lam@apple.com>
     2
     3        Add some tests for dynamically allocated StaticStringImpls.
     4        https://bugs.webkit.org/show_bug.cgi?id=206802
     5
     6        Reviewed by Darin Adler.
     7
     8        * TestWebKitAPI/Tests/WTF/StringImpl.cpp:
     9        (TestWebKitAPI::doStaticStringImplTests):
     10        (TestWebKitAPI::TEST):
     11
    1122020-01-25  Aakash Jain  <aakash_jain@apple.com>
    213
  • TabularUnified trunk/Tools/TestWebKitAPI/Tests/WTF/StringImpl.cpp

    r246636 r255125  
    11/*
    2  * Copyright (C) 2012, 2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2012-2020 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    687687};
    688688
     689enum class StaticStringImplTestSet {
     690    StaticallyAllocatedImpl,
     691    DynamicallyAllocatedImpl
     692};
     693
     694static void doStaticStringImplTests(StaticStringImplTestSet testSet, String& hello, String& world, String& longer, String& hello2)
     695{
     696    ASSERT_EQ(strlen("hello"), hello.length());
     697    ASSERT_EQ(strlen("world"), world.length());
     698    ASSERT_EQ(strlen("longer"), longer.length());
     699    ASSERT_EQ(strlen("hello"), hello2.length());
     700
     701    ASSERT_TRUE(equal(hello, "hello"));
     702    ASSERT_TRUE(equal(world, "world"));
     703    ASSERT_TRUE(equal(longer, "longer"));
     704    ASSERT_TRUE(equal(hello2, "hello"));
     705
     706    // Each StaticStringImpl* returned by MAKE_STATIC_STRING_IMPL should be unique.
     707    ASSERT_NE(hello.impl(), hello2.impl());
     708
     709    if (testSet == StaticStringImplTestSet::StaticallyAllocatedImpl) {
     710        // Test that MAKE_STATIC_STRING_IMPL isn't allocating a StaticStringImpl on the stack.
     711        const String& str1 = getNeverDestroyedStringAtStackDepth(10);
     712        ASSERT_EQ(strlen("NeverDestroyedString"), str1.length());
     713        ASSERT_TRUE(equal(str1, "NeverDestroyedString"));
     714
     715        const String& str2 = getNeverDestroyedStringAtStackDepth(20);
     716        ASSERT_EQ(strlen("NeverDestroyedString"), str2.length());
     717        ASSERT_TRUE(equal(str2, "NeverDestroyedString"));
     718
     719        ASSERT_TRUE(equal(str1, str2));
     720        ASSERT_EQ(&str1, &str2);
     721        ASSERT_EQ(str1.impl(), str2.impl());
     722    }
     723
     724    // Test that the StaticStringImpl's hash has already been set.
     725    // We're relying on an ASSERT in setHash() to detect that the hash hasn't
     726    // already been set. If the hash has already been set, the hash() method
     727    // will not call setHash().
     728    ASSERT_EQ(hello.hash(), 0xd17551u);
     729}
     730
    689731TEST(WTF, StaticStringImpl)
    690732{
     
    695737    String hello2(MAKE_STATIC_STRING_IMPL("hello"));
    696738
    697     ASSERT_EQ(strlen("hello"), hello.length());
    698     ASSERT_EQ(strlen("world"), world.length());
    699     ASSERT_EQ(strlen("longer"), longer.length());
    700     ASSERT_EQ(strlen("hello"), hello2.length());
    701 
    702     ASSERT_TRUE(equal(hello, "hello"));
    703     ASSERT_TRUE(equal(world, "world"));
    704     ASSERT_TRUE(equal(longer, "longer"));
    705     ASSERT_TRUE(equal(hello2, "hello"));
    706 
    707     // Each StaticStringImpl* returned by MAKE_STATIC_STRING_IMPL should be unique.
    708     ASSERT_NE(hello.impl(), hello2.impl());
    709 
    710     // Test that MAKE_STATIC_STRING_IMPL isn't allocating a StaticStringImpl on the stack.
    711     const String& str1 = getNeverDestroyedStringAtStackDepth(10);
    712     ASSERT_EQ(strlen("NeverDestroyedString"), str1.length());
    713     ASSERT_TRUE(equal(str1, "NeverDestroyedString"));
    714 
    715     const String& str2 = getNeverDestroyedStringAtStackDepth(20);
    716     ASSERT_EQ(strlen("NeverDestroyedString"), str2.length());
    717     ASSERT_TRUE(equal(str2, "NeverDestroyedString"));
    718 
    719     ASSERT_TRUE(equal(str1, str2));
    720     ASSERT_EQ(&str1, &str2);
    721     ASSERT_EQ(str1.impl(), str2.impl());
     739    doStaticStringImplTests(StaticStringImplTestSet::StaticallyAllocatedImpl, hello, world, longer, hello2);
     740}
     741
     742TEST(WTF, DynamicStaticStringImpl)
     743{
     744    // Construct using MAKE_STATIC_STRING_IMPL.
     745    String hello = StringImpl::createStaticStringImpl("hello", 5);
     746    String world = StringImpl::createStaticStringImpl("world", 5);
     747    String longer = StringImpl::createStaticStringImpl("longer", 6);
     748    String hello2 = StringImpl::createStaticStringImpl("hello", 5);
     749
     750    doStaticStringImplTests(StaticStringImplTestSet::DynamicallyAllocatedImpl, hello, world, longer, hello2);
    722751}
    723752
Note: See TracChangeset for help on using the changeset viewer.