Merge "Revert "app_voicemail: Remove need to subscribe to stasis""
[asterisk/asterisk.git] / tests / test_stasis_channels.c
index a3f8828..f8d2a03 100644 (file)
@@ -17,7 +17,8 @@
  */
 
 /*!
- * \file \brief Test Stasis Channel messages and objects
+ * \file
+ * \brief Test Stasis Channel messages and objects
  *
  * \author\verbatim Matt Jordan <mjordan@digium.com> \endverbatim
  *
@@ -31,8 +32,6 @@
 
 #include "asterisk.h"
 
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
 #include "asterisk/astobj2.h"
 #include "asterisk/module.h"
 #include "asterisk/stasis.h"
@@ -71,16 +70,19 @@ AST_TEST_DEFINE(channel_blob_create)
                break;
        }
 
-       type = stasis_message_type_create("test-type", NULL);
-       chan = ast_channel_alloc(0, AST_STATE_DOWN, "100", "Alice", "100", "100", "default", NULL, 0, "TEST/Alice");
+       ast_test_validate(test, stasis_message_type_create("test-type", NULL, &type) == STASIS_MESSAGE_TYPE_SUCCESS);
+       chan = ast_channel_alloc(0, AST_STATE_DOWN, "100", "Alice", "100", "100", "default", NULL, NULL, 0, "TEST/Alice");
+       ast_channel_unlock(chan);
        json = ast_json_pack("{s: s}",
                     "foo", "bar");
 
        /* Off nominal creation */
+       ast_channel_lock(chan);
        ast_test_validate(test, NULL == ast_channel_blob_create(chan, NULL, json));
 
        /* Test for single channel */
        msg = ast_channel_blob_create(chan, type, json);
+       ast_channel_unlock(chan);
        ast_test_validate(test, NULL != msg);
        blob = stasis_message_data(msg);
        ast_test_validate(test, NULL != blob);
@@ -123,13 +125,16 @@ AST_TEST_DEFINE(null_blob)
                break;
        }
 
-       type = stasis_message_type_create("test-type", NULL);
-       chan = ast_channel_alloc(0, AST_STATE_DOWN, "100", "Alice", "100", "100", "default", NULL, 0, "TEST/Alice");
+       ast_test_validate(test, stasis_message_type_create("test-type", NULL, &type) == STASIS_MESSAGE_TYPE_SUCCESS);
+       chan = ast_channel_alloc(0, AST_STATE_DOWN, "100", "Alice", "100", "100", "default", NULL, NULL, 0, "TEST/Alice");
+       ast_channel_unlock(chan);
        json = ast_json_pack("{s: s}",
                     "foo", "bar");
 
        /* Test for single channel */
+       ast_channel_lock(chan);
        msg = ast_channel_blob_create(chan, type, NULL);
+       ast_channel_unlock(chan);
        ast_test_validate(test, NULL != msg);
        blob = stasis_message_data(msg);
        ast_test_validate(test, NULL != blob);
@@ -191,14 +196,23 @@ AST_TEST_DEFINE(multi_channel_blob_snapshots)
 
        json = ast_json_pack("{s: s}",
                     "type", "test");
-       chan_alice = ast_channel_alloc(0, AST_STATE_DOWN, "100", "Alice", "100", "100", "default", NULL, 0, "TEST/Alice");
-       chan_bob = ast_channel_alloc(0, AST_STATE_DOWN, "200", "Bob", "200", "200", "default", NULL, 0, "TEST/Bob");
-       chan_charlie = ast_channel_alloc(0, AST_STATE_DOWN, "300", "Bob", "300", "300", "default", NULL, 0, "TEST/Charlie");
+       chan_alice = ast_channel_alloc(0, AST_STATE_DOWN, "100", "Alice", "100", "100", "default", NULL, NULL, 0, "TEST/Alice");
+       ast_channel_unlock(chan_alice);
+       chan_bob = ast_channel_alloc(0, AST_STATE_DOWN, "200", "Bob", "200", "200", "default", NULL, NULL, 0, "TEST/Bob");
+       ast_channel_unlock(chan_bob);
+       chan_charlie = ast_channel_alloc(0, AST_STATE_DOWN, "300", "Bob", "300", "300", "default", NULL, NULL, 0, "TEST/Charlie");
+       ast_channel_unlock(chan_charlie);
 
        blob = ast_multi_channel_blob_create(json);
