BOOST_FIXTURE_TEST_CASE(add_method_twice, F) { const char path[] = "/foo/bar"; cJSON *error = add_state_or_method_to_peer(&owner_peer, path, NULL, 0x00, CONFIG_ROUTED_MESSAGES_TIMEOUT); BOOST_CHECK(error == NULL); error = add_state_or_method_to_peer(&owner_peer, path, NULL, 0x00, CONFIG_ROUTED_MESSAGES_TIMEOUT); BOOST_REQUIRE(error != NULL); check_invalid_params(error); cJSON_Delete(error); }
BOOST_FIXTURE_TEST_CASE(add_method_existing_state, F) { const char path[] = "/foo/bar"; int state_value = 12345; cJSON *value = cJSON_CreateNumber(state_value); cJSON *error = add_state_or_method_to_peer(&owner_peer, path, value, 0x00, CONFIG_ROUTED_MESSAGES_TIMEOUT); BOOST_CHECK(error == NULL); cJSON_Delete(value); error = add_state_or_method_to_peer(&owner_peer, path, NULL, 0x00, CONFIG_ROUTED_MESSAGES_TIMEOUT); BOOST_REQUIRE(error != NULL); check_invalid_params(error); cJSON_Delete(error); }
BOOST_FIXTURE_TEST_CASE(set_wrong_id_type, F) { cJSON *error = add_state_or_method_to_peer(&owner_peer, method_no_args_path, NULL, 0x00, CONFIG_ROUTED_MESSAGES_TIMEOUT); BOOST_CHECK(error == NULL); cJSON *call_json_rpc = create_call_json_rpc_wrong_id_type(method_no_args_path); error = set_or_call(&call_peer, method_no_args_path, NULL, NULL, call_json_rpc, METHOD); cJSON_Delete(call_json_rpc); if ((error != NULL) && (error != (cJSON *)ROUTED_MESSAGE)) { check_invalid_params(error); cJSON_Delete(error); } else { BOOST_FAIL("expected to get an error!"); } }
BOOST_FIXTURE_TEST_CASE(add_method_existing_state, F) { const char path[] = "/foo/bar"; cJSON *request = create_add(path); cJSON *response = add_element_to_peer(&owner_peer, request); BOOST_REQUIRE_MESSAGE(response != NULL, "add_element_to_peer() had no response!"); BOOST_CHECK_MESSAGE(!response_is_error(response), "add_element_to_peer() failed!"); cJSON_Delete(response); response = add_element_to_peer(&owner_peer, request); BOOST_REQUIRE_MESSAGE(response != NULL, "add_element_to_peer() had no response!"); check_invalid_params(response); cJSON_Delete(response); cJSON_Delete(request); }
BOOST_FIXTURE_TEST_CASE(call_wrong_path, F) { const char path[] = "/foo/bar/"; cJSON *request = create_add(path); cJSON *response = add_element_to_peer(&owner_peer, request); BOOST_REQUIRE_MESSAGE(response != NULL, "add_element_to_peer() had no response!"); BOOST_CHECK_MESSAGE(!response_is_error(response), "add_element_to_peer() failed!"); cJSON_Delete(response); cJSON *call_json_rpc = create_call_json_rpc(method_no_args_path); response = set_or_call(&owner_peer, call_json_rpc, METHOD); cJSON_Delete(call_json_rpc); BOOST_REQUIRE_MESSAGE(response != NULL, "set_or_call() had no response!"); check_invalid_params(response); cJSON_Delete(response); cJSON_Delete(request); }
BOOST_FIXTURE_TEST_CASE(call_on_state, F) { const char path[] = "/foo/bar"; int state_value = 12345; cJSON *value = cJSON_CreateNumber(state_value); cJSON *error = add_state_or_method_to_peer(&owner_peer, path, value, 0x00, CONFIG_ROUTED_MESSAGES_TIMEOUT); BOOST_CHECK(error == NULL); cJSON_Delete(value); cJSON *call_json_rpc = create_call_json_rpc(method_no_args_path); error = set_or_call(&call_peer, path, NULL, NULL, call_json_rpc, METHOD); cJSON_Delete(call_json_rpc); if (error != NULL) { check_invalid_params(error); cJSON_Delete(error); } else { BOOST_FAIL("expected to get an error!"); } }