tests: avoid printing in stdout by default

Tests had either their own g_print()s or they would enable a _mm_log() method to
get all g_debug()s from the libraries printed. In order to cleanup the result of
the tests run, avoid this stdout dumps by default, and only enable them if
explicitly enabled in CFLAGS, e.g.:

  $> ./configure CFLAGS="-DENABLE_TEST_MESSAGE_TRACES"
This commit is contained in:
Aleksander Morgado
2013-06-18 17:15:03 +02:00
parent 2a922f836d
commit 6a01e51a5c
3 changed files with 35 additions and 25 deletions

View File

@@ -316,6 +316,7 @@ _mm_log (const char *loc,
const char *fmt, const char *fmt,
...) ...)
{ {
#if defined ENABLE_TEST_MESSAGE_TRACES
/* Dummy log function */ /* Dummy log function */
va_list args; va_list args;
gchar *msg; gchar *msg;
@@ -325,6 +326,7 @@ _mm_log (const char *loc,
va_end (args); va_end (args);
g_print ("%s\n", msg); g_print ("%s\n", msg);
g_free (msg); g_free (msg);
#endif
} }
int main (int argc, char **argv) int main (int argc, char **argv)

View File

@@ -22,6 +22,12 @@
#include "mm-modem-helpers.h" #include "mm-modem-helpers.h"
#include "mm-log.h" #include "mm-log.h"
#if defined ENABLE_TEST_MESSAGE_TRACES
#define trace(message, ...) g_print (message, ##__VA_ARGS__)
#else
#define trace(...)
#endif
/*****************************************************************************/ /*****************************************************************************/
/* Test CMGL responses */ /* Test CMGL responses */
@@ -202,7 +208,7 @@ test_cops_results (const gchar *desc,
GError *error = NULL; GError *error = NULL;
GList *results; GList *results;
g_print ("\nTesting %s +COPS response...\n", desc); trace ("\nTesting %s +COPS response...\n", desc);
results = mm_3gpp_parse_cops_test_response (reply, &error); results = mm_3gpp_parse_cops_test_response (reply, &error);
g_assert (results); g_assert (results);
@@ -679,7 +685,7 @@ test_creg_match (const char *test,
g_assert (data); g_assert (data);
g_assert (result); g_assert (result);
g_print ("\nTesting '%s' +C%sREG %s response...\n", trace ("\nTesting '%s' +C%sREG %s response...\n",
test, test,
result->cgreg ? "G" : "", result->cgreg ? "G" : "",
solicited ? "solicited" : "unsolicited"); solicited ? "solicited" : "unsolicited");
@@ -689,7 +695,7 @@ test_creg_match (const char *test,
GRegex *r = g_ptr_array_index (array, i); GRegex *r = g_ptr_array_index (array, i);
if (g_regex_match (r, reply, 0, &info)) { if (g_regex_match (r, reply, 0, &info)) {
g_print (" matched with %d\n", i); trace (" matched with %d\n", i);
regex_num = i + 1; regex_num = i + 1;
break; break;
} }
@@ -697,7 +703,7 @@ test_creg_match (const char *test,
info = NULL; info = NULL;
} }
g_print (" regex_num (%u) == result->regex_num (%u)\n", trace (" regex_num (%u) == result->regex_num (%u)\n",
regex_num, regex_num,
result->regex_num); result->regex_num);
@@ -711,7 +717,7 @@ test_creg_match (const char *test,
g_assert (lac == result->lac); g_assert (lac == result->lac);
g_assert (ci == result->ci); g_assert (ci == result->ci);
g_print (" access_tech (%d) == result->act (%d)\n", trace (" access_tech (%d) == result->act (%d)\n",
access_tech, result->act); access_tech, result->act);
g_assert_cmpuint (access_tech, ==, result->act); g_assert_cmpuint (access_tech, ==, result->act);
g_assert_cmpuint (cgreg, ==, result->cgreg); g_assert_cmpuint (cgreg, ==, result->cgreg);
@@ -1366,7 +1372,7 @@ test_devid_item (void *f, gpointer d)
DevidItem *item = (DevidItem *) d; DevidItem *item = (DevidItem *) d;
char *devid; char *devid;
g_print ("%s... ", item->desc); trace ("%s... ", item->desc);
devid = mm_create_device_identifier (item->vid, devid = mm_create_device_identifier (item->vid,
item->pid, item->pid,
item->ati, item->ati,
@@ -1400,7 +1406,7 @@ test_cind_results (const char *desc,
GError *error = NULL; GError *error = NULL;
GHashTable *results; GHashTable *results;
g_print ("\nTesting %s +CIND response...\n", desc); trace ("\nTesting %s +CIND response...\n", desc);
results = mm_3gpp_parse_cind_test_response (reply, &error); results = mm_3gpp_parse_cind_test_response (reply, &error);
g_assert (results); g_assert (results);
@@ -1469,7 +1475,7 @@ test_cgdcont_test_results (const gchar *desc,
GError *error = NULL; GError *error = NULL;
GList *results; GList *results;
g_print ("\nTesting %s +CGDCONT test response...\n", desc); trace ("\nTesting %s +CGDCONT test response...\n", desc);
results = mm_3gpp_parse_cgdcont_test_response (reply, &error); results = mm_3gpp_parse_cgdcont_test_response (reply, &error);
g_assert (results); g_assert (results);
@@ -1555,7 +1561,7 @@ test_cgdcont_read_results (const gchar *desc,
GError *error = NULL; GError *error = NULL;
GList *results; GList *results;
g_print ("\nTesting %s +CGDCONT response...\n", desc); trace ("\nTesting %s +CGDCONT response...\n", desc);
results = mm_3gpp_parse_cgdcont_read_response (reply, &error); results = mm_3gpp_parse_cgdcont_read_response (reply, &error);
g_assert (results); g_assert (results);
@@ -1637,7 +1643,7 @@ test_cpms_response_cinterion (void *f, gpointer d)
GArray *mem2 = NULL; GArray *mem2 = NULL;
GArray *mem3 = NULL; GArray *mem3 = NULL;
g_print ("\nTesting Cinterion +CPMS=? response...\n"); trace ("\nTesting Cinterion +CPMS=? response...\n");
g_assert (mm_3gpp_parse_cpms_test_response (reply, &mem1, &mem2, &mem3)); g_assert (mm_3gpp_parse_cpms_test_response (reply, &mem1, &mem2, &mem3));
g_assert (mem1->len == 3); g_assert (mem1->len == 3);
@@ -1665,7 +1671,7 @@ test_cnum_results (const gchar *desc,
GError *error = NULL; GError *error = NULL;
guint i; guint i;
g_print ("\nTesting +CNUM response (%s)...\n", desc); trace ("\nTesting +CNUM response (%s)...\n", desc);
results = mm_3gpp_parse_cnum_exec_response (reply, &error); results = mm_3gpp_parse_cnum_exec_response (reply, &error);
g_assert (results); g_assert (results);
@@ -1767,17 +1773,17 @@ common_parse_operator_id (const gchar *operator_id,
GError *error = NULL; GError *error = NULL;
if (expected_mcc) { if (expected_mcc) {
g_print ("Parsing Operator ID '%s' " trace ("\nParsing Operator ID '%s' "
"(%" G_GUINT16_FORMAT ", %" G_GUINT16_FORMAT ")...\n", "(%" G_GUINT16_FORMAT ", %" G_GUINT16_FORMAT ")...\n",
operator_id, expected_mcc, expected_mnc); operator_id, expected_mcc, expected_mnc);
result = mm_3gpp_parse_operator_id (operator_id, &mcc, &mnc, &error); result = mm_3gpp_parse_operator_id (operator_id, &mcc, &mnc, &error);
} else { } else {
g_print ("Validating Operator ID '%s'...\n", operator_id); trace ("\nValidating Operator ID '%s'...\n", operator_id);
result = mm_3gpp_parse_operator_id (operator_id, NULL, NULL, &error); result = mm_3gpp_parse_operator_id (operator_id, NULL, NULL, &error);
} }
if (error) if (error)
g_printerr ("\tGot %s error: %s...\n", trace ("\tGot %s error: %s...\n",
expected_success ? "unexpected" : "expected", expected_success ? "unexpected" : "expected",
error->message); error->message);
@@ -1799,7 +1805,7 @@ common_parse_operator_id (const gchar *operator_id,
static void static void
test_parse_operator_id (void *f, gpointer d) test_parse_operator_id (void *f, gpointer d)
{ {
g_print ("\n"); trace ("\n");
/* Valid MCC+MNC(2) */ /* Valid MCC+MNC(2) */
common_parse_operator_id ("41201", TRUE, 412, 1); common_parse_operator_id ("41201", TRUE, 412, 1);
common_parse_operator_id ("41201", TRUE, 0, 0); common_parse_operator_id ("41201", TRUE, 0, 0);

View File

@@ -842,6 +842,7 @@ _mm_log (const char *loc,
const char *fmt, const char *fmt,
...) ...)
{ {
#if defined ENABLE_TEST_MESSAGE_TRACES
/* Dummy log function */ /* Dummy log function */
va_list args; va_list args;
gchar *msg; gchar *msg;
@@ -851,6 +852,7 @@ _mm_log (const char *loc,
va_end (args); va_end (args);
g_print ("%s\n", msg); g_print ("%s\n", msg);
g_free (msg); g_free (msg);
#endif
} }
int main (int argc, char **argv) int main (int argc, char **argv)