+       ast_channel_lock(chan_alice);
        ast_multi_channel_blob_add_channel(blob, "Caller", ast_channel_snapshot_create(chan_alice));
+       ast_channel_unlock(chan_alice);
+       ast_channel_lock(chan_bob);
        ast_multi_channel_blob_add_channel(blob, "Peer", ast_channel_snapshot_create(chan_bob));
+       ast_channel_unlock(chan_bob);
+       ast_channel_lock(chan_charlie);
        ast_multi_channel_blob_add_channel(blob, "Peer", ast_channel_snapshot_create(chan_charlie));
+       ast_channel_unlock(chan_charlie);
 
        /* Test for unknown role */
        ast_test_validate(test, NULL == ast_multi_channel_blob_get_channel(blob, "Foobar"));
@@ -206,12 +220,12 @@ AST_TEST_DEFINE(multi_channel_blob_snapshots)
        /* Test for single match */
        snapshot = ast_multi_channel_blob_get_channel(blob, "Caller");
        ast_test_validate(test, NULL != snapshot);
-       ast_test_validate(test, 0 == strcmp("TEST/Alice", snapshot->name));
+       ast_test_validate(test, 0 == strcmp("TEST/Alice", snapshot->base->name));
 
        /* Test for single match, multiple possibilities */
        snapshot = ast_multi_channel_blob_get_channel(blob, "Peer");
        ast_test_validate(test, NULL != snapshot);
-       ast_test_validate(test, 0 != strcmp("TEST/Alice", snapshot->name));
+       ast_test_validate(test, 0 != strcmp("TEST/Alice", snapshot->base->name));
 
        /* Multi-match */
        matches = ast_multi_channel_blob_get_channels(blob, "Peer");
@@ -248,18 +262,22 @@ AST_TEST_DEFINE(channel_snapshot_json)
                break;
        }
 
-       ast_test_validate(test, NULL == ast_channel_snapshot_to_json(NULL));
+       ast_test_validate(test, NULL == ast_channel_snapshot_to_json(NULL, NULL));
 
-       chan = ast_channel_alloc(0, AST_STATE_DOWN, "cid_num", "cid_name", "acctcode", "exten", "context", NULL, 0, "TEST/name");
+       chan = ast_channel_alloc(0, AST_STATE_DOWN, "cid_num", "cid_name", "acctcode", "exten", "context", NULL, NULL, 0, "TEST/name");
+       ast_channel_unlock(chan);
        ast_test_validate(test, NULL != chan);
+       ast_channel_lock(chan);
        snapshot = ast_channel_snapshot_create(chan);
+       ast_channel_unlock(chan);
        ast_test_validate(test, NULL != snapshot);
 
-       actual = ast_channel_snapshot_to_json(snapshot);
+       actual = ast_channel_snapshot_to_json(snapshot, NULL);
        expected = ast_json_pack("{ s: s, s: s, s: s, s: s,"
                                 "  s: { s: s, s: s, s: i },"
                                 "  s: { s: s, s: s },"
                                 "  s: { s: s, s: s },"
+                                "  s: s"
                                 "  s: o"
                                 "}",
                                 "name", "TEST/name",
@@ -276,6 +294,7 @@ AST_TEST_DEFINE(channel_snapshot_json)
                                 "connected",
                                 "name", "",
                                 "number", "",
+                                "language", "en",
                                 "creationtime",
                                 ast_json_timeval(
                                         ast_channel_creationtime(chan), NULL));
@@ -308,6 +327,7 @@ static int load_module(void)
 }
 
 AST_MODULE_INFO(ASTERISK_GPL_KEY, 0, "Stasis Channel Testing",
-               .load = load_module,
-               .unload = unload_module
-       );
+       .support_level = AST_MODULE_SUPPORT_CORE,
+       .load = load_module,
+       .unload = unload_module
+);