summaryrefslogtreecommitdiff
path: root/core/src/fxcrt/fx_bidi_unittest.cpp
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2015-08-17 18:00:48 -0700
committerLei Zhang <thestig@chromium.org>2015-08-17 18:00:48 -0700
commit2ae87d2e8ddff79d0e96aad3db97e090db21fb99 (patch)
tree9bbae4e8d6b554a4b4b12fe0cfc5a8a5b54e43b7 /core/src/fxcrt/fx_bidi_unittest.cpp
parent1d9dbd53b205b2b4d9e75a7eeb95e80837917ea3 (diff)
downloadpdfium-2ae87d2e8ddff79d0e96aad3db97e090db21fb99.tar.xz
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 R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1197643002 .
Diffstat (limited to 'core/src/fxcrt/fx_bidi_unittest.cpp')
-rw-r--r--core/src/fxcrt/fx_bidi_unittest.cpp136
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());
+}