summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdf_structtree_embeddertest.cpp
diff options
context:
space:
mode:
authorthestig <thestig@chromium.org>2016-11-23 14:10:06 -0800
committerCommit bot <commit-bot@chromium.org>2016-11-23 14:10:06 -0800
commit9067fd683ebf8d6467f8cc5aa7daf5e1f950f846 (patch)
treec967cfe1c94ca9049896d3c3b54d81594c2e9a9f /fpdfsdk/fpdf_structtree_embeddertest.cpp
parent841a85b19cc10d719505ea2c7e0e49bae843db6e (diff)
downloadpdfium-9067fd683ebf8d6467f8cc5aa7daf5e1f950f846.tar.xz
Add APIs for limited use of document tagged code.
BUG=pdfium:568 Review-Url: https://codereview.chromium.org/2519343002
Diffstat (limited to 'fpdfsdk/fpdf_structtree_embeddertest.cpp')
-rw-r--r--fpdfsdk/fpdf_structtree_embeddertest.cpp70
1 files changed, 70 insertions, 0 deletions
diff --git a/fpdfsdk/fpdf_structtree_embeddertest.cpp b/fpdfsdk/fpdf_structtree_embeddertest.cpp
new file mode 100644
index 0000000000..58b3172057
--- /dev/null
+++ b/fpdfsdk/fpdf_structtree_embeddertest.cpp
@@ -0,0 +1,70 @@
+// Copyright 2016 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/fxcrt/fx_string.h"
+#include "public/fpdf_structtree.h"
+#include "testing/embedder_test.h"
+#include "testing/test_support.h"
+
+class FPDFStructTreeEmbeddertest : public EmbedderTest, public TestSaver {};
+
+TEST_F(FPDFStructTreeEmbeddertest, GetAltText) {
+ ASSERT_TRUE(OpenDocument("tagged_alt_text.pdf"));
+ FPDF_PAGE page = LoadPage(0);
+ ASSERT_TRUE(page);
+
+ FPDF_STRUCTTREE struct_tree = FPDF_StructTree_GetForPage(page);
+ ASSERT_TRUE(struct_tree);
+ ASSERT_EQ(1, FPDF_StructTree_CountChildren(struct_tree));
+
+ FPDF_STRUCTELEMENT element = FPDF_StructTree_GetChildAtIndex(struct_tree, -1);
+ EXPECT_EQ(nullptr, element);
+ element = FPDF_StructTree_GetChildAtIndex(struct_tree, 1);
+ EXPECT_EQ(nullptr, element);
+ element = FPDF_StructTree_GetChildAtIndex(struct_tree, 0);
+ ASSERT_NE(nullptr, element);
+ EXPECT_EQ(0U, FPDF_StructElement_GetAltText(element, nullptr, 0));
+
+ ASSERT_EQ(1, FPDF_StructElement_CountChildren(element));
+ FPDF_STRUCTELEMENT child_element =
+ FPDF_StructElement_GetChildAtIndex(element, -1);
+ EXPECT_EQ(nullptr, child_element);
+ child_element = FPDF_StructElement_GetChildAtIndex(element, 1);
+ EXPECT_EQ(nullptr, child_element);
+ child_element = FPDF_StructElement_GetChildAtIndex(element, 0);
+ ASSERT_NE(nullptr, child_element);
+ EXPECT_EQ(0U, FPDF_StructElement_GetAltText(child_element, nullptr, 0));
+
+ ASSERT_EQ(1, FPDF_StructElement_CountChildren(child_element));
+ FPDF_STRUCTELEMENT gchild_element =
+ FPDF_StructElement_GetChildAtIndex(child_element, -1);
+ EXPECT_EQ(nullptr, gchild_element);
+ gchild_element = FPDF_StructElement_GetChildAtIndex(child_element, 1);
+ EXPECT_EQ(nullptr, gchild_element);
+ gchild_element = FPDF_StructElement_GetChildAtIndex(child_element, 0);
+ ASSERT_NE(nullptr, gchild_element);
+ ASSERT_EQ(24U, FPDF_StructElement_GetAltText(gchild_element, nullptr, 0));
+
+ unsigned short buffer[12];
+ memset(buffer, 0, sizeof(buffer));
+ // Deliberately pass in a small buffer size to make sure |buffer| remains
+ // untouched.
+ ASSERT_EQ(24U, FPDF_StructElement_GetAltText(gchild_element, buffer, 1));
+ for (size_t i = 0; i < FX_ArraySize(buffer); ++i)
+ EXPECT_EQ(0U, buffer[i]);
+
+ ASSERT_EQ(24U, FPDF_StructElement_GetAltText(gchild_element, buffer,
+ sizeof(buffer)));
+ const FX_WCHAR kExpected[] = L"Black Image";
+ EXPECT_EQ(CFX_WideString(kExpected),
+ CFX_WideString::FromUTF16LE(buffer, FXSYS_len(kExpected)));
+
+ ASSERT_EQ(1, FPDF_StructElement_CountChildren(gchild_element));
+ FPDF_STRUCTELEMENT ggchild_element =
+ FPDF_StructElement_GetChildAtIndex(gchild_element, 0);
+ EXPECT_EQ(nullptr, ggchild_element);
+
+ FPDF_StructTree_Close(struct_tree);
+ FPDF_ClosePage(page);
+}