Commit dce0250c authored by Slava Monich's avatar Slava Monich

[test] Make sure that temporary directories are deleted

Some tests did't delete temporary directories.
parent a911b08b
/*
* Copyright (C) 2016 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
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* 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.
*
*/
#include "test_util.h"
#include "mms_file_util.h"
#include "mms_log.h"
void
test_dirs_init(
TestDirs* dirs,
const char* test)
{
const char* tmp = g_get_tmp_dir();
dirs->root = g_mkdtemp(g_strconcat(tmp, "/", test, "_XXXXXX", NULL));
dirs->msg = g_strconcat(dirs->root, "/" MMS_MESSAGE_DIR, NULL);
dirs->attic = g_strconcat(dirs->root, "/" MMS_ATTIC_DIR, NULL);
MMS_VERBOSE("Temporary directory %s", dirs->root);
}
static
void
test_dir_remove(
const char* dir)
{
if (rmdir(dir) < 0) {
if (errno != ENOENT) {
MMS_ERR("Failed to remove %s: %s", dir, strerror(errno));
}
} else {
MMS_VERBOSE("Deleted %s", dir);
}
}
void
test_dirs_cleanup(
TestDirs* dirs,
gboolean remove)
{
if (remove) {
test_dir_remove(dirs->attic);
test_dir_remove(dirs->msg);
test_dir_remove(dirs->root);
}
g_free(dirs->root);
g_free(dirs->msg);
g_free(dirs->attic);
}
/*
* Local Variables:
* mode: C
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*/
/*
* Copyright (C) 2016 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
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* 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_UTIL_H
#define TEST_UTIL_H
#include "mms_lib_types.h"
typedef struct test_dirs {
char* root;
char* msg;
char* attic;
} TestDirs;
void
test_dirs_init(
TestDirs* dirs,
const char* test);
void
test_dirs_cleanup(
TestDirs* dirs,
gboolean remove);
#endif /* TEST_UTIL_H */
/*
* Local Variables:
* mode: C
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*/
# -*- Mode: makefile-gmake -*-
EXE = test_delivery_ind
SRC = test_delivery_ind.c
COMMON_SRC = test_connection.c test_connman.c test_handler.c
SRC = $(EXE).c
COMMON_SRC = test_connection.c test_connman.c test_handler.c test_util.c
include ../common/Makefile
/*
* Copyright (C) 2013-2014 Jolla Ltd.
* Copyright (C) 2013-2016 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
......@@ -14,6 +15,7 @@
#include "test_connman.h"
#include "test_handler.h"
#include "test_util.h"
#include "mms_file_util.h"
#include "mms_lib_log.h"
......@@ -232,11 +234,12 @@ int main(int argc, char* argv[])
{
int ret;
MMSConfig config;
const char* test_name = NULL;
const char* test = "test_delivery_ind";
const char* testcase = NULL;
mms_lib_init(argv[0]);
mms_lib_default_config(&config);
mms_log_default.name = "test_delivery_ind";
mms_log_default.name = test;
if (argc > 1 && !strcmp(argv[1], "-v")) {
mms_log_default.level = MMS_LOGLEVEL_VERBOSE;
......@@ -249,18 +252,17 @@ int main(int argc, char* argv[])
}
if (argc == 2 && argv[1][0] != '-') {
test_name = argv[1];
testcase = argv[1];
}
if (argc == 1 || test_name) {
char* tmpd = g_mkdtemp(g_strdup("/tmp/test_delivery_ind_XXXXXX"));
MMS_VERBOSE("Temporary directory %s", tmpd);
config.root_dir = tmpd;
if (argc == 1 || testcase) {
TestDirs dirs;
test_dirs_init(&dirs, test);
config.root_dir = dirs.root;
config.idle_secs = 0;
config.attic_enabled = TRUE;
ret = test_run(&config, test_name);
remove(tmpd);
g_free(tmpd);
ret = test_run(&config, testcase);
test_dirs_cleanup(&dirs, TRUE);
} else {
printf("Usage: test_delivery_ind [-v] [TEST]\n");
ret = RET_ERR;
......
# -*- Mode: makefile-gmake -*-
EXE = test_read_ind
SRC = test_read_ind.c
COMMON_SRC = test_connection.c test_connman.c test_handler.c
SRC = $(EXE).c
COMMON_SRC = test_connection.c test_connman.c test_handler.c test_util.c
include ../common/Makefile
/*
* Copyright (C) 2013-2014 Jolla Ltd.
* Copyright (C) 2013-2016 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
......@@ -14,6 +15,7 @@
#include "test_connman.h"
#include "test_handler.h"
#include "test_util.h"
#include "mms_file_util.h"
#include "mms_lib_log.h"
......@@ -232,11 +234,12 @@ int main(int argc, char* argv[])
{
int ret;
MMSConfig config;
const char* test_name = NULL;
const char* test = "test_read_ind";
const char* testcase = NULL;
mms_lib_init(argv[0]);
mms_lib_default_config(&config);
mms_log_default.name = "test_read_ind";
mms_log_default.name = test;
if (argc > 1 && !strcmp(argv[1], "-v")) {
mms_log_default.level = MMS_LOGLEVEL_VERBOSE;
......@@ -249,18 +252,17 @@ int main(int argc, char* argv[])
}
if (argc == 2 && argv[1][0] != '-') {
test_name = argv[1];
testcase = argv[1];
}
if (argc == 1 || test_name) {
char* tmpd = g_mkdtemp(g_strdup("/tmp/test_read_ind_XXXXXX"));
MMS_VERBOSE("Temporary directory %s", tmpd);
config.root_dir = tmpd;
if (argc == 1 || testcase) {
TestDirs dirs;
test_dirs_init(&dirs, test);
config.root_dir = dirs.root;
config.idle_secs = 0;
config.attic_enabled = TRUE;
ret = test_run(&config, test_name);
remove(tmpd);
g_free(tmpd);
ret = test_run(&config, testcase);
test_dirs_cleanup(&dirs, TRUE);
} else {
printf("Usage: test_read_ind [-v] [TEST]\n");
ret = RET_ERR;
......
# -*- Mode: makefile-gmake -*-
EXE = test_read_report
SRC = test_read_report.c
COMMON_SRC = test_connection.c test_connman.c test_handler.c test_http.c
SRC = $(EXE).c
COMMON_SRC = test_connection.c test_connman.c test_handler.c test_http.c \
test_util.c
include ../common/Makefile
/*
* Copyright (C) 2013-2015 Jolla Ltd.
* Copyright (C) 2013-2016 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
*
* This program is free software; you can redistribute it and/or modify
......@@ -16,6 +16,7 @@
#include "test_connman.h"
#include "test_handler.h"
#include "test_http.h"
#include "test_util.h"
#include "mms_log.h"
#include "mms_codec.h"
......@@ -253,15 +254,12 @@ int main(int argc, char* argv[])
options = g_option_context_new("[TEST] - MMS read report test");
g_option_context_add_main_entries(options, entries, NULL);
if (g_option_context_parse(options, &argc, &argv, &error)) {
const char* test = "test_read_report";
MMSConfig config;
char* tmpd = g_mkdtemp(g_strdup("/tmp/test_read_report_XXXXXX"));
char* msgdir = g_strconcat(tmpd, "/msg", NULL);
TestDirs dirs;
mms_lib_init(argv[0]);
mms_lib_default_config(&config);
config.idle_secs = 0;
config.root_dir = tmpd;
mms_log_default.name = "test_read_report";
mms_log_default.name = test;
if (verbose) {
mms_log_default.level = MMS_LOGLEVEL_VERBOSE;
} else {
......@@ -272,7 +270,10 @@ int main(int argc, char* argv[])
mms_log_stdout_timestamp = FALSE;
}
MMS_VERBOSE("Temporary directory %s", tmpd);
test_dirs_init(&dirs, test);
mms_lib_default_config(&config);
config.idle_secs = 0;
config.root_dir = dirs.root;
if (argc < 2) {
ret = test_read_report(&config, NULL, debug);
} else {
......@@ -282,11 +283,7 @@ int main(int argc, char* argv[])
if (ret == RET_OK && test_status != RET_OK) ret = test_status;
}
}
rmdir(msgdir);
rmdir(tmpd);
remove(tmpd);
g_free(tmpd);
g_free(msgdir);
test_dirs_cleanup(&dirs, TRUE);
mms_lib_deinit();
} else {
fprintf(stderr, "%s\n", MMS_ERRMSG(error));
......
# -*- Mode: makefile-gmake -*-
EXE = test_retrieve
SRC = test_retrieve.c
COMMON_SRC = test_connection.c test_connman.c test_handler.c test_http.c
SRC = $(EXE).c
COMMON_SRC = test_connection.c test_connman.c test_handler.c test_http.c \
test_util.c
include ../common/Makefile
......@@ -16,6 +16,7 @@
#include "test_connman.h"
#include "test_handler.h"
#include "test_http.h"
#include "test_util.h"
#include "mms_codec.h"
#include "mms_file_util.h"
......@@ -758,18 +759,12 @@ int main(int argc, char* argv[])
options = g_option_context_new("[TEST] - MMS retrieve test");
g_option_context_add_main_entries(options, entries, NULL);
if (g_option_context_parse(options, &argc, &argv, &error)) {
const char* test = "test_retrieve";
MMSConfig config;
char* tmpd = g_mkdtemp(g_strdup("/tmp/test_retrieve_XXXXXX"));
char* msgdir = g_strconcat(tmpd, "/msg", NULL);
mms_lib_init(argv[0]);
mms_lib_default_config(&config);
config.root_dir = tmpd;
config.keep_temp_files = keep_temp;
config.idle_secs = 0;
config.attic_enabled = TRUE;
TestDirs dirs;
mms_log_set_type(MMS_LOG_TYPE_STDOUT, "test_retrieve");
mms_lib_init(argv[0]);
mms_log_set_type(MMS_LOG_TYPE_STDOUT, test);
if (verbose) {
mms_log_default.level = MMS_LOGLEVEL_VERBOSE;
} else {
......@@ -781,7 +776,13 @@ int main(int argc, char* argv[])
mms_log_stdout_timestamp = FALSE;
}
MMS_VERBOSE("Temporary directory %s", tmpd);
test_dirs_init(&dirs, test);
mms_lib_default_config(&config);
config.root_dir = dirs.root;
config.keep_temp_files = keep_temp;
config.idle_secs = 0;
config.attic_enabled = TRUE;
if (argc < 2) {
ret = test_retrieve(&config, NULL, debug);
} else {
......@@ -792,10 +793,7 @@ int main(int argc, char* argv[])
}
}
rmdir(msgdir);
rmdir(tmpd);
g_free(msgdir);
g_free(tmpd);
test_dirs_cleanup(&dirs, !keep_temp);
mms_lib_deinit();
} else {
fprintf(stderr, "%s\n", MMS_ERRMSG(error));
......
......@@ -2,6 +2,7 @@
EXE = test_retrieve_no_proxy
SRC = $(EXE).c
COMMON_SRC = test_connection.c test_connman.c test_handler.c test_http.c
COMMON_SRC = test_connection.c test_connman.c test_handler.c test_http.c \
test_util.c
include ../common/Makefile
/*
* Copyright (C) 2013-2014 Jolla Ltd.
* Copyright (C) 2013-2016 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
......@@ -15,6 +16,7 @@
#include "test_connman.h"
#include "test_handler.h"
#include "test_http.h"
#include "test_util.h"
#include "mms_log.h"
#include "mms_codec.h"
......@@ -227,10 +229,11 @@ int main(int argc, char* argv[])
{
int ret;
MMSConfig config;
const char* test = "test_retrieve_no_proxy";
mms_lib_init(argv[0]);
mms_lib_default_config(&config);
mms_log_default.name = "test_retrieve_no_proxy";
mms_log_default.name = test;
if (argc > 1 && !strcmp(argv[1], "-v")) {
mms_log_default.level = MMS_LOGLEVEL_VERBOSE;
......@@ -239,19 +242,19 @@ int main(int argc, char* argv[])
mms_log_default.level = MMS_LOGLEVEL_INFO;
mms_task_decode_log.level =
mms_task_retrieve_log.level =
mms_task_http_log.level =
mms_task_notification_log.level = MMS_LOGLEVEL_NONE;
mms_log_stdout_timestamp = FALSE;
}
if (argc == 1) {
char* tmpd = g_mkdtemp(g_strdup("/tmp/test_retrieve_XXXXXX"));
MMS_VERBOSE("Temporary directory %s", tmpd);
config.root_dir = tmpd;
TestDirs dirs;
test_dirs_init(&dirs, test);
config.root_dir = dirs.root;
config.idle_secs = 0;
config.attic_enabled = TRUE;
ret = test_retrieve_no_proxy(&config);
remove(tmpd);
g_free(tmpd);
test_dirs_cleanup(&dirs, TRUE);
} else {
printf("Usage: test_retrieve [-v] [TEST]\n");
ret = RET_ERR;
......
......@@ -2,6 +2,7 @@
EXE = test_retrieve_order
SRC = $(EXE).c
COMMON_SRC = test_connection.c test_connman.c test_handler.c test_http.c
COMMON_SRC = test_connection.c test_connman.c test_handler.c test_http.c \
test_util.c
include ../common/Makefile
......@@ -16,6 +16,7 @@
#include "test_connman.h"
#include "test_handler.h"
#include "test_http.h"
#include "test_util.h"
#include "mms_codec.h"
#include "mms_file_util.h"
......@@ -375,21 +376,15 @@ int main(int argc, char* argv[])
{ NULL }
};
options = g_option_context_new("[TEST] - MMS retrieve test");
options = g_option_context_new("[TEST] - MMS task order test");
g_option_context_add_main_entries(options, entries, NULL);
if (g_option_context_parse(options, &argc, &argv, &error)) {
const char* test = "test_retrieve_order";
MMSConfig config;
char* tmpd = g_mkdtemp(g_strdup("/tmp/test_retrieve_order_XXXXXX"));
char* msgdir = g_strconcat(tmpd, "/msg", NULL);
TestDirs dirs;
mms_lib_init(argv[0]);
mms_lib_default_config(&config);
config.root_dir = tmpd;
config.keep_temp_files = keep_temp;
config.idle_secs = 0;
config.attic_enabled = TRUE;
mms_log_set_type(MMS_LOG_TYPE_STDOUT, "test_retrieve_order");
mms_log_default.name = test;
if (verbose) {
mms_log_default.level = MMS_LOGLEVEL_VERBOSE;
} else {
......@@ -401,7 +396,11 @@ int main(int argc, char* argv[])
mms_log_stdout_timestamp = FALSE;
}
MMS_VERBOSE("Temporary directory %s", tmpd);
test_dirs_init(&dirs, test);
mms_lib_default_config(&config);
config.root_dir = dirs.root;
config.keep_temp_files = keep_temp;
config.idle_secs = 0;
if (argc < 2) {
ret = test_order(&config, NULL, debug);
} else {
......@@ -412,10 +411,7 @@ int main(int argc, char* argv[])
}
}
rmdir(msgdir);
rmdir(tmpd);
g_free(msgdir);
g_free(tmpd);
test_dirs_cleanup(&dirs, TRUE);
mms_lib_deinit();
} else {
fprintf(stderr, "%s\n", MMS_ERRMSG(error));
......
# -*- Mode: makefile-gmake -*-
EXE = test_send
SRC = test_send.c
COMMON_SRC = test_connection.c test_connman.c test_handler.c test_http.c
SRC = $(EXE).c
COMMON_SRC = test_connection.c test_connman.c test_handler.c test_http.c \
test_util.c
include ../common/Makefile
......@@ -16,6 +16,7 @@
#include "test_connman.h"
#include "test_handler.h"
#include "test_http.h"
#include "test_util.h"
#include "mms_log.h"
#include "mms_codec.h"
......@@ -528,17 +529,12 @@ int main(int argc, char* argv[])
options = g_option_context_new("[TEST] - MMS send test");
g_option_context_add_main_entries(options, entries, NULL);
if (g_option_context_parse(options, &argc, &argv, NULL) && argc < 3) {
const char* test = "test_send";
const char* testcase = (argc == 2) ? argv[1] : NULL;
MMSConfig config;
const char* test_name = (argc == 2) ? argv[1] : NULL;
char* tmpd = g_mkdtemp(g_strdup("/tmp/test_send_XXXXXX"));
MMS_VERBOSE("Temporary directory %s", tmpd);
TestDirs dirs;
mms_lib_default_config(&config);
config.keep_temp_files = keep_temp;
config.root_dir = tmpd;
config.idle_secs = 0;
mms_log_set_type(MMS_LOG_TYPE_STDOUT, "test_send");
mms_log_set_type(MMS_LOG_TYPE_STDOUT, test);
if (verbose) {
mms_log_default.level = MMS_LOGLEVEL_VERBOSE;
} else {
......@@ -548,9 +544,14 @@ int main(int argc, char* argv[])
mms_log_stdout_timestamp = FALSE;
}
ret = test_run(&config, test_name, debug);
remove(tmpd);
g_free(tmpd);
test_dirs_init(&dirs, test);
mms_lib_default_config(&config);
config.keep_temp_files = keep_temp;
config.root_dir = dirs.root;
config.idle_secs = 0;
ret = test_run(&config, testcase, debug);
test_dirs_cleanup(&dirs, !keep_temp);
} else {
printf("Usage: test_send [-v] [TEST]\n");
ret = RET_ERR;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment