in unmaintained/modules/json/json-test.cpp [222:288]
bool testJSONRPC() {
gc_scoped_pool pool;
js::JSContext cx;
{
const string lm("{\"id\": 1, \"method\": \"test\", \"params\": []}");
const list<value> e = content(readJSON(mklist(lm), cx));
const list<value> v = elementsToValues(e);
assert(assoc<value>("id", v) == mklist<value>("id", 1));
assert(assoc<value>("method", v) == mklist<value>("method", string("test")));
assert(assoc<value>("params", v) == mklist<value>("params", list<value>()));
}
{
const string i2 = "{\"id\": 3,\"result\": {\"0\": {\"price\": \"$2.99\",\"name\": \"Apple\"},\"1\": {\"price\": \"$3.55\",\"name\": \"Orange\"},\"2\": {\"price\": \"$1.55\",\"name\": \"Pear\"}}}";
const list<value> e = content(readJSON(mklist(jsitem), cx));
const list<value> e2 = content(readJSON(mklist(i2), cx));
assert(e == e2);
}
{
const list<value> e = content(readJSON(mklist(jsitem), cx));
ostringstream os;
write(content(writeJSON(e, cx)), os);
assert(str(os) == jsitem);
const list<value> v = elementsToValues(e);
const list<value> r = valuesToElements(v);
assert(r == e);
}
{
const list<value> r = mklist<value>(mklist<value>("id", 1), mklist<value>("result", mklist<value>(string("Service.get"), string("Service.getTotal"))));
const list<value> e = valuesToElements(r);
ostringstream os;
write(content(writeJSON(e, cx)), os);
assert(str(os) == jsresult);
}
{
const list<value> r = content(readJSON(mklist(jsfeed), cx));
const list<value> v = elementsToValues(r);
const list<value> e = valuesToElements(v);
ostringstream os;
write(content(writeJSON(e, cx)), os);
assert(str(os) == jsfeed);
}
{
const list<value> arg = mklist<value>(list<value>() + "ns1:echoString" + (list<value>() + "@xmlns:ns1" + string("http://ws.apache.org/axis2/services/echo")) + (list<value>() + "text" + string("Hello World!")));
const failable<list<string> > r = jsonRequest(1, "echo", mklist<value>(arg), cx);
ostringstream os;
write(content(r), os);
assert(str(os) == jsechoreq);
istringstream is(str(os));
const list<string> il = streamList(is);
const list<value> ir = elementsToValues(content(readJSON(il, cx)));
assert(car<value>(cadr<value>(caddr<value>(ir))) == arg);
}
{
const list<value> res = mklist<value>(list<value>() + "ns1:echoString" + (list<value>() + "@xmlns:ns1" + string("http://ws.apache.org/axis2/c/samples")) + (list<value>() + "text" + string("Hello World!")));
const failable<list<string> > r = jsonResult(1, res, cx);
ostringstream os;
write(content(r), os);
assert(str(os) == jsechores);
istringstream is(str(os));
const list<string> il = streamList(is);
const list<value> ir = elementsToValues(content(readJSON(il, cx)));
assert(cdr<value>(cadr<value>(ir)) == res);
}
return true;
}