*/
static void response_free(struct stasis_http_response *resp)
{
+ if (!resp) {
+ return;
+ }
ast_free(resp->headers);
ast_json_unref(resp->message);
ast_free(resp);
invocation_count = 0;
r = stasis_http_add_handler(&test_root);
ast_assert(r == 0);
- return NULL;
+ return &invocation_count;
}
/*!
* Tear down test fixture for invocation tests.
*/
static void tear_down_invocation_test(void *ignore) {
+ if (!ignore) {
+ return;
+ }
stasis_http_remove_handler(&test_root);
}
AST_TEST_DEFINE(get_docs)
{
- RAII_VAR(struct stasis_http_response *, response, response_alloc(), response_free);
+ RAII_VAR(struct stasis_http_response *, response, NULL, response_free);
RAII_VAR(struct ast_variable *, headers, NULL, ast_variables_destroy);
struct ast_json *basePathJson;
const char *basePath;
break;
}
+ response = response_alloc();
headers = ast_variable_new("Host", "stasis.asterisk.org", __FILE__);
stasis_http_get_docs("resources.json", headers, response);
ast_test_validate(test, 200 == response->response_code);
AST_TEST_DEFINE(get_docs_nohost)
{
- RAII_VAR(struct stasis_http_response *, response, response_alloc(), response_free);
+ RAII_VAR(struct stasis_http_response *, response, NULL, response_free);
struct ast_variable *headers = NULL;
struct ast_json *basePathJson;
break;
}
+ response = response_alloc();
stasis_http_get_docs("resources.json", headers, response);
ast_test_validate(test, 200 == response->response_code);
AST_TEST_DEFINE(get_docs_notfound)
{
- RAII_VAR(struct stasis_http_response *, response, response_alloc(), response_free);
+ RAII_VAR(struct stasis_http_response *, response, NULL, response_free);
struct ast_variable *headers = NULL;
switch (cmd) {
break;
}
+ response = response_alloc();
stasis_http_get_docs("i-am-not-a-resource.json", headers, response);
ast_test_validate(test, 404 == response->response_code);
AST_TEST_DEFINE(get_docs_hackerz)
{
- RAII_VAR(struct stasis_http_response *, response, response_alloc(), response_free);
+ RAII_VAR(struct stasis_http_response *, response, NULL, response_free);
struct ast_variable *headers = NULL;
switch (cmd) {
break;
}
+ response = response_alloc();
stasis_http_get_docs("../../../../sbin/asterisk", headers, response);
ast_test_validate(test, 404 == response->response_code);
AST_TEST_DEFINE(invoke_get)
{
- RAII_VAR(void *, fixture, setup_invocation_test(), tear_down_invocation_test);
- RAII_VAR(struct stasis_http_response *, response, response_alloc(), response_free);
+ RAII_VAR(void *, fixture, NULL, tear_down_invocation_test);
+ RAII_VAR(struct stasis_http_response *, response, NULL, response_free);
RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
struct ast_variable *get_params = NULL;
struct ast_variable *headers = NULL;
break;
}
+ fixture = setup_invocation_test();
+ response = response_alloc();
get_params = ast_variable_new("get1", "get-one", __FILE__);
ast_assert(get_params != NULL);
get_params->next = ast_variable_new("get2", "get-two", __FILE__);
AST_TEST_DEFINE(invoke_wildcard)
{
- RAII_VAR(void *, fixture, setup_invocation_test(), tear_down_invocation_test);
- RAII_VAR(struct stasis_http_response *, response, response_alloc(), response_free);
+ RAII_VAR(void *, fixture, NULL, tear_down_invocation_test);
+ RAII_VAR(struct stasis_http_response *, response, NULL, response_free);
RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
struct ast_variable *get_params = NULL;
struct ast_variable *headers = NULL;
break;
}
+ fixture = setup_invocation_test();
+ response = response_alloc();
expected = ast_json_pack("{s: s, s: {}, s: {}, s: {s: s}}",
"name", "bam_get",
"get_params",
AST_TEST_DEFINE(invoke_delete)
{
- RAII_VAR(void *, fixture, setup_invocation_test(), tear_down_invocation_test);
- RAII_VAR(struct stasis_http_response *, response, response_alloc(), response_free);
+ RAII_VAR(void *, fixture, NULL, tear_down_invocation_test);
+ RAII_VAR(struct stasis_http_response *, response, NULL, response_free);
RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
struct ast_variable *get_params = NULL;
struct ast_variable *headers = NULL;
break;
}
+ fixture = setup_invocation_test();
+ response = response_alloc();
expected = ast_json_pack("{s: s, s: {}, s: {}, s: {s: s}}",
"name", "bang_delete",
"get_params",
AST_TEST_DEFINE(invoke_post)
{
- RAII_VAR(void *, fixture, setup_invocation_test(), tear_down_invocation_test);
- RAII_VAR(struct stasis_http_response *, response, response_alloc(), response_free);
+ RAII_VAR(void *, fixture, NULL, tear_down_invocation_test);
+ RAII_VAR(struct stasis_http_response *, response, NULL, response_free);
RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
struct ast_variable *get_params = NULL;
struct ast_variable *headers = NULL;
break;
}
+ fixture = setup_invocation_test();
+ response = response_alloc();
get_params = ast_variable_new("get1", "get-one", __FILE__);
ast_assert(get_params != NULL);
get_params->next = ast_variable_new("get2", "get-two", __FILE__);
AST_TEST_DEFINE(invoke_bad_post)
{
- RAII_VAR(void *, fixture, setup_invocation_test(), tear_down_invocation_test);
- RAII_VAR(struct stasis_http_response *, response, response_alloc(), response_free);
+ RAII_VAR(void *, fixture, NULL, tear_down_invocation_test);
+ RAII_VAR(struct stasis_http_response *, response, NULL, response_free);
struct ast_variable *get_params = NULL;
struct ast_variable *headers = NULL;
break;
}
+ fixture = setup_invocation_test();
+ response = response_alloc();
stasis_http_invoke("foo", AST_HTTP_POST, get_params, headers, response);
ast_test_validate(test, 0 == invocation_count);
AST_TEST_DEFINE(invoke_not_found)
{
- RAII_VAR(void *, fixture, setup_invocation_test(), tear_down_invocation_test);
- RAII_VAR(struct stasis_http_response *, response, response_alloc(), response_free);
+ RAII_VAR(void *, fixture, NULL, tear_down_invocation_test);
+ RAII_VAR(struct stasis_http_response *, response, NULL, response_free);
struct ast_variable *get_params = NULL;
struct ast_variable *headers = NULL;
break;
}
+ fixture = setup_invocation_test();
+ response = response_alloc();
stasis_http_invoke("foo/fizzle/i-am-not-a-resource", AST_HTTP_GET, get_params, headers, response);
ast_test_validate(test, 0 == invocation_count);