Changeset 248903 in webkit


Ignore:
Timestamp:
Aug 20, 2019 10:14:37 AM (5 years ago)
Author:
Darin Adler
Message:

Variadic StringBuilder::append does not handle upconverting from 8-bit to 16-bit correctly
https://bugs.webkit.org/show_bug.cgi?id=200921

Reviewed by Saam Barati.

Source/WTF:

  • wtf/text/StringBuilder.cpp:

(WTF::StringBuilder::appendUninitialized8): Renamed from
appendUninitializedWithoutOverflowCheckForLChar and moved the length overflow
check in here to cut down on unnecessary inlining and code size.
(WTF::StringBuilder::appendUninitialized16): Renamed from
appendUninitializedWithoutOverflowCheckForUChar, moved the length overflow check
in here, and moved the necessary upconversion code from the const UChar* overload of
the appendCharacters function.
(WTF::StringBuilder::appendCharacters): Removed unneeded "length has already overflowed"
check at the start of the function since the code in the function already handles that
case correctly. Refactored the const UChar* overload to use the new appendCharacters16
function so it can share more code with StringBuilder::appendFromAdapters.

  • wtf/text/StringBuilder.h:

(WTF::StringBuilder::appendFromAdapters): Updated the function names for the
two appendUninitialized functions, which now do a bit more than before. Removed the
overflow check since the appendUninitialized8/16 functions now handle that; better to
not make the inlined code larger to handle a failure case.

Tools:

  • TestWebKitAPI/Tests/WTF/StringBuilder.cpp:

