diff options
author | Lei Zhang <thestig@chromium.org> | 2018-09-15 04:29:30 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-09-15 04:29:30 +0000 |
commit | 79d9be89e4c6c69c9a5b851c7b1d691b29ea55fd (patch) | |
tree | 28149d6f9376a8d81050b6d57f8bb2d86c6b028c /fpdfsdk/fpdf_structtree_embeddertest.cpp | |
parent | a94b40f73598b84063d121e29164d71b5d977fcc (diff) | |
download | pdfium-79d9be89e4c6c69c9a5b851c7b1d691b29ea55fd.tar.xz |
Use ScopedFPDFStructTree in tests.
Change-Id: Ia457942238ca2a9f48210c080a93412c09ae932c
Reviewed-on: https://pdfium-review.googlesource.com/42570
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'fpdfsdk/fpdf_structtree_embeddertest.cpp')
-rw-r--r-- | fpdfsdk/fpdf_structtree_embeddertest.cpp | 170 |
1 files changed, 88 insertions, 82 deletions
diff --git a/fpdfsdk/fpdf_structtree_embeddertest.cpp b/fpdfsdk/fpdf_structtree_embeddertest.cpp index b638cdc315..016d29d222 100644 --- a/fpdfsdk/fpdf_structtree_embeddertest.cpp +++ b/fpdfsdk/fpdf_structtree_embeddertest.cpp @@ -15,62 +15,64 @@ TEST_F(FPDFStructTreeEmbeddertest, GetAltText) { 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(-1, FPDF_StructElement_GetMarkedContentID(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(-1, FPDF_StructElement_GetMarkedContentID(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); - EXPECT_EQ(-1, FPDF_StructElement_GetMarkedContentID(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]); - - EXPECT_EQ(-1, FPDF_StructElement_GetMarkedContentID(gchild_element)); - ASSERT_EQ(24U, FPDF_StructElement_GetAltText(gchild_element, buffer, - sizeof(buffer))); - const wchar_t kExpected[] = L"Black Image"; - EXPECT_EQ(WideString(kExpected), - 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); + { + ScopedFPDFStructTree struct_tree(FPDF_StructTree_GetForPage(page)); + ASSERT_TRUE(struct_tree); + ASSERT_EQ(1, FPDF_StructTree_CountChildren(struct_tree.get())); + + FPDF_STRUCTELEMENT element = + FPDF_StructTree_GetChildAtIndex(struct_tree.get(), -1); + EXPECT_EQ(nullptr, element); + element = FPDF_StructTree_GetChildAtIndex(struct_tree.get(), 1); + EXPECT_EQ(nullptr, element); + element = FPDF_StructTree_GetChildAtIndex(struct_tree.get(), 0); + ASSERT_NE(nullptr, element); + EXPECT_EQ(-1, FPDF_StructElement_GetMarkedContentID(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(-1, FPDF_StructElement_GetMarkedContentID(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); + EXPECT_EQ(-1, FPDF_StructElement_GetMarkedContentID(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]); + + EXPECT_EQ(-1, FPDF_StructElement_GetMarkedContentID(gchild_element)); + ASSERT_EQ(24U, FPDF_StructElement_GetAltText(gchild_element, buffer, + sizeof(buffer))); + const wchar_t kExpected[] = L"Black Image"; + EXPECT_EQ(WideString(kExpected), + 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); + } + UnloadPage(page); } @@ -79,14 +81,16 @@ TEST_F(FPDFStructTreeEmbeddertest, GetMarkedContentID) { 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)); + { + ScopedFPDFStructTree struct_tree(FPDF_StructTree_GetForPage(page)); + ASSERT_TRUE(struct_tree); + ASSERT_EQ(1, FPDF_StructTree_CountChildren(struct_tree.get())); - FPDF_STRUCTELEMENT element = FPDF_StructTree_GetChildAtIndex(struct_tree, 0); - EXPECT_EQ(0, FPDF_StructElement_GetMarkedContentID(element)); + FPDF_STRUCTELEMENT element = + FPDF_StructTree_GetChildAtIndex(struct_tree.get(), 0); + EXPECT_EQ(0, FPDF_StructElement_GetMarkedContentID(element)); + } - FPDF_StructTree_Close(struct_tree); UnloadPage(page); } @@ -95,26 +99,28 @@ TEST_F(FPDFStructTreeEmbeddertest, GetType) { 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(WideString(kExpected), - WideString::FromUTF16LE(buffer, FXSYS_len(kExpected))); + { + ScopedFPDFStructTree struct_tree(FPDF_StructTree_GetForPage(page)); + ASSERT_TRUE(struct_tree); + ASSERT_EQ(1, FPDF_StructTree_CountChildren(struct_tree.get())); + + FPDF_STRUCTELEMENT element = + FPDF_StructTree_GetChildAtIndex(struct_tree.get(), 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(WideString(kExpected), + WideString::FromUTF16LE(buffer, FXSYS_len(kExpected))); + } - FPDF_StructTree_Close(struct_tree); UnloadPage(page); } |