TEST_F(FXJSV8EmbedderTest, Getters) {
  v8::Isolate::Scope isolate_scope(isolate());
  v8::HandleScope handle_scope(isolate());
  v8::Context::Scope context_scope(GetV8Context());

  ExecuteInCurrentContext(CFX_WideString(kScript1));
  CheckAssignmentInCurrentContext(kExpected1);
}
Ejemplo n.º 2
0
TEST_F(FXJSV8Embeddertest, Getters) {
  v8::Isolate::Scope isolate_scope(isolate());
  v8::HandleScope handle_scope(isolate());
  v8::Context::Scope context_scope(GetV8Context());

  FXJSErr error;
  int sts = FXJS_Execute(isolate(), nullptr, kScript, &error);
  EXPECT_EQ(0, sts);

  v8::Local<v8::Object> This = FXJS_GetThisObj(isolate());
  v8::Local<v8::Value> fred = FXJS_GetObjectElement(isolate(), This, L"fred");
  EXPECT_TRUE(fred->IsNumber());
}
TEST_F(FXJSV8EmbedderTest, MultipleRutimes) {
  v8::Isolate::Scope isolate_scope(isolate());
  v8::HandleScope handle_scope(isolate());

  v8::Global<v8::Context> global_context1;
  std::vector<v8::Global<v8::Object>*> static_objects1;
  FXJS_InitializeRuntime(isolate(), nullptr, &global_context1,
                         &static_objects1);

  v8::Global<v8::Context> global_context2;
  std::vector<v8::Global<v8::Object>*> static_objects2;
  FXJS_InitializeRuntime(isolate(), nullptr, &global_context2,
                         &static_objects2);

  v8::Context::Scope context_scope(GetV8Context());
  ExecuteInCurrentContext(CFX_WideString(kScript0));
  CheckAssignmentInCurrentContext(kExpected0);

  {
    v8::Local<v8::Context> context1 =
        v8::Local<v8::Context>::New(isolate(), global_context1);
    v8::Context::Scope context_scope1(context1);
    ExecuteInCurrentContext(CFX_WideString(kScript1));
    CheckAssignmentInCurrentContext(kExpected1);
  }
  FXJS_ReleaseRuntime(isolate(), &global_context1, &static_objects1);

  {
    v8::Local<v8::Context> context2 =
        v8::Local<v8::Context>::New(isolate(), global_context2);
    v8::Context::Scope context_scope2(context2);
    ExecuteInCurrentContext(CFX_WideString(kScript2));
    CheckAssignmentInCurrentContext(kExpected2);
  }
  FXJS_ReleaseRuntime(isolate(), &global_context2, &static_objects2);

  CheckAssignmentInCurrentContext(kExpected0);
}
TEST_F(PublicMethodsEmbedderTest, MakeRegularDate) {
  v8::Isolate::Scope isolate_scope(isolate());
  v8::HandleScope handle_scope(isolate());
  v8::Context::Scope context_scope(GetV8Context());
  bool bWrongFormat;
  double date;

  // 1968
  bWrongFormat = false;
  date = CJS_PublicMethods::MakeRegularDate(L"06/25/1968", L"mm/dd/yyyy",
                                            &bWrongFormat);
  date = RoundDownDate(date);
  EXPECT_DOUBLE_EQ(-47865600000, date);
  EXPECT_FALSE(bWrongFormat);

  // 1968
  bWrongFormat = false;
  date = CJS_PublicMethods::MakeRegularDate(L"25061968", L"ddmmyyyy",
                                            &bWrongFormat);
  date = RoundDownDate(date);
  EXPECT_DOUBLE_EQ(-47865600000, date);
  EXPECT_FALSE(bWrongFormat);

  // 1968
  bWrongFormat = false;
  date = CJS_PublicMethods::MakeRegularDate(L"19680625", L"yyyymmdd",
                                            &bWrongFormat);
  date = RoundDownDate(date);
  EXPECT_DOUBLE_EQ(-47865600000, date);
  EXPECT_FALSE(bWrongFormat);

  // 1985
  bWrongFormat = false;
  date = CJS_PublicMethods::MakeRegularDate(L"31121985", L"ddmmyyyy",
                                            &bWrongFormat);
  date = RoundDownDate(date);
  EXPECT_DOUBLE_EQ(504835200000.0, date);
  EXPECT_FALSE(bWrongFormat);

  // 2085, the other '85.
  bWrongFormat = false;
  date =
      CJS_PublicMethods::MakeRegularDate(L"311285", L"ddmmyy", &bWrongFormat);
  date = RoundDownDate(date);
  EXPECT_DOUBLE_EQ(3660595200000.0, date);
  EXPECT_FALSE(bWrongFormat);

  // 1995
  bWrongFormat = false;
  date = CJS_PublicMethods::MakeRegularDate(L"01021995", L"ddmmyyyy",
                                            &bWrongFormat);
  date = RoundDownDate(date);
  EXPECT_DOUBLE_EQ(791596800000.0, date);
  EXPECT_FALSE(bWrongFormat);

  // 2095, the other '95.
  bWrongFormat = false;
  date =
      CJS_PublicMethods::MakeRegularDate(L"010295", L"ddmmyy", &bWrongFormat);
  date = RoundDownDate(date);
  EXPECT_DOUBLE_EQ(3947356800000.0, date);
  EXPECT_FALSE(bWrongFormat);

  // 2005
  bWrongFormat = false;
  date = CJS_PublicMethods::MakeRegularDate(L"01022005", L"ddmmyyyy",
                                            &bWrongFormat);
  date = RoundDownDate(date);
  EXPECT_DOUBLE_EQ(1107216000000.0, date);
  EXPECT_FALSE(bWrongFormat);

  // 2005
  bWrongFormat = false;
  date =
      CJS_PublicMethods::MakeRegularDate(L"010205", L"ddmmyy", &bWrongFormat);
  date = RoundDownDate(date);
  EXPECT_DOUBLE_EQ(1107216000000.0, date);
  EXPECT_FALSE(bWrongFormat);
}
TEST_F(PublicMethodsEmbedderTest, MakeFormatDate) {
  v8::Isolate::Scope isolate_scope(isolate());
  v8::HandleScope handle_scope(isolate());
  v8::Context::Scope context_scope(GetV8Context());
  CFX_WideString formatted_date;

  // 1968-06-25
  formatted_date = CJS_PublicMethods::MakeFormatDate(-47952000000, L"ddmmyy");
  EXPECT_STREQ(L"250668", formatted_date.c_str());
  formatted_date = CJS_PublicMethods::MakeFormatDate(-47952000000, L"yy/mm/dd");
  EXPECT_STREQ(L"68/06/25", formatted_date.c_str());

  // 1969-12-31
  formatted_date = CJS_PublicMethods::MakeFormatDate(-0.0001, L"ddmmyy");
  EXPECT_STREQ(L"311269", formatted_date.c_str());
  formatted_date = CJS_PublicMethods::MakeFormatDate(-0.0001, L"yy!mmdd");
  EXPECT_STREQ(L"69!1231", formatted_date.c_str());

  // 1970-01-01
  formatted_date = CJS_PublicMethods::MakeFormatDate(0, L"ddmmyy");
  EXPECT_STREQ(L"010170", formatted_date.c_str());
  formatted_date = CJS_PublicMethods::MakeFormatDate(0, L"mm-yyyy-dd");
  EXPECT_STREQ(L"01-1970-01", formatted_date.c_str());

  // 1985-12-31
  formatted_date = CJS_PublicMethods::MakeFormatDate(504835200000.0, L"ddmmyy");
  EXPECT_STREQ(L"311285", formatted_date.c_str());
  formatted_date = CJS_PublicMethods::MakeFormatDate(504835200000.0, L"yymmdd");
  EXPECT_STREQ(L"851231", formatted_date.c_str());

  // 1995-02-01
  formatted_date = CJS_PublicMethods::MakeFormatDate(791596800000.0, L"ddmmyy");
  EXPECT_STREQ(L"010295", formatted_date.c_str());
  formatted_date =
      CJS_PublicMethods::MakeFormatDate(791596800000.0, L"yyyymmdd");
  EXPECT_STREQ(L"19950201", formatted_date.c_str());

  // 2005-02-01
  formatted_date =
      CJS_PublicMethods::MakeFormatDate(1107216000000.0, L"ddmmyy");
  EXPECT_STREQ(L"010205", formatted_date.c_str());
  formatted_date =
      CJS_PublicMethods::MakeFormatDate(1107216000000.0, L"yyyyddmm");
  EXPECT_STREQ(L"20050102", formatted_date.c_str());

  // 2085-12-31
  formatted_date =
      CJS_PublicMethods::MakeFormatDate(3660595200000.0, L"ddmmyy");
  EXPECT_STREQ(L"311285", formatted_date.c_str());
  formatted_date =
      CJS_PublicMethods::MakeFormatDate(3660595200000.0, L"yyyydd");
  EXPECT_STREQ(L"208531", formatted_date.c_str());

  // 2095-02-01
  formatted_date =
      CJS_PublicMethods::MakeFormatDate(3947356800000.0, L"ddmmyy");
  EXPECT_STREQ(L"010295", formatted_date.c_str());
  formatted_date =
      CJS_PublicMethods::MakeFormatDate(3947356800000.0, L"mmddyyyy");
  EXPECT_STREQ(L"02012095", formatted_date.c_str());
}