Author: file
Date: Sun Aug  4 18:44:30 2013
New Revision: 396165

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=396165
Log:
Address some of the review feedback. Lots to go, though!

Modified:
    team/file/bucket/include/asterisk/bucket.h
    team/file/bucket/main/bucket.c
    team/file/bucket/main/sorcery.c
    team/file/bucket/tests/test_bucket.c

Modified: team/file/bucket/include/asterisk/bucket.h
URL: 
http://svnview.digium.com/svn/asterisk/team/file/bucket/include/asterisk/bucket.h?view=diff&rev=396165&r1=396164&r2=396165
==============================================================================
--- team/file/bucket/include/asterisk/bucket.h (original)
+++ team/file/bucket/include/asterisk/bucket.h Sun Aug  4 18:44:30 2013
@@ -45,7 +45,7 @@
        const char *name;
        /*! \brief Value of the attribute */
        const char *value;
-       /*! \brief Actual blob of data */
+       /*! \brief Storage for the above name and value */
        char data[0];
 };
 
@@ -55,8 +55,8 @@
        SORCERY_OBJECT(details);
        /*! \brief Stringfields */
        AST_DECLARE_STRING_FIELDS(
-               /*! \brief Full URI to the bucket */
-               AST_STRING_FIELD(uri);
+               /*! \brief Name of the bucket */
+               AST_STRING_FIELD(name);
                /*! \brief Scheme in use */
                AST_STRING_FIELD(scheme);
        );
@@ -76,8 +76,8 @@
        SORCERY_OBJECT(details);
        /*! \brief Stringfields */
        AST_DECLARE_STRING_FIELDS(
-               /*! \brief Full URI to the bucket */
-               AST_STRING_FIELD(uri);
+               /*! \brief Name of the file */
+               AST_STRING_FIELD(name);
                /*! \brief Scheme in use */
                AST_STRING_FIELD(scheme);
        );
@@ -108,6 +108,8 @@
  *
  * \retval 0 success
  * \retval -1 failure
+ *
+ * \note Once a scheme has been registered it can not be unregistered
  */
 #define ast_bucket_scheme_register(name, bucket, file) 
__ast_bucket_scheme_register(name, bucket, file, ast_module_info ? 
ast_module_info->self : NULL)
 
@@ -121,21 +123,13 @@
  *
  * \retval 0 success
  * \retval -1 failure
+ *
+ * \note Once a scheme has been registered it can not be unregistered
  */
 int __ast_bucket_scheme_register(const char *name, struct ast_sorcery_wizard 
*bucket,
        struct ast_sorcery_wizard *file, struct ast_module *module);
 
 /*!
- * \brief Unregister support for a specific scheme
- *
- * \param name Name of the scheme
- *
- * \retval 0 success
- * \retval -1 failure
- */
-int ast_bucket_scheme_unregister(const char *name);
-
-/*!
  * \brief Set a metadata attribute on a file to a specific value
  *
  * \param file The bucket file
@@ -264,20 +258,6 @@
 struct ast_bucket_file *ast_bucket_file_alloc(const char *uri);
 
 /*!
- * \brief Allocate a new temporary local bucket file
- *
- * \param uri Complete URI for the bucket file
- *
- * \param non-NULL success
- * \param NULL failure
- *
- * \note To persist the temporary file in backend storage you must call 
ast_bucket_file_create
- *
- * \note Path will automatically be filled with a local temporary file that is 
deleted upon destruction
- */
-struct ast_bucket_file *ast_bucket_file_temporary_alloc(const char *uri);
-
-/*!
  * \brief Create a new bucket file in backend storage
  *
  * \param file The bucket file
@@ -296,39 +276,21 @@
  * \retval non-NULL success
  * \retval NULL failure
  *
- * \note This does not create the new file in backend storage, you must call 
ast_bucket_file_create
- * on the resulting file to do so
+ * \note This operation stages things locally, you must call 
ast_bucket_file_create on the file
+ * that is returned to commit the copy to backend storage
  *
  */
 struct ast_bucket_file *ast_bucket_file_copy(struct ast_bucket_file *file, 
const char *uri);
 
 /*!
- * \brief Move a bucket file to a new URI
- *
- * \param file The source bucket file
- * \param uri The new URI
- *
- * \retval non-NULL success
- * \retval NULL failure
- *
- * \note This does not create the new file in backend storage, you must call 
ast_bucket_file_create
- * on the resulting file to do so
- *
- * \note This does not delete the old file in backend storage, you must call 
ast_bucket_file_delete
- * on the source file to do so
- *
- * \note The source file is left in an undefined state, the only safe 
operation to call is
- * ast_bucket_file_delete
- */
-struct ast_bucket_file *ast_bucket_file_move(struct ast_bucket_file *file, 
const char *uri);
-
-/*!
  * \brief Update an existing bucket file in backend storage
  *
  * \param file The bucket file
  *
  * \retval 0 success
  * \retval -1 failure
+ *
+ * \note This operation will update both the actual content of the file and 
the metadata associated with it
  */
 int ast_bucket_file_update(struct ast_bucket_file *file);
 

