Example #1
0
Value XmlRpcSystemMethods::SystemMulticall(
  const Request::Parameters& parameters) const
{
  const Value dummyId;
  Value::Array result;
  for (auto& call : parameters.at(0).AsArray()) {
    try {
      if (call[xml::METHOD_NAME_TAG].AsString() == SYSTEM_MULTICALL) {
        throw InternalErrorFault("Recursive system.multicall forbidden");
      }

      auto& array = call[xml::PARAMS_TAG].AsArray();
      Request::Parameters callParams(array.begin(), array.end());
      auto retval = myDispatcher.Invoke(
        call[xml::METHOD_NAME_TAG].AsString(), callParams, dummyId);

      retval.ThrowIfFault();
      Value::Array a;
      a.emplace_back(std::move(retval.GetResult()));
      result.push_back(std::move(a));
    }
    catch (const Fault& ex) {
      Value::Struct fault;
      fault[xml::FAULT_CODE_NAME] = ex.GetCode();
      fault[xml::FAULT_STRING_NAME] = ex.GetString();
      result.push_back(std::move(fault));
    }
    catch (const std::exception& ex) {
      Value::Struct fault;
      fault[xml::FAULT_CODE_NAME] = 0;
      fault[xml::FAULT_STRING_NAME] = ex.what();
      result.push_back(std::move(fault));
    }
    catch (...) {
      Value::Struct fault;
      fault[xml::FAULT_CODE_NAME] = 0;
      fault[xml::FAULT_STRING_NAME] = "Unknown error";
      result.push_back(std::move(fault));
    }
  }
  return std::move(result);
}
Example #2
0
TEST(ValueTest, SetValue)
{
    Value b;
    b.set(true);
    EXPECT_EQ(true, b.getBoolean());

    Value i1;
    i1.set(42);
    EXPECT_EQ(42, i1.getInteger());

    Value i2;
    i2.set(42L);
    EXPECT_EQ(42, i2.getInteger());

    Value f1;
    f1.set(0.42F);
    EXPECT_NEAR(0.42, f1.getFloat(), 0.000001);

    Value f2;
    f2.set(0.42);
    EXPECT_NEAR(0.42, f2.getFloat(), 0.000001);

    Value s1;
    s1.set("foobar");
    EXPECT_EQ("foobar", s1.getString());

    Value s2;
    s2.set(std::string("foobar"));
    EXPECT_EQ("foobar", s2.getString());

    Value s3;
    s3.set(QString("foobar"));
    EXPECT_EQ("foobar", s3.getString());

    Value::Array arr;
    arr.push_back(Value(42));
    Value a;
    a.set(arr);
    EXPECT_EQ(arr, a.getArray());

    Value::Object obj;
    obj["foobar"] = Value(42);
    Value o1;
    o1.set(obj);
    EXPECT_EQ(obj, o1.getObject());

    Value o2;
    o2.set(o1);
    EXPECT_EQ(o1, o2);
}
Example #3
0
TEST(ValueTest, CreateValue)
{
    Value b = true;
    EXPECT_EQ(true, b.getBoolean());

    Value i1 = 42;
    EXPECT_EQ(42, i1.getInteger());

    Value i2 = 42L;
    EXPECT_EQ(42, i2.getInteger());

    Value f1 = 0.42F;
    EXPECT_NEAR(0.42, f1.getFloat(), 0.000001);

    Value f2 = 0.42;
    EXPECT_NEAR(0.42, f2.getFloat(), 0.000001);

    Value s1 = "foobar";
    EXPECT_EQ("foobar", s1.getString());

    Value s2 = std::string("foobar");
    EXPECT_EQ("foobar", s2.getString());

    Value s3 = QString("foobar");
    EXPECT_EQ("foobar", s3.getString());

    Value::Array arr;
    arr.push_back(Value(42));
    Value a = arr;
    EXPECT_EQ(arr, a.getArray());

    Value::Object obj;
    obj["foobar"] = Value(42);
    Value o1 = obj;
    EXPECT_EQ(obj, o1.getObject());

    Value o2 = o1;
    EXPECT_EQ(o1, o2);
}