TEST_F(JsEngineTest, ValueCreation) { AdblockPlus::JsValuePtr value; value = jsEngine->NewValue("foo"); ASSERT_TRUE(value->IsString()); ASSERT_EQ("foo", value->AsString()); value = jsEngine->NewValue(12345678901234); ASSERT_TRUE(value->IsNumber()); ASSERT_EQ(12345678901234, value->AsInt()); value = jsEngine->NewValue(true); ASSERT_TRUE(value->IsBool()); ASSERT_TRUE(value->AsBool()); value = jsEngine->NewObject(); ASSERT_TRUE(value->IsObject()); ASSERT_EQ(0u, value->GetOwnPropertyNames().size()); }
TEST_F(JsValueTest, IntValue) { AdblockPlus::JsValuePtr value = jsEngine->Evaluate("12345678901234"); ASSERT_FALSE(value->IsUndefined()); ASSERT_FALSE(value->IsNull()); ASSERT_FALSE(value->IsString()); ASSERT_FALSE(value->IsBool()); ASSERT_TRUE(value->IsNumber()); ASSERT_FALSE(value->IsObject()); ASSERT_FALSE(value->IsArray()); ASSERT_FALSE(value->IsFunction()); ASSERT_EQ("12345678901234", value->AsString()); ASSERT_EQ(12345678901234, value->AsInt()); ASSERT_TRUE(value->AsBool()); ASSERT_ANY_THROW(value->AsList()); ASSERT_ANY_THROW(value->GetProperty("foo")); ASSERT_ANY_THROW(value->SetProperty("foo", false)); ASSERT_ANY_THROW(value->GetClass()); ASSERT_ANY_THROW(value->GetOwnPropertyNames()); ASSERT_ANY_THROW(value->Call()); }