Home | History | Annotate | Download | only in fxcrt
      1 // Copyright 2015 PDFium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "core/include/fxcrt/fx_bidi.h"
      6 #include "testing/gtest/include/gtest/gtest.h"
      7 
      8 namespace {
      9 
     10 const FX_WCHAR kNeutralChar = 32;
     11 const FX_WCHAR kLeftChar = 65;
     12 const FX_WCHAR kRightChar = 1424;
     13 
     14 }  // namespace
     15 
     16 TEST(fxcrt, BidiCharEmpty) {
     17   int32_t start = -1;
     18   int32_t count = -1;
     19   CFX_BidiChar bidi;
     20   CFX_BidiChar::Direction dir = bidi.GetBidiInfo(nullptr, nullptr);
     21   EXPECT_EQ(CFX_BidiChar::NEUTRAL, dir);
     22 
     23   dir = bidi.GetBidiInfo(&start, nullptr);
     24   EXPECT_EQ(CFX_BidiChar::NEUTRAL, dir);
     25   EXPECT_EQ(0, start);
     26 
     27   dir = bidi.GetBidiInfo(nullptr, &count);
     28   EXPECT_EQ(CFX_BidiChar::NEUTRAL, dir);
     29   EXPECT_EQ(0, count);
     30 
     31   start = -1;
     32   count = -1;
     33   dir = bidi.GetBidiInfo(&start, &count);
     34   EXPECT_EQ(CFX_BidiChar::NEUTRAL, dir);
     35   EXPECT_EQ(0, start);
     36   EXPECT_EQ(0, count);
     37 
     38   EXPECT_FALSE(bidi.EndChar());
     39 }
     40 
     41 TEST(fxcrt, BidiCharLeft) {
     42   int32_t start = -1;
     43   int32_t count = -1;
     44   CFX_BidiChar bidi;
     45 
     46   EXPECT_TRUE(bidi.AppendChar(kLeftChar));
     47   CFX_BidiChar::Direction dir = bidi.GetBidiInfo(&start, &count);
     48   EXPECT_EQ(0, start);
     49   EXPECT_EQ(0, count);
     50 
     51   EXPECT_FALSE(bidi.AppendChar(kLeftChar));
     52   EXPECT_FALSE(bidi.AppendChar(kLeftChar));
     53 
     54   dir = bidi.GetBidiInfo(&start, &count);
     55   EXPECT_EQ(CFX_BidiChar::NEUTRAL, dir);
     56   EXPECT_EQ(0, start);
     57   EXPECT_EQ(0, count);
     58 
     59   EXPECT_TRUE(bidi.EndChar());
     60   dir = bidi.GetBidiInfo(&start, &count);
     61   EXPECT_EQ(CFX_BidiChar::LEFT, dir);
     62   EXPECT_EQ(0, start);
     63   EXPECT_EQ(3, count);
     64 
     65   EXPECT_FALSE(bidi.EndChar());
     66 }
     67 
     68 TEST(fxcrt, BidiCharLeftNeutralRight) {
     69   int32_t start = -1;
     70   int32_t count = -1;
     71   CFX_BidiChar bidi;
     72 
     73   EXPECT_TRUE(bidi.AppendChar(kLeftChar));
     74   CFX_BidiChar::Direction dir = bidi.GetBidiInfo(&start, &count);
     75   EXPECT_EQ(0, start);
     76   EXPECT_EQ(0, count);
     77 
     78   EXPECT_FALSE(bidi.AppendChar(kLeftChar));
     79   EXPECT_FALSE(bidi.AppendChar(kLeftChar));
     80   EXPECT_TRUE(bidi.AppendChar(kNeutralChar));
     81   dir = bidi.GetBidiInfo(&start, &count);
     82   EXPECT_EQ(0, start);
     83   EXPECT_EQ(3, count);
     84 
     85   EXPECT_FALSE(bidi.AppendChar(kNeutralChar));
     86   EXPECT_FALSE(bidi.AppendChar(kNeutralChar));
     87   EXPECT_FALSE(bidi.AppendChar(kNeutralChar));
     88   EXPECT_TRUE(bidi.AppendChar(kRightChar));
     89   dir = bidi.GetBidiInfo(&start, &count);
     90   EXPECT_EQ(CFX_BidiChar::NEUTRAL, dir);
     91   EXPECT_EQ(3, start);
     92   EXPECT_EQ(4, count);
     93 
     94   EXPECT_TRUE(bidi.EndChar());
     95   dir = bidi.GetBidiInfo(&start, &count);
     96   EXPECT_EQ(CFX_BidiChar::RIGHT, dir);
     97   EXPECT_EQ(7, start);
     98   EXPECT_EQ(1, count);
     99 
    100   EXPECT_FALSE(bidi.EndChar());
    101 }
    102 
    103 TEST(fxcrt, BidiCharLeftRightLeft) {
    104   int32_t start = -1;
    105   int32_t count = -1;
    106   CFX_BidiChar bidi;
    107 
    108   EXPECT_TRUE(bidi.AppendChar(kLeftChar));
    109   CFX_BidiChar::Direction dir = bidi.GetBidiInfo(&start, &count);
    110   EXPECT_EQ(0, start);
    111   EXPECT_EQ(0, count);
    112 
    113   EXPECT_FALSE(bidi.AppendChar(kLeftChar));
    114   EXPECT_FALSE(bidi.AppendChar(kLeftChar));
    115   EXPECT_TRUE(bidi.AppendChar(kRightChar));
    116   dir = bidi.GetBidiInfo(&start, &count);
    117   EXPECT_EQ(0, start);
    118   EXPECT_EQ(3, count);
    119 
    120   EXPECT_FALSE(bidi.AppendChar(kRightChar));
    121   EXPECT_FALSE(bidi.AppendChar(kRightChar));
    122   EXPECT_FALSE(bidi.AppendChar(kRightChar));
    123   EXPECT_TRUE(bidi.AppendChar(kLeftChar));
    124   dir = bidi.GetBidiInfo(&start, &count);
    125   EXPECT_EQ(CFX_BidiChar::RIGHT, dir);
    126   EXPECT_EQ(3, start);
    127   EXPECT_EQ(4, count);
    128 
    129   EXPECT_TRUE(bidi.EndChar());
    130   dir = bidi.GetBidiInfo(&start, &count);
    131   EXPECT_EQ(CFX_BidiChar::LEFT, dir);
    132   EXPECT_EQ(7, start);
    133   EXPECT_EQ(1, count);
    134 
    135   EXPECT_FALSE(bidi.EndChar());
    136 }
    137