static void test_messages(void) { struct mgcp_config *cfg; int i; cfg = mgcp_config_alloc(); cfg->trunk.number_endpoints = 64; mgcp_endpoints_allocate(&cfg->trunk); mgcp_endpoints_allocate(mgcp_trunk_alloc(cfg, 1)); 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 (!t->exp_resp) { if (msg) printf("%s failed '%s'\n", t->name, (char *) msg->data); } else 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); }
static void test_auep(void) { struct msgb *inp; struct msgb *msg; struct mgcp_config *cfg = mgcp_config_alloc(); cfg->trunk.number_endpoints = 64; mgcp_endpoints_allocate(&cfg->trunk); mgcp_endpoints_allocate(mgcp_trunk_alloc(cfg, 1)); inp = create_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_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); talloc_free(cfg); }
static void test_rqnt_cb(void) { struct mgcp_config *cfg; struct msgb *inp, *msg; cfg = mgcp_config_alloc(); cfg->rqnt_cb = rqnt_cb; cfg->trunk.number_endpoints = 64; mgcp_endpoints_allocate(&cfg->trunk); mgcp_endpoints_allocate(mgcp_trunk_alloc(cfg, 1)); inp = create_msg(CRCX); msgb_free(mgcp_handle_message(cfg, inp)); msgb_free(inp); /* send the RQNT and check for the CB */ inp = create_msg(RQNT); msg = mgcp_handle_message(cfg, inp); if (strncmp((const char *) msg->l2h, "200", 3) != 0) { printf("FAILED: message is not 200. '%s'\n", msg->l2h); abort(); } if (cfg->data != (void *) '9') { printf("FAILED: callback not called: %p\n", cfg->data); abort(); } msgb_free(msg); msgb_free(inp); inp = create_msg(DLCX); msgb_free(mgcp_handle_message(cfg, inp)); msgb_free(inp); talloc_free(cfg); }