summaryrefslogtreecommitdiff
path: root/core/src/fxcrt/fx_bidi_unittest.cpp
diff options
context:
space:
mode:
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());
+}