Modified: team/file/bucket/main/bucket.c
URL: 
http://svnview.digium.com/svn/asterisk/team/file/bucket/main/bucket.c?view=diff&rev=396165&r1=396164&r2=396165
==============================================================================
--- team/file/bucket/main/bucket.c (original)
+++ team/file/bucket/main/bucket.c Sun Aug  4 18:44:30 2013
@@ -68,8 +68,6 @@
        struct ast_sorcery_wizard *bucket;
        /*! \brief Wizard for files */
        struct ast_sorcery_wizard *file;
-       /*! \brief Module which implements this scheme */
-       struct ast_module *module;
        /*! \brief Name of the scheme */
        char name[0];
 };
@@ -116,26 +114,16 @@
        return 0;
 }
 
-/*! \brief Helper function which increases reference count of a module and 
returns it */
-static struct ast_module *module_ref(struct ast_module *module)
-{
-       ast_module_ref(module);
-       return module;
-}
-
 /*! \brief Callback function for creating a bucket */
 static int bucket_wizard_create(const struct ast_sorcery *sorcery, void *data, 
void *object)
 {
        struct ast_bucket *bucket = object;
        SCOPED_AO2RDLOCK(lock, schemes);
        RAII_VAR(struct bucket_scheme *, scheme, ao2_find(schemes, 
bucket->scheme, OBJ_KEY | OBJ_NOLOCK), ao2_cleanup);
-       RAII_VAR(struct ast_module *, module, NULL, ast_module_unref);
 
        if (!scheme) {
                return -1;
        }
-
-       module = module_ref(scheme->module);
 
        return scheme->bucket->create(sorcery, data, object);
 }
@@ -147,7 +135,6 @@
        char *uri, *uri_scheme, *uri_name;
        SCOPED_AO2RDLOCK(lock, schemes);
        RAII_VAR(struct bucket_scheme *, scheme, NULL, ao2_cleanup);
-       RAII_VAR(struct ast_module *, module, NULL, ast_module_unref);
 
        if (!(uri = ast_strdupa(id))) {
                return NULL;
@@ -162,8 +149,6 @@
        if (!scheme) {
                return NULL;
        }
-
-       module = module_ref(scheme->module);
 
        return scheme->bucket->retrieve_id(sorcery, data, type, id);
 }
@@ -174,13 +159,10 @@
        struct ast_bucket *bucket = object;
        SCOPED_AO2RDLOCK(lock, schemes);
        RAII_VAR(struct bucket_scheme *, scheme, ao2_find(schemes, 
bucket->scheme, OBJ_KEY | OBJ_NOLOCK), ao2_cleanup);
-       RAII_VAR(struct ast_module *, module, NULL, ast_module_unref);
 
        if (!scheme) {
                return -1;
        }
-
-       module = module_ref(scheme->module);
 
        return scheme->bucket->delete(sorcery, data, object);
 }
@@ -199,13 +181,10 @@
        struct ast_bucket_file *file = object;
        SCOPED_AO2RDLOCK(lock, schemes);
        RAII_VAR(struct bucket_scheme *, scheme, ao2_find(schemes, 
file->scheme, OBJ_KEY | OBJ_NOLOCK), ao2_cleanup);
-       RAII_VAR(struct ast_module *, module, NULL, ast_module_unref);
 
        if (!scheme) {
                return -1;
        }
-
-       module = module_ref(scheme->module);
 
        return scheme->file->create(sorcery, data, object);
 }
@@ -217,7 +196,6 @@
        char *uri, *uri_scheme, *uri_name;
        SCOPED_AO2RDLOCK(lock, schemes);
        RAII_VAR(struct bucket_scheme *, scheme, NULL, ao2_cleanup);
