Ejemplo n.º 1
0
TEST(Value, Basic)
{
  AnyReference v;
  int twelve = 12;
  v = AutoAnyReference(twelve);
  ASSERT_TRUE(v.type() != 0);
  ASSERT_TRUE(v.rawValue() != 0);
  ASSERT_EQ(v.toInt(), 12);
  ASSERT_EQ(v.toFloat(), 12.0f);
  ASSERT_EQ(v.toDouble(), 12.0);
  double five = 5.0;
  v = AutoAnyReference(five);
  ASSERT_EQ(v.toInt(), 5);
  ASSERT_EQ(v.toFloat(), 5.0f);
  ASSERT_EQ(v.toDouble(), 5.0);
  v = AutoAnyReference("foo");
  ASSERT_EQ("foo", v.toString());
}
Ejemplo n.º 2
0
TEST(Value, list_at)
{
  std::vector<int> v{2, 5, 7};
  AnyReference list = AnyReference::from(v);
  const AnyReference listc = AnyReference::from(v);

  // at(T)
  {
    AnyReference val = list.at(1);
    EXPECT_EQ(5, val.toInt());
    AnyReference valInvalid = list.at(4);
    EXPECT_EQ(nullptr, valInvalid.type());
  }
  // at(T) const
  {
    const AnyReference val = listc.at(1);
    EXPECT_EQ(5, val.toInt());
    const AnyReference valInvalid = listc.at(4);
    EXPECT_EQ(nullptr, valInvalid.type());
  }
}
Ejemplo n.º 3
0
TEST(Value, Map_at)
{
  std::map<std::string, double> map;
  map["foo"] = 1;
  map["bar"] = 2;
  AutoAnyReference v(map);
  const AutoAnyReference vc(map);

  // at(T)
  {
    AnyReference val1 = v.at("foo");
    EXPECT_EQ(1, val1.toInt());
    AnyReference valInvalid = v.at("nokey");
    EXPECT_EQ(nullptr, valInvalid.type());
  }
  // at(T) const
  {
    const AnyReference val1 = vc.at("bar");
    EXPECT_EQ(2, val1.toInt());
    const AnyReference valInvalid = vc.at("nokey");
    EXPECT_EQ(nullptr, valInvalid.type());
  }
  // at(AnyReference)
  {
    AnyReference val1 = v.at(AnyReference::from("foo"));
    EXPECT_EQ(1, val1.toInt());
    AnyReference valInvalid = v.at(AnyReference::from("nokey"));
    EXPECT_EQ(nullptr, valInvalid.type());
  }
  // at(AnyReference) const
  {
    const AnyReference val1 = vc.at(AnyReference::from("bar"));
    EXPECT_EQ(2, val1.toInt());
    const AnyReference valInvalid = vc.at(AnyReference::from("nokey"));
    EXPECT_EQ(nullptr, valInvalid.type());
  }
}