Changed tests to use EXPECT macros instead of ASSERT macros since we don't
need to abort after the first failure. Added three new tests to the VariadicAppend
test to cover various cases of upconverting from 8-bit to 16-bit strings.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r248892 r248903  
     12019-08-20  Darin Adler  <darin@apple.com>
     2
     3        Variadic StringBuilder::append does not handle upconverting from 8-bit to 16-bit correctly
     4        https://bugs.webkit.org/show_bug.cgi?id=200921
     5
     6        Reviewed by Saam Barati.
     7
     8        * wtf/text/StringBuilder.cpp:
     9        (WTF::StringBuilder::appendUninitialized8): Renamed from
     10        appendUninitializedWithoutOverflowCheckForLChar and moved the length overflow
     11        check in here to cut down on unnecessary inlining and code size.
     12        (WTF::StringBuilder::appendUninitialized16): Renamed from
     13        appendUninitializedWithoutOverflowCheckForUChar, moved the length overflow check
     14        in here, and moved the necessary upconversion code from the const UChar* overload of
     15        the appendCharacters function.
     16        (WTF::StringBuilder::appendCharacters): Removed unneeded "length has already overflowed"
     17        check at the start of the function since the code in the function already handles that
     18        case correctly. Refactored the const UChar* overload to use the new appendCharacters16
     19        function so it can share more code with StringBuilder::appendFromAdapters.
     20
     21        * wtf/text/StringBuilder.h:
     22        (WTF::StringBuilder::appendFromAdapters): Updated the function names for the
     23        two appendUninitialized functions, which now do a bit more than before. Removed the
     24        overflow check since the appendUninitialized8/16 functions now handle that; better to
     25        not make the inlined code larger to handle a failure case.
     26
    1272019-08-19  Sam Weinig  <weinig@apple.com>
    228
  • trunk/Source/WTF/wtf/text/StringBuilder.cpp

    r248831 r248903  
    11/*
    2  * Copyright (C) 2010-2018 Apple Inc. All rights reserved.
     2 * Copyright (C) 2010-2019 Apple Inc. All rights reserved.
    33 * Copyright (C) 2012 Google Inc. All rights reserved.
    44 *
     
    260260        return getBufferCharacters<CharacterType>() + currentLength;
    261261    }
    262    
     262
    263263    return appendUninitializedSlow<CharacterType>(requiredLength.unsafeGet());
    264264}
    265265
    266 UChar* StringBuilder::appendUninitializedWithoutOverflowCheckForUChar(CheckedInt32 requiredLength)
    267 {
     266LChar* StringBuilder::appendUninitialized8(CheckedInt32 requiredLength)
     267{
     268    if (UNLIKELY(requiredLength.hasOverflowed())) {
     269        didOverflow();
     270        return nullptr;
     271    }
     272    return appendUninitializedWithoutOverflowCheck<LChar>(requiredLength);
     273}
     274
     275UChar* StringBuilder::appendUninitialized16(CheckedInt32 requiredLength)
     276{
     277    if (UNLIKELY(requiredLength.hasOverflowed())) {
     278        didOverflow();
     279        return nullptr;
     280    }
     281    if (m_is8Bit) {
     282        const LChar* characters;
     283        if (m_buffer) {
     284            ASSERT(m_buffer->length() >= m_length.unsafeGet<unsigned>());
     285            characters = m_buffer->characters8();
     286        } else {
     287            ASSERT(m_string.length() == m_length.unsafeGet<unsigned>());
     288            characters = m_string.isNull() ? nullptr : m_string.characters8();
     289        }
     290        allocateBufferUpConvert(characters, expandedCapacity(capacity(), requiredLength.unsafeGet()));
     291        if (UNLIKELY(hasOverflowed()))
     292            return nullptr;
     293        unsigned oldLength = m_length.unsafeGet();
     294        m_length = requiredLength.unsafeGet();
     295        return m_bufferCharacters16 + oldLength;
     296    }
    268297    return appendUninitializedWithoutOverflowCheck<UChar>(requiredLength);
    269 }
    270 
    271 LChar* StringBuilder::appendUninitializedWithoutOverflowCheckForLChar(CheckedInt32 requiredLength)
    272 {
    273     return appendUninitializedWithoutOverflowCheck<LChar>(requiredLength);
    274298}
    275299
     
    302326void StringBuilder::appendCharacters(const UChar* characters, unsigned length)
    303327{
    304     if (!length || hasOverflowed())
     328    if (!length)
    305329        return;
    306330
    307331    ASSERT(characters);
    308332
    309     if (m_is8Bit) {
    310         if (length == 1 && isLatin1(characters[0])) {
    311             append(static_cast<LChar>(characters[0]));
    312             return;
    313         }
    314 
    315         // FIXME: Should we optimize memory by keeping the string 8-bit when all the characters are Latin-1?
    316 
    317         // Calculate the new size of the builder after appending.
    318         CheckedInt32 requiredLength = m_length + length;
    319         if (requiredLength.hasOverflowed())
    320             return didOverflow();
    321        
    322         if (m_buffer) {
    323             // If the buffer is valid it must be at least as long as the current builder contents!
    324             ASSERT(m_buffer->length() >= m_length.unsafeGet<unsigned>());
    325             allocateBufferUpConvert(m_buffer->characters8(), expandedCapacity(capacity(), requiredLength.unsafeGet()));
    326         } else {
    327             ASSERT(m_string.length() == m_length.unsafeGet<unsigned>());
    328             allocateBufferUpConvert(m_string.isNull() ? nullptr : m_string.characters8(), expandedCapacity(capacity(), requiredLength.unsafeGet()));
    329         }
    330         if (UNLIKELY(hasOverflowed()))
    331             return;
    332 
    333         memcpy(m_bufferCharacters16 + m_length.unsafeGet<unsigned>(), characters, static_cast<size_t>(length) * sizeof(UChar));
    334         m_length = requiredLength;
    335     } else {
    336         UChar* dest = appendUninitialized<UChar>(length);
    337         if (!dest)
    338             return;
    339         memcpy(dest, characters, static_cast<size_t>(length) * sizeof(UChar));
    340     }
     333    if (m_is8Bit && length == 1 && isLatin1(characters[0])) {
     334        append(static_cast<LChar>(characters[0]));
     335        return;
     336    }
     337
     338    // FIXME: Should we optimize memory by keeping the string 8-bit when all the characters are Latin-1?
     339
     340    UChar* destination = appendUninitialized16(m_length + length);
     341    if (UNLIKELY(!destination))
     342        return;
     343    std::memcpy(destination, characters, static_cast<size_t>(length) * sizeof(UChar));
    341344    ASSERT(!hasOverflowed());
    342345    ASSERT(m_buffer->length() >= m_length.unsafeGet<unsigned>());
     
    345348void StringBuilder::appendCharacters(const LChar* characters, unsigned length)
    346349{
    347     if (!length || hasOverflowed())
     350    if (!length)
    348351        return;
    349352
  • trunk/Source/WTF/wtf/text/StringBuilder.h

    r248831 r248903  
    11/*
    2  * Copyright (C) 2009-2018 Apple Inc. All rights reserved.
     2 * Copyright (C) 2009-2019 Apple Inc. All rights reserved.
    33 * Copyright (C) 2012 Google Inc. All rights reserved.
    44 *
     
    361361    template<typename CharacterType> ALWAYS_INLINE CharacterType* appendUninitializedWithoutOverflowCheck(CheckedInt32 requiredLength);
    362362    template<typename CharacterType> CharacterType* appendUninitializedSlow(unsigned requiredLength);
    363    
    364     WTF_EXPORT_PRIVATE UChar* appendUninitializedWithoutOverflowCheckForUChar(CheckedInt32 requiredLength);
    365     WTF_EXPORT_PRIVATE LChar* appendUninitializedWithoutOverflowCheckForLChar(CheckedInt32 requiredLength);
    366    
     363    WTF_EXPORT_PRIVATE LChar* appendUninitialized8(CheckedInt32 requiredLength);
     364    WTF_EXPORT_PRIVATE UChar* appendUninitialized16(CheckedInt32 requiredLength);
     365
    367366    template<typename CharacterType> ALWAYS_INLINE CharacterType* getBufferCharacters();
    368367    WTF_EXPORT_PRIVATE void reifyString() const;
     
    402401{
    403402    auto requiredLength = checkedSum<int32_t>(m_length, adapters.length()...);
    404     if (requiredLength.hasOverflowed()) {
    405         didOverflow();
    406         return;
    407     }
    408 
    409403    if (m_is8Bit && are8Bit(adapters...)) {
    410         LChar* dest = appendUninitializedWithoutOverflowCheckForLChar(requiredLength);
    411         if (!dest) {
     404        LChar* destination = appendUninitialized8(requiredLength);
     405        if (!destination) {
    412406            ASSERT(hasOverflowed());
    413407            return;
    414408        }
    415         stringTypeAdapterAccumulator(dest, adapters...);
     409        stringTypeAdapterAccumulator(destination, adapters...);
    416410    } else {
    417         UChar* dest = appendUninitializedWithoutOverflowCheckForUChar(requiredLength);
    418         if (!dest) {
     411        UChar* destination = appendUninitialized16(requiredLength);
     412        if (!destination) {
    419413            ASSERT(hasOverflowed());
    420414            return;
    421415        }
    422         stringTypeAdapterAccumulator(dest, adapters...);
     416        stringTypeAdapterAccumulator(destination, adapters...);
    423417    }
    424418}
  • trunk/Tools/ChangeLog

    r248900 r248903  
     12019-08-20  Darin Adler  <darin@apple.com>
     2
     3        Variadic StringBuilder::append does not handle upconverting from 8-bit to 16-bit correctly
     4        https://bugs.webkit.org/show_bug.cgi?id=200921
     5
     6        Reviewed by Saam Barati.
     7
     8        * TestWebKitAPI/Tests/WTF/StringBuilder.cpp:
     9        Changed tests to use EXPECT macros instead of ASSERT macros since we don't
     10        need to abort after the first failure. Added three new tests to the VariadicAppend
     11        test to cover various cases of upconverting from 8-bit to 16-bit strings.
     12
    1132019-08-20  Dean Jackson  <dino@apple.com>
    214
  • trunk/Tools/TestWebKitAPI/Tests/WTF/StringBuilder.cpp

    r248822 r248903  
    11/*
    22 * Copyright (C) 2011 Google Inc. All rights reserved.
    3  * Copyright (C) 2013 Apple Inc. All rights reserved.
     3 * Copyright (C) 2013-2019 Apple Inc. All rights reserved.
    44 *
    55 * Redistribution and use in source and binary forms, with or without
     
    3333#include "WTFStringUtilities.h"
    3434
     35#include <wtf/unicode/CharacterNames.h>
     36
    3537namespace TestWebKitAPI {
    3638
     
    8688    const LChar* characters = builder2.characters8();
    8789    builder2.append("0123456789");
    88     ASSERT_EQ(characters, builder2.characters8());
     90    EXPECT_EQ(characters, builder2.characters8());
    8991    builder2.toStringPreserveCapacity(); // Test after reifyString with buffer preserved.
    9092    builder2.append("abcd");
    91     ASSERT_EQ(characters, builder2.characters8());
     93    EXPECT_EQ(characters, builder2.characters8());
    9294
    9395    // Test appending UChar32 characters to StringBuilder.
     
    9597    UChar32 frakturAChar = 0x1D504;
    9698    builderForUChar32Append.appendCharacter(frakturAChar); // The fraktur A is not in the BMP, so it's two UTF-16 code units long.
    97     ASSERT_EQ(2U, builderForUChar32Append.length());
     99    EXPECT_EQ(2U, builderForUChar32Append.length());
    98100    builderForUChar32Append.appendCharacter(static_cast<UChar32>('A'));
    99     ASSERT_EQ(3U, builderForUChar32Append.length());
     101    EXPECT_EQ(3U, builderForUChar32Append.length());
    100102    const UChar resultArray[] = { U16_LEAD(frakturAChar), U16_TRAIL(frakturAChar), 'A' };
    101103    expectBuilderContent(String(resultArray, WTF_ARRAY_LENGTH(resultArray)), builderForUChar32Append);
     
    106108        const UChar data[] = { U16_LEAD(frakturAChar), U16_TRAIL(frakturAChar) };
    107109        builder2.appendCharacters(data, 2);
    108         ASSERT_EQ(2U, builder2.length());
     110        EXPECT_EQ(2U, builder2.length());
    109111        String result2 = builder2.toString();
    110         ASSERT_EQ(2U, result2.length());
     112        EXPECT_EQ(2U, result2.length());
    111113        builder.append(builder2);
    112114        builder.appendCharacters(data, 2);
    113         ASSERT_EQ(4U, builder.length());
     115        EXPECT_EQ(4U, builder.length());
    114116        const UChar resultArray[] = { U16_LEAD(frakturAChar), U16_TRAIL(frakturAChar), U16_LEAD(frakturAChar), U16_TRAIL(frakturAChar) };
    115117        expectBuilderContent(String(resultArray, WTF_ARRAY_LENGTH(resultArray)), builder);
     
    138140        expectBuilderContent("0123456789abcdeABC", builder);
    139141    }
     142
     143    {
     144        StringBuilder builder;
     145        builder.append(String("0123456789"), "abcd", bullseye, "");
     146        expectBuilderContent("0123456789abcd" + String(&bullseye, 1), builder);
     147        builder.append(String("A"), "B", 'C', "");
     148        expectBuilderContent("0123456789abcd" + String(&bullseye, 1) + "ABC", builder);
     149    }
     150
     151    {
     152        // Test where we upconvert the StringBuilder from 8-bit to 16-bit, and don't fit in the existing capacity.
     153        StringBuilder builder;
     154        builder.append(String("0123456789"), "abcd", 'e', "");
     155        expectBuilderContent("0123456789abcde", builder);
     156        EXPECT_TRUE(builder.is8Bit());
     157        EXPECT_LT(builder.capacity(), builder.length() + 3);
     158        builder.append(String("A"), "B", bullseye, "");
     159        expectBuilderContent("0123456789abcdeAB" + String(&bullseye, 1), builder);
     160    }
     161
     162    {
     163        // Test where we upconvert the StringBuilder from 8-bit to 16-bit, but would have fit in the capacity if the upconvert wasn't necessary.
     164        StringBuilder builder;
     165        builder.append(String("0123456789"), "abcd", 'e', "");
     166        expectBuilderContent("0123456789abcde", builder);
     167        builder.reserveCapacity(32);
     168        EXPECT_TRUE(builder.is8Bit());
     169        EXPECT_GE(builder.capacity(), builder.length() + 3);
     170        builder.append(String("A"), "B", bullseye, "");
     171        expectBuilderContent("0123456789abcdeAB" + String(&bullseye, 1), builder);
     172    }
    140173}
    141174
     
    145178    builder.append("0123456789");
    146179    String string = builder.toString();
    147     ASSERT_EQ(String("0123456789"), string);
    148     ASSERT_EQ(string.impl(), builder.toString().impl());
     180    EXPECT_EQ(String("0123456789"), string);
     181    EXPECT_EQ(string.impl(), builder.toString().impl());
    149182
    150183    // Changing the StringBuilder should not affect the original result of toString().
    151184    builder.append("abcdefghijklmnopqrstuvwxyz");
    152     ASSERT_EQ(String("0123456789"), string);
     185    EXPECT_EQ(String("0123456789"), string);
    153186
    154187    // Changing the StringBuilder should not affect the original result of toString() in case the capacity is not changed.
    155188    builder.reserveCapacity(200);
    156189    string = builder.toString();
    157     ASSERT_EQ(String("0123456789abcdefghijklmnopqrstuvwxyz"), string);
     190    EXPECT_EQ(String("0123456789abcdefghijklmnopqrstuvwxyz"), string);
    158191    builder.append("ABC");
    159     ASSERT_EQ(String("0123456789abcdefghijklmnopqrstuvwxyz"), string);
     192    EXPECT_EQ(String("0123456789abcdefghijklmnopqrstuvwxyz"), string);
    160193
    161194    // Changing the original result of toString() should not affect the content of the StringBuilder.
    162195    String string1 = builder.toString();
    163     ASSERT_EQ(String("0123456789abcdefghijklmnopqrstuvwxyzABC"), string1);
     196    EXPECT_EQ(String("0123456789abcdefghijklmnopqrstuvwxyzABC"), string1);
    164197    string1.append("DEF");
    165     ASSERT_EQ(String("0123456789abcdefghijklmnopqrstuvwxyzABC"), builder.toString());
    166     ASSERT_EQ(String("0123456789abcdefghijklmnopqrstuvwxyzABCDEF"), string1);
     198    EXPECT_EQ(String("0123456789abcdefghijklmnopqrstuvwxyzABC"), builder.toString());
     199    EXPECT_EQ(String("0123456789abcdefghijklmnopqrstuvwxyzABCDEF"), string1);
    167200
    168201    // Resizing the StringBuilder should not affect the original result of toString().
     
    170203    builder.resize(10);
    171204    builder.append("###");
    172     ASSERT_EQ(String("0123456789abcdefghijklmnopqrstuvwxyzABC"), string1);
     205    EXPECT_EQ(String("0123456789abcdefghijklmnopqrstuvwxyzABC"), string1);
    173206}
    174207
     
    179212    unsigned capacity = builder.capacity();
    180213    String string = builder.toStringPreserveCapacity();
    181     ASSERT_EQ(capacity, builder.capacity());
    182     ASSERT_EQ(String("0123456789"), string);
    183     ASSERT_EQ(string.impl(), builder.toStringPreserveCapacity().impl());
    184     ASSERT_EQ(string.characters8(), builder.characters8());
     214    EXPECT_EQ(capacity, builder.capacity());
     215    EXPECT_EQ(String("0123456789"), string);
     216    EXPECT_EQ(string.impl(), builder.toStringPreserveCapacity().impl());
     217    EXPECT_EQ(string.characters8(), builder.characters8());
    185218
    186219    // Changing the StringBuilder should not affect the original result of toStringPreserveCapacity().
    187220    builder.append("abcdefghijklmnopqrstuvwxyz");
    188     ASSERT_EQ(String("0123456789"), string);
     221    EXPECT_EQ(String("0123456789"), string);
    189222
    190223    // Changing the StringBuilder should not affect the original result of toStringPreserveCapacity() in case the capacity is not changed.
     
    192225    capacity = builder.capacity();
    193226    string = builder.toStringPreserveCapacity();
    194     ASSERT_EQ(capacity, builder.capacity());
    195     ASSERT_EQ(string.characters8(), builder.characters8());
    196     ASSERT_EQ(String("0123456789abcdefghijklmnopqrstuvwxyz"), string);
     227    EXPECT_EQ(capacity, builder.capacity());
     228    EXPECT_EQ(string.characters8(), builder.characters8());
     229    EXPECT_EQ(String("0123456789abcdefghijklmnopqrstuvwxyz"), string);
    197230    builder.append("ABC");
    198     ASSERT_EQ(String("0123456789abcdefghijklmnopqrstuvwxyz"), string);
     231    EXPECT_EQ(String("0123456789abcdefghijklmnopqrstuvwxyz"), string);
    199232
    200233    // Changing the original result of toStringPreserveCapacity() should not affect the content of the StringBuilder.
    201234    capacity = builder.capacity();
    202235    String string1 = builder.toStringPreserveCapacity();
    203     ASSERT_EQ(capacity, builder.capacity());
    204     ASSERT_EQ(string1.characters8(), builder.characters8());
    205     ASSERT_EQ(String("0123456789abcdefghijklmnopqrstuvwxyzABC"), string1);
     236    EXPECT_EQ(capacity, builder.capacity());
     237    EXPECT_EQ(string1.characters8(), builder.characters8());
     238    EXPECT_EQ(String("0123456789abcdefghijklmnopqrstuvwxyzABC"), string1);
    206239    string1.append("DEF");
    207     ASSERT_EQ(String("0123456789abcdefghijklmnopqrstuvwxyzABC"), builder.toStringPreserveCapacity());
    208     ASSERT_EQ(String("0123456789abcdefghijklmnopqrstuvwxyzABCDEF"), string1);
     240    EXPECT_EQ(String("0123456789abcdefghijklmnopqrstuvwxyzABC"), builder.toStringPreserveCapacity());
     241    EXPECT_EQ(String("0123456789abcdefghijklmnopqrstuvwxyzABCDEF"), string1);
    209242
    210243    // Resizing the StringBuilder should not affect the original result of toStringPreserveCapacity().
    211244    capacity = builder.capacity();
    212245    string1 = builder.toStringPreserveCapacity();
    213     ASSERT_EQ(capacity, builder.capacity());
    214     ASSERT_EQ(string.characters8(), builder.characters8());
     246    EXPECT_EQ(capacity, builder.capacity());
     247    EXPECT_EQ(string.characters8(), builder.characters8());
    215248    builder.resize(10);
    216249    builder.append("###");
    217     ASSERT_EQ(String("0123456789abcdefghijklmnopqrstuvwxyzABC"), string1);
     250    EXPECT_EQ(String("0123456789abcdefghijklmnopqrstuvwxyzABC"), string1);
    218251}
    219252
     
    260293    StringBuilder builder1;
    261294    StringBuilder builder2;
    262     ASSERT_TRUE(builder1 == builder2);
    263     ASSERT_TRUE(equal(builder1, static_cast<LChar*>(0), 0));
    264     ASSERT_TRUE(builder1 == String());
    265     ASSERT_TRUE(String() == builder1);
    266     ASSERT_TRUE(builder1 != String("abc"));
     295    EXPECT_TRUE(builder1 == builder2);
     296    EXPECT_TRUE(equal(builder1, static_cast<LChar*>(0), 0));
     297    EXPECT_TRUE(builder1 == String());
     298    EXPECT_TRUE(String() == builder1);
     299    EXPECT_TRUE(builder1 != String("abc"));
    267300
    268301    builder1.append("123");
     
    270303    builder2.append("123");
    271304    builder1.reserveCapacity(64);
    272     ASSERT_TRUE(builder1 == builder2);
    273     ASSERT_TRUE(builder1 == String("123"));
    274     ASSERT_TRUE(String("123") == builder1);
     305    EXPECT_TRUE(builder1 == builder2);
     306    EXPECT_TRUE(builder1 == String("123"));
     307    EXPECT_TRUE(String("123") == builder1);
    275308
    276309    builder2.append("456");
    277     ASSERT_TRUE(builder1 != builder2);
    278     ASSERT_TRUE(builder2 != builder1);
    279     ASSERT_TRUE(String("123") != builder2);
    280     ASSERT_TRUE(builder2 != String("123"));
     310    EXPECT_TRUE(builder1 != builder2);
     311    EXPECT_TRUE(builder2 != builder1);
     312    EXPECT_TRUE(String("123") != builder2);
     313    EXPECT_TRUE(builder2 != String("123"));
    281314    builder2.toString(); // Test after reifyString().
    282     ASSERT_TRUE(builder1 != builder2);
     315    EXPECT_TRUE(builder1 != builder2);
    283316
    284317    builder2.resize(3);
    285     ASSERT_TRUE(builder1 == builder2);
     318    EXPECT_TRUE(builder1 == builder2);
    286319
    287320    builder1.toString(); // Test after reifyString().
    288     ASSERT_TRUE(builder1 == builder2);
     321    EXPECT_TRUE(builder1 == builder2);
    289322}
    290323
     
    293326    StringBuilder builder;
    294327    builder.reserveCapacity(256);
    295     ASSERT_TRUE(builder.canShrink());
     328    EXPECT_TRUE(builder.canShrink());
    296329    for (int i = 0; i < 256; i++)
    297330        builder.append('x');
    298     ASSERT_EQ(builder.length(), builder.capacity());
    299     ASSERT_FALSE(builder.canShrink());
     331    EXPECT_EQ(builder.length(), builder.capacity());
     332    EXPECT_FALSE(builder.canShrink());
    300333}
    301334
     
    305338    builder.append("123");
    306339    AtomString atomString = builder.toAtomString();
    307     ASSERT_EQ(String("123"), atomString);
     340    EXPECT_EQ(String("123"), atomString);
    308341
    309342    builder.reserveCapacity(256);
    310     ASSERT_TRUE(builder.canShrink());
     343    EXPECT_TRUE(builder.canShrink());
    311344    for (int i = builder.length(); i < 128; i++)
    312345        builder.append('x');
    313346    AtomString atomString1 = builder.toAtomString();
    314     ASSERT_EQ(128u, atomString1.length());
    315     ASSERT_EQ('x', atomString1[127]);
     347    EXPECT_EQ(128u, atomString1.length());
     348    EXPECT_EQ('x', atomString1[127]);
    316349
    317350    // Later change of builder should not affect the atomic string.
    318351    for (int i = builder.length(); i < 256; i++)
    319352        builder.append('x');
    320     ASSERT_EQ(128u, atomString1.length());
    321 
    322     ASSERT_FALSE(builder.canShrink());
     353    EXPECT_EQ(128u, atomString1.length());
     354
     355    EXPECT_FALSE(builder.canShrink());
    323356    String string = builder.toString();
    324357    AtomString atomString2 = builder.toAtomString();
    325358    // They should share the same StringImpl.
    326     ASSERT_EQ(atomString2.impl(), string.impl());
     359    EXPECT_EQ(atomString2.impl(), string.impl());
    327360}
    328361
     
    332365        StringBuilder builder;
    333366        AtomString atomString = builder.toAtomString();
    334         ASSERT_EQ(emptyAtom(), atomString);
     367        EXPECT_EQ(emptyAtom(), atomString);
    335368    }
    336369    { // With capacity.
     
    338371        builder.reserveCapacity(64);
    339372        AtomString atomString = builder.toAtomString();
    340         ASSERT_EQ(emptyAtom(), atomString);
     373        EXPECT_EQ(emptyAtom(), atomString);
    341374    }
    342375    { // AtomString constructed from a null string.
     
    344377        builder.append(String());
    345378        AtomString atomString = builder.toAtomString();
    346         ASSERT_EQ(emptyAtom(), atomString);
     379        EXPECT_EQ(emptyAtom(), atomString);
    347380    }
    348381    { // AtomString constructed from an empty string.
     
    350383        builder.append(emptyString());
    351384        AtomString atomString = builder.toAtomString();
    352         ASSERT_EQ(emptyAtom(), atomString);
     385        EXPECT_EQ(emptyAtom(), atomString);
    353386    }
    354387    { // AtomString constructed from an empty StringBuilder.
     
    357390        builder.append(emptyBuilder);
    358391        AtomString atomString = builder.toAtomString();
    359         ASSERT_EQ(emptyAtom(), atomString);
     392        EXPECT_EQ(emptyAtom(), atomString);
    360393    }
    361394    { // AtomString constructed from an empty char* string.
     
    363396        builder.appendCharacters("", 0);
    364397        AtomString atomString = builder.toAtomString();
    365         ASSERT_EQ(emptyAtom(), atomString);
     398        EXPECT_EQ(emptyAtom(), atomString);
    366399    }
    367400    { // Cleared StringBuilder.
     
    370403        builder.clear();
    371404        AtomString atomString = builder.toAtomString();
    372         ASSERT_EQ(emptyAtom(), atomString);
     405        EXPECT_EQ(emptyAtom(), atomString);
    373406    }
    374407}
Note: See TracChangeset for help on using the changeset viewer.