1 // Copyright 2019 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "public/fpdfview.h"
6 #include "testing/gtest/include/gtest/gtest.h"
7 
8 #ifdef PDF_ENABLE_XFA
TEST(FPDFView,BstrBadArgs)9 TEST(FPDFView, BstrBadArgs) {
10   EXPECT_EQ(-1, FPDF_BStr_Init(nullptr));
11   EXPECT_EQ(-1, FPDF_BStr_Set(nullptr, "clams", -1));
12   EXPECT_EQ(-1, FPDF_BStr_Clear(nullptr));
13 }
14 
TEST(FPDFView,BstrEmpty)15 TEST(FPDFView, BstrEmpty) {
16   FPDF_BSTR bst;
17   EXPECT_EQ(0, FPDF_BStr_Init(&bst));
18   EXPECT_FALSE(bst.str);
19   EXPECT_FALSE(bst.len);
20   EXPECT_EQ(0, FPDF_BStr_Clear(&bst));
21 }
22 
TEST(FPDFView,BstrNormal)23 TEST(FPDFView, BstrNormal) {
24   FPDF_BSTR bst;
25   EXPECT_EQ(0, FPDF_BStr_Init(&bst));
26   EXPECT_EQ(0, FPDF_BStr_Set(&bst, "clams", -1));
27   EXPECT_STREQ("clams", bst.str);
28   EXPECT_EQ(5, bst.len);
29 
30   EXPECT_EQ(0, FPDF_BStr_Clear(&bst));
31   EXPECT_FALSE(bst.str);
32   EXPECT_FALSE(bst.len);
33 }
34 
TEST(FPDFView,BstrReassign)35 TEST(FPDFView, BstrReassign) {
36   FPDF_BSTR bst;
37   EXPECT_EQ(0, FPDF_BStr_Init(&bst));
38   EXPECT_EQ(0, FPDF_BStr_Set(&bst, "clams", 3));
39   EXPECT_STREQ("cla", bst.str);
40   EXPECT_EQ(3, bst.len);
41 
42   EXPECT_EQ(0, FPDF_BStr_Set(&bst, "clams", 5));
43   EXPECT_STREQ("clams", bst.str);
44   EXPECT_EQ(5, bst.len);
45 
46   EXPECT_EQ(0, FPDF_BStr_Set(&bst, "clams", 1));
47   EXPECT_STREQ("c", bst.str);
48   EXPECT_EQ(1, bst.len);
49 
50   EXPECT_EQ(0, FPDF_BStr_Set(&bst, "clams", 0));
51   EXPECT_FALSE(bst.str);
52   EXPECT_EQ(0, bst.len);
53 
54   EXPECT_EQ(0, FPDF_BStr_Clear(&bst));
55 }
56 #endif  // PDF_ENABLE_XFA
57