diff options
author | Lei Zhang <thestig@chromium.org> | 2015-10-29 15:01:55 -0700 |
---|---|---|
committer | Lei Zhang <thestig@chromium.org> | 2015-10-29 15:01:55 -0700 |
commit | ee02ea37e8f85920885600d56df706d690e648ff (patch) | |
tree | 055bbc66a5c95a8bc75ccc491f73505bb8eb6676 /core/src/fxcrt/fx_bidi_unittest.cpp | |
parent | 5a88b1131c450dee0500a02f80f0838385e4c4d2 (diff) | |
download | pdfium-ee02ea37e8f85920885600d56df706d690e648ff.tar.xz |
XFA: Manual merge of Clean up IFX_BidiChar
- Replace IFX_BidiChar with just CFX_BidiChar
- Document implementation
- Change out parameters to pointers
- Remove dead code
- Add an enum for bidi directions
- Move several externs to a header
- Add unit tests
Original CL: https://codereview.chromium.org/1197643002
This version does not remove fx_arb.h and fx_arabic.h, as there is code
on the XFA branch that still uses parts of it.
R=tsepez@chromium.org
Review URL: https://codereview.chromium.org/1423103002 .
Diffstat (limited to 'core/src/fxcrt/fx_bidi_unittest.cpp')
-rw-r--r-- | core/src/fxcrt/fx_bidi_unittest.cpp | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/core/src/fxcrt/fx_bidi_unittest.cpp b/core/src/fxcrt/fx_bidi_unittest.cpp new file mode 100644 index 0000000000..c629cbbdc6 --- /dev/null +++ b/core/src/fxcrt/fx_bidi_unittest.cpp @@ -0,0 +1,136 @@ +// Copyright 2015 PDFium 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 "testing/gtest/include/gtest/gtest.h" +#include "../../include/fxcrt/fx_bidi.h" + +namespace { + +const FX_WCHAR kNeutralChar = 32; +const FX_WCHAR kLeftChar = 65; +const FX_WCHAR kRightChar = 1424; + +} // namespace + +TEST(fxcrt, BidiCharEmpty) { + int32_t start = -1; + int32_t count = -1; + CFX_BidiChar bidi; + CFX_BidiChar::Direction dir = bidi.GetBidiInfo(nullptr, nullptr); + EXPECT_EQ(CFX_BidiChar::NEUTRAL, dir); + + dir = bidi.GetBidiInfo(&start, nullptr); + EXPECT_EQ(CFX_BidiChar::NEUTRAL, dir); + EXPECT_EQ(0, start); + + dir = bidi.GetBidiInfo(nullptr, &count); + EXPECT_EQ(CFX_BidiChar::NEUTRAL, dir); + EXPECT_EQ(0, count); + + start = -1; + count = -1; + dir = bidi.GetBidiInfo(&start, &count); + EXPECT_EQ(CFX_BidiChar::NEUTRAL, dir); + EXPECT_EQ(0, start); + EXPECT_EQ(0, count); + + EXPECT_FALSE(bidi.EndChar()); +} + +TEST(fxcrt, BidiCharLeft) { + int32_t start = -1; + int32_t count = -1; + CFX_BidiChar bidi; + + EXPECT_TRUE(bidi.AppendChar(kLeftChar)); + CFX_BidiChar::Direction dir = bidi.GetBidiInfo(&start, &count); + EXPECT_EQ(0, start); + EXPECT_EQ(0, count); + + EXPECT_FALSE(bidi.AppendChar(kLeftChar)); + EXPECT_FALSE(bidi.AppendChar(kLeftChar)); + + dir = bidi.GetBidiInfo(&start, &count); + EXPECT_EQ(CFX_BidiChar::NEUTRAL, dir); + EXPECT_EQ(0, start); + EXPECT_EQ(0, count); + + EXPECT_TRUE(bidi.EndChar()); + dir = bidi.GetBidiInfo(&start, &count); + EXPECT_EQ(CFX_BidiChar::LEFT, dir); + EXPECT_EQ(0, start); + EXPECT_EQ(3, count); + + EXPECT_FALSE(bidi.EndChar()); +} + +TEST(fxcrt, BidiCharLeftNeutralRight) { + int32_t start = -1; + int32_t count = -1; + CFX_BidiChar bidi; + + EXPECT_TRUE(bidi.AppendChar(kLeftChar)); + CFX_BidiChar::Direction dir = bidi.GetBidiInfo(&start, &count); + EXPECT_EQ(0, start); + EXPECT_EQ(0, count); + + EXPECT_FALSE(bidi.AppendChar(kLeftChar)); + EXPECT_FALSE(bidi.AppendChar(kLeftChar)); + EXPECT_TRUE(bidi.AppendChar(kNeutralChar)); + dir = bidi.GetBidiInfo(&start, &count); + EXPECT_EQ(0, start); + EXPECT_EQ(3, count); + + EXPECT_FALSE(bidi.AppendChar(kNeutralChar)); + EXPECT_FALSE(bidi.AppendChar(kNeutralChar)); + EXPECT_FALSE(bidi.AppendChar(kNeutralChar)); + EXPECT_TRUE(bidi.AppendChar(kRightChar)); + dir = bidi.GetBidiInfo(&start, &count); + EXPECT_EQ(CFX_BidiChar::NEUTRAL, dir); + EXPECT_EQ(3, start); + EXPECT_EQ(4, count); + + EXPECT_TRUE(bidi.EndChar()); + dir = bidi.GetBidiInfo(&start, &count); + EXPECT_EQ(CFX_BidiChar::RIGHT, dir); + EXPECT_EQ(7, start); + EXPECT_EQ(1, count); + + EXPECT_FALSE(bidi.EndChar()); +} + +TEST(fxcrt, BidiCharLeftRightLeft) { + int32_t start = -1; + int32_t count = -1; + CFX_BidiChar bidi; + + EXPECT_TRUE(bidi.AppendChar(kLeftChar)); + CFX_BidiChar::Direction dir = bidi.GetBidiInfo(&start, &count); + EXPECT_EQ(0, start); + EXPECT_EQ(0, count); + + EXPECT_FALSE(bidi.AppendChar(kLeftChar)); + EXPECT_FALSE(bidi.AppendChar(kLeftChar)); + EXPECT_TRUE(bidi.AppendChar(kRightChar)); + dir = bidi.GetBidiInfo(&start, &count); + EXPECT_EQ(0, start); + EXPECT_EQ(3, count); + + EXPECT_FALSE(bidi.AppendChar(kRightChar)); + EXPECT_FALSE(bidi.AppendChar(kRightChar)); + EXPECT_FALSE(bidi.AppendChar(kRightChar)); + EXPECT_TRUE(bidi.AppendChar(kLeftChar)); + dir = bidi.GetBidiInfo(&start, &count); + EXPECT_EQ(CFX_BidiChar::RIGHT, dir); + EXPECT_EQ(3, start); + EXPECT_EQ(4, count); + + EXPECT_TRUE(bidi.EndChar()); + dir = bidi.GetBidiInfo(&start, &count); + EXPECT_EQ(CFX_BidiChar::LEFT, dir); + EXPECT_EQ(7, start); + EXPECT_EQ(1, count); + + EXPECT_FALSE(bidi.EndChar()); +} |