-       RAII_VAR(struct ast_module *, module, NULL, ast_module_unref);
 
        if (!(uri = ast_strdupa(id))) {
                return NULL;
@@ -232,8 +210,6 @@
        if (!scheme) {
                return NULL;
        }
-
-       module = module_ref(scheme->module);
 
        return scheme->file->retrieve_id(sorcery, data, type, id);
 }
@@ -244,13 +220,10 @@
        struct ast_bucket_file *file = object;
        SCOPED_AO2RDLOCK(lock, schemes);
        RAII_VAR(struct bucket_scheme *, scheme, ao2_find(schemes, 
file->scheme, OBJ_KEY | OBJ_NOLOCK), ao2_cleanup);
-       RAII_VAR(struct ast_module *, module, NULL, ast_module_unref);
 
        if (!scheme) {
                return -1;
        }
-
-       module = module_ref(scheme->module);
 
        return scheme->file->update(sorcery, data, object);
 }
@@ -261,13 +234,10 @@
        struct ast_bucket_file *file = object;
        SCOPED_AO2RDLOCK(lock, schemes);
        RAII_VAR(struct bucket_scheme *, scheme, ao2_find(schemes, 
file->scheme, OBJ_KEY), ao2_cleanup);
-       RAII_VAR(struct ast_module *, module, NULL, ast_module_unref);
 
        if (!scheme) {
                return -1;
        }
-
-       module = module_ref(scheme->module);
 
        return scheme->file->delete(sorcery, data, object);
 }
@@ -302,7 +272,6 @@
                return -1;
        }
 
-       scheme->module = module;
        strcpy(scheme->name, name);
        scheme->bucket = bucket;
        scheme->file = file;
@@ -311,21 +280,7 @@
 
        ast_verb(2, "Registered bucket scheme '%s'\n", name);
 
-       return 0;
-}
-
-int ast_bucket_scheme_unregister(const char *name)
-{
-       SCOPED_AO2WRLOCK(lock, schemes);
-       struct bucket_scheme *scheme;
-
-       scheme = ao2_find(schemes, name, OBJ_KEY | OBJ_NOLOCK | OBJ_UNLINK);
-       if (!scheme) {
-               return -1;
-       }
-       ao2_ref(scheme, -1);
-
-       ast_verb(2, "Unregistered bucket scheme '%s'\n", name);
+       ast_module_ref(module);
 
        return 0;
 }
@@ -351,7 +306,7 @@
 
 int ast_bucket_file_metadata_set(struct ast_bucket_file *file, const char 
*name, const char *value)
 {
-       struct ast_bucket_metadata *metadata = bucket_metadata_alloc(name, 
value);
+       RAII_VAR(struct ast_bucket_metadata *, metadata, 
bucket_metadata_alloc(name, value), ao2_cleanup);
 
        if (!metadata) {
                return -1;
@@ -359,20 +314,18 @@
 
        ao2_find(file->metadata, name, OBJ_NODATA | OBJ_UNLINK | OBJ_KEY);
        ao2_link(file->metadata, metadata);
-       ao2_ref(metadata, -1);
 
        return 0;
 }
 
 int ast_bucket_file_metadata_unset(struct ast_bucket_file *file, const char 
*name)
 {
-       struct ast_bucket_metadata *metadata = ao2_find(file->metadata, name, 
OBJ_UNLINK | OBJ_KEY);
+       RAII_VAR(struct ast_bucket_metadata *, metadata, 
ao2_find(file->metadata, name, OBJ_UNLINK | OBJ_KEY), ao2_cleanup);
 
        if (!metadata) {
                return -1;
        }
 
-       ao2_ref(metadata, -1);
        return 0;
 }
 
@@ -433,11 +386,11 @@
                return NULL;
        }
 
-       if (!(bucket = ast_sorcery_alloc(bucket_sorcery, "bucket", uri_name))) {
-               return NULL;
-       }
-
-       ast_string_field_set(bucket, uri, uri);
+       if (!(bucket = ast_sorcery_alloc(bucket_sorcery, "bucket", uri))) {
+               return NULL;
+       }
+
+       ast_string_field_set(bucket, name, uri_name);
        ast_string_field_set(bucket, scheme, uri_scheme);
 
        return bucket;
