| 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/OrientationIterator.h" | 5 #include "platform/fonts/OrientationIterator.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, OrientationIterator::RenderOrientation theRen
derOrientation) | 22 ExpectedRun(unsigned theLimit, OrientationIterator::RenderOrientation theRen
derOrientation) |
| 23 : limit(theLimit) | 23 : limit(theLimit) |
| 24 , renderOrientation(theRenderOrientation) | 24 , renderOrientation(theRenderOrientation) |
| 25 { | 25 { |
| 26 } | 26 } |
| 27 }; | 27 }; |
| 28 | 28 |
| 29 class OrientationIteratorTest : public testing::Test { | 29 class OrientationIteratorTest : 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 OrientationIterator orientationIterator(text.characters16(), text.length
(), FontOrientation::VerticalMixed); | 39 OrientationIterator orientationIterator(text.characters16(), text.length
(), FontOrientation::VerticalMixed); |
| 47 VerifyRuns(&orientationIterator, expect); | 40 VerifyRuns(&orientationIterator, expect); |
| 48 } | 41 } |
| 49 | 42 |
| 50 void VerifyRuns(OrientationIterator* orientationIterator, | 43 void VerifyRuns(OrientationIterator* orientationIterator, |
| 51 const Vector<ExpectedRun>& expect) | 44 const Vector<ExpectedRun>& expect) |
| 52 { | 45 { |
| 53 unsigned limit; | 46 unsigned limit; |
| 54 OrientationIterator::RenderOrientation renderOrientation; | 47 OrientationIterator::RenderOrientation renderOrientation; |
| 55 unsigned long runCount = 0; | 48 unsigned long runCount = 0; |
| 56 while (orientationIterator->consume(&limit, &renderOrientation)) { | 49 while (orientationIterator->consume(&limit, &renderOrientation)) { |
| 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].renderOrientation, renderOrientation); | 52 ASSERT_EQ(expect[runCount].renderOrientation, renderOrientation); |
| 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 // TODO(esprehn): WTF::Vector should allow initialization from a literal. | 59 // TODO(esprehn): WTF::Vector should allow initialization from a literal. |
| 68 #define CHECK_RUNS(...) \ | 60 #define CHECK_RUNS(...) \ |
| 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 CheckRuns(runs); | 64 CheckRuns(runs); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 { "ほへと", OrientationIterator::OrientationKeep }, | 167 { "ほへと", OrientationIterator::OrientationKeep }, |
| 176 { "Xyz", OrientationIterator::OrientationRotateSideways } }); | 168 { "Xyz", OrientationIterator::OrientationRotateSideways } }); |
| 177 } | 169 } |
| 178 | 170 |
| 179 TEST_F(OrientationIteratorTest, JapaneseMahjonggMixed) | 171 TEST_F(OrientationIteratorTest, JapaneseMahjonggMixed) |
| 180 { | 172 { |
| 181 CHECK_RUNS({ { "いろはに🀤ほへと", OrientationIterator::OrientationKeep } }); | 173 CHECK_RUNS({ { "いろはに🀤ほへと", OrientationIterator::OrientationKeep } }); |
| 182 } | 174 } |
| 183 | 175 |
| 184 } // namespace blink | 176 } // namespace blink |
| OLD | NEW |