Skip to content

Commit

Permalink
[test] Test removal of leading zeros from MMS proxy IP address. JB#38990
Browse files Browse the repository at this point in the history
  • Loading branch information
monich committed Jun 19, 2017
1 parent d0bf187 commit a7a0c55
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 24 deletions.
8 changes: 4 additions & 4 deletions mms-lib/test/common/test_connection.c
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013-2016 Jolla Ltd.
* Copyright (C) 2013-2017 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -74,8 +74,8 @@ mms_connection_test_set_state(
MMSConnection*
mms_connection_test_new(
const char* imsi,
unsigned short port,
gboolean proxy)
const char* proxy,
unsigned short port)
{
MMSConnectionTest* test = g_object_new(MMS_TYPE_CONNECTION_TEST, NULL);
MMSConnection* conn = &test->connection;
Expand All @@ -84,7 +84,7 @@ mms_connection_test_new(
conn->netif = test->netif = g_strdup("lo");
if (proxy) {
test->mmsc = g_strdup("http://mmsc");
test->mmsproxy = g_strdup_printf("127.0.0.1:%hu", port);
test->mmsproxy = g_strdup_printf("%s:%hu", proxy, port);
} else {
test->mmsc = g_strdup_printf("http://127.0.0.1:%hu", port);
}
Expand Down
8 changes: 4 additions & 4 deletions mms-lib/test/common/test_connection.h
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2013-2014 Jolla Ltd.
* Copyright (C) 2013-2017 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
Expand All @@ -9,7 +10,6 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/

#ifndef TEST_CONNECTION_H
Expand All @@ -20,8 +20,8 @@
MMSConnection*
mms_connection_test_new(
const char* imsi,
unsigned short port,
gboolean proxy);
const char* proxy,
unsigned short port);

#endif /* TEST_CONNECTION_H */

Expand Down
25 changes: 18 additions & 7 deletions mms-lib/test/common/test_connman.c
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013-2016 Jolla Ltd.
* Copyright (C) 2013-2017 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
*
* This program is free software; you can redistribute it and/or modify
Expand All @@ -25,7 +25,7 @@ typedef struct mms_connman_test {
MMSConnMan cm;
MMSConnection* conn;
unsigned short port;
gboolean proxy;
char* proxy;
char* default_imsi;
gboolean offline;
mms_connman_test_connect_fn connect_fn;
Expand Down Expand Up @@ -58,15 +58,24 @@ mms_connman_test_make_busy(
g_idle_add(mms_connman_test_busy_cb, test);
}

void
mms_connman_test_set_proxy(
MMSConnMan* cm,
const char* proxy,
unsigned short port)
{
MMSConnManTest* test = MMS_CONNMAN_TEST(cm);
test->proxy = g_strdup(proxy);
test->port = port;
}

void
mms_connman_test_set_port(
MMSConnMan* cm,
unsigned short port,
gboolean proxy)
{
MMSConnManTest* test = MMS_CONNMAN_TEST(cm);
test->port = port;
test->proxy = proxy;
return mms_connman_test_set_proxy(cm, proxy ? "127.0.0.1" : NULL, port);
}

void
Expand Down Expand Up @@ -133,7 +142,7 @@ mms_connman_test_open_connection(
return NULL;
} else {
mms_connman_test_make_busy(test);
test->conn = mms_connection_test_new(imsi, test->port, test->proxy);
test->conn = mms_connection_test_new(imsi, test->proxy, test->port);
if (test->connect_fn) test->connect_fn(test->connect_param);
return mms_connection_ref(test->conn);
}
Expand All @@ -153,7 +162,9 @@ void
mms_connman_test_finalize(
GObject* object)
{
g_free(MMS_CONNMAN_TEST(object)->default_imsi);
MMSConnManTest* test = MMS_CONNMAN_TEST(object);
g_free(test->proxy);
g_free(test->default_imsi);
G_OBJECT_CLASS(mms_connman_test_parent_class)->finalize(object);
}

Expand Down
10 changes: 8 additions & 2 deletions mms-lib/test/common/test_connman.h
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2013-2014 Jolla Ltd.
* Copyright (C) 2013-2017 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
Expand All @@ -9,7 +10,6 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/

#ifndef TEST_CONNMAN_H
Expand All @@ -25,6 +25,12 @@ void
MMSConnMan*
mms_connman_test_new(void);

void
mms_connman_test_set_proxy(
MMSConnMan* cm,
const char* proxy,
unsigned short port);

void
mms_connman_test_set_port(
MMSConnMan* cm,
Expand Down
10 changes: 7 additions & 3 deletions mms-lib/test/coverage/run
Expand Up @@ -33,9 +33,13 @@ for t in $TESTS ; do
popd
done

# LCOV 1.10 has branch coverage disabled per default
LCOV_OPT="--rc lcov_branch_coverage=1"
GENHTML_OPT="--branch-coverage"

FULL_COV="$COV_DIR/full.gcov"
MMSLIB_COV="$COV_DIR/mms-lib.gcov"
rm -f "$FULL_COV" "$MMSLIB_COV"
lcov -c -d "$BASE_DIR/build/$FLAVOR" -b "$BASE_DIR" -o "$FULL_COV" || exit 1
lcov -e "$FULL_COV" "$BASE_DIR/src/*" -o "$MMSLIB_COV" || exit 1
genhtml "$MMSLIB_COV" --output-directory "$COV_DIR/results" || exit 1
lcov $LCOV_OPT -c -d "$BASE_DIR/build/$FLAVOR" -b "$BASE_DIR" -o "$FULL_COV" || exit 1
lcov $LCOV_OPT -e "$FULL_COV" "$BASE_DIR/src/*" -o "$MMSLIB_COV" || exit 1
genhtml $GENHTML_OPT -t mms-engine "$MMSLIB_COV" --output-directory "$COV_DIR/results" || exit 1
29 changes: 25 additions & 4 deletions mms-lib/test/test_retrieve/test_retrieve.c
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013-2016 Jolla Ltd.
* Copyright (C) 2013-2017 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -35,7 +35,8 @@

#define MMS_MESSAGE_TYPE_NONE (0)

#define DATA_DIR "data/"
#define DATA_DIR "data/"
#define LOCALHOST "127.0.0.1"

#define TEST_TIMEOUT (10) /* seconds */

Expand All @@ -57,6 +58,7 @@ typedef struct test_desc {
enum mms_message_type reply_msg;
const TestPartDesc* parts;
unsigned int nparts;
const char* proxy;
int flags;

#define TEST_PUSH_HANDLING_FAILURE_OK (0x01)
Expand Down Expand Up @@ -130,6 +132,7 @@ static const TestDesc retrieve_tests[] = {
MMS_RECEIVE_STATE_DECODING,
MMS_MESSAGE_TYPE_ACKNOWLEDGE_IND,
TEST_PARTS(retrieve_success1_parts),
"0127.000.000.001",
0
},{
"Success2", /* Generated by Nokia C6 (Symbian "Belle") */
Expand All @@ -142,6 +145,7 @@ static const TestDesc retrieve_tests[] = {
MMS_RECEIVE_STATE_DECODING,
MMS_MESSAGE_TYPE_ACKNOWLEDGE_IND,
TEST_PARTS(retrieve_success2_parts),
"127.0.0.001",
0
},{
"Success3", /* Generated by Nokia N9 */
Expand All @@ -154,6 +158,7 @@ static const TestDesc retrieve_tests[] = {
MMS_RECEIVE_STATE_DECODING,
MMS_MESSAGE_TYPE_ACKNOWLEDGE_IND,
TEST_PARTS(retrieve_success3_parts),
LOCALHOST,
0
},{
"QuotedPrintable", /* quoted-printable transfer encoding for text */
Expand All @@ -166,6 +171,7 @@ static const TestDesc retrieve_tests[] = {
MMS_RECEIVE_STATE_DECODING,
MMS_MESSAGE_TYPE_ACKNOWLEDGE_IND,
TEST_PARTS(retrieve_transfer_encoding_parts),
LOCALHOST,
0
},{
"Base64", /* Base64 transfer encoding for text */
Expand All @@ -178,6 +184,7 @@ static const TestDesc retrieve_tests[] = {
MMS_RECEIVE_STATE_DECODING,
MMS_MESSAGE_TYPE_ACKNOWLEDGE_IND,
TEST_PARTS(retrieve_transfer_encoding_parts),
LOCALHOST,
0
},{
"InvalidSubject",
Expand All @@ -190,6 +197,7 @@ static const TestDesc retrieve_tests[] = {
MMS_RECEIVE_STATE_DECODING,
MMS_MESSAGE_TYPE_ACKNOWLEDGE_IND,
TEST_PARTS(retrieve_invalid_subject),
LOCALHOST,
0
},{
"DeferSuccess",
Expand All @@ -202,6 +210,7 @@ static const TestDesc retrieve_tests[] = {
MMS_RECEIVE_STATE_DECODING,
MMS_MESSAGE_TYPE_ACKNOWLEDGE_IND,
TEST_PARTS(retrieve_success1_parts),
LOCALHOST,
TEST_DEFER_RECEIVE
},{
"CancelReceive",
Expand All @@ -214,6 +223,7 @@ static const TestDesc retrieve_tests[] = {
MMS_RECEIVE_STATE_DECODING,
MMS_MESSAGE_TYPE_ACKNOWLEDGE_IND,
TEST_PARTS(retrieve_success1_parts),
LOCALHOST,
TEST_DEFER_RECEIVE | TEST_CANCEL_RECEIVED
},{
"Expired1",
Expand All @@ -226,6 +236,7 @@ static const TestDesc retrieve_tests[] = {
MMS_RECEIVE_STATE_DOWNLOAD_ERROR,
MMS_MESSAGE_TYPE_NONE,
TEST_PARTS_NONE,
LOCALHOST,
0
},{
"Expired2",
Expand All @@ -238,6 +249,7 @@ static const TestDesc retrieve_tests[] = {
MMS_RECEIVE_STATE_INVALID,
MMS_MESSAGE_TYPE_NOTIFYRESP_IND,
TEST_PARTS_NONE,
LOCALHOST,
TEST_REJECT_RECEIVE
},{
"SoonExpired",
Expand All @@ -250,6 +262,7 @@ static const TestDesc retrieve_tests[] = {
MMS_RECEIVE_STATE_DOWNLOAD_ERROR,
MMS_MESSAGE_TYPE_NONE,
TEST_PARTS_NONE,
LOCALHOST,
0
},{
"Offline",
Expand All @@ -262,6 +275,7 @@ static const TestDesc retrieve_tests[] = {
MMS_RECEIVE_STATE_DOWNLOAD_ERROR,
MMS_MESSAGE_TYPE_NONE,
TEST_PARTS_NONE,
LOCALHOST,
TEST_OFFLINE
},{
"Timeout",
Expand All @@ -274,6 +288,7 @@ static const TestDesc retrieve_tests[] = {
MMS_RECEIVE_STATE_DOWNLOAD_ERROR,
MMS_MESSAGE_TYPE_NONE,
TEST_PARTS_NONE,
LOCALHOST,
TEST_CONNECTION_FAILURE
},{
"NotAllowed",
Expand All @@ -286,6 +301,7 @@ static const TestDesc retrieve_tests[] = {
MMS_RECEIVE_STATE_DOWNLOAD_ERROR,
MMS_MESSAGE_TYPE_NONE,
TEST_PARTS_NONE,
LOCALHOST,
0
},{
"NotFound",
Expand All @@ -298,6 +314,7 @@ static const TestDesc retrieve_tests[] = {
MMS_RECEIVE_STATE_DOWNLOAD_ERROR,
MMS_MESSAGE_TYPE_NONE,
TEST_PARTS_NONE,
LOCALHOST,
0
},{
"MessageNotFound",
Expand All @@ -310,6 +327,7 @@ static const TestDesc retrieve_tests[] = {
MMS_RECEIVE_STATE_DOWNLOAD_ERROR,
MMS_MESSAGE_TYPE_NONE,
TEST_PARTS_NONE,
LOCALHOST,
0
},{
"GarbageRetrieve",
Expand All @@ -322,6 +340,7 @@ static const TestDesc retrieve_tests[] = {
MMS_RECEIVE_STATE_DECODING_ERROR,
MMS_MESSAGE_TYPE_NOTIFYRESP_IND,
TEST_PARTS_NONE,
LOCALHOST,
0
},{
"GarbagePush",
Expand All @@ -334,6 +353,7 @@ static const TestDesc retrieve_tests[] = {
MMS_RECEIVE_STATE_INVALID,
MMS_MESSAGE_TYPE_NONE,
TEST_PARTS_NONE,
LOCALHOST,
TEST_PUSH_HANDLING_FAILURE_OK
},{
"UnsupportedPush",
Expand All @@ -346,6 +366,7 @@ static const TestDesc retrieve_tests[] = {
MMS_RECEIVE_STATE_INVALID,
MMS_MESSAGE_TYPE_NONE,
TEST_PARTS_NONE,
LOCALHOST,
TEST_PUSH_HANDLING_FAILURE_OK
}
};
Expand Down Expand Up @@ -624,8 +645,8 @@ test_init(
if (!(desc->flags & TEST_CONNECTION_FAILURE)) {
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), TRUE);
mms_connman_test_set_proxy(test->cm, desc->proxy,
test_http_get_port(test->http));
}
if (desc->flags & TEST_OFFLINE) {
mms_connman_test_set_offline(test->cm, TRUE);
Expand Down

0 comments on commit a7a0c55

Please sign in to comment.