@@ -607,6 +560,7 @@
 {
        char *full_uri, *uri_scheme, *uri_name;
        struct ast_bucket_file *file;
+       int fd;
 
        if (!(full_uri = ast_strdupa(uri))) {
                return NULL;
@@ -617,14 +571,18 @@
                return NULL;
        }
 
-       if (!(file = ast_sorcery_alloc(bucket_sorcery, "file", uri_name))) {
-               return NULL;
-       }
-
-       ast_string_field_set(file, uri, uri);
+       if (!(file = ast_sorcery_alloc(bucket_sorcery, "file", uri))) {
+               return NULL;
+       }
+
+       ast_string_field_set(file, name, uri_name);
        ast_string_field_set(file, scheme, uri_scheme);
 
-       if (!tmpnam(file->path)) {
+       snprintf(file->path, sizeof(file->path), "/tmp/bucket-file-XXXXXX");
+
+       fd = mkstemp(file->path);
+       if (fd == -1) {
+               ao2_cleanup(file);
                return NULL;
        }
 
@@ -698,28 +656,6 @@
        return copy;
 }
 
-struct ast_bucket_file *ast_bucket_file_move(struct ast_bucket_file *file, 
const char *uri)
-{
-       struct ast_bucket_file *moved;
-
-       moved = ast_bucket_file_alloc(uri);
-       if (!moved) {
-               return NULL;
-       }
-
-       if (rename(file->path, moved->path)) {
-               ao2_ref(moved, -1);
-               return NULL;
-       }
-       file->path[0] = '\0';
-
-       ao2_cleanup(moved->metadata);
-       moved->metadata = file->metadata;
-       file->metadata = NULL;
-
-       return moved;
-}
-
 struct ast_bucket_file *ast_bucket_file_retrieve(const char *uri)
 {
        if (ast_strlen_zero(uri)) {
@@ -843,7 +779,7 @@
 static int timeval_struct2str(const void *obj, const intptr_t *args, char 
**buf)
 {
        struct timeval *field = (struct timeval *)(obj + args[0]);
-       return (ast_asprintf(buf, "%lu", field->tv_sec) < 0) ? -1 : 0;
+       return (ast_asprintf(buf, "%lu.%06lu", field->tv_sec, field->tv_usec) < 
0) ? -1 : 0;
 }
 
 /*! \brief Initialize bucket support */
@@ -881,7 +817,7 @@
                goto failure;
        }
 
-       ast_sorcery_object_field_register(bucket_sorcery, "bucket", "uri", "", 
OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_bucket, uri));
+       ast_sorcery_object_field_register(bucket_sorcery, "bucket", "name", "", 
OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_bucket, name));
        ast_sorcery_object_field_register(bucket_sorcery, "bucket", "scheme", 
"", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_bucket, scheme));
        ast_sorcery_object_field_register_custom(bucket_sorcery, "bucket", 
"created", "", timeval_str2struct, timeval_struct2str, 0, FLDSET(struct 
ast_bucket, created));
        ast_sorcery_object_field_register_custom(bucket_sorcery, "bucket", 
"modified", "", timeval_str2struct, timeval_struct2str, 0, FLDSET(struct 
ast_bucket, modified));
@@ -896,7 +832,7 @@
                goto failure;
        }
 
-       ast_sorcery_object_field_register(bucket_sorcery, "file", "uri", "", 
OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_bucket_file, uri));
+       ast_sorcery_object_field_register(bucket_sorcery, "file", "name", "", 
OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_bucket_file, name));
        ast_sorcery_object_field_register(bucket_sorcery, "file", "scheme", "", 
OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_bucket_file, scheme));
        ast_sorcery_object_field_register_custom(bucket_sorcery, "file", 
"created", "", timeval_str2struct, timeval_struct2str, 0, FLDSET(struct 
ast_bucket_file, created));
        ast_sorcery_object_field_register_custom(bucket_sorcery, "file", 
"modified", "", timeval_str2struct, timeval_struct2str, 0, FLDSET(struct 
ast_bucket_file, modified));

Modified: team/file/bucket/main/sorcery.c
URL: 
http://svnview.digium.com/svn/asterisk/team/file/bucket/main/sorcery.c?view=diff&rev=396165&r1=396164&r2=396165
==============================================================================
--- team/file/bucket/main/sorcery.c (original)
+++ team/file/bucket/main/sorcery.c Sun Aug  4 18:44:30 2013
@@ -61,7 +61,7 @@
 /*! \brief Structure for internal sorcery object information */
 struct ast_sorcery_object {
        /*! \brief Unique identifier of this object */
-       char id[AST_UUID_STR_LEN];
+       char *id;
 
        /*! \brief Type of object */
        char type[MAX_OBJECT_TYPE];
@@ -1040,6 +1040,7 @@
        }
 
        ast_variables_destroy(details->object->extended);
