Merge "core: Tweak startup order."
[asterisk/asterisk.git] / tests / test_stasis_channels.c
index de44545..5744873 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,17 +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);
@@ -124,14 +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);
@@ -193,17 +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_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, 0, "TEST/Bob");
+       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, 0, "TEST/Charlie");
+       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"));
@@ -255,10 +264,12 @@ AST_TEST_DEFINE(channel_snapshot_json)
 
        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, NULL);
@@ -266,6 +277,7 @@ AST_TEST_DEFINE(channel_snapshot_json)
                                 "  s: { s: s, s: s, s: i },"
                                 "  s: { s: s, s: s },"
                                 "  s: { s: s, s: s },"
+                                "  s: s"
                                 "  s: o"
                                 "}",
                                 "name", "TEST/name",
@@ -282,6 +294,7 @@ AST_TEST_DEFINE(channel_snapshot_json)
                                 "connected",
                                 "name", "",
                                 "number", "",
+                                "language", "en",
                                 "creationtime",
                                 ast_json_timeval(
                                         ast_channel_creationtime(chan), NULL));
@@ -314,6 +327,6 @@ static int load_module(void)
 }
 
 AST_MODULE_INFO(ASTERISK_GPL_KEY, 0, "Stasis Channel Testing",
-               .load = load_module,
-               .unload = unload_module
-       );
+       .load = load_module,
+       .unload = unload_module
+);