summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdf_structtree_embeddertest.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-04-04 10:48:19 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-04-04 15:00:53 +0000
commit29479f6380942515b06240c4933bf3b4cf502013 (patch)
tree17c63412945c264cf3087a2f959d157f2ad1b19b /fpdfsdk/fpdf_structtree_embeddertest.cpp
parentf02c8bf51c992057376e0acdd262c18540bd8e13 (diff)
downloadpdfium-29479f6380942515b06240c4933bf3b4cf502013.tar.xz
Add method to get tagged type
This CL adds a FPDF_StructElement_GetType method to get the type of a given tagged struct. This corresponds to the /S key in the structure element dictionary. See PDF1.7 Table 10.10. Bug: pdfium:672 Change-Id: I313eb886dc9623715995d73a76bce01ba9985e4b Reviewed-on: https://pdfium-review.googlesource.com/3623 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'fpdfsdk/fpdf_structtree_embeddertest.cpp')
-rw-r--r--fpdfsdk/fpdf_structtree_embeddertest.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/fpdfsdk/fpdf_structtree_embeddertest.cpp b/fpdfsdk/fpdf_structtree_embeddertest.cpp
index 8ddde5317c..3110988d82 100644
--- a/fpdfsdk/fpdf_structtree_embeddertest.cpp
+++ b/fpdfsdk/fpdf_structtree_embeddertest.cpp
@@ -68,3 +68,32 @@ TEST_F(FPDFStructTreeEmbeddertest, GetAltText) {
FPDF_StructTree_Close(struct_tree);
FPDF_ClosePage(page);
}
+
+TEST_F(FPDFStructTreeEmbeddertest, GetType) {
+ 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, 0);
+ ASSERT_NE(nullptr, element);
+
+ unsigned short buffer[12];
+ memset(buffer, 0, sizeof(buffer));
+ // Deliberately pass in a small buffer size to make sure |buffer| remains
+ // untouched.
+ ASSERT_EQ(18U, FPDF_StructElement_GetType(element, buffer, 1));
+ for (size_t i = 0; i < FX_ArraySize(buffer); ++i)
+ EXPECT_EQ(0U, buffer[i]);
+
+ ASSERT_EQ(18U, FPDF_StructElement_GetType(element, buffer, sizeof(buffer)));
+ const wchar_t kExpected[] = L"Document";
+ EXPECT_EQ(CFX_WideString(kExpected),
+ CFX_WideString::FromUTF16LE(buffer, FXSYS_len(kExpected)));
+
+ FPDF_StructTree_Close(struct_tree);
+ FPDF_ClosePage(page);
+}