+       ast_free(details->object->id);
 }
 
 void *ast_sorcery_generic_alloc(size_t size, ao2_destructor_fn destructor)
@@ -1068,9 +1069,12 @@
        }
 
        if (ast_strlen_zero(id)) {
-               ast_uuid_generate_str(details->object->id, 
sizeof(details->object->id));
+               char uuid[AST_UUID_STR_LEN];
+
+               ast_uuid_generate_str(uuid, sizeof(uuid));
+               details->object->id = ast_strdup(uuid);
        } else {
-               ast_copy_string(details->object->id, id, 
sizeof(details->object->id));
+               details->object->id = ast_strdup(id);
        }
 
        ast_copy_string(details->object->type, type, 
sizeof(details->object->type));

Modified: team/file/bucket/tests/test_bucket.c
URL: 
http://svnview.digium.com/svn/asterisk/team/file/bucket/tests/test_bucket.c?view=diff&rev=396165&r1=396164&r2=396165
==============================================================================
--- team/file/bucket/tests/test_bucket.c (original)
+++ team/file/bucket/tests/test_bucket.c Sun Aug  4 18:44:30 2013
@@ -48,7 +48,6 @@
        unsigned int created:1;
        /*! \brief Whether the object has been updated or not */
        unsigned int updated:1;
-
        /*! \brief Whether the object has been deleted or not */
        unsigned int deleted:1;
 };
@@ -85,7 +84,7 @@
        return 0;
 }
 
