Example #1
0
TEST(Value, Tuple2)
{
  Point2 p;
  StructTypeInterface* t = static_cast<qi::StructTypeInterface*>(qi::typeOf<Point2>());
  ASSERT_EQ(6u, t->memberTypes().size());
  EXPECT_EQ("(ddsddd)<Point2,x,y,str,z,a,b>", t->signature());
  AnyValueVector vd;
  vd.push_back(AnyValue(AutoAnyReference(1.5)));
  vd.push_back(AnyValue(AutoAnyReference(2.5)));
  vd.push_back(AnyValue(AutoAnyReference("coin")));
  vd.push_back(AnyValue(AutoAnyReference(1.5)));
  vd.push_back(AnyValue(AutoAnyReference(1.5)));
  vd.push_back(AnyValue(AutoAnyReference(3.5)));
  p = AnyReference::from(vd).toTuple(true).to<Point2>();
  EXPECT_EQ(1.5, p.x);
  EXPECT_EQ(2.5, p.y);
  EXPECT_EQ("coin", p.s);
  EXPECT_EQ(3.5, p.b);
  AnyReferenceVector pcomps = t->values(&p);
  EXPECT_EQ(1.5, pcomps[0].toDouble());
  EXPECT_EQ(2.5, pcomps[1].toDouble());
  EXPECT_EQ("coin", pcomps[2].toString());
  EXPECT_EQ(3.5, pcomps[5].toDouble());
}
TEST_F(TestObject, meta)
{
  using namespace qi;
  qi::int64_t time = os::ustime();
  // Remote test
  AnyObject target = oclient;
  std::string function = "value";
  ASSERT_TRUE(target);
  {
  target.call<void>(function, 12);
  ASSERT_EQ(v.toDouble(), 12);
  {
    int myint = 12;
    qi::Future<void> fut = target.async<void>(function, myint);
    myint = 5;
    fut.wait();
    ASSERT_EQ(v.toDouble(), 12);
  }
  {
    int myint = 12;
    qi::Future<void> fut = target.async<void>(function, AnyValue::from(myint));
    myint = 5;
    fut.wait();
    ASSERT_EQ(v.toDouble(), 12);
  }
  target.call<void>(function, qi::AnyValue::from(12));
  ASSERT_EQ(v.toDouble(), 12);
  target.call<void>(function, qi::AnyValue::from(12.0));
  ASSERT_EQ(v.toDouble(), 12);
  target.call<void>(function, qi::AnyValue::from(12.0f));
  ASSERT_EQ(v.toDouble(), 12);
  target.call<void>(function, qi::AnyValue::from("foo"));
  ASSERT_EQ(v.toString(), "foo");
  target.call<void>(function, "foo");
  ASSERT_EQ(v.toString(), "foo");
  std::vector<double> in;
  in.push_back(1); in.push_back(2);
  target.call<void>(function, qi::AnyValue::from(in));
  ASSERT_EQ(v.to<std::vector<double> >(), in);
  target.call<void>(function, in);
  ASSERT_EQ(v.to<std::vector<double> >(), in);
  AnyValueVector args;
  args.push_back(AnyValue::from(12));
  args.push_back(AnyValue::from("foo"));
  args.push_back(AnyValue::from(in));
  target.call<void>(function, args);
  ASSERT_EQ(v.kind(), TypeKind_List);
  ASSERT_EQ(static_cast<size_t>(3), v.size());

  // iterate
  EXPECT_EQ(12, v[0].toDouble());
  ASSERT_EQ("foo", v[1].toString());
  ASSERT_EQ(in, v[2].to<std::vector<double> >());
  }
  qiLogVerbose() << "remote us: " << os::ustime() - time;
  time = os::ustime();

  // Plugin copy test
  target = oserver;
  function = "valueAsync";
  {
  target.call<void>(function, 12);
  ASSERT_EQ(v.toDouble(), 12);
  {
    int myint = 12;
    qi::Future<void> fut = target.async<void>(function, myint);
    myint = 5;
    fut.wait();
    ASSERT_EQ(v.toDouble(), 12);
  }
  {
    int myint = 12;
    qi::Future<void> fut = target.async<void>(function, AnyValue::from(myint));
    myint = 5;
    fut.wait();
    ASSERT_EQ(v.toDouble(), 12);
  }
  target.call<void>(function, qi::AnyValue::from(12));
  ASSERT_EQ(v.toDouble(), 12);
  target.call<void>(function, qi::AnyValue::from(12.0));
  ASSERT_EQ(v.toDouble(), 12);
  target.call<void>(function, qi::AnyValue::from(12.0f));
  ASSERT_EQ(v.toDouble(), 12);
  target.call<void>(function, qi::AnyValue::from("foo"));
  ASSERT_EQ(v.toString(), "foo");
  target.call<void>(function, "foo");
  ASSERT_EQ(v.toString(), "foo");
  std::vector<double> in;
  in.push_back(1); in.push_back(2);
  target.call<void>(function, qi::AnyValue::from(in));
  ASSERT_EQ(v.to<std::vector<double> >(), in);
  target.call<void>(function, in);
  ASSERT_EQ(v.to<std::vector<double> >(), in);
  target.call<void>(function, in);
  ASSERT_EQ(v.to<std::vector<double> >(), in);
  AnyValueVector args;
  args.push_back(AnyValue::from(12));
  args.push_back(AnyValue::from("foo"));
  args.push_back(AnyValue::from(in));
  target.call<void>(function, args);
  ASSERT_EQ(v.kind(), TypeKind_List);
  // iterate
  ASSERT_EQ(12, v[0].toDouble());
  ASSERT_EQ("foo", v[1].toString());
  ASSERT_EQ(in, v[2].to<std::vector<double> >());
  }
  qiLogVerbose() << "plugin async us: " << os::ustime() - time;
  time = os::ustime();
  // plugin direct test
  function = "value";
  {
  target.call<void>(function, 12);
  ASSERT_EQ(v.toDouble(), 12);
  {
    int myint = 12;
    qi::Future<void> fut = target.async<void>(function, myint);
    myint = 5;
    fut.wait();
    ASSERT_EQ(v.toDouble(), 12);
  }
  {
    int myint = 12;
    qi::Future<void> fut = target.async<void>(function, AnyValue::from(myint));
    myint = 5;
    fut.wait();
    ASSERT_EQ(v.toDouble(), 12);
  }
  target.call<void>(function, qi::AnyValue::from(12));
  ASSERT_EQ(v.toDouble(), 12);
  target.call<void>(function, qi::AnyValue::from(12.0));
  ASSERT_EQ(v.toDouble(), 12);
  target.call<void>(function, qi::AnyValue::from(12.0f));
  ASSERT_EQ(v.toDouble(), 12);
  target.call<void>(function, qi::AnyValue::from("foo"));
  ASSERT_EQ(v.toString(), "foo");
  target.call<void>(function, "foo");
  ASSERT_EQ(v.toString(), "foo");
  std::vector<double> in;
  in.push_back(1); in.push_back(2);
  target.call<void>(function, qi::AnyValue::from(in));
  ASSERT_EQ(v.to<std::vector<double> >(), in);
  target.call<void>(function, in);
  ASSERT_EQ(v.to<std::vector<double> >(), in);
  AnyValueVector args;
  args.push_back(AnyValue::from(12));
  args.push_back(AnyValue::from("foo"));
  args.push_back(AnyValue::from(in));
  target.call<void>(function, args);
  ASSERT_EQ(v.kind(), TypeKind_List);
  // iterate
  ASSERT_EQ(12, v[0].toDouble());
  ASSERT_EQ("foo", v[1].toString());
  ASSERT_EQ(in, v[2].to<std::vector<double> >());
  }
  qiLogVerbose() << "plugin sync us: " << os::ustime() - time;
  time = os::ustime();
}