| 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/SymbolsIterator.h" | 5 #include "platform/fonts/SymbolsIterator.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, FontFallbackPriority theFontFallbackPriority) | 22 ExpectedRun(unsigned theLimit, FontFallbackPriority theFontFallbackPriority) |
| 23 : limit(theLimit) | 23 : limit(theLimit) |
| 24 , fontFallbackPriority(theFontFallbackPriority) | 24 , fontFallbackPriority(theFontFallbackPriority) |
| 25 { | 25 { |
| 26 } | 26 } |
| 27 }; | 27 }; |
| 28 | 28 |
| 29 class SymbolsIteratorTest : public testing::Test { | 29 class SymbolsIteratorTest : 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.fontFallbackPriority)); | 37 expect.append(ExpectedRun(text.length(), run.fontFallbackPriority)); |
| 45 } | 38 } |
| 46 SymbolsIterator symbolsIterator(text.characters16(), text.length()); | 39 SymbolsIterator symbolsIterator(text.characters16(), text.length()); |
| 47 VerifyRuns(&symbolsIterator, expect); | 40 VerifyRuns(&symbolsIterator, expect); |
| 48 } | 41 } |
| 49 | 42 |
| 50 void VerifyRuns(SymbolsIterator* symbolsIterator, | 43 void VerifyRuns(SymbolsIterator* symbolsIterator, |
| 51 const Vector<ExpectedRun>& expect) | 44 const Vector<ExpectedRun>& expect) |
| 52 { | 45 { |
| 53 unsigned limit; | 46 unsigned limit; |
| 54 FontFallbackPriority fontFallbackPriority; | 47 FontFallbackPriority fontFallbackPriority; |
| 55 unsigned long runCount = 0; | 48 unsigned long runCount = 0; |
| 56 while (symbolsIterator->consume(&limit, &fontFallbackPriority)) { | 49 while (symbolsIterator->consume(&limit, &fontFallbackPriority)) { |
| 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].fontFallbackPriority, fontFallbackPriorit
y); | 52 ASSERT_EQ(expect[runCount].fontFallbackPriority, fontFallbackPriorit
y); |
| 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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 | 183 |
| 192 TEST_F(SymbolsIteratorTest, Arrows) | 184 TEST_F(SymbolsIteratorTest, Arrows) |
| 193 { | 185 { |
| 194 CHECK_RUNS({ { "x", FontFallbackPriority::Text }, | 186 CHECK_RUNS({ { "x", FontFallbackPriority::Text }, |
| 195 { "→←", FontFallbackPriority::Math }, | 187 { "→←", FontFallbackPriority::Math }, |
| 196 { "x", FontFallbackPriority::Text }, | 188 { "x", FontFallbackPriority::Text }, |
| 197 { "←↑↓→", FontFallbackPriority::Math } }); | 189 { "←↑↓→", FontFallbackPriority::Math } }); |
| 198 } | 190 } |
| 199 | 191 |
| 200 } // namespace blink | 192 } // namespace blink |
| OLD | NEW |