Chromium Code Reviews| Index: third_party/WebKit/Source/core/editing/iterators/ForwardsTextBufferTest.cpp |
| diff --git a/third_party/WebKit/Source/core/editing/iterators/ForwardsTextBufferTest.cpp b/third_party/WebKit/Source/core/editing/iterators/ForwardsTextBufferTest.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..064d7d10465636d9ba25f30158b0186a69b4a5dc |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/core/editing/iterators/ForwardsTextBufferTest.cpp |
| @@ -0,0 +1,89 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "core/editing/iterators/ForwardsTextBuffer.h" |
| + |
| +#include "core/editing/EditingTestBase.h" |
| + |
| +namespace blink { |
| + |
| +class ForwardsTextBufferTest : public EditingTestBase { |
| +}; |
| + |
| +TEST_F(ForwardsTextBufferTest, pushCharacters) |
| +{ |
| + const unsigned numPush = 16; |
|
yosin_UTC9
2016/02/01 03:40:55
This test seems to be complex.
Can we make simpler
Xiaocheng
2016/02/01 04:36:24
I'll see if the tests can be simplified. Maybe I s
|
| + unsigned lengths[numPush]; |
| + UChar chars[numPush]; |
| + for (unsigned i = 0; i < numPush; ++i) { |
| + lengths[i] = 1 << i; |
| + chars[i] = 'a' + i; |
| + } |
| + |
| + ForwardsTextBuffer buffer; |
| + for (unsigned i = 0; i < numPush; ++i) { |
| + buffer.pushCharacters(chars[i], lengths[i]); |
| + unsigned accumulatedLength = 0; |
| + for (unsigned j = 0; j <= i; ++j) { |
| + for (unsigned k = 0; k < lengths[j]; ++k) |
| + EXPECT_EQ(chars[j], buffer[accumulatedLength + k]); |
| + accumulatedLength += lengths[j]; |
| + } |
| + } |
| +} |
| + |
| +TEST_F(ForwardsTextBufferTest, pushRange) |
| +{ |
| + const unsigned numPush = 16; |
| + Vector<UChar> ranges[numPush]; |
| + for (unsigned i = 0; i < numPush; ++i) |
| + ranges[i].fill('a' + i, 1 << i); |
| + |
| + ForwardsTextBuffer buffer; |
| + for (unsigned i = 0; i < numPush; ++i) { |
| + buffer.pushRange(ranges[i].data(), ranges[i].size()); |
| + unsigned accumulatedLength = 0; |
| + for (unsigned j = 0; j <= i; ++j) { |
| + for (unsigned k = 0; k < ranges[j].size(); ++k) |
| + EXPECT_EQ(ranges[j][k], buffer[accumulatedLength + k]); |
| + accumulatedLength += ranges[j].size(); |
| + } |
| + } |
| +} |
| + |
| +TEST_F(ForwardsTextBufferTest, pushMixed) |
| +{ |
| + const unsigned numPush = 16; |
| + unsigned lengths[numPush]; |
| + Vector<UChar> ranges[numPush]; |
| + UChar chars[numPush]; |
| + bool pushRange[numPush]; |
| + for (unsigned i = 0; i < numPush; ++i) { |
| + lengths[i] = 1 << i; |
| + pushRange[i] = (i % 2 == 0); |
| + if (pushRange[i]) |
| + ranges[i].fill('a' + i, lengths[i]); |
| + else |
| + chars[i] = 'a' + i; |
| + } |
| + |
| + ForwardsTextBuffer buffer; |
| + for (unsigned i = 0; i < numPush; ++i) { |
| + if (pushRange[i]) |
| + buffer.pushRange(ranges[i].data(), lengths[i]); |
| + else |
| + buffer.pushCharacters(chars[i], lengths[i]); |
| + unsigned accumulatedLength = 0; |
| + for (unsigned j = 0; j <= i; ++j) { |
| + for (unsigned k = 0; k < lengths[j]; ++k) { |
| + if (pushRange[j]) |
| + EXPECT_EQ(ranges[j][k], buffer[accumulatedLength + k]); |
| + else |
| + EXPECT_EQ(chars[j], buffer[accumulatedLength + k]); |
| + } |
| + accumulatedLength += lengths[j]; |
| + } |
| + } |
| +} |
| +} // namespace blink |