| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
#include "asterisk.h" |
| 34 |
|
| 35 |
#include "asterisk/astobj2.h" |
| 36 |
#include "asterisk/endpoints.h" |
| 37 |
#include "asterisk/module.h" |
| 38 |
#include "asterisk/stasis_endpoints.h" |
| 39 |
#include "asterisk/test.h" |
| 40 |
|
| 41 |
static const char *test_category = "/core/endpoints/"; |
| 42 |
|
| 43 |
AST_TEST_DEFINE(create) |
| 44 |
{ |
| 45 |
RAII_VAR(struct ast_endpoint *, uut, NULL, ast_endpoint_shutdown); |
| 46 |
|
| 47 |
switch (cmd) { |
| 48 |
case TEST_INIT: |
| 49 |
info->name = __func__; |
| 50 |
info->category = test_category; |
| 51 |
info->summary = "Test endpoint creation"; |
| 52 |
info->description = "Test endpoint creation"; |
| 53 |
return AST_TEST_NOT_RUN; |
| 54 |
case TEST_EXECUTE: |
| 55 |
break; |
| 56 |
} |
| 57 |
|
| 58 |
ast_test_validate(test, NULL == ast_endpoint_create(NULL, NULL)); |
| 59 |
ast_test_validate(test, NULL == ast_endpoint_create("", "")); |
| 60 |
ast_test_validate(test, NULL == ast_endpoint_create("TEST", "")); |
| 61 |
ast_test_validate(test, NULL == ast_endpoint_create("", "test_res")); |
| 62 |
|
| 63 |
uut = ast_endpoint_create("TEST", "test_res"); |
| 64 |
ast_test_validate(test, NULL != uut); |
| 65 |
|
| 66 |
ast_test_validate(test, |
| 67 |
0 == strcmp("TEST", ast_endpoint_get_tech(uut))); |
| 68 |
ast_test_validate(test, |
| 69 |
0 == strcmp("test_res", ast_endpoint_get_resource(uut))); |
| 70 |
|
| 71 |
return AST_TEST_PASS; |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
AST_TEST_DEFINE(defaults) |
| 76 |
{ |
| 77 |
RAII_VAR(struct ast_endpoint *, uut, NULL, ast_endpoint_shutdown); |
| 78 |
RAII_VAR(struct ast_endpoint_snapshot *, snapshot, NULL, ao2_cleanup); |
| 79 |
|
| 80 |
switch (cmd) { |
| 81 |
case TEST_INIT: |
| 82 |
info->name = __func__; |
| 83 |
info->category = test_category; |
| 84 |
info->summary = "Test defaults for new endpoints"; |
| 85 |
info->description = "Test defaults for new endpoints"; |
| 86 |
return AST_TEST_NOT_RUN; |
| 87 |
case TEST_EXECUTE: |
| 88 |
break; |
| 89 |
} |
| 90 |
|
| 91 |
uut = ast_endpoint_create("TEST", "test_res"); |
| 92 |
ast_test_validate(test, NULL != uut); |
| 93 |
snapshot = ast_endpoint_snapshot_create(uut); |
| 94 |
ast_test_validate(test, NULL != snapshot); |
| 95 |
|
| 96 |
ast_test_validate(test, 0 == strcmp("TEST/test_res", snapshot->id)); |
| 97 |
ast_test_validate(test, 0 == strcmp("TEST", snapshot->tech)); |
| 98 |
ast_test_validate(test, 0 == strcmp("test_res", snapshot->resource)); |
| 99 |
ast_test_validate(test, AST_ENDPOINT_UNKNOWN == snapshot->state); |
| 100 |
ast_test_validate(test, -1 == snapshot->max_channels); |
| 101 |
ast_test_validate(test, 0 == snapshot->num_channels); |
| 102 |
|
| 103 |
return AST_TEST_PASS; |
| 104 |
} |
| 105 |
|
| 106 |
AST_TEST_DEFINE(setters) |
| 107 |
{ |
| 108 |
RAII_VAR(struct ast_endpoint *, uut, NULL, ast_endpoint_shutdown); |
| 109 |
RAII_VAR(struct ast_endpoint_snapshot *, snapshot, NULL, ao2_cleanup); |
| 110 |
|
| 111 |
switch (cmd) { |
| 112 |
case TEST_INIT: |
| 113 |
info->name = __func__; |
| 114 |
info->category = test_category; |
| 115 |
info->summary = "Test endpoint setters"; |
| 116 |
info->description = "Test endpoint setters"; |
| 117 |
return AST_TEST_NOT_RUN; |
| 118 |
case TEST_EXECUTE: |
| 119 |
break; |
| 120 |
} |
| 121 |
|
| 122 |
uut = ast_endpoint_create("TEST", "test_res"); |
| 123 |
ast_test_validate(test, NULL != uut); |
| 124 |
|
| 125 |
ast_endpoint_set_state(uut, AST_ENDPOINT_ONLINE); |
| 126 |
ast_endpoint_set_max_channels(uut, 314159); |
| 127 |
|
| 128 |
snapshot = ast_endpoint_snapshot_create(uut); |
| 129 |
ast_test_validate(test, NULL != snapshot); |
| 130 |
|
| 131 |
ast_test_validate(test, AST_ENDPOINT_ONLINE == snapshot->state); |
| 132 |
ast_test_validate(test, 314159 == snapshot->max_channels); |
| 133 |
|
| 134 |
return AST_TEST_PASS; |
| 135 |
} |
| 136 |
|
| 137 |
static int unload_module(void) |
| 138 |
{ |
| 139 |
AST_TEST_UNREGISTER(create); |
| 140 |
AST_TEST_UNREGISTER(defaults); |
| 141 |
AST_TEST_UNREGISTER(setters); |
| 142 |
return 0; |
| 143 |
} |
| 144 |
|
| 145 |
static int load_module(void) |
| 146 |
{ |
| 147 |
AST_TEST_REGISTER(create); |
| 148 |
AST_TEST_REGISTER(defaults); |
| 149 |
AST_TEST_REGISTER(setters); |
| 150 |
return AST_MODULE_LOAD_SUCCESS; |
| 151 |
} |
| 152 |
|
| 153 |
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Endpoint testing", |
| 154 |
.support_level = AST_MODULE_SUPPORT_CORE, |
| 155 |
.load = load_module, |
| 156 |
.unload = unload_module, |
| 157 |
); |