Fix some tests that didn't get opaquification changes
authorTerry Wilson <twilson@digium.com>
Thu, 23 Feb 2012 01:53:17 +0000 (01:53 +0000)
committerTerry Wilson <twilson@digium.com>
Thu, 23 Feb 2012 01:53:17 +0000 (01:53 +0000)
Review: https://reviewboard.asterisk.org/r/1766/

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@356397 65c4cc65-6c06-0410-ace0-fbb531ad65f3

tests/test_substitution.c
tests/test_utils.c

index 645d69d..3df9036 100644 (file)
@@ -69,6 +69,29 @@ static enum ast_test_result_state test_chan_integer(struct ast_test *test,
        return okay ? AST_TEST_PASS : AST_TEST_FAIL;
 }
 
+static enum ast_test_result_state test_chan_integer_accessor(struct ast_test *test,
+               struct ast_channel *c, void (*setter)(struct ast_channel *, int),const char *expression)
+{
+       int i, okay = 1, value1 = -1, value2 = -1;
+       char workspace[4096];
+       struct ast_str *str = ast_str_create(16);
+
+       ast_test_status_update(test, "Testing '%s' . . . . . %s\n", expression, okay ? "passed" : "FAILED");
+       for (i = 0; i < 256; i++) {
+               setter(c, i);
+               ast_str_substitute_variables(&str, 0, c, expression);
+               pbx_substitute_variables_helper(c, expression, workspace, sizeof(workspace));
+               if (sscanf(workspace, "%d", &value1) != 1 || value1 != i || sscanf(ast_str_buffer(str), "%d", &value2) != 1 || value2 != i) {
+                       ast_test_status_update(test, "%s != %s and/or %d != %d != %d\n", ast_str_buffer(str), workspace, value1, value2, i);
+                       okay = 0;
+               }
+       }
+
+       ast_free(str);
+
+       return okay ? AST_TEST_PASS : AST_TEST_FAIL;
+}
+
 static enum ast_test_result_state test_chan_string(struct ast_test *test,
                struct ast_channel *c, void (*setter)(struct ast_channel *, const char *),
                const char *(*getter)(const struct ast_channel *), const char *expression)
@@ -232,8 +255,8 @@ AST_TEST_DEFINE(test_substitution)
        TEST(test_chan_integer(test, c, &c->caller.ani2, "${CALLINGANI2}"));
        TEST(test_chan_integer(test, c, &c->caller.id.number.plan, "${CALLINGTON}"));
        TEST(test_chan_integer(test, c, &c->dialed.transit_network_select, "${CALLINGTNS}"));
-       TEST(test_chan_integer(test, c, &c->hangupcause, "${HANGUPCAUSE}"));
-       TEST(test_chan_integer(test, c, &c->priority, "${PRIORITY}"));
+       TEST(test_chan_integer_accessor(test, c, ast_channel_hangupcause_set, "${HANGUPCAUSE}"));
+       TEST(test_chan_integer_accessor(test, c, ast_channel_priority_set, "${PRIORITY}"));
        TEST(test_chan_string(test, c, ast_channel_context_set, ast_channel_context, "${CONTEXT}"));
        TEST(test_chan_string(test, c, ast_channel_exten_set, ast_channel_exten, "${EXTEN}"));
        TEST(test_chan_variable(test, c, "CHANNEL(language)"));
index 1204ff1..ece63a4 100644 (file)
@@ -341,7 +341,8 @@ AST_TEST_DEFINE(crypto_loaded_test)
 
 AST_TEST_DEFINE(adsi_loaded_test)
 {
-       struct ast_channel c = { .adsicpe = AST_ADSI_AVAILABLE, };
+       struct ast_channel *c;
+       int res;
        switch (cmd) {
        case TEST_INIT:
                info->name = "adsi_loaded_test";
@@ -353,7 +354,13 @@ AST_TEST_DEFINE(adsi_loaded_test)
                break;
        }
 
-       return ast_adsi_available(&c) ? AST_TEST_PASS : AST_TEST_FAIL;
+       if (!(c = ast_dummy_channel_alloc())) {
+               return AST_TEST_FAIL;
+       }
+       ast_channel_adsicpe_set(c, AST_ADSI_AVAILABLE);
+       res = ast_adsi_available(c) ? AST_TEST_PASS : AST_TEST_FAIL;
+       c = ast_channel_unref(c);
+       return res;
 }
 
 static int handle_noop(struct ast_channel *chan, AGI *agi, int arg, const char * const argv[])