diff options
author | dan sinclair <dsinclair@chromium.org> | 2018-04-13 18:04:56 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-04-13 18:04:56 +0000 |
commit | 00e72c1d1787c71e08d42a06cca3a53419e369da (patch) | |
tree | 8378cec61796ded909d75dad0b5621ce0568f501 /core/fpdfdoc/cpdf_metadata_unittest.cpp | |
parent | 27e364389e507f69ee9dc256cd4dbe558d05f887 (diff) | |
download | pdfium-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>
Diffstat (limited to 'core/fpdfdoc/cpdf_metadata_unittest.cpp')
-rw-r--r-- | core/fpdfdoc/cpdf_metadata_unittest.cpp | 157 |
1 files changed, 157 insertions, 0 deletions
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]); +} |