diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-09-20 11:17:52 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-09-20 16:10:03 +0000 |
commit | d56fd77ef0b2e2a14ceb127283ac0e7cf7ca090b (patch) | |
tree | 65728013e4f43b8ce2728cbbf8038b8707e08739 /xfa/fde/cfde_texteditengine_unittest.cpp | |
parent | bc48185643b3983fd9620ba2f987ada1478fbdc2 (diff) | |
download | pdfium-d56fd77ef0b2e2a14ceb127283ac0e7cf7ca090b.tar.xz |
Implement CFDE_TextEditEngine::GetIndex* methods.
This CL adds unittests and implementations for the text edit engine
methods to get various indexes based on cursor position.
The |RebuildPieces| method was fixed to correctly keep track of
character position when dealing with BIDI characters.
Change-Id: Ie3c5ee5d63bfd00f6f0cdcb1c6fcfe6e05bba50e
Reviewed-on: https://pdfium-review.googlesource.com/14430
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Diffstat (limited to 'xfa/fde/cfde_texteditengine_unittest.cpp')
-rw-r--r-- | xfa/fde/cfde_texteditengine_unittest.cpp | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/xfa/fde/cfde_texteditengine_unittest.cpp b/xfa/fde/cfde_texteditengine_unittest.cpp index 51940f21a8..b0a27f331c 100644 --- a/xfa/fde/cfde_texteditengine_unittest.cpp +++ b/xfa/fde/cfde_texteditengine_unittest.cpp @@ -571,3 +571,126 @@ TEST_F(CFDE_TextEditEngineTest, BoundsForWordAt) { } } } + +TEST_F(CFDE_TextEditEngineTest, CursorMovement) { + engine()->Clear(); + engine()->Insert(0, L"Hello"); + + EXPECT_EQ(0U, engine()->GetIndexLeft(0)); + EXPECT_EQ(5U, engine()->GetIndexRight(5)); + EXPECT_EQ(2U, engine()->GetIndexUp(2)); + EXPECT_EQ(2U, engine()->GetIndexDown(2)); + EXPECT_EQ(1U, engine()->GetIndexLeft(2)); + EXPECT_EQ(1U, engine()->GetIndexBefore(2)); + EXPECT_EQ(3U, engine()->GetIndexRight(2)); + EXPECT_EQ(0U, engine()->GetIndexAtStartOfLine(2)); + EXPECT_EQ(5U, engine()->GetIndexAtEndOfLine(2)); + + engine()->Clear(); + engine()->Insert(0, L"The book is \"مدخل إلى C++\""); + EXPECT_EQ(2U, engine()->GetIndexBefore(3)); // Before is to left. + EXPECT_EQ(16U, engine()->GetIndexBefore(15)); // Before is to right. + EXPECT_EQ(22U, engine()->GetIndexBefore(23)); // Before is to left. + + engine()->Clear(); + engine()->Insert(0, L"Hello\r\nWorld\r\nTest"); + // Move to end of Hello from start of World. + engine()->SetSelection(engine()->GetIndexBefore(7U), 7); + EXPECT_STREQ(L"\r\nWorld", engine()->GetSelectedText().c_str()); + + // Second letter in Hello from second letter in World. + engine()->SetSelection(engine()->GetIndexUp(8U), 2); + EXPECT_STREQ(L"el", engine()->GetSelectedText().c_str()); + + // Second letter in World from second letter in Test. + engine()->SetSelection(engine()->GetIndexUp(15U), 2); + EXPECT_STREQ(L"or", engine()->GetSelectedText().c_str()); + + // Second letter in World from second letter in Hello. + engine()->SetSelection(engine()->GetIndexDown(1U), 2); + EXPECT_STREQ(L"or", engine()->GetSelectedText().c_str()); + + // Second letter in Test from second letter in World. + engine()->SetSelection(engine()->GetIndexDown(8U), 2); + EXPECT_STREQ(L"es", engine()->GetSelectedText().c_str()); + + size_t start_idx = engine()->GetIndexAtStartOfLine(8U); + size_t end_idx = engine()->GetIndexAtEndOfLine(8U); + engine()->SetSelection(start_idx, end_idx - start_idx); + EXPECT_STREQ(L"World", engine()->GetSelectedText().c_str()); + + // Move past \r\n to before W. + engine()->SetSelection(engine()->GetIndexRight(5U), 5); + EXPECT_STREQ(L"World", engine()->GetSelectedText().c_str()); + + engine()->Clear(); + engine()->Insert(0, L"Short\nAnd a very long line"); + engine()->SetSelection(engine()->GetIndexUp(14U), 11); + EXPECT_STREQ(L"\nAnd a very", engine()->GetSelectedText().c_str()); + + engine()->Clear(); + engine()->Insert(0, L"A Very long line\nShort"); + EXPECT_EQ(engine()->GetLength(), engine()->GetIndexDown(8U)); + + engine()->Clear(); + engine()->Insert(0, L"Hello\rWorld\rTest"); + // Move to end of Hello from start of World. + engine()->SetSelection(engine()->GetIndexBefore(6U), 6); + EXPECT_STREQ(L"\rWorld", engine()->GetSelectedText().c_str()); + + // Second letter in Hello from second letter in World. + engine()->SetSelection(engine()->GetIndexUp(7U), 2); + EXPECT_STREQ(L"el", engine()->GetSelectedText().c_str()); + + // Second letter in World from second letter in Test. + engine()->SetSelection(engine()->GetIndexUp(13U), 2); + EXPECT_STREQ(L"or", engine()->GetSelectedText().c_str()); + + // Second letter in World from second letter in Hello. + engine()->SetSelection(engine()->GetIndexDown(1U), 2); + EXPECT_STREQ(L"or", engine()->GetSelectedText().c_str()); + + // Second letter in Test from second letter in World. + engine()->SetSelection(engine()->GetIndexDown(7U), 2); + EXPECT_STREQ(L"es", engine()->GetSelectedText().c_str()); + + start_idx = engine()->GetIndexAtStartOfLine(7U); + end_idx = engine()->GetIndexAtEndOfLine(7U); + engine()->SetSelection(start_idx, end_idx - start_idx); + EXPECT_STREQ(L"World", engine()->GetSelectedText().c_str()); + + // Move past \r to before W. + engine()->SetSelection(engine()->GetIndexRight(5U), 5); + EXPECT_STREQ(L"World", engine()->GetSelectedText().c_str()); + + engine()->Clear(); + engine()->Insert(0, L"Hello\nWorld\nTest"); + // Move to end of Hello from start of World. + engine()->SetSelection(engine()->GetIndexBefore(6U), 6); + EXPECT_STREQ(L"\nWorld", engine()->GetSelectedText().c_str()); + + // Second letter in Hello from second letter in World. + engine()->SetSelection(engine()->GetIndexUp(7U), 2); + EXPECT_STREQ(L"el", engine()->GetSelectedText().c_str()); + + // Second letter in World from second letter in Test. + engine()->SetSelection(engine()->GetIndexUp(13U), 2); + EXPECT_STREQ(L"or", engine()->GetSelectedText().c_str()); + + // Second letter in World from second letter in Hello. + engine()->SetSelection(engine()->GetIndexDown(1U), 2); + EXPECT_STREQ(L"or", engine()->GetSelectedText().c_str()); + + // Second letter in Test from second letter in World. + engine()->SetSelection(engine()->GetIndexDown(7U), 2); + EXPECT_STREQ(L"es", engine()->GetSelectedText().c_str()); + + start_idx = engine()->GetIndexAtStartOfLine(7U); + end_idx = engine()->GetIndexAtEndOfLine(7U); + engine()->SetSelection(start_idx, end_idx - start_idx); + EXPECT_STREQ(L"World", engine()->GetSelectedText().c_str()); + + // Move past \r to before W. + engine()->SetSelection(engine()->GetIndexRight(5U), 5); + EXPECT_STREQ(L"World", engine()->GetSelectedText().c_str()); +} |