Skip to content

Commit

Permalink
Added NoProxy test
Browse files Browse the repository at this point in the history
  • Loading branch information
monich committed Feb 18, 2014
1 parent 8238ae1 commit 0c20bc8
Show file tree
Hide file tree
Showing 14 changed files with 312 additions and 28 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -12,6 +12,7 @@ mms-lib/test/mms_lib_test.opt
mms-lib/test/read_report/build
mms-lib/test/retrieve/build
mms-lib/test/retrieve_cancel/build
mms-lib/test/retrieve_no_proxy/build
mms-ofono/mms-ofono.pro.user
mms-ofono/build
mms-handler-dbus/mms-handler-dbus.pro.user
Expand Down
1 change: 1 addition & 0 deletions mms-lib/test/Makefile
Expand Up @@ -6,3 +6,4 @@ all:
@$(MAKE) -C read_report $*
@$(MAKE) -C retrieve $*
@$(MAKE) -C retrieve_cancel $*
@$(MAKE) -C retrieve_no_proxy $*
11 changes: 8 additions & 3 deletions mms-lib/test/common/test_connection.c
Expand Up @@ -58,14 +58,19 @@ test_connection_test_open(
MMSConnection*
mms_connection_test_new(
const char* imsi,
unsigned short port)
unsigned short port,
gboolean proxy)
{
MMSConnectionTest* test = g_object_new(MMS_TYPE_CONNECTION_TEST, NULL);
test->imsi = g_strdup(imsi);
test->mmsc = g_strdup("http://mmsc");
if (port) {
test->mmsproxy = g_strdup_printf("127.0.0.1:%hu", port);
test->netif = g_strdup("lo");
if (proxy) {
test->mmsc = g_strdup("http://mmsc");
test->mmsproxy = g_strdup_printf("127.0.0.1:%hu", port);
} else {
test->mmsc = g_strdup_printf("http://127.0.0.1:%hu", port);
}
}
test->state = MMS_CONNECTION_STATE_OPENING;
g_idle_add(test_connection_test_open, mms_connection_ref(test));
Expand Down
3 changes: 2 additions & 1 deletion mms-lib/test/common/test_connection.h
Expand Up @@ -20,7 +20,8 @@
MMSConnection*
mms_connection_test_new(
const char* imsi,
unsigned short port);
unsigned short port,
gboolean proxy);

#endif /* TEST_CONNECTION_H */

Expand Down
19 changes: 11 additions & 8 deletions mms-lib/test/common/test_connman.c
Expand Up @@ -23,8 +23,9 @@ MMS_LOG_MODULE_DEFINE("mms-connman-test");
typedef MMSConnManClass MMSConnManTestClass;
typedef struct mms_connman_test {
MMSConnMan cm;
MMSConnection* connection;
MMSConnection* conn;
unsigned short port;
gboolean proxy;
} MMSConnManTest;

G_DEFINE_TYPE(MMSConnManTest, mms_connman_test, MMS_TYPE_CONNMAN);
Expand All @@ -35,22 +36,24 @@ G_DEFINE_TYPE(MMSConnManTest, mms_connman_test, MMS_TYPE_CONNMAN);
void
mms_connman_test_set_port(
MMSConnMan* cm,
unsigned short port)
unsigned short port,
gboolean proxy)
{
MMSConnManTest* test = MMS_CONNMAN_TEST(cm);
test->port = port;
test->proxy = proxy;
}

