summaryrefslogtreecommitdiff
path: root/xfa/fxfa/fm2js/cxfa_fm2jscontext_embeddertest.cpp
blob: a94e8a9aa23d08235d54276168b26c08e3e4ebe6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright 2017 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 "testing/gtest/include/gtest/gtest.h"
#include "testing/xfa_js_embedder_test.h"

class FM2JSContextEmbedderTest : public XFAJSEmbedderTest {};

TEST_F(FM2JSContextEmbedderTest, TranslateEmpty) {
  ASSERT_TRUE(OpenDocument("simple_xfa.pdf"));

  const char input[] = "";
  EXPECT_TRUE(Execute(input));
  // TODO(dsinclair): This should probably throw as a blank formcalc script
  // is invalid.
}

TEST_F(FM2JSContextEmbedderTest, TranslateNumber) {
  ASSERT_TRUE(OpenDocument("simple_xfa.pdf"));

  const char input[] = "123";
  EXPECT_TRUE(Execute(input));

  CFXJSE_Value* value = GetValue();
  ASSERT_TRUE(value->IsNumber());
  EXPECT_EQ(123, value->ToInteger());
}

TEST_F(FM2JSContextEmbedderTest, Add) {
  ASSERT_TRUE(OpenDocument("simple_xfa.pdf"));

  const char input[] = "123 + 456";
  EXPECT_TRUE(Execute(input));

  CFXJSE_Value* value = GetValue();
  ASSERT_TRUE(value->IsNumber());
  EXPECT_EQ(579, value->ToInteger());
}