<commit_before>/*************************************************************************
 * libjson-rpc-cpp
 *************************************************************************
 * @file    test_server.cpp
 * @date    28.09.2013
 * @author  <NAME> <<EMAIL>>
 * @license See attached LICENSE.txt
 ************************************************************************/

#include <catch.hpp>
#include "testserver.h"
#include "mockserverconnector.h"

#define TEST_MODULE "[server]"

using namespace jsonrpc;
using namespace std;

namespace testserver
{
    struct F {
            MockServerConnector c;
            TestServer server;

            F() : server(c) {}
    };

    struct F1 {
            MockServerConnector c;
            TestServer server;

            F1() : server(c, JSONRPC_SERVER_V1) {}
    };
}
using namespace testserver;

TEST_CASE_METHOD(F, "test_server_v2_method_success", TEST_MODULE)
{
    c.SetRequest("{\"jsonrpc\":\"2.0\", \"id\": 1, \"method\": \"sayHello\",\"params\":{\"name\":\"Peter\"}}");
    CHECK(c.GetJsonResponse()["result"].asString() == "Hello: Peter!");
    CHECK(c.GetJsonResponse()["id"].asInt() ==  1);
    CHECK(c.GetJsonResponse()["jsonrpc"].asString() ==  "2.0");
    CHECK(c.GetJsonResponse().isMember("error") ==  false);

    c.SetRequest("{\"jsonrpc\":\"2.0\", \"id\": 1, \"method\": \"add\",\"params\":{\"value1\":5,\"value2\":7}}");
    CHECK(c.GetJsonResponse()["result"].asInt() == 12);
    CHECK(c.GetJsonResponse()["id"].asInt() ==  1);
    CHECK(c.GetJsonResponse()["jsonrpc"].asString() ==  "2.0");
    CHECK(c.GetJsonResponse().isMember("error") ==  false);

    c.SetRequest("{\"jsonrpc\":\"2.0\", \"id\": 1, \"method\": \"sub\",\"params\":[5,7]}");
    CHECK(c.GetJsonResponse()["result"].asInt() == -2);
    CHECK(c.GetJsonResponse()["id"].asInt() ==  1);
    CHECK(c.GetJsonResponse()["jsonrpc"].asString() ==  "2.0");
    CHECK(c.GetJsonResponse().isMember("error") ==  false);

    c.SetRequest("{\"jsonrpc\":\"2.0\", \"id\": null, \"method\": \"sub\",\"params\":[5,7]}");
    CHECK(c.GetJsonResponse()["result"].asInt() == -2);
    CHECK(c.GetJsonResponse()["id"].isNull() ==  true);
    CHECK(c.GetJsonResponse()["jsonrpc"].asString() ==  "2.0");
    CHECK(c.GetJsonResponse().isMember("error") ==  false);

    c.SetRequest("{\"jsonrpc\":\"2.0\", \"id\": \"1\", \"method\": \"sub\",\"params\":[5,7]}");
    CHECK(c.GetJsonResponse()["result"].asInt() == -2);
    CHECK(c.GetJsonResponse()["id"].asString() ==  "1");
    CHECK(c.GetJsonResponse()["jsonrpc"].asString() ==  "2.0");
    CHECK(c.GetJsonResponse().isMember("error") ==  false);

    c.SetRequest("{\"jsonrpc\":\"2.0\", \"id\": 4294967295, \"method\": \"sub\",\"params\":[5,7]}");
    CHECK(c.GetJsonResponse()["result"].asInt() == -2);
    CHECK(c.GetJsonResponse()["id"].asString() ==  "4294967295");
    CHECK(c.GetJsonResponse()["jsonrpc"].asString() ==  "2.0");
    CHECK(c.GetJsonResponse().isMember("error") ==  false);

}
<commit_msg>refer to prev.<commit_after>/*************************************************************************
 * libjson-rpc-cpp
 *************************************************************************
 * @file    test_server.cpp
 * @date    28.09.2013
 * @author  <NAME> <<EMAIL>>
 * @license See attached LICENSE.txt
 ************************************************************************/

