// 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) {
static 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) {
static 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) {
static 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) {
static 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) {
static 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) {
static 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) {
static 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) {
static 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]);
}