diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-04-18 13:56:39 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-04-18 18:08:17 +0000 |
commit | 994acdc1a31015674e786d24cc37d08dfae6d863 (patch) | |
tree | cc0fc6e15f4dd439b86e2cb673282613867ce4bb /xfa/fgas/layout/cfx_rtfbreak_unittest.cpp | |
parent | 5ae87922cb96810a05b2262c66b55b7e8f00e46d (diff) | |
download | pdfium-994acdc1a31015674e786d24cc37d08dfae6d863.tar.xz |
Rename text break files to match class names.
This CL renames several fgas/layout files to match the class names
contained in the files.
Change-Id: Ib4feaa902618e577261e51dbac743cb4cb500ea1
Reviewed-on: https://pdfium-review.googlesource.com/4290
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Nicolás Peña <npm@chromium.org>
Diffstat (limited to 'xfa/fgas/layout/cfx_rtfbreak_unittest.cpp')
-rw-r--r-- | xfa/fgas/layout/cfx_rtfbreak_unittest.cpp | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/xfa/fgas/layout/cfx_rtfbreak_unittest.cpp b/xfa/fgas/layout/cfx_rtfbreak_unittest.cpp new file mode 100644 index 0000000000..c8ffc4eb33 --- /dev/null +++ b/xfa/fgas/layout/cfx_rtfbreak_unittest.cpp @@ -0,0 +1,87 @@ +// Copyright 2017 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. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fgas/layout/cfx_rtfbreak.h" + +#include <memory> + +#include "testing/gtest/include/gtest/gtest.h" +#include "testing/test_support.h" +#include "third_party/base/ptr_util.h" +#include "xfa/fgas/font/cfgas_fontmgr.h" +#include "xfa/fgas/font/cfgas_gefont.h" + +class CFX_RTFBreakTest : public testing::Test { + public: + void SetUp() override { + CFX_GEModule::Get()->GetFontMgr()->SetSystemFontInfo( + IFX_SystemFontInfo::CreateDefault(nullptr)); + +#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ + font_mgr_ = CFGAS_FontMgr::Create(FX_GetDefFontEnumerator()); +#else + font_source_ = pdfium::MakeUnique<CFX_FontSourceEnum_File>(); + font_mgr_ = CFGAS_FontMgr::Create(font_source_.get()); +#endif + + font_ = CFGAS_GEFont::LoadFont(L"Arial Black", 0, 0, font_mgr_.get()); + ASSERT(font_.Get() != nullptr); + } + + std::unique_ptr<CFX_RTFBreak> CreateBreak(int32_t args) { + auto b = pdfium::MakeUnique<CFX_RTFBreak>(args); + b->SetFont(font_); + return b; + } + + private: + std::unique_ptr<CFGAS_FontMgr> font_mgr_; + CFX_RetainPtr<CFGAS_GEFont> font_; + +#if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ + std::unique_ptr<CFX_FontSourceEnum_File> font_source_; +#endif +}; + +// As soon as you get one of the control characters the break is complete +// and must be consumed before you get any more characters .... + +TEST_F(CFX_RTFBreakTest, AddChars) { + auto b = CreateBreak(FX_LAYOUTSTYLE_ExpandTab); + + CFX_WideString str(L"Input String."); + for (const auto& c : str) + EXPECT_EQ(CFX_BreakType::None, b->AppendChar(c)); + + EXPECT_EQ(CFX_BreakType::Paragraph, b->AppendChar(L'\n')); + ASSERT_EQ(1, b->CountBreakPieces()); + EXPECT_EQ(str + L"\n", b->GetBreakPieceUnstable(0)->GetString()); + + b->ClearBreakPieces(); + b->Reset(); + EXPECT_EQ(0, b->GetCurrentLineForTesting()->GetLineEnd()); + + str = L"Second str."; + for (const auto& c : str) + EXPECT_EQ(CFX_BreakType::None, b->AppendChar(c)); + + // Force the end of the break at the end of the string. + b->EndBreak(CFX_BreakType::Paragraph); + ASSERT_EQ(1, b->CountBreakPieces()); + EXPECT_EQ(str, b->GetBreakPieceUnstable(0)->GetString()); +} + +TEST_F(CFX_RTFBreakTest, ControlCharacters) { + auto b = CreateBreak(FX_LAYOUTSTYLE_ExpandTab); + EXPECT_EQ(CFX_BreakType::Line, b->AppendChar(L'\v')); + EXPECT_EQ(CFX_BreakType::Page, b->AppendChar(L'\f')); + // 0x2029 is the Paragraph Separator unicode character. + EXPECT_EQ(CFX_BreakType::Paragraph, b->AppendChar(0x2029)); + EXPECT_EQ(CFX_BreakType::Paragraph, b->AppendChar(L'\n')); + + ASSERT_EQ(1, b->CountBreakPieces()); + EXPECT_EQ(L"\v", b->GetBreakPieceUnstable(0)->GetString()); +} |