void
mms_connman_test_close_connection(
MMSConnMan* cm)
{
MMSConnManTest* test = MMS_CONNMAN_TEST(cm);
if (test->connection) {
if (test->conn) {
MMS_DEBUG("Closing connection...");
mms_connection_close(test->connection);
mms_connection_unref(test->connection);
test->connection = NULL;
mms_connection_close(test->conn);
mms_connection_unref(test->conn);
test->conn = NULL;
}
}

Expand All @@ -64,8 +67,8 @@ mms_connman_test_open_connection(
MMSConnManTest* test = MMS_CONNMAN_TEST(cm);
mms_connman_test_close_connection(cm);
if (test->port) {
test->connection = mms_connection_test_new(imsi, test->port);
return mms_connection_ref(test->connection);
test->conn = mms_connection_test_new(imsi, test->port, test->proxy);
return mms_connection_ref(test->conn);
} else {
return NULL;
}
Expand Down
3 changes: 2 additions & 1 deletion mms-lib/test/common/test_connman.h
Expand Up @@ -23,7 +23,8 @@ mms_connman_test_new(void);
void
mms_connman_test_set_port(
MMSConnMan* cm,
unsigned short port);
unsigned short port,
gboolean proxy);

void
mms_connman_test_close_connection(
Expand Down
2 changes: 1 addition & 1 deletion mms-lib/test/coverage/run
Expand Up @@ -3,7 +3,7 @@
# This script requires lcov to be installed
#

TESTS="mms_codec read_report retrieve retrieve_cancel"
TESTS="mms_codec read_report retrieve retrieve_cancel retrieve_no_proxy"
FLAVOR="release"

pushd `dirname $0` > /dev/null
Expand Down
2 changes: 1 addition & 1 deletion mms-lib/test/read_report/test_read_report.c
Expand Up @@ -99,7 +99,7 @@ test_init(
test->delegate.fn_done = test_done;
mms_dispatcher_set_delegate(test->disp, &test->delegate);
test->http = test_http_new(NULL, NULL, SOUP_STATUS_OK);
mms_connman_test_set_port(test->cm, test_http_get_port(test->http));
mms_connman_test_set_port(test->cm, test_http_get_port(test->http), TRUE);
test->ret = RET_ERR;
}

Expand Down
22 changes: 12 additions & 10 deletions mms-lib/test/retrieve/test_retrieve.c
Expand Up @@ -203,7 +203,7 @@ test_finish(
state = mms_handler_test_receive_state(test->handler, NULL);
if (state != desc->expected_state) {
test->ret = RET_ERR;
MMS_ERR("Test %s state %d, expected %d", name, state,
MMS_ERR("%s state %d, expected %d", name, state,
desc->expected_state);
} else {
const void* resp_data = NULL;
Expand All @@ -216,21 +216,21 @@ test_finish(
if (mms_message_decode(resp_data, resp_len, pdu)) {
if (pdu->type != desc->reply_msg) {
test->ret = RET_ERR;
MMS_ERR("Test %s reply %u, expected %u", name,
MMS_ERR("%s reply %u, expected %u", name,
pdu->type, desc->reply_msg);
}
} else {
test->ret = RET_ERR;
MMS_ERR("Test %s can't decode reply message", name);
MMS_ERR("%s can't decode reply message", name);
}
mms_message_free(pdu);
} else {
test->ret = RET_ERR;
MMS_ERR("Test %s expects no reply", name);
MMS_ERR("%s expects no reply", name);
}
} else if (desc->reply_msg) {
test->ret = RET_ERR;
MMS_ERR("Test %s expects reply", name);
MMS_ERR("%s expects reply", name);
}
}
}
Expand Down Expand Up @@ -266,7 +266,7 @@ test_finish(
g_free(f1);
g_free(f2);
}
MMS_INFO("Test %s %s", name, (test->ret == RET_OK) ? "OK" : "FAILED");
MMS_INFO("%s %s", name, (test->ret == RET_OK) ? "OK" : "FAILED");
mms_handler_test_reset(test->handler);
g_main_loop_quit(test->loop);
}
Expand All @@ -291,7 +291,7 @@ test_timeout(
Test* test = data;
test->timeout_id = 0;
test->ret = RET_TIMEOUT;
MMS_INFO("Test %s TIMEOUT", test->desc->name);
MMS_INFO("%s TIMEOUT", test->desc->name);
if (test->http) test_http_close(test->http);
mms_connman_test_close_connection(test->cm);
mms_dispatcher_cancel(test->disp, NULL);
Expand All @@ -317,6 +317,7 @@ test_init(
if (test->notification_ind) {
if (rc) test->retrieve_conf = g_mapped_file_new(rc, FALSE, &error);
if (test->retrieve_conf || !rc) {
guint port;
g_mapped_file_ref(test->notification_ind);
test->desc = desc;
test->cm = mms_connman_test_new();
Expand All @@ -328,7 +329,8 @@ test_init(
mms_dispatcher_set_delegate(test->disp, &test->delegate);
test->http = test_http_new(test->retrieve_conf,
test->desc->content_type, test->desc->status);
mms_connman_test_set_port(test->cm, test_http_get_port(test->http));
port = test_http_get_port(test->http);
mms_connman_test_set_port(test->cm, port, TRUE);
if (desc->flags & TEST_DEFER_RECEIVE) {
mms_handler_test_defer_receive(test->handler, test->disp);
}
Expand Down Expand Up @@ -386,14 +388,14 @@ test_retrieve_once(
test.ret = RET_OK;
g_main_loop_run(test.loop);
} else {
MMS_INFO("Test %s FAILED", desc->name);
MMS_INFO("%s FAILED", desc->name);
}
} else {
if (desc->flags & TEST_PUSH_HANDLING_FAILURE_OK) {
test.ret = RET_OK;
test_finish(&test);
} else {
MMS_INFO("Test %s FAILED", desc->name);
MMS_INFO("%s FAILED", desc->name);
}
}
g_bytes_unref(push);
Expand Down
2 changes: 1 addition & 1 deletion mms-lib/test/retrieve_cancel/test_connman.c
Expand Up @@ -59,7 +59,7 @@ mms_connman_test_open_connection(
return NULL;
} else {
test->fail = TRUE;
return mms_connection_test_new(imsi, 0);
return mms_connection_test_new(imsi, 0, FALSE);
}
}

Expand Down
4 changes: 2 additions & 2 deletions mms-lib/test/retrieve_cancel/test_retrieve_cancel.c
Expand Up @@ -55,7 +55,7 @@ test_done(
MMSDispatcher* dispatcher)
{
Test* test = MMS_CAST(delegate,Test,delegate);
MMS_INFO("%s test %s", test->desc->name, (test->ret == RET_OK) ?
MMS_INFO("%s %s", test->desc->name, (test->ret == RET_OK) ?
"OK" : "FAILED");
g_main_loop_quit(test->loop);
}
Expand All @@ -68,7 +68,7 @@ test_timeout(
Test* test = data;
test->timeout_id = 0;
test->ret = RET_TIMEOUT;
MMS_INFO("%s test TIMEOUT", test->desc->name);
MMS_INFO("%s TIMEOUT", test->desc->name);
mms_dispatcher_cancel(test->disp, NULL);
return FALSE;
}
Expand Down
7 changes: 7 additions & 0 deletions mms-lib/test/retrieve_no_proxy/Makefile
@@ -0,0 +1,7 @@
# -*- Mode: makefile-gmake -*-

EXE = test_retrieve_no_proxy
SRC = $(EXE).c
COMMON_SRC = test_connection.c test_connman.c test_handler.c test_http.c

include ../common/Makefile
Binary file not shown.

0 comments on commit 0c20bc8

Please sign in to comment.