| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/fonts/SmallCapsIterator.h" | 5 #include "platform/fonts/SmallCapsIterator.h" |
| 6 | 6 |
| 7 #include "platform/Logging.h" | 7 #include "platform/Logging.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 ExpectedRun(unsigned theLimit, SmallCapsIterator::SmallCapsBehavior theSmall
CapsBehavior) | 22 ExpectedRun(unsigned theLimit, SmallCapsIterator::SmallCapsBehavior theSmall
CapsBehavior) |
| 23 : limit(theLimit) | 23 : limit(theLimit) |
| 24 , smallCapsBehavior(theSmallCapsBehavior) | 24 , smallCapsBehavior(theSmallCapsBehavior) |
| 25 { | 25 { |
| 26 } | 26 } |
| 27 }; | 27 }; |
| 28 | 28 |
| 29 class SmallCapsIteratorTest : public testing::Test { | 29 class SmallCapsIteratorTest : public testing::Test { |
| 30 protected: | 30 protected: |
| 31 #if !LOG_DISABLED | |
| 32 static void SetUpTestCase() | |
| 33 { | |
| 34 LogFonts = { WTFLogChannelOn }; | |
| 35 } | |
| 36 #endif | |
| 37 | |
| 38 void CheckRuns(const Vector<TestRun>& runs) | 31 void CheckRuns(const Vector<TestRun>& runs) |
| 39 { | 32 { |
| 40 String text(emptyString16Bit()); | 33 String text(emptyString16Bit()); |
| 41 Vector<ExpectedRun> expect; | 34 Vector<ExpectedRun> expect; |
| 42 for (auto& run : runs) { | 35 for (auto& run : runs) { |
| 43 text.append(String::fromUTF8(run.text.c_str())); | 36 text.append(String::fromUTF8(run.text.c_str())); |
| 44 expect.append(ExpectedRun(text.length(), run.code)); | 37 expect.append(ExpectedRun(text.length(), run.code)); |
| 45 } | 38 } |
| 46 SmallCapsIterator smallCapsIterator(text.characters16(), text.length()); | 39 SmallCapsIterator smallCapsIterator(text.characters16(), text.length()); |
| 47 VerifyRuns(&smallCapsIterator, expect); | 40 VerifyRuns(&smallCapsIterator, expect); |
| 48 } | 41 } |
| 49 | 42 |
| 50 void VerifyRuns(SmallCapsIterator* smallCapsIterator, | 43 void VerifyRuns(SmallCapsIterator* smallCapsIterator, |
| 51 const Vector<ExpectedRun>& expect) | 44 const Vector<ExpectedRun>& expect) |
| 52 { | 45 { |
| 53 unsigned limit; | 46 unsigned limit; |
| 54 SmallCapsIterator::SmallCapsBehavior smallCapsBehavior; | 47 SmallCapsIterator::SmallCapsBehavior smallCapsBehavior; |
| 55 unsigned long runCount = 0; | 48 unsigned long runCount = 0; |
| 56 while (smallCapsIterator->consume(&limit, &smallCapsBehavior)) { | 49 while (smallCapsIterator->consume(&limit, &smallCapsBehavior)) { |
| 57 ASSERT_LT(runCount, expect.size()); | 50 ASSERT_LT(runCount, expect.size()); |
| 58 ASSERT_EQ(expect[runCount].limit, limit); | 51 ASSERT_EQ(expect[runCount].limit, limit); |
| 59 ASSERT_EQ(expect[runCount].smallCapsBehavior, smallCapsBehavior); | 52 ASSERT_EQ(expect[runCount].smallCapsBehavior, smallCapsBehavior); |
| 60 ++runCount; | 53 ++runCount; |
| 61 } | 54 } |
| 62 WTF_LOG(Fonts, "Expected %zu runs, got %lu ", expect.size(), runCount); | |
| 63 ASSERT_EQ(expect.size(), runCount); | 55 ASSERT_EQ(expect.size(), runCount); |
| 64 } | 56 } |
| 65 }; | 57 }; |
| 66 | 58 |
| 67 // Some of our compilers cannot initialize a vector from an array yet. | 59 // Some of our compilers cannot initialize a vector from an array yet. |
| 68 #define DECLARE_RUNSVECTOR(...) \ | 60 #define DECLARE_RUNSVECTOR(...) \ |
| 69 static const TestRun runsArray[] = __VA_ARGS__; \ | 61 static const TestRun runsArray[] = __VA_ARGS__; \ |
| 70 Vector<TestRun> runs; \ | 62 Vector<TestRun> runs; \ |
| 71 runs.append(runsArray, sizeof(runsArray) / sizeof(*runsArray)); | 63 runs.append(runsArray, sizeof(runsArray) / sizeof(*runsArray)); |
| 72 | 64 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 CHECK_RUNS({ { "աբգդ", SmallCapsIterator::SmallCapsUppercaseNeeded }, | 122 CHECK_RUNS({ { "աբգդ", SmallCapsIterator::SmallCapsUppercaseNeeded }, |
| 131 { "ԵԶԷԸ", SmallCapsIterator::SmallCapsSameCase } }); | 123 { "ԵԶԷԸ", SmallCapsIterator::SmallCapsSameCase } }); |
| 132 } | 124 } |
| 133 | 125 |
| 134 TEST_F(SmallCapsIteratorTest, CombiningCharacterSequence) | 126 TEST_F(SmallCapsIteratorTest, CombiningCharacterSequence) |
| 135 { | 127 { |
| 136 CHECK_RUNS({ { "èü", SmallCapsIterator::SmallCapsUppercaseNeeded } }); | 128 CHECK_RUNS({ { "èü", SmallCapsIterator::SmallCapsUppercaseNeeded } }); |
| 137 } | 129 } |
| 138 | 130 |
| 139 } // namespace blink | 131 } // namespace blink |
| OLD | NEW |