From 2b797295d6851b3189bcb38c5994074f36453865 Mon Sep 17 00:00:00 2001 From: Chris Palmer Date: Thu, 6 Apr 2017 14:45:39 -0700 Subject: Fix unit tests to initialize PartitionAlloc. Tests need to be subclasses of FPDF_Test. BUG=pdfium:700 Change-Id: I317ec2c49567e58cb57c6222e387574226f594b3 Reviewed-on: https://pdfium-review.googlesource.com/3890 Reviewed-by: Tom Sepez Commit-Queue: Chris Palmer --- xfa/fxfa/cxfa_ffapp_unitest.cpp | 87 ----------------------- xfa/fxfa/cxfa_ffapp_unittest.cpp | 90 ++++++++++++++++++++++++ xfa/fxfa/fm2js/xfa_simpleexpression_unittest.cpp | 5 +- xfa/fxfa/parser/xfa_utils_unittest.cpp | 7 +- 4 files changed, 99 insertions(+), 90 deletions(-) delete mode 100644 xfa/fxfa/cxfa_ffapp_unitest.cpp create mode 100644 xfa/fxfa/cxfa_ffapp_unittest.cpp (limited to 'xfa/fxfa') diff --git a/xfa/fxfa/cxfa_ffapp_unitest.cpp b/xfa/fxfa/cxfa_ffapp_unitest.cpp deleted file mode 100644 index e8accdfeb2..0000000000 --- a/xfa/fxfa/cxfa_ffapp_unitest.cpp +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright 2016 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 "xfa/fxfa/cxfa_ffapp.h" - -#include -#include - -#include "core/fpdfapi/parser/cpdf_dictionary.h" -#include "core/fpdfapi/parser/cpdf_stream.h" -#include "core/fxcrt/fx_memory.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "third_party/base/ptr_util.h" - -TEST(CXFAFileRead, NoStreams) { - std::vector streams; - CFX_RetainPtr fileread = - MakeSeekableReadStream(streams); - - uint8_t output_buffer[16]; - memset(output_buffer, 0xbd, sizeof(output_buffer)); - EXPECT_FALSE(fileread->ReadBlock(output_buffer, 0, 0)); - EXPECT_EQ(0xbd, output_buffer[0]); -} - -TEST(CXFAFileRead, EmptyStreams) { - std::vector streams; - auto stream1 = pdfium::MakeUnique(); - streams.push_back(stream1.get()); - CFX_RetainPtr fileread = - MakeSeekableReadStream(streams); - - uint8_t output_buffer[16]; - memset(output_buffer, 0xbd, sizeof(output_buffer)); - EXPECT_FALSE(fileread->ReadBlock(output_buffer, 0, 0)); - EXPECT_EQ(0xbd, output_buffer[0]); -} - -TEST(CXFAFileRead, NormalStreams) { - std::vector streams; - auto stream1 = pdfium::MakeUnique(); - auto stream2 = pdfium::MakeUnique(); - auto stream3 = pdfium::MakeUnique(); - - // 16 chars total. - stream1->InitStream(reinterpret_cast("one t"), 5, - pdfium::MakeUnique()); - stream2->InitStream(reinterpret_cast("wo "), 3, - pdfium::MakeUnique()); - stream3->InitStream(reinterpret_cast("three!!!"), 8, - pdfium::MakeUnique()); - - streams.push_back(stream1.get()); - streams.push_back(stream2.get()); - streams.push_back(stream3.get()); - CFX_RetainPtr fileread = - MakeSeekableReadStream(streams); - - uint8_t output_buffer[16]; - memset(output_buffer, 0xbd, sizeof(output_buffer)); - EXPECT_TRUE(fileread->ReadBlock(output_buffer, 0, 0)); - EXPECT_EQ(0xbd, output_buffer[0]); - - memset(output_buffer, 0xbd, sizeof(output_buffer)); - EXPECT_TRUE(fileread->ReadBlock(output_buffer, 1, 0)); - EXPECT_EQ(0xbd, output_buffer[0]); - - memset(output_buffer, 0xbd, sizeof(output_buffer)); - EXPECT_TRUE(fileread->ReadBlock(output_buffer, 0, 1)); - EXPECT_EQ(0, memcmp(output_buffer, "o", 1)); - EXPECT_EQ(0xbd, output_buffer[1]); - - memset(output_buffer, 0xbd, sizeof(output_buffer)); - EXPECT_TRUE(fileread->ReadBlock(output_buffer, 0, sizeof(output_buffer))); - EXPECT_EQ(0, memcmp(output_buffer, "one two three!!!", 16)); - - memset(output_buffer, 0xbd, sizeof(output_buffer)); - EXPECT_TRUE(fileread->ReadBlock(output_buffer, 2, 10)); - EXPECT_EQ(0, memcmp(output_buffer, "e two thre", 10)); - EXPECT_EQ(0xbd, output_buffer[11]); - - memset(output_buffer, 0xbd, sizeof(output_buffer)); - EXPECT_FALSE(fileread->ReadBlock(output_buffer, 1, sizeof(output_buffer))); - EXPECT_EQ(0, memcmp(output_buffer, "ne two three!!!", 15)); - EXPECT_EQ(0xbd, output_buffer[15]); -} diff --git a/xfa/fxfa/cxfa_ffapp_unittest.cpp b/xfa/fxfa/cxfa_ffapp_unittest.cpp new file mode 100644 index 0000000000..4d65ccbb2f --- /dev/null +++ b/xfa/fxfa/cxfa_ffapp_unittest.cpp @@ -0,0 +1,90 @@ +// Copyright 2016 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 "xfa/fxfa/cxfa_ffapp.h" + +#include +#include + +#include "core/fpdfapi/parser/cpdf_dictionary.h" +#include "core/fpdfapi/parser/cpdf_stream.h" +#include "core/fxcrt/fx_memory.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "testing/test_support.h" +#include "third_party/base/ptr_util.h" + +class CXFAFileReadTest : public pdfium::FPDF_Test {}; + +TEST_F(CXFAFileReadTest, NoStreams) { + std::vector streams; + CFX_RetainPtr fileread = + MakeSeekableReadStream(streams); + + uint8_t output_buffer[16]; + memset(output_buffer, 0xbd, sizeof(output_buffer)); + EXPECT_FALSE(fileread->ReadBlock(output_buffer, 0, 0)); + EXPECT_EQ(0xbd, output_buffer[0]); +} + +TEST_F(CXFAFileReadTest, EmptyStreams) { + std::vector streams; + auto stream1 = pdfium::MakeUnique(); + streams.push_back(stream1.get()); + CFX_RetainPtr fileread = + MakeSeekableReadStream(streams); + + uint8_t output_buffer[16]; + memset(output_buffer, 0xbd, sizeof(output_buffer)); + EXPECT_FALSE(fileread->ReadBlock(output_buffer, 0, 0)); + EXPECT_EQ(0xbd, output_buffer[0]); +} + +TEST_F(CXFAFileReadTest, NormalStreams) { + std::vector streams; + auto stream1 = pdfium::MakeUnique(); + auto stream2 = pdfium::MakeUnique(); + auto stream3 = pdfium::MakeUnique(); + + // 16 chars total. + stream1->InitStream(reinterpret_cast("one t"), 5, + pdfium::MakeUnique()); + stream2->InitStream(reinterpret_cast("wo "), 3, + pdfium::MakeUnique()); + stream3->InitStream(reinterpret_cast("three!!!"), 8, + pdfium::MakeUnique()); + + streams.push_back(stream1.get()); + streams.push_back(stream2.get()); + streams.push_back(stream3.get()); + CFX_RetainPtr fileread = + MakeSeekableReadStream(streams); + + uint8_t output_buffer[16]; + memset(output_buffer, 0xbd, sizeof(output_buffer)); + EXPECT_TRUE(fileread->ReadBlock(output_buffer, 0, 0)); + EXPECT_EQ(0xbd, output_buffer[0]); + + memset(output_buffer, 0xbd, sizeof(output_buffer)); + EXPECT_TRUE(fileread->ReadBlock(output_buffer, 1, 0)); + EXPECT_EQ(0xbd, output_buffer[0]); + + memset(output_buffer, 0xbd, sizeof(output_buffer)); + EXPECT_TRUE(fileread->ReadBlock(output_buffer, 0, 1)); + EXPECT_EQ(0, memcmp(output_buffer, "o", 1)); + EXPECT_EQ(0xbd, output_buffer[1]); + + memset(output_buffer, 0xbd, sizeof(output_buffer)); + EXPECT_TRUE(fileread->ReadBlock(output_buffer, 0, sizeof(output_buffer))); + EXPECT_EQ(0, memcmp(output_buffer, "one two three!!!", 16)); + + memset(output_buffer, 0xbd, sizeof(output_buffer)); + EXPECT_TRUE(fileread->ReadBlock(output_buffer, 2, 10)); + EXPECT_EQ(0, memcmp(output_buffer, "e two thre", 10)); + EXPECT_EQ(0xbd, output_buffer[11]); + + memset(output_buffer, 0xbd, sizeof(output_buffer)); + EXPECT_FALSE(fileread->ReadBlock(output_buffer, 1, sizeof(output_buffer))); + EXPECT_EQ(0, memcmp(output_buffer, "ne two three!!!", 15)); + EXPECT_EQ(0xbd, output_buffer[15]); +} diff --git a/xfa/fxfa/fm2js/xfa_simpleexpression_unittest.cpp b/xfa/fxfa/fm2js/xfa_simpleexpression_unittest.cpp index 7826d9b53c..a2c7f1b878 100644 --- a/xfa/fxfa/fm2js/xfa_simpleexpression_unittest.cpp +++ b/xfa/fxfa/fm2js/xfa_simpleexpression_unittest.cpp @@ -8,10 +8,13 @@ #include #include "testing/gtest/include/gtest/gtest.h" +#include "testing/test_support.h" #include "third_party/base/ptr_util.h" #include "xfa/fxfa/fm2js/xfa_lexer.h" -TEST(FMCallExpression, more_than_32_arguments) { +class FMCallExpressionTest : public pdfium::FPDF_Test {}; + +TEST_F(FMCallExpressionTest, more_than_32_arguments) { // Use sign as it has 3 object parameters at positions 0, 5, and 6. auto exp = pdfium::MakeUnique(0, L"sign"); diff --git a/xfa/fxfa/parser/xfa_utils_unittest.cpp b/xfa/fxfa/parser/xfa_utils_unittest.cpp index c39ed69306..e4dd09419e 100644 --- a/xfa/fxfa/parser/xfa_utils_unittest.cpp +++ b/xfa/fxfa/parser/xfa_utils_unittest.cpp @@ -8,9 +8,12 @@ #include #include "testing/gtest/include/gtest/gtest.h" +#include "testing/test_support.h" #include "third_party/base/ptr_util.h" -TEST(XfaUtilsImp, XFA_MapRotation) { +class XfaUtilsImpTest : public pdfium::FPDF_Test {}; + +TEST_F(XfaUtilsImpTest, XFA_MapRotation) { struct TestCase { int input; int expected_output; @@ -26,7 +29,7 @@ TEST(XfaUtilsImp, XFA_MapRotation) { } } -class XFANodeIteratorTest : public testing::Test { +class XFANodeIteratorTest : public pdfium::FPDF_Test { public: class Node { public: -- cgit v1.2.3