// 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 =
"\n"
"\n"
"0\n"
"1.1\n"
"";
CPDF_Stream stream;
stream.SetData(ByteStringView(data).span());
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 =
"\n"
"\n"
"1\n"
"1.1\n"
"";
CPDF_Stream stream;
stream.SetData(ByteStringView(data).span());
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 =
"\n"
"\n"
"2\n"
"1.1\n"
"";
CPDF_Stream stream;
stream.SetData(ByteStringView(data).span());
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 =
"\n"
"\n"
"2\n"
"1.1\n"
"";
CPDF_Stream stream;
stream.SetData(ByteStringView(data).span());
CPDF_Metadata metadata(&stream);
auto results = metadata.CheckForSharedForm();
EXPECT_EQ(0U, results.size());
}
TEST(CPDF_MetadataTest, CheckSharedFormAsChild) {
const char* data =
"\n"
"\n"
"\n"
"0\n"
"1.1\n"
""
"";
CPDF_Stream stream;
stream.SetData(ByteStringView(data).span());
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 =
"\n"
"";
CPDF_Stream stream;
stream.SetData(ByteStringView(data).span());
CPDF_Metadata metadata(&stream);
auto results = metadata.CheckForSharedForm();
EXPECT_EQ(0U, results.size());
}
TEST(CPDF_MetadataTest, CheckSharedFormWrongNamespace) {
const char* data =
"\n"
"\n"
"1\n"
"1.1\n"
"";
CPDF_Stream stream;
stream.SetData(ByteStringView(data).span());
CPDF_Metadata metadata(&stream);
auto results = metadata.CheckForSharedForm();
EXPECT_EQ(0U, results.size());
}
TEST(CPDF_MetadataTest, CheckSharedFormMultipleErrors) {
const char* data =
"\n"
""
"\n"
"\n"
"0\n"
"1.1\n"
""
""
"\n"
"2\n"
"1.1\n"
""
"\n"
"1\n"
"1.1\n"
""
"";
CPDF_Stream stream;
stream.SetData(ByteStringView(data).span());
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]);
}