summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordan sinclair <dsinclair@chromium.org>2018-04-13 18:04:56 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-04-13 18:04:56 +0000
commit00e72c1d1787c71e08d42a06cca3a53419e369da (patch)
tree8378cec61796ded909d75dad0b5621ce0568f501
parent27e364389e507f69ee9dc256cd4dbe558d05f887 (diff)
downloadpdfium-00e72c1d1787c71e08d42a06cca3a53419e369da.tar.xz
Add CPDF_Metadata unittests
Add unittests for the CPDF_Metadata class. Change-Id: I1afeb0ab1434a1ebeb4f92bb91032a0f662e750d Reviewed-on: https://pdfium-review.googlesource.com/30630 Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
-rw-r--r--BUILD.gn1
-rw-r--r--core/fpdfdoc/cpdf_metadata_unittest.cpp157
2 files changed, 158 insertions, 0 deletions
diff --git a/BUILD.gn b/BUILD.gn
index 2f74e43bf3..ff9bb08465 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -2871,6 +2871,7 @@ test("pdfium_unittests") {
"core/fpdfdoc/cpdf_dest_unittest.cpp",
"core/fpdfdoc/cpdf_filespec_unittest.cpp",
"core/fpdfdoc/cpdf_formfield_unittest.cpp",
+ "core/fpdfdoc/cpdf_metadata_unittest.cpp",
"core/fpdfdoc/cpdf_nametree_unittest.cpp",
"core/fpdftext/cpdf_linkextract_unittest.cpp",
"core/fxcodec/codec/fx_codec_a85_unittest.cpp",
diff --git a/core/fpdfdoc/cpdf_metadata_unittest.cpp b/core/fpdfdoc/cpdf_metadata_unittest.cpp
new file mode 100644
index 0000000000..6e6d2f63dd
--- /dev/null
+++ b/core/fpdfdoc/cpdf_metadata_unittest.cpp
@@ -0,0 +1,157 @@
+// Copyright 2018 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 "core/fpdfdoc/cpdf_metadata.h"
+
+#include "core/fpdfapi/parser/cpdf_stream.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "testing/test_support.h"
+
+TEST(CPDF_MetadataTest, CheckSharedFormEmailAtTopLevel) {
+ const char* data =
+ "<?xml charset=utf-8?>\n"
+ "<node xmlns:adhocwf=\"http://ns.adobe.com/AcrobatAdhocWorkflow/1.0/\">\n"
+ "<adhocwf:workflowType>0</adhocwf:workflowType>\n"
+ "<adhocwf:version>1.1</adhocwf:version>\n"
+ "</node>";
+
+ CPDF_Stream stream;
+ stream.SetData(reinterpret_cast<const uint8_t*>(data), strlen(data));
+ CPDF_Metadata metadata(&stream);
+
+ auto results = metadata.CheckForSharedForm();
+ ASSERT_EQ(1U, results.size());
+ EXPECT_EQ(UnsupportedFeature::kDocumentSharedFormEmail, results[0]);
+}
+
+TEST(CPDF_MetadataTest, CheckSharedFormAcrobatAtTopLevel) {
+ const char* data =
+ "<?xml charset=utf-8?>\n"
+ "<node xmlns:adhocwf=\"http://ns.adobe.com/AcrobatAdhocWorkflow/1.0/\">\n"
+ "<adhocwf:workflowType>1</adhocwf:workflowType>\n"
+ "<adhocwf:version>1.1</adhocwf:version>\n"
+ "</node>";
+
+ CPDF_Stream stream;
+ stream.SetData(reinterpret_cast<const uint8_t*>(data), strlen(data));
+ CPDF_Metadata metadata(&stream);
+
+ auto results = metadata.CheckForSharedForm();
+ ASSERT_EQ(1U, results.size());
+ EXPECT_EQ(UnsupportedFeature::kDocumentSharedFormAcrobat, results[0]);
+}
+
+TEST(CPDF_MetadataTest, CheckSharedFormFilesystemAtTopLevel) {
+ const char* data =
+ "<?xml charset=utf-8?>\n"
+ "<node xmlns:adhocwf=\"http://ns.adobe.com/AcrobatAdhocWorkflow/1.0/\">\n"
+ "<adhocwf:workflowType>2</adhocwf:workflowType>\n"
+ "<adhocwf:version>1.1</adhocwf:version>\n"
+ "</node>";
+
+ CPDF_Stream stream;
+ stream.SetData(reinterpret_cast<const uint8_t*>(data), strlen(data));
+ CPDF_Metadata metadata(&stream);
+
+ auto results = metadata.CheckForSharedForm();
+ ASSERT_EQ(1U, results.size());
+ EXPECT_EQ(UnsupportedFeature::kDocumentSharedFormFilesystem, results[0]);
+}
+
+TEST(CPDF_MetadataTest, CheckSharedFormWithoutWorkflow) {
+ const char* data =
+ "<?xml charset=utf-8?>\n"
+ "<node xmlns:adhocwf=\"http://ns.adobe.com/AcrobatAdhocWorkflow/1.0/\">\n"
+ "<adhocwf:state>2</adhocwf:state>\n"
+ "<adhocwf:version>1.1</adhocwf:version>\n"
+ "</node>";
+
+ CPDF_Stream stream;
+ stream.SetData(reinterpret_cast<const uint8_t*>(data), strlen(data));
+ CPDF_Metadata metadata(&stream);
+
+ auto results = metadata.CheckForSharedForm();
+ EXPECT_EQ(0U, results.size());
+}
+
+TEST(CPDF_MetadataTest, CheckSharedFormAsChild) {
+ const char* data =
+ "<?xml charset=utf-8?>\n"
+ "<grandparent><parent>\n"
+ "<node xmlns:adhocwf=\"http://ns.adobe.com/AcrobatAdhocWorkflow/1.0/\">\n"
+ "<adhocwf:workflowType>0</adhocwf:workflowType>\n"
+ "<adhocwf:version>1.1</adhocwf:version>\n"
+ "</node>"
+ "</parent></grandparent>";
+
+ CPDF_Stream stream;
+ stream.SetData(reinterpret_cast<const uint8_t*>(data), strlen(data));
+ CPDF_Metadata metadata(&stream);
+
+ auto results = metadata.CheckForSharedForm();
+ ASSERT_EQ(1U, results.size());
+ EXPECT_EQ(UnsupportedFeature::kDocumentSharedFormEmail, results[0]);
+}
+
+TEST(CPDF_MetadataTest, CheckSharedFormAsNoAdhoc) {
+ const char* data =
+ "<?xml charset=utf-8?>\n"
+ "<node></node>";
+
+ CPDF_Stream stream;
+ stream.SetData(reinterpret_cast<const uint8_t*>(data), strlen(data));
+ CPDF_Metadata metadata(&stream);
+
+ auto results = metadata.CheckForSharedForm();
+ EXPECT_EQ(0U, results.size());
+}
+
+TEST(CPDF_MetadataTest, CheckSharedFormWrongNamespace) {
+ const char* data =
+ "<?xml charset=utf-8?>\n"
+ "<node xmlns:adhocwf=\"http://ns.adobe.com/AcrobatAdhocWorkflow/2.0/\">\n"
+ "<adhocwf:workflowType>1</adhocwf:workflowType>\n"
+ "<adhocwf:version>1.1</adhocwf:version>\n"
+ "</node>";
+
+ CPDF_Stream stream;
+ stream.SetData(reinterpret_cast<const uint8_t*>(data), strlen(data));
+ CPDF_Metadata metadata(&stream);
+
+ auto results = metadata.CheckForSharedForm();
+ EXPECT_EQ(0U, results.size());
+}
+
+TEST(CPDF_MetadataTest, CheckSharedFormMultipleErrors) {
+ const char* data =
+ "<?xml charset=utf-8?>\n"
+ "<grandparent>"
+ "<parent>\n"
+ "<node xmlns:adhocwf=\"http://ns.adobe.com/AcrobatAdhocWorkflow/1.0/\">\n"
+ "<adhocwf:workflowType>0</adhocwf:workflowType>\n"
+ "<adhocwf:version>1.1</adhocwf:version>\n"
+ "</node>"
+ "</parent>"
+ "<node2 "
+ "xmlns:adhocwf=\"http://ns.adobe.com/AcrobatAdhocWorkflow/1.0/\">\n"
+ "<adhocwf:workflowType>2</adhocwf:workflowType>\n"
+ "<adhocwf:version>1.1</adhocwf:version>\n"
+ "</node2>"
+ "<node3 "
+ "xmlns:adhocwf=\"http://ns.adobe.com/AcrobatAdhocWorkflow/1.0/\">\n"
+ "<adhocwf:workflowType>1</adhocwf:workflowType>\n"
+ "<adhocwf:version>1.1</adhocwf:version>\n"
+ "</node3>"
+ "</grandparent>";
+
+ CPDF_Stream stream;
+ stream.SetData(reinterpret_cast<const uint8_t*>(data), strlen(data));
+ CPDF_Metadata metadata(&stream);
+
+ auto results = metadata.CheckForSharedForm();
+ ASSERT_EQ(3U, results.size());
+ EXPECT_EQ(UnsupportedFeature::kDocumentSharedFormEmail, results[0]);
+ EXPECT_EQ(UnsupportedFeature::kDocumentSharedFormFilesystem, results[1]);
+ EXPECT_EQ(UnsupportedFeature::kDocumentSharedFormAcrobat, results[2]);
+}