91 if (!strcmp(type,
"bucket")) {
93 }
else if (!strcmp(type,
"file")) {
137 info->name =
"bucket_scheme_register_unregister";
138 info->category =
"/main/bucket/";
139 info->summary =
"bucket scheme registration/unregistration unit test";
141 "Test registration and unregistration of bucket scheme";
166 info->name =
"bucket_alloc";
167 info->category =
"/main/bucket/";
168 info->summary =
"bucket allocation unit test";
170 "Test allocation of buckets";
192 if (strcmp(bucket->scheme,
"test")) {
207 info->name =
"bucket_create";
208 info->category =
"/main/bucket/";
209 info->summary =
"bucket creation unit test";
211 "Test creation of buckets";
251 info->name =
"bucket_clone";
252 info->category =
"/main/bucket/";
253 info->summary =
"bucket clone unit test";
255 "Test cloning a bucket";
282 ast_test_validate(
test, bucket->scheme_impl == clone->scheme_impl);
283 ast_test_validate(
test, strcmp(bucket->scheme, clone->scheme) == 0);
294 info->name =
"bucket_delete";
295 info->category =
"/main/bucket/";
296 info->summary =
"bucket deletion unit test";
298 "Test deletion of buckets";
337 info->name =
"bucket_is_stale";
338 info->category =
"/main/bucket/";
339 info->summary =
"bucket staleness unit test";
341 "Test if staleness of a bucket is reported correctly";
371 info->name =
"bucket_json";
372 info->category =
"/main/bucket/";
373 info->summary =
"bucket json unit test";
375 "Test creation of JSON for a bucket";
389 expected =
ast_json_pack(
"{s: s, s: s, s: [s], s: s, s: [s], s: s}",
390 "modified",
"0.000000",
"created",
"0.000000",
391 "buckets",
"test:///tmp/bob/joe",
393 "files",
"test:///tmp/bob/recording.wav",
394 "id",
"test:///tmp/bob");
420 info->name =
"bucket_retrieve";
421 info->category =
"/main/bucket/";
422 info->summary =
"bucket retrieval unit test";
424 "Test retrieval of buckets";
444 info->name =
"bucket_file_alloc";
445 info->category =
"/main/bucket/";
446 info->summary =
"bucket file allocation unit test";
448 "Test allocation of bucket files";
475 if (strcmp(
file->scheme,
"test")) {
490 info->name =
"bucket_file_create";
491 info->category =
"/main/bucket/";
492 info->summary =
"file creation unit test";
494 "Test creation of files";
534 info->name =
"bucket_file_clone";
535 info->category =
"/main/bucket/";
536 info->summary =
"file clone unit test";
538 "Test cloning a file";
566 ast_test_validate(
test,
file->scheme_impl == clone->scheme_impl);
567 ast_test_validate(
test, strcmp(
file->scheme, clone->scheme) == 0);
578 struct stat old, new;
583 info->name =
"bucket_file_copy";
584 info->category =
"/main/bucket/";
585 info->summary =
"bucket file copying unit test";
587 "Test copying of bucket files";
600 if (!(temporary = fopen(
file->path,
"w"))) {
605 fprintf(temporary,
"bob");
614 if (stat(
file->path, &old)) {
619 if (stat(
copy->path, &
new)) {
624 if (old.st_size !=
new.st_size) {
640 if (strcmp(metadata->value,
"joe")) {
654 info->name =
"bucket_file_retrieve";
655 info->category =
"/main/bucket/";
656 info->summary =
"file retrieval unit test";
658 "Test retrieval of files";
678 info->name =
"bucket_file_update";
679 info->category =
"/main/bucket/";
680 info->summary =
"file updating unit test";
682 "Test updating of files";
721 info->name =
"bucket_file_delete";
722 info->category =
"/main/bucket/";
723 info->summary =
"file deletion unit test";
725 "Test deletion of files";
764 info->name =
"bucket_file_is_stale";
765 info->category =
"/main/bucket/";
766 info->summary =
"file staleness unit test";
768 "Test if staleness of a bucket file is reported correctly";
797 info->name =
"bucket_file_metadata_set";
798 info->category =
"/main/bucket/";
799 info->summary =
"file metadata setting unit test";
801 "Test setting of metadata on files";
828 if (strcmp(metadata->value,
"joe")) {
847 if (strcmp(metadata->value,
"fred")) {
863 info->name =
"bucket_file_metadata_unset";
864 info->category =
"/main/bucket/";
865 info->summary =
"file metadata unsetting unit test";
867 "Test unsetting of metadata on files";
903 info->name =
"bucket_file_metadata_get";
904 info->category =
"/main/bucket/";
905 info->summary =
"file metadata getting unit test";
907 "Test getting of metadata on files";
928 if (strcmp(metadata->value,
"joe")) {
945 info->name =
"bucket_file_json";
946 info->category =
"/main/bucket/";
947 info->summary =
"file json unit test";
949 "Test creation of JSON for a file";
965 expected =
ast_json_pack(
"{s: s, s: s, s: s, s: s, s: {s :s}}",
966 "modified",
"0.000000",
"created",
"0.000000",
"scheme",
"test",
967 "id",
"test:///tmp/bob",
"metadata",
"bob",
"joe");
1014 ast_log(
LOG_ERROR,
"Failed to register Bucket test wizard scheme implementation\n");
struct ast_bucket_metadata * ast_bucket_file_metadata_get(struct ast_bucket_file *file, const char *name)
Retrieve a metadata attribute from a file.
struct ast_bucket * ast_bucket_alloc(const char *uri)
Allocate a new bucket.
static struct ast_sorcery_wizard bucket_file_test_wizard
int ast_bucket_create(struct ast_bucket *bucket)
Create a new bucket in backend storage.
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Asterisk main include file. File version handling, generic pbx functions.
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
int ast_bucket_file_metadata_set(struct ast_bucket_file *file, const char *name, const char *value)
Set a metadata attribute on a file to a specific value.
struct ast_bucket * ast_bucket_clone(struct ast_bucket *bucket)
Clone a bucket.
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Bucket structure, contains other buckets and files.
struct ast_bucket_file * ast_bucket_file_retrieve(const char *uri)
Retrieve a bucket file.
#define AST_TEST_REGISTER(cb)
Full structure for sorcery.
struct ast_bucket_file * ast_bucket_file_copy(struct ast_bucket_file *file, const char *uri)
Copy a bucket file to a new URI.
static int copy(char *infile, char *outfile)
Utility function to copy a file.
Generic File Format Support. Should be included by clients of the file handling routines. File service providers should instead include mod_format.h.
static int bucket_test_wizard_delete(const struct ast_sorcery *sorcery, void *data, void *object)
struct ast_bucket_file * ast_bucket_file_alloc(const char *uri)
Allocate a new bucket file.
const char * name
Name of the wizard.
unsigned int is_stale
Whether the object is stale or not.
static void * bucket_test_wizard_retrieve_id(const struct ast_sorcery *sorcery, void *data, const char *type, const char *id)
#define ast_strlen_zero(foo)
static int bucket_test_wizard_is_stale(const struct ast_sorcery *sorcery, void *data, void *object)
static int bucket_test_wizard_create(const struct ast_sorcery *sorcery, void *data, void *object)
static struct ast_sorcery_wizard bucket_test_wizard
unsigned int updated
Whether the object has been updated or not.
unsigned int created
Whether the object has been created or not.
static void * bucket_file_alloc(const char *name)
Allocator for bucket files.
Asterisk JSON abstraction layer.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
#define ast_test_status_update(a, b, c...)
struct ast_bucket_file * ast_bucket_file_clone(struct ast_bucket_file *file)
Clone a bucket file.
static int bucket_test_wizard_update(const struct ast_sorcery *sorcery, void *data, void *object)
int ast_bucket_file_delete(struct ast_bucket_file *file)
Delete a bucket file from backend storage.
struct ast_json * ast_bucket_file_json(const struct ast_bucket_file *file)
Get a JSON representation of a bucket file.
int ast_bucket_file_is_stale(struct ast_bucket_file *file)
Retrieve whether or not the backing datastore views the bucket file as stale.
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.
static int unload_module(void)
struct ast_bucket * ast_bucket_retrieve(const char *uri)
Retrieve information about a bucket.
#define AST_TEST_UNREGISTER(cb)
int ast_bucket_delete(struct ast_bucket *bucket)
Delete a bucket from backend storage.
static struct bucket_test_state bucket_test_wizard_state
Global scope structure for testing bucket wizards.
Module has failed to load, may be in an inconsistent state.
#define ao2_find(container, arg, flags)
int ast_bucket_file_temporary_create(struct ast_bucket_file *file)
Common file snapshot creation callback for creating a temporary file.
AST_TEST_DEFINE(bucket_scheme_register)
Support for logging to various files, console and syslog Configuration in file logger.conf.
Interface for a sorcery wizard.
Test state structure for scheme wizards.
static struct ast_sorcery * sorcery
int ast_bucket_file_update(struct ast_bucket_file *file)
Update an existing bucket file in backend storage.
int ast_json_equal(const struct ast_json *lhs, const struct ast_json *rhs)
Compare two JSON objects.
static void * bucket_alloc(const char *name)
Allocator for buckets.
#define ast_bucket_scheme_register(name, bucket, file, create_cb, destroy_cb)
Register support for a specific scheme.
int ast_bucket_file_metadata_unset(struct ast_bucket_file *file, const char *name)
Unset a specific metadata attribute on a file.
Abstract JSON element (object, array, string, int, ...).
struct ast_json * ast_bucket_json(const struct ast_bucket *bucket)
Get a JSON representation of a bucket.
void ast_bucket_file_temporary_destroy(struct ast_bucket_file *file)
Common file snapshot destruction callback for deleting a temporary file.
#define ASTERISK_GPL_KEY
The text the key() function should return.
int ast_bucket_is_stale(struct ast_bucket *bucket)
Retrieve whether or not the backing datastore views the bucket as stale.
Asterisk module definitions.
static int load_module(void)
unsigned int deleted
Whether the object has been deleted or not.
int ast_bucket_file_create(struct ast_bucket_file *file)
Create a new bucket file in backend storage.
int ast_str_container_add(struct ao2_container *str_container, const char *add)
Adds a string to a string container allocated by ast_str_container_alloc.
static void bucket_test_wizard_clear(void)