summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2012-01-27 00:36:56 +0100
committerHarald Welte <laforge@gnumonks.org>2012-01-27 00:36:56 +0100
commitf74da14c0105dae12179acf8c94348c4b84ced84 (patch)
tree75069e994215f003562be18b8cfee2004ec7d4ab
parent8819d8289dd2c11627ba93189ad627ce1f818608 (diff)
further generalize mgcp testing code
use a data-structure driven approach
-rw-r--r--openbsc/tests/mgcp/mgcp_test.c49
1 files changed, 30 insertions, 19 deletions
diff --git a/openbsc/tests/mgcp/mgcp_test.c b/openbsc/tests/mgcp/mgcp_test.c
index 66d0428b7..6add9b375 100644
--- a/openbsc/tests/mgcp/mgcp_test.c
+++ b/openbsc/tests/mgcp/mgcp_test.c
@@ -25,7 +25,21 @@
#include <string.h>
#define AUEP1 "AUEP 158663169 ds/e1-1/2@172.16.6.66 MGCP 1.0\r\n"
+#define AUEP1_RET "200 158663169 OK\r\n"
#define AUEP2 "AUEP 18983213 ds/e1-2/1@172.16.6.66 MGCP 1.0\r\n"
+#define AUEP2_RET "500 18983213 FAIL\r\n"
+
+
+struct mgcp_test {
+ const char *name;
+ const char *req;
+ const char *exp_resp;
+};
+
+const struct mgcp_test tests[] = {
+ { "AUEP1", AUEP1, AUEP1_RET },
+ { "AUEP2", AUEP2, AUEP2_RET },
+};
static struct msgb *create_msg(const char *str)
{
@@ -39,33 +53,30 @@ static struct msgb *create_msg(const char *str)
static void test_auep(void)
{
- struct msgb *inp;
- struct msgb *msg;
struct mgcp_config *cfg;
-
- printf("Testing AUEP\n");
+ int i;
cfg = mgcp_config_alloc();
+
cfg->trunk.number_endpoints = 64;
mgcp_endpoints_allocate(&cfg->trunk);
mgcp_endpoints_allocate(mgcp_trunk_alloc(cfg, 1));
- inp = create_msg(AUEP1);
- msg = mgcp_handle_message(cfg, inp);
- msgb_free(inp);
- if (strcmp((char *) msg->data, "200 158663169 OK\r\n") != 0)
- printf("Result1 failed '%s'\n", (char *) msg->data);
- /* Verify that the endpoint is fine */
- msgb_free(msg);
-
- inp = create_msg(AUEP2);
- msg = mgcp_handle_message(cfg, inp);
- msgb_free(inp);
- /* Verify that the endpoint is not fine */
- if (strcmp((char *) msg->data, "500 18983213 FAIL\r\n") != 0)
- printf("Result2 failed '%s'\n", (char *) msg->data);
- msgb_free(msg);
+ for (i = 0; i < ARRAY_SIZE(tests); i++) {
+ const struct mgcp_test *t = &tests[i];
+ struct msgb *inp;
+ struct msgb *msg;
+
+ printf("Testing %s\n", t->name);
+
+ inp = create_msg(t->req);
+ msg = mgcp_handle_message(cfg, inp);
+ msgb_free(inp);
+ if (strcmp((char *) msg->data, t->exp_resp) != 0)
+ printf("%s failed '%s'\n", t->name, (char *) msg->data);
+ msgb_free(msg);
+ }
talloc_free(cfg);
}