#include <catch.hpp>
#include "testserver.h"
#include "mockserverconnector.h"

#define TEST_MODULE "[server]"

using namespace jsonrpc;
using namespace std;

namespace testserver
{
    struct F {
            MockServerConnector c;
            TestServer server;

            F() : server(c) {}
    };

    struct F1 {
            MockServerConnector c;
            TestServer server;

            F1() : server(c, JSONRPC_SERVER_V1) {}
    };
}
using namespace testserver;

TEST_CASE_METHOD(F, "test_server_v2_method_success", TEST_MODULE)
{
    c.SetRequest("{\"jsonrpc\":\"2.0\", \"id\": 1, \"method\": \"sayHello\",\"params\":{\"name\":\"Peter\"}}");
    CHECK(c.GetJsonResponse()["result"].asString() == "Hello: Peter!");
    CHECK(c.GetJsonResponse()["id"].asInt() ==  1);
    CHECK(c.GetJsonResponse()["jsonrpc"].asString() ==  "2.0");
    CHECK(c.GetJsonResponse().isMember("error") ==  false);

    c.SetRequest("{\"jsonrpc\":\"2.0\", \"id\": 1, \"method\": \"add\",\"params\":{\"value1\":5,\"value2\":7}}");
    CHECK(c.GetJsonResponse()["result"].asInt() == 12);
    CHECK(c.GetJsonResponse()["id"].asInt() ==  1);
    CHECK(c.GetJsonResponse()["jsonrpc"].asString() ==  "2.0");
    CHECK(c.GetJsonResponse().isMember("error") ==  false);

    c.SetRequest("{\"jsonrpc\":\"2.0\", \"id\": 1, \"method\": \"sub\",\"params\":[5,7]}");
    CHECK(c.GetJsonResponse()["result"].asInt() == -2);
    CHECK(c.GetJsonResponse()["id"].asInt() ==  1);
    CHECK(c.GetJsonResponse()["jsonrpc"].asString() ==  "2.0");
    CHECK(c.GetJsonResponse().isMember("error") ==  false);

    c.SetRequest("{\"jsonrpc\":\"2.0\", \"id\": null, \"method\": \"sub\",\"params\":[5,7]}");
    CHECK(c.GetJsonResponse()["result"].asInt() == -2);
    CHECK(c.GetJsonResponse()["id"].isNull() ==  true);
    CHECK(c.GetJsonResponse()["jsonrpc"].asString() ==  "2.0");
    CHECK(c.GetJsonResponse().isMember("error") ==  false);

    c.SetRequest("{\"jsonrpc\":\"2.0\", \"id\": \"1\", \"method\": \"sub\",\"params\":[5,7]}");
    CHECK(c.GetJsonResponse()["result"].asInt() == -2);
    CHECK(c.GetJsonResponse()["id"].asString() ==  "1");
    CHECK(c.GetJsonResponse()["jsonrpc"].asString() ==  "2.0");
    CHECK(c.GetJsonResponse().isMember("error") ==  false);

    c.SetRequest("{\"jsonrpc\":\"2.0\", \"id\": 4294967295, \"method\": \"sub\",\"params\":[5,7]}");
    CHECK(c.GetJsonResponse()["result"].asInt() == -2);
    CHECK(c.GetJsonResponse()["id"].asLargestUInt() ==  (unsigned long)4294967295);
    CHECK(c.GetJsonResponse()["jsonrpc"].asString() ==  "2.0");
    CHECK(c.GetJsonResponse().isMember("error") ==  false);

}

{'fraction_non_alphanumeric': 0.32028767352400067, 'fraction_numerical': 0.027429336009366114, 'mean_word_length': 4.029436501261564, 'pattern_counts': {'":': 54, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3186642', 'n_tokens_mistral': 2055, 'n_tokens_neox': 1971, 'n_words': 267}