-static void *bucket_test_wizard_retrieve_id(const struct ast_sorcery *sorcery, 
void *data, const char *type, 
+static void *bucket_test_wizard_retrieve_id(const struct ast_sorcery *sorcery, 
void *data, const char *type,
        const char *id)
 {
        if (!strcmp(type, "bucket")) {
@@ -123,7 +122,7 @@
        .delete = bucket_test_wizard_delete,
 };
 
-AST_TEST_DEFINE(bucket_scheme_register_unregister)
+AST_TEST_DEFINE(bucket_scheme_register)
 {
        switch (cmd) {
        case TEST_INIT:
@@ -142,26 +141,11 @@
                return AST_TEST_FAIL;
        }
 
-       if (ast_bucket_scheme_register("test", &bucket_test_wizard, 
&bucket_file_test_wizard)) {
-               ast_test_status_update(test, "Could not register a perfectly 
good Bucket scheme\n");
-               return AST_TEST_FAIL;
-       }
-
        if (!ast_bucket_scheme_register("test", &bucket_test_wizard, 
&bucket_file_test_wizard)) {
                ast_test_status_update(test, "Successfully registered a Bucket 
scheme twice\n");
                return AST_TEST_FAIL;
        }
 
-       if (ast_bucket_scheme_unregister("test")) {
-               ast_test_status_update(test, "Could not unregister a registered 
Bucket scheme\n");
-               return AST_TEST_FAIL;
-       }
-
-       if (!ast_bucket_scheme_unregister("test")) {
-               ast_test_status_update(test, "Successfully unregistered a 
Bucket scheme twice\n");
-               return AST_TEST_FAIL;
-       }
-
        return AST_TEST_PASS;
 }
 
@@ -196,9 +180,9 @@
                return AST_TEST_FAIL;
        }
 
-       if (strcmp(bucket->uri, "goat:///tmp/bob")) {
+       if (strcmp(ast_sorcery_object_get_id(bucket), "goat:///tmp/bob")) {
                ast_test_status_update(test, "URI within allocated bucket is 
'%s' and should be goat:///tmp/bob\n",
-                       bucket->uri);
+                       ast_sorcery_object_get_id(bucket));
                return AST_TEST_FAIL;
        }
 
@@ -208,32 +192,18 @@
                return AST_TEST_FAIL;
        }
 
-       if (strcmp(ast_sorcery_object_get_id(bucket), "bob")) {
+       if (strcmp(bucket->name, "bob")) {
                ast_test_status_update(test, "Bucket id is '%s' and should be 
bob\n",
-                       ast_sorcery_object_get_id(bucket));
-               return AST_TEST_FAIL;
-       }
-
-       return AST_TEST_PASS;
-}
-
-/*! \brief Constructor function for registering test scheme */
-static void *bucket_test_scheme_register(void)
-{
-       ast_bucket_scheme_register("test", &bucket_test_wizard, 
&bucket_file_test_wizard);
-       return NULL;
-}
-
-/*! \brief Destructor function for unregistering test scheme */
-static void bucket_test_scheme_unregister(void *obj)
-{
-       ast_bucket_scheme_unregister("test");
+                       bucket->name);
+               return AST_TEST_FAIL;
+       }
+
+       return AST_TEST_PASS;
 }
 
 AST_TEST_DEFINE(bucket_create)
 {
        RAII_VAR(struct ast_bucket *, bucket, NULL, ao2_cleanup);
-       RAII_VAR(void *, dummy, bucket_test_scheme_register(), 
bucket_test_scheme_unregister);
 
        switch (cmd) {
        case TEST_INIT:
@@ -256,18 +226,18 @@
 
        if (ast_bucket_create(bucket)) {
                ast_test_status_update(test, "Failed to create bucket with URI 
'%s'\n",
-                       bucket->uri);
+                       ast_sorcery_object_get_id(bucket));
                return AST_TEST_FAIL;
        }
 
        if (!bucket_test_wizard_state.created) {
-               ast_test_status_update(test, "Successfully returned bucket was 
created, but it was not\n");
+               ast_test_status_update(test, "Bucket creation returned success 
but scheme implementation never actually created it\n");
                return AST_TEST_FAIL;
        }
 
        if (!ast_bucket_create(bucket)) {
                ast_test_status_update(test, "Successfully created bucket with 
URI '%s' twice\n",
-                       bucket->uri);
+                       ast_sorcery_object_get_id(bucket));
                return AST_TEST_FAIL;
        }
 
@@ -277,7 +247,6 @@
 AST_TEST_DEFINE(bucket_delete)
 {
        RAII_VAR(struct ast_bucket *, bucket, NULL, ao2_cleanup);
-       RAII_VAR(void *, dummy, bucket_test_scheme_register(), 
bucket_test_scheme_unregister);
 
        switch (cmd) {
        case TEST_INIT:
@@ -300,18 +269,18 @@
 
        if (ast_bucket_delete(bucket)) {
                ast_test_status_update(test, "Failed to delete bucket with URI 
'%s'\n",
-                       bucket->uri);
+                       ast_sorcery_object_get_id(bucket));
                return AST_TEST_FAIL;
        }
 
        if (!bucket_test_wizard_state.deleted) {
-               ast_test_status_update(test, "Successfully returned bucket was 
deleted, but it was not\n");
+               ast_test_status_update(test, "Bucket deletion returned success 
but scheme implementation never actually deleted it\n");
                return AST_TEST_FAIL;
        }
 
        if (!ast_bucket_delete(bucket)) {
                ast_test_status_update(test, "Successfully deleted bucket with 
URI '%s' twice\n",
-                       bucket->uri);
+                       ast_sorcery_object_get_id(bucket));
                return AST_TEST_FAIL;
        }
 
@@ -424,7 +393,6 @@
 AST_TEST_DEFINE(bucket_retrieve)
 {
        RAII_VAR(struct ast_bucket *, bucket, NULL, ao2_cleanup);
-       RAII_VAR(void *, dummy, bucket_test_scheme_register(), 
bucket_test_scheme_unregister);
 
        switch (cmd) {
        case TEST_INIT:
@@ -482,9 +450,9 @@
                return AST_TEST_FAIL;
        }
 
-       if (strcmp(file->uri, "goat:///tmp/bob")) {
+       if (strcmp(ast_sorcery_object_get_id(file), "goat:///tmp/bob")) {
                ast_test_status_update(test, "URI within allocated file is '%s' 
and should be goat:///tmp/bob\n",
-                       file->uri);
+                       ast_sorcery_object_get_id(file));
                return AST_TEST_FAIL;
        }
 
@@ -494,7 +462,7 @@
                return AST_TEST_FAIL;
        }
 
-       if (strcmp(ast_sorcery_object_get_id(file), "bob")) {
+       if (strcmp(file->name, "bob")) {
                ast_test_status_update(test, "File id is '%s' and should be 
bob\n",
                        ast_sorcery_object_get_id(file));
                return AST_TEST_FAIL;
@@ -565,7 +533,6 @@
 AST_TEST_DEFINE(bucket_file_create)
 {
        RAII_VAR(struct ast_bucket_file *, file, NULL, ao2_cleanup);
-       RAII_VAR(void *, dummy, bucket_test_scheme_register(), 
bucket_test_scheme_unregister);
 
        switch (cmd) {
        case TEST_INIT:
@@ -588,18 +555,18 @@
 
        if (ast_bucket_file_create(file)) {
                ast_test_status_update(test, "Failed to create file with URI 
'%s'\n",
-                       file->uri);
+                       ast_sorcery_object_get_id(file));
                return AST_TEST_FAIL;
        }
 
        if (!bucket_test_wizard_state.created) {
-               ast_test_status_update(test, "Successfully returned file was 
created, but it was not\n");
+               ast_test_status_update(test, "Bucket file creation returned 
success but scheme implementation never actually created it\n");
                return AST_TEST_FAIL;
        }
 
        if (!ast_bucket_file_create(file)) {
                ast_test_status_update(test, "Successfully created file with 
URI '%s' twice\n",
-                       file->uri);
+                       ast_sorcery_object_get_id(file));
                return AST_TEST_FAIL;
        }
 
@@ -642,7 +609,7 @@
 
        if (!(copy = ast_bucket_file_copy(file, "goat:///tmp/bob2"))) {
                ast_test_status_update(test, "Failed to copy file '%s' to 
goat:///tmp/bob2\n",
-                       file->uri);
+                       ast_sorcery_object_get_id(file));
                return AST_TEST_FAIL;
        }
 
@@ -669,78 +636,9 @@
        return AST_TEST_PASS;
 }
 
-AST_TEST_DEFINE(bucket_file_move)
+AST_TEST_DEFINE(bucket_file_retrieve)
 {
        RAII_VAR(struct ast_bucket_file *, file, NULL, ao2_cleanup);
-       RAII_VAR(struct ast_bucket_file *, moved, NULL, ao2_cleanup);
-       FILE *temporary;
-       struct stat old, new;
-
-       switch (cmd) {
-       case TEST_INIT:
-               info->name = "bucket_file_move";
-               info->category = "/main/bucket/";
-               info->summary = "bucket file moving unit test";
-               info->description =
-                       "Test moving of bucket files";
-               return AST_TEST_NOT_RUN;
-       case TEST_EXECUTE:
-               break;
-       }
-
-       if (!(file = ast_bucket_file_alloc("goat:///tmp/bob"))) {
-               ast_test_status_update(test, "Failed to allocate file\n");
-               return AST_TEST_FAIL;
-       }
-
-       ast_bucket_file_metadata_set(file, "bob", "joe");
-
-       if (!(temporary = fopen(file->path, "w"))) {
-               ast_test_status_update(test, "Failed to open temporary file 
'%s'\n", file->path);
-               return AST_TEST_FAIL;
-       }
-
-       fprintf(temporary, "bob");
-       fclose(temporary);
-
-       if (stat(file->path, &old)) {
-               ast_test_status_update(test, "File '%s' does not exist after 
writing to it\n", file->path);
-               return AST_TEST_FAIL;
-       }
-
-       if (!(moved = ast_bucket_file_move(file, "goat:///tmp/bob2"))) {
-               ast_test_status_update(test, "Failed to move file '%s' to 
goat:///tmp/bob2\n",
-                       file->uri);
-               return AST_TEST_FAIL;
-       }
-
-       if (file->metadata) {
-               ast_test_status_update(test, "Old file '%s' still has metadata 
when it should not\n", file->uri);
-               return AST_TEST_FAIL;
-       }
-
-       if (stat(moved->path, &new)) {
-               ast_test_status_update(test, "New file '%s' does not exist 
after moving\n", moved->path);
-               return AST_TEST_FAIL;
-       }
-
-       if (old.st_size != new.st_size) {
-               ast_test_status_update(test, "Moving of underlying temporary 
file failed\n");
-               return AST_TEST_FAIL;
-       }
-
-       if (!stat(file->path, &old)) {
-               ast_test_status_update(test, "Old file continues to exist after 
moving\n");
-               return AST_TEST_FAIL;
-       }
-
-       return AST_TEST_PASS;
-}
-
-AST_TEST_DEFINE(bucket_file_retrieve)
-{
-       RAII_VAR(struct ast_bucket_file *, file, NULL, ao2_cleanup);
-       RAII_VAR(void *, dummy, bucket_test_scheme_register(), 
bucket_test_scheme_unregister);
 
        switch (cmd) {
        case TEST_INIT:
@@ -765,7 +663,6 @@
 AST_TEST_DEFINE(bucket_file_update)
 {
        RAII_VAR(struct ast_bucket_file *, file, NULL, ao2_cleanup);
-       RAII_VAR(void *, dummy, bucket_test_scheme_register(), 
bucket_test_scheme_unregister);
 
        switch (cmd) {
        case TEST_INIT:
@@ -788,7 +685,7 @@
 
        if (ast_bucket_file_update(file)) {
                ast_test_status_update(test, "Failed to update file with URI 
'%s'\n",
-                       file->uri);
+                       ast_sorcery_object_get_id(file));
                return AST_TEST_FAIL;
        }
 
@@ -799,7 +696,7 @@
 
        if (!ast_bucket_file_update(file)) {
                ast_test_status_update(test, "Successfully updated file with 
URI '%s' twice\n",
-                       file->uri);
+                       ast_sorcery_object_get_id(file));
                return AST_TEST_FAIL;
        }
 
@@ -809,7 +706,6 @@
 AST_TEST_DEFINE(bucket_file_delete)
 {
        RAII_VAR(struct ast_bucket_file *, file, NULL, ao2_cleanup);
-       RAII_VAR(void *, dummy, bucket_test_scheme_register(), 
bucket_test_scheme_unregister);
 
        switch (cmd) {
        case TEST_INIT:
@@ -832,18 +728,18 @@
 
        if (ast_bucket_file_delete(file)) {
                ast_test_status_update(test, "Failed to delete file with URI 
'%s'\n",
-                       file->uri);
+                       ast_sorcery_object_get_id(file));
                return AST_TEST_FAIL;
        }
 
        if (!bucket_test_wizard_state.deleted) {
-               ast_test_status_update(test, "Successfully returned file was 
deleted, but it was not\n");
+               ast_test_status_update(test, "Bucket file deletion returned 
success but scheme implementation never actually deleted it\n");
                return AST_TEST_FAIL;
        }
 
        if (!ast_bucket_file_delete(file)) {
                ast_test_status_update(test, "Successfully deleted file with 
URI '%s' twice\n",
-                       file->uri);
+                       ast_sorcery_object_get_id(file));
                return AST_TEST_FAIL;
        }
 
@@ -1079,7 +975,7 @@
 
 static int unload_module(void)
 {
-       AST_TEST_UNREGISTER(bucket_scheme_register_unregister);
+       AST_TEST_UNREGISTER(bucket_scheme_register);
        AST_TEST_UNREGISTER(bucket_alloc);
        AST_TEST_UNREGISTER(bucket_create);
        AST_TEST_UNREGISTER(bucket_delete);
@@ -1089,7 +985,6 @@
        AST_TEST_UNREGISTER(bucket_file_temporary_deletion);
        AST_TEST_UNREGISTER(bucket_file_create);
        AST_TEST_UNREGISTER(bucket_file_copy);
-       AST_TEST_UNREGISTER(bucket_file_move);
        AST_TEST_UNREGISTER(bucket_file_retrieve);
        AST_TEST_UNREGISTER(bucket_file_update);
        AST_TEST_UNREGISTER(bucket_file_delete);
@@ -1102,7 +997,12 @@
 
 static int load_module(void)
 {
-       AST_TEST_REGISTER(bucket_scheme_register_unregister);
+       if (ast_bucket_scheme_register("test", &bucket_test_wizard, 
&bucket_file_test_wizard)) {
+               ast_log(LOG_ERROR, "Failed to register Bucket test wizard 
scheme implementation\n");
+               return AST_MODULE_LOAD_FAILURE;
+       }
+
+       AST_TEST_REGISTER(bucket_scheme_register);
        AST_TEST_REGISTER(bucket_alloc);
        AST_TEST_REGISTER(bucket_create);
        AST_TEST_REGISTER(bucket_delete);
@@ -1112,7 +1012,6 @@
        AST_TEST_REGISTER(bucket_file_temporary_deletion);
        AST_TEST_REGISTER(bucket_file_create);
        AST_TEST_REGISTER(bucket_file_copy);
-       AST_TEST_REGISTER(bucket_file_move);
        AST_TEST_REGISTER(bucket_file_retrieve);
        AST_TEST_REGISTER(bucket_file_update);
        AST_TEST_REGISTER(bucket_file_delete);


--
_____________________________________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

svn-commits mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/svn-commits

Reply via email to