42 #define CATEGORY "/main/media_cache/"
45 #define VALID_RESOURCE "httptest://localhost:8088/test_media_cache/monkeys.wav"
48 #define INVALID_RESOURCE "httptest://localhost:8088/test_media_cache/bad.wav"
51 #define INVALID_SCHEME "foo://localhost:8088/test_media_cache/monkeys.wav"
54 #define NO_SCHEME "localhost:8088/test_media_cache/monkeys.wav"
60 static int bucket_http_test_wizard_create(
const struct ast_sorcery *sorcery,
void *data,
74 static int bucket_http_test_wizard_update(
const struct ast_sorcery *sorcery,
void *data,
88 static void *bucket_http_test_wizard_retrieve_id(
const struct ast_sorcery *sorcery,
89 void *data,
const char *type,
const char *
id)
109 static int bucket_http_test_wizard_delete(
const struct ast_sorcery *sorcery,
void *data,
121 .create = bucket_http_test_wizard_create,
122 .retrieve_id = bucket_http_test_wizard_retrieve_id,
123 .delete = bucket_http_test_wizard_delete,
128 .create = bucket_http_test_wizard_create,
129 .update = bucket_http_test_wizard_update,
130 .retrieve_id = bucket_http_test_wizard_retrieve_id,
131 .delete = bucket_http_test_wizard_delete,
140 info->name = __func__;
142 info->summary =
"Test nominal existance of resources in the cache";
144 "This test verifies that if a known resource is in the cache, "
145 "calling ast_media_cache_exists will return logical True. If "
146 "a resource does not exist, the same function call will return "
148 return AST_TEST_NOT_RUN;
154 ast_test_validate(
test, res == 0);
157 ast_test_validate(
test, res == 1);
159 return AST_TEST_PASS;
168 info->name = __func__;
170 info->summary =
"Test off nominal existance of resources in the cache";
172 "This test verifies that checking for bad resources (NULL, bad "
173 "scheme, etc.) does not result in false positives.";
174 return AST_TEST_NOT_RUN;
180 ast_test_validate(
test, res != 1);
183 ast_test_validate(
test, res != 1);
186 ast_test_validate(
test, res != 1);
189 ast_test_validate(
test, res != 1);
191 return AST_TEST_PASS;
197 char file_path[PATH_MAX];
198 char tmp_path_one[PATH_MAX] =
"/tmp/test-media-cache-XXXXXX";
199 char tmp_path_two[PATH_MAX] =
"/tmp/test-media-cache-XXXXXX";
204 info->name = __func__;
206 info->summary =
"Test nominal creation/updating of a resource";
208 "This test creates a resource and associates it with a file. "
209 "It then updates the resource with a new file. In both cases, "
210 "the test verifies that the resource is associated with the "
212 return AST_TEST_NOT_RUN;
218 fd = mkstemp(tmp_path_one);
220 ast_test_status_update(
test,
"Failed to create first tmp file: %s\n",
222 return AST_TEST_FAIL;
227 fd = mkstemp(tmp_path_two);
229 ast_test_status_update(
test,
"Failed to create second tmp file: %s\n",
231 return AST_TEST_FAIL;
235 ast_test_status_update(
test,
"Creating resource with %s\n", tmp_path_one);
237 ast_test_validate(
test, res == 0);
240 ast_test_status_update(
test,
"Got %s for first file path\n", file_path);
241 ast_test_validate(
test, res == 0);
242 ast_test_validate(
test, strcmp(file_path, tmp_path_one) == 0);
244 ast_test_status_update(
test,
"Creating resource with %s\n", tmp_path_two);
246 ast_test_validate(
test, res == 0);
249 ast_test_status_update(
test,
"Got %s for second file path\n", file_path);
250 ast_test_validate(
test, res == 0);
251 ast_test_validate(
test, strcmp(file_path, tmp_path_two) == 0);
253 unlink(tmp_path_one);
254 unlink(tmp_path_two);
256 return AST_TEST_PASS;
262 char tmp_path[PATH_MAX] =
"/tmp/test-media-cache-XXXXXX";
267 info->name = __func__;
269 info->summary =
"Test off nominal creation/updating of a resource";
271 "Test creation/updating of a resource with a variety of invalid\n"
273 return AST_TEST_NOT_RUN;
279 fd = mkstemp(tmp_path);
281 ast_test_status_update(
test,
"Failed to create first tmp file: %s\n",
283 return AST_TEST_FAIL;
289 ast_test_validate(
test, res != 0);
292 ast_test_validate(
test, res != 0);
295 ast_test_validate(
test, res != 0);
298 ast_test_validate(
test, res != 0);
301 ast_test_validate(
test, res != 0);
304 ast_test_validate(
test, res != 0);
308 return AST_TEST_PASS;
314 char tmp_path[PATH_MAX] =
"/tmp/test-media-cache-XXXXXX";
315 char file_path[PATH_MAX];
316 char actual_metadata[32];
323 info->name = __func__;
325 info->summary =
"Test nominal creation/updating of a resource";
327 "This test creates a resource and associates it with a file. "
328 "It then updates the resource with a new file. In both cases, "
329 "the test verifies that the resource is associated with the "
331 return AST_TEST_NOT_RUN;
337 fd = mkstemp(tmp_path);
339 ast_test_status_update(
test,
"Failed to create first tmp file: %s\n",
341 return AST_TEST_FAIL;
346 tmp = ast_variable_new(
"meta1",
"value1", __FILE__);
348 ast_test_status_update(
test,
"Failed to create metadata 1 for test\n");
349 return AST_TEST_FAIL;
351 ast_variable_list_append(&meta_list, tmp);
353 tmp = ast_variable_new(
"meta2",
"value2", __FILE__);
355 ast_test_status_update(
test,
"Failed to create metadata 2 for test\n");
356 return AST_TEST_FAIL;
358 ast_variable_list_append(&meta_list, tmp);
361 ast_test_validate(
test, res == 0);
364 ast_test_status_update(
test,
"Got %s for second file path\n", file_path);
365 ast_test_validate(
test, res == 0);
366 ast_test_validate(
test, strcmp(file_path, tmp_path) == 0);
369 actual_metadata,
sizeof(actual_metadata));
370 ast_test_validate(
test, res == 0);
371 ast_test_validate(
test, strcmp(actual_metadata,
"value1") == 0);
374 actual_metadata,
sizeof(actual_metadata));
375 ast_test_validate(
test, res == 0);
376 ast_test_validate(
test, strcmp(actual_metadata,
"value2") == 0);
380 return AST_TEST_PASS;
383 static int unload_module(
void)
385 AST_TEST_UNREGISTER(exists_nominal);
386 AST_TEST_UNREGISTER(exists_off_nominal);
388 AST_TEST_UNREGISTER(create_update_nominal);
389 AST_TEST_UNREGISTER(create_update_metadata);
390 AST_TEST_UNREGISTER(create_update_off_nominal);
395 static int load_module(
void)
398 &bucket_file_test_wizard, NULL, NULL)) {
399 ast_log(LOG_ERROR,
"Failed to register Bucket HTTP test wizard scheme implementation\n");
403 AST_TEST_REGISTER(exists_nominal);
404 AST_TEST_REGISTER(exists_off_nominal);
406 AST_TEST_REGISTER(create_update_nominal);
407 AST_TEST_REGISTER(create_update_metadata);
408 AST_TEST_REGISTER(create_update_off_nominal);
Asterisk main include file. File version handling, generic pbx functions.
Structure for variables, used for configurations and for channel variables.
Full structure for sorcery.
struct ast_bucket_file * ast_bucket_file_alloc(const char *uri)
Allocate a new bucket file.
const char * name
Name of the wizard.
void(* close)(void *data)
Callback for closing a wizard.
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Bucket file structure, contains reference to file and information about it.
Module has failed to load, may be in an inconsistent state.
int ast_bucket_file_temporary_create(struct ast_bucket_file *file)
Common file snapshot creation callback for creating a temporary file.
Interface for a sorcery wizard.
#define ast_bucket_scheme_register(name, bucket, file, create_cb, destroy_cb)
Register support for a specific scheme.
#define AST_TEST_DEFINE(hdr)
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.