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 "fxjs/xfa/cfxjse_value.h"
6 
7 #include <memory>
8 #include <utility>
9 #include <vector>
10 
11 #include "fxjs/xfa/cfxjse_engine.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "testing/xfa_js_embedder_test.h"
14 #include "third_party/base/ptr_util.h"
15 
16 class CFXJSE_ValueEmbedderTest : public XFAJSEmbedderTest {};
17 
TEST_F(CFXJSE_ValueEmbedderTest,Empty)18 TEST_F(CFXJSE_ValueEmbedderTest, Empty) {
19   ASSERT_TRUE(OpenDocument("simple_xfa.pdf"));
20 
21   auto pValue = pdfium::MakeUnique<CFXJSE_Value>(GetIsolate());
22   EXPECT_TRUE(pValue->IsEmpty());
23   EXPECT_FALSE(pValue->IsUndefined());
24   EXPECT_FALSE(pValue->IsNull());
25   EXPECT_FALSE(pValue->IsBoolean());
26   EXPECT_FALSE(pValue->IsString());
27   EXPECT_FALSE(pValue->IsNumber());
28   EXPECT_FALSE(pValue->IsObject());
29   EXPECT_FALSE(pValue->IsArray());
30   EXPECT_FALSE(pValue->IsFunction());
31 }
32 
TEST_F(CFXJSE_ValueEmbedderTest,EmptyArrayInsert)33 TEST_F(CFXJSE_ValueEmbedderTest, EmptyArrayInsert) {
34   ASSERT_TRUE(OpenDocument("simple_xfa.pdf"));
35 
36   // Test inserting empty values into arrays.
37   auto pValue = pdfium::MakeUnique<CFXJSE_Value>(GetIsolate());
38   std::vector<std::unique_ptr<CFXJSE_Value>> vec;
39   vec.push_back(std::move(pValue));
40 
41   CFXJSE_Value array(GetIsolate());
42   array.SetArray(vec);
43   EXPECT_TRUE(array.IsArray());
44 }
45