Merge to XFA: Don't call FPDF_InitLibrary() in individual unit_tests.
authorTom Sepez <tsepez@chromium.org>
Fri, 10 Apr 2015 17:40:55 +0000 (10:40 -0700)
committerTom Sepez <tsepez@chromium.org>
Fri, 10 Apr 2015 17:40:55 +0000 (10:40 -0700)
Original Review URL: https://codereview.chromium.org/1071343002
TBR=thestig@chromium.org

Review URL: https://codereview.chromium.org/1079623002

BUILD.gn
core/src/fpdfapi/fpdf_parser/fpdf_parser_decode_embeddertest.cpp [new file with mode: 0644]
core/src/fpdfapi/fpdf_parser/fpdf_parser_decode_unittest.cpp [deleted file]
pdfium.gyp

index 3bbd94c..7f6bcc1 100644 (file)
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -1552,7 +1552,6 @@ static_library("xfa") {
 
 test("pdfium_unittests") {
   sources = [
-    "core/src/fpdfapi/fpdf_parser/fpdf_parser_decode_unittest.cpp",
     "core/src/fxcodec/codec/fx_codec_jpx_unittest.cpp",
     "core/src/fxcrt/fx_basic_bstring_unittest.cpp",
     "core/src/fxcrt/fx_basic_wstring_unittest.cpp",
@@ -1572,6 +1571,7 @@ test("pdfium_unittests") {
 
 test("pdfium_embeddertests") {
   sources = [
+    "core/src/fpdfapi/fpdf_parser/fpdf_parser_decode_embeddertest.cpp",
     "core/src/fpdfapi/fpdf_parser/fpdf_parser_parser_embeddertest.cpp",
     "fpdfsdk/src/fpdf_dataavail_embeddertest.cpp",
     "fpdfsdk/src/fpdfdoc_embeddertest.cpp",
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode_embeddertest.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode_embeddertest.cpp
new file mode 100644 (file)
index 0000000..2769f3c
--- /dev/null
@@ -0,0 +1,98 @@
+// 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 <cstring>
+#include <string>
+
+#include "../../../../fpdfsdk/include/fpdfview.h"
+#include "../../../../testing/fx_string_testhelpers.h"
+#include "../../../include/fpdfapi/fpdf_parser.h"
+#include "../../../include/fxcrt/fx_basic.h"
+#include "../../../testing/embedder_test.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+class FPDFParserDecodeEmbeddertest : public EmbedderTest {
+};
+
+// NOTE: python's zlib.compress() and zlib.decompress() may be useful for
+// external validation of the FlateEncode/FlateDecode test cases.
+
+#define TEST_CASE(input_literal, expected_literal) \
+  { (const unsigned char*)input_literal, sizeof(input_literal) - 1, \
+    (const unsigned char*)expected_literal, sizeof(expected_literal) - 1 }
+
+TEST_F(FPDFParserDecodeEmbeddertest, FlateEncode) {
+  struct FlateEncodeCase {
+    const unsigned char* input;
+    unsigned int input_size;
+    const unsigned char* expected;
+    unsigned int expected_size;
+  } flate_encode_cases[] = {
+    TEST_CASE("", "\x78\x9c\x03\x00\x00\x00\x00\x01"),
+    TEST_CASE(" ", "\x78\x9c\x53\x00\x00\x00\x21\x00\x21"),
+    TEST_CASE("123", "\x78\x9c\x33\x34\x32\x06\x00\01\x2d\x00\x97"),
+    TEST_CASE("\x00\xff", "\x78\x9c\x63\xf8\x0f\x00\x01\x01\x01\x00"),
+    TEST_CASE("1 0 0 -1 29 763 cm\n0 0 555 735 re\nW n\nq\n0 0 555 734.394 re\n"
+              "W n\nq\n0.8009 0 0 0.8009 0 0 cm\n1 1 1 RG 1 1 1 rg\n/G0 gs\n"
+              "0 0 693 917 re\nf\nQ\nQ\n"
+              ,
+              "\x78\x9c\x33\x54\x30\x00\x42\x5d\x43\x05\x23\x4b\x05\x73\x33\x63"
+              "\x85\xe4\x5c\x2e\x90\x80\xa9\xa9\xa9\x82\xb9\xb1\xa9\x42\x51\x2a"
+              "\x57\xb8\x42\x1e\x57\x21\x92\xa0\x89\x9e\xb1\xa5\x09\x92\x84\x9e"
+              "\x85\x81\x81\x25\xd8\x14\x24\x26\xd0\x18\x43\x05\x10\x0c\x72\x57"
+              "\x80\x30\x8a\xd2\xb9\xf4\xdd\x0d\x14\xd2\x8b\xc1\x46\x99\x59\x1a"
+              "\x2b\x58\x1a\x9a\x83\x8c\x49\xe3\x0a\x04\x42\x00\x37\x4c\x1b\x42"
+              ),
+  };
+
+  for (size_t i = 0; i < FX_ArraySize(flate_encode_cases); ++i) {
+    FlateEncodeCase* ptr = &flate_encode_cases[i];
+    unsigned char* result;
+    unsigned int result_size;
+    FlateEncode(ptr->input, ptr->input_size, result, result_size); // Leaks.
+    EXPECT_EQ(std::string((const char*)ptr->expected, ptr->expected_size),
+              std::string((const char*)result, result_size))
+        << " for case " << i;
+  }
+}
+
+TEST_F(FPDFParserDecodeEmbeddertest, FlateDecode) {
+  struct FlateDecodeCase {
+    const unsigned char* input;
+    unsigned int input_size;
+    const unsigned char* expected;
+    unsigned int expected_size;
+  } flate_decode_cases[] = {
+    TEST_CASE("", ""),
+    TEST_CASE("preposterous nonsense", ""),
+    TEST_CASE("\x78\x9c\x03\x00\x00\x00\x00\x01", ""),
+    TEST_CASE("\x78\x9c\x53\x00\x00\x00\x21\x00\x21", " "),
+    TEST_CASE("\x78\x9c\x33\x34\x32\x06\x00\01\x2d\x00\x97", "123"),
+    TEST_CASE("\x78\x9c\x63\xf8\x0f\x00\x01\x01\x01\x00", "\x00\xff"),
+    TEST_CASE("\x78\x9c\x33\x54\x30\x00\x42\x5d\x43\x05\x23\x4b\x05\x73\x33\x63"
+              "\x85\xe4\x5c\x2e\x90\x80\xa9\xa9\xa9\x82\xb9\xb1\xa9\x42\x51\x2a"
+              "\x57\xb8\x42\x1e\x57\x21\x92\xa0\x89\x9e\xb1\xa5\x09\x92\x84\x9e"
+              "\x85\x81\x81\x25\xd8\x14\x24\x26\xd0\x18\x43\x05\x10\x0c\x72\x57"
+              "\x80\x30\x8a\xd2\xb9\xf4\xdd\x0d\x14\xd2\x8b\xc1\x46\x99\x59\x1a"
+              "\x2b\x58\x1a\x9a\x83\x8c\x49\xe3\x0a\x04\x42\x00\x37\x4c\x1b\x42"
+              ,
+              "1 0 0 -1 29 763 cm\n0 0 555 735 re\nW n\nq\n0 0 555 734.394 re\n"
+              "W n\nq\n0.8009 0 0 0.8009 0 0 cm\n1 1 1 RG 1 1 1 rg\n/G0 gs\n"
+              "0 0 693 917 re\nf\nQ\nQ\n"
+              ),
+  };
+
+  for (size_t i = 0; i < FX_ArraySize(flate_decode_cases); ++i) {
+    FlateDecodeCase* ptr = &flate_decode_cases[i];
+    unsigned char* result;
+    unsigned int result_size;
+    FlateDecode(ptr->input, ptr->input_size, result, result_size); // Leaks.
+    EXPECT_EQ(std::string((const char*)ptr->expected, ptr->expected_size),
+              std::string((const char*)result, result_size))
+        << " for case " << i;
+  }
+}
+
+
+#undef TEST_CASE
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode_unittest.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode_unittest.cpp
deleted file mode 100644 (file)
index 18196a1..0000000
+++ /dev/null
@@ -1,98 +0,0 @@
-// 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 <cstring>
-#include <string>
-
-#include "../../../../fpdfsdk/include/fpdfview.h"
-#include "../../../../testing/fx_string_testhelpers.h"
-#include "../../../include/fxcrt/fx_basic.h"
-#include "../../../include/fpdfapi/fpdf_parser.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-// NOTE: python's zlib.compress() and zlib.decompress() may be useful for
-// external validation of the FlateEncode/FlateDecode test cases.
-
-#define TEST_CASE(input_literal, expected_literal) \
-  { (const unsigned char*)input_literal, sizeof(input_literal) - 1, \
-    (const unsigned char*)expected_literal, sizeof(expected_literal) - 1 }
-
-TEST(ParserDecode, FlateEncode) {
-  struct FlateEncodeCase {
-    const unsigned char* input;
-    unsigned int input_size;
-    const unsigned char* expected;
-    unsigned int expected_size;
-  } flate_encode_cases[] = {
-    TEST_CASE("", "\x78\x9c\x03\x00\x00\x00\x00\x01"),
-    TEST_CASE(" ", "\x78\x9c\x53\x00\x00\x00\x21\x00\x21"),
-    TEST_CASE("123", "\x78\x9c\x33\x34\x32\x06\x00\01\x2d\x00\x97"),
-    TEST_CASE("\x00\xff", "\x78\x9c\x63\xf8\x0f\x00\x01\x01\x01\x00"),
-    TEST_CASE("1 0 0 -1 29 763 cm\n0 0 555 735 re\nW n\nq\n0 0 555 734.394 re\n"
-              "W n\nq\n0.8009 0 0 0.8009 0 0 cm\n1 1 1 RG 1 1 1 rg\n/G0 gs\n"
-              "0 0 693 917 re\nf\nQ\nQ\n"
-              ,
-              "\x78\x9c\x33\x54\x30\x00\x42\x5d\x43\x05\x23\x4b\x05\x73\x33\x63"
-              "\x85\xe4\x5c\x2e\x90\x80\xa9\xa9\xa9\x82\xb9\xb1\xa9\x42\x51\x2a"
-              "\x57\xb8\x42\x1e\x57\x21\x92\xa0\x89\x9e\xb1\xa5\x09\x92\x84\x9e"
-              "\x85\x81\x81\x25\xd8\x14\x24\x26\xd0\x18\x43\x05\x10\x0c\x72\x57"
-              "\x80\x30\x8a\xd2\xb9\xf4\xdd\x0d\x14\xd2\x8b\xc1\x46\x99\x59\x1a"
-              "\x2b\x58\x1a\x9a\x83\x8c\x49\xe3\x0a\x04\x42\x00\x37\x4c\x1b\x42"
-              ),
-  };
-
-  FPDF_InitLibrary();
-  for (size_t i = 0; i < FX_ArraySize(flate_encode_cases); ++i) {
-    FlateEncodeCase* ptr = &flate_encode_cases[i];
-    unsigned char* result;
-    unsigned int result_size;
-    FlateEncode(ptr->input, ptr->input_size, result, result_size); // Leaks.
-    EXPECT_EQ(std::string((const char*)ptr->expected, ptr->expected_size),
-              std::string((const char*)result, result_size))
-        << " for case " << i;
-  }
-  FPDF_DestroyLibrary();
-}
-
-TEST(ParserDecode, FlateDecode) {
-  struct FlateDecodeCase {
-    const unsigned char* input;
-    unsigned int input_size;
-    const unsigned char* expected;
-    unsigned int expected_size;
-  } flate_decode_cases[] = {
-    TEST_CASE("", ""),
-    TEST_CASE("preposterous nonsense", ""),
-    TEST_CASE("\x78\x9c\x03\x00\x00\x00\x00\x01", ""),
-    TEST_CASE("\x78\x9c\x53\x00\x00\x00\x21\x00\x21", " "),
-    TEST_CASE("\x78\x9c\x33\x34\x32\x06\x00\01\x2d\x00\x97", "123"),
-    TEST_CASE("\x78\x9c\x63\xf8\x0f\x00\x01\x01\x01\x00", "\x00\xff"),
-    TEST_CASE("\x78\x9c\x33\x54\x30\x00\x42\x5d\x43\x05\x23\x4b\x05\x73\x33\x63"
-              "\x85\xe4\x5c\x2e\x90\x80\xa9\xa9\xa9\x82\xb9\xb1\xa9\x42\x51\x2a"
-              "\x57\xb8\x42\x1e\x57\x21\x92\xa0\x89\x9e\xb1\xa5\x09\x92\x84\x9e"
-              "\x85\x81\x81\x25\xd8\x14\x24\x26\xd0\x18\x43\x05\x10\x0c\x72\x57"
-              "\x80\x30\x8a\xd2\xb9\xf4\xdd\x0d\x14\xd2\x8b\xc1\x46\x99\x59\x1a"
-              "\x2b\x58\x1a\x9a\x83\x8c\x49\xe3\x0a\x04\x42\x00\x37\x4c\x1b\x42"
-              ,
-              "1 0 0 -1 29 763 cm\n0 0 555 735 re\nW n\nq\n0 0 555 734.394 re\n"
-              "W n\nq\n0.8009 0 0 0.8009 0 0 cm\n1 1 1 RG 1 1 1 rg\n/G0 gs\n"
-              "0 0 693 917 re\nf\nQ\nQ\n"
-              ),
-  };
-
-  FPDF_InitLibrary();
-  for (size_t i = 0; i < FX_ArraySize(flate_decode_cases); ++i) {
-    FlateDecodeCase* ptr = &flate_decode_cases[i];
-    unsigned char* result;
-    unsigned int result_size;
-    FlateDecode(ptr->input, ptr->input_size, result, result_size); // Leaks.
-    EXPECT_EQ(std::string((const char*)ptr->expected, ptr->expected_size),
-              std::string((const char*)result, result_size))
-        << " for case " << i;
-  }
-  FPDF_DestroyLibrary();
-}
-
-
-#undef TEST_CASE
index 56d33b5..b84647c 100644 (file)
         '<(DEPTH)'
       ],
       'sources': [
-        'core/src/fpdfapi/fpdf_parser/fpdf_parser_decode_unittest.cpp',
         'core/src/fxcodec/codec/fx_codec_jpx_unittest.cpp',
         'core/src/fxcrt/fx_basic_bstring_unittest.cpp',
         'core/src/fxcrt/fx_basic_wstring_unittest.cpp',
         '<(DEPTH)/v8/include',
       ],
       'sources': [
+        'core/src/fpdfapi/fpdf_parser/fpdf_parser_decode_embeddertest.cpp',
         'core/src/fpdfapi/fpdf_parser/fpdf_parser_parser_embeddertest.cpp',
         'fpdfsdk/src/fpdf_dataavail_embeddertest.cpp',
         'fpdfsdk/src/fpdfdoc_embeddertest.cpp',