2011-11-23 23:15:21 +01:00
|
|
|
/*
|
2012-03-07 23:10:21 +01:00
|
|
|
** Copyright (C) 2008-2012 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
2010-01-25 09:24:33 +01:00
|
|
|
**
|
|
|
|
** This program is free software; you can redistribute it and/or modify it
|
|
|
|
** under the terms of the GNU General Public License as published by the
|
|
|
|
** Free Software Foundation; either version 3, or (at your option) any
|
|
|
|
** later version.
|
|
|
|
**
|
|
|
|
** 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.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with this program; if not, write to the Free Software Foundation,
|
2011-11-23 23:15:21 +01:00
|
|
|
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
**
|
2010-01-25 09:24:33 +01:00
|
|
|
*/
|
|
|
|
|
2010-12-04 18:08:23 +01:00
|
|
|
#if HAVE_CONFIG_H
|
2010-01-25 09:24:33 +01:00
|
|
|
#include "config.h"
|
|
|
|
#endif /*HAVE_CONFIG_H*/
|
|
|
|
|
|
|
|
#include <glib.h>
|
2010-01-31 11:15:00 +01:00
|
|
|
#include <glib/gstdio.h>
|
|
|
|
|
2010-01-25 09:24:33 +01:00
|
|
|
#include <stdlib.h>
|
2010-01-25 12:27:02 +01:00
|
|
|
#include <unistd.h>
|
2012-03-07 23:10:21 +01:00
|
|
|
#include <limits.h>
|
2010-01-25 09:24:33 +01:00
|
|
|
|
2010-09-26 14:23:17 +02:00
|
|
|
#include "test-mu-common.h"
|
2012-05-20 16:41:18 +02:00
|
|
|
#include "lib/mu-util.h"
|
2010-01-25 09:24:33 +01:00
|
|
|
|
2010-12-04 18:14:31 +01:00
|
|
|
static void
|
|
|
|
test_mu_util_dir_expand_00 (void)
|
|
|
|
{
|
2012-11-08 21:19:28 +01:00
|
|
|
#ifdef HAVE_WORDEXP_H
|
2012-03-07 23:10:21 +01:00
|
|
|
gchar *got, *expected;
|
2011-11-23 23:15:21 +01:00
|
|
|
|
2012-03-07 23:10:21 +01:00
|
|
|
got = mu_util_dir_expand ("~/IProbablyDoNotExist");
|
|
|
|
expected = g_strdup_printf ("%s%cIProbablyDoNotExist",
|
|
|
|
getenv("HOME"), G_DIR_SEPARATOR);
|
2011-11-23 23:15:21 +01:00
|
|
|
|
2012-03-07 23:10:21 +01:00
|
|
|
g_assert_cmpstr (got,==,expected);
|
2011-11-23 23:15:21 +01:00
|
|
|
|
2012-03-07 23:10:21 +01:00
|
|
|
g_free (got);
|
|
|
|
g_free (expected);
|
2012-11-08 21:19:28 +01:00
|
|
|
#endif /*HAVE_WORDEXP_H*/
|
2010-12-04 18:14:31 +01:00
|
|
|
}
|
|
|
|
|
2010-01-25 09:24:33 +01:00
|
|
|
static void
|
2010-01-25 12:27:02 +01:00
|
|
|
test_mu_util_dir_expand_01 (void)
|
2010-01-25 09:24:33 +01:00
|
|
|
{
|
2012-11-08 21:19:28 +01:00
|
|
|
#ifdef HAVE_WORDEXP_H
|
2012-03-07 23:10:21 +01:00
|
|
|
gchar *got, *expected;
|
2011-11-23 23:15:21 +01:00
|
|
|
|
2012-03-07 23:10:21 +01:00
|
|
|
got = mu_util_dir_expand ("~/Desktop");
|
|
|
|
expected = g_strdup_printf ("%s%cDesktop",
|
|
|
|
getenv("HOME"), G_DIR_SEPARATOR);
|
2011-11-23 23:15:21 +01:00
|
|
|
|
2012-03-07 23:10:21 +01:00
|
|
|
g_assert_cmpstr (got,==,expected);
|
2011-11-23 23:15:21 +01:00
|
|
|
|
2012-03-07 23:10:21 +01:00
|
|
|
g_free (got);
|
|
|
|
g_free (expected);
|
2012-11-08 21:19:28 +01:00
|
|
|
#endif /*HAVE_WORDEXP_H*/
|
2010-01-25 12:27:02 +01:00
|
|
|
}
|
2010-01-25 09:24:33 +01:00
|
|
|
|
2010-12-04 18:14:31 +01:00
|
|
|
|
2010-10-09 10:56:55 +02:00
|
|
|
|
2010-01-25 12:27:02 +01:00
|
|
|
static void
|
|
|
|
test_mu_util_guess_maildir_01 (void)
|
|
|
|
{
|
2012-03-07 23:10:21 +01:00
|
|
|
char *got;
|
|
|
|
const char *expected;
|
2010-01-25 12:27:02 +01:00
|
|
|
|
2012-03-07 23:10:21 +01:00
|
|
|
/* skip the test if there's no /tmp */
|
|
|
|
if (access ("/tmp", F_OK))
|
|
|
|
return;
|
2011-11-23 23:15:21 +01:00
|
|
|
|
2012-03-07 23:10:21 +01:00
|
|
|
g_setenv ("MAILDIR", "/tmp", TRUE);
|
2010-01-25 12:27:02 +01:00
|
|
|
|
2012-03-07 23:10:21 +01:00
|
|
|
got = mu_util_guess_maildir ();
|
|
|
|
expected = "/tmp";
|
2010-01-25 12:27:02 +01:00
|
|
|
|
2012-03-07 23:10:21 +01:00
|
|
|
g_assert_cmpstr (got,==,expected);
|
|
|
|
g_free (got);
|
2010-01-25 12:27:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_mu_util_guess_maildir_02 (void)
|
|
|
|
{
|
2012-03-07 23:10:21 +01:00
|
|
|
char *got, *mdir;
|
2011-11-23 23:15:21 +01:00
|
|
|
|
2012-03-07 23:10:21 +01:00
|
|
|
g_unsetenv ("MAILDIR");
|
2010-01-25 12:27:02 +01:00
|
|
|
|
2012-03-07 23:10:21 +01:00
|
|
|
mdir = g_strdup_printf ("%s%cMaildir",
|
|
|
|
getenv("HOME"), G_DIR_SEPARATOR);
|
|
|
|
got = mu_util_guess_maildir ();
|
2010-01-25 12:27:02 +01:00
|
|
|
|
2012-03-07 23:10:21 +01:00
|
|
|
if (access (mdir, F_OK) == 0)
|
|
|
|
g_assert_cmpstr (got, ==, mdir);
|
|
|
|
else
|
|
|
|
g_assert_cmpstr (got, == , NULL);
|
2011-11-23 23:15:21 +01:00
|
|
|
|
2012-03-07 23:10:21 +01:00
|
|
|
g_free (got);
|
|
|
|
g_free (mdir);
|
2010-01-25 12:27:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-25 21:21:11 +01:00
|
|
|
static void
|
|
|
|
test_mu_util_check_dir_01 (void)
|
|
|
|
{
|
2012-03-07 23:10:21 +01:00
|
|
|
if (g_access ("/usr/bin", F_OK) == 0) {
|
|
|
|
g_assert_cmpuint (
|
|
|
|
mu_util_check_dir ("/usr/bin", TRUE, FALSE) == TRUE,
|
|
|
|
==,
|
|
|
|
g_access ("/usr/bin", R_OK) == 0);
|
|
|
|
}
|
2010-01-25 21:21:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_mu_util_check_dir_02 (void)
|
|
|
|
{
|
2012-03-07 23:10:21 +01:00
|
|
|
if (g_access ("/tmp", F_OK) == 0) {
|
|
|
|
g_assert_cmpuint (
|
|
|
|
mu_util_check_dir ("/tmp", FALSE, TRUE) == TRUE,
|
|
|
|
==,
|
|
|
|
g_access ("/tmp", W_OK) == 0);
|
|
|
|
}
|
2010-01-25 21:21:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_mu_util_check_dir_03 (void)
|
|
|
|
{
|
2012-03-07 23:10:21 +01:00
|
|
|
if (g_access (".", F_OK) == 0) {
|
|
|
|
g_assert_cmpuint (
|
|
|
|
mu_util_check_dir (".", TRUE, TRUE) == TRUE,
|
|
|
|
==,
|
|
|
|
g_access (".", W_OK | R_OK) == 0);
|
|
|
|
}
|
2010-01-25 21:21:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_mu_util_check_dir_04 (void)
|
|
|
|
{
|
2012-03-07 23:10:21 +01:00
|
|
|
/* not a dir, so it must be false */
|
|
|
|
g_assert_cmpuint (
|
|
|
|
mu_util_check_dir ("test-util.c", TRUE, TRUE),
|
|
|
|
==,
|
|
|
|
FALSE);
|
2010-01-25 21:21:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-04 21:48:13 +01:00
|
|
|
static void
|
|
|
|
test_mu_util_str_from_strv_01 (void)
|
2011-11-23 23:15:21 +01:00
|
|
|
{
|
2012-03-07 23:10:21 +01:00
|
|
|
const gchar *strv[] = { "aap", "noot", "mies", NULL };
|
|
|
|
gchar *str = mu_util_str_from_strv (strv);
|
|
|
|
g_assert_cmpstr (str, ==, "aap noot mies");
|
|
|
|
g_free (str);
|
2010-02-04 21:48:13 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_mu_util_str_from_strv_02 (void)
|
2011-11-23 23:15:21 +01:00
|
|
|
{
|
2012-03-07 23:10:21 +01:00
|
|
|
const gchar *strv[] = { "test", NULL };
|
|
|
|
gchar *str = mu_util_str_from_strv (strv);
|
|
|
|
g_assert_cmpstr (str, ==, "test");
|
|
|
|
g_free (str);
|
2010-02-04 21:48:13 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_mu_util_str_from_strv_03 (void)
|
2011-11-23 23:15:21 +01:00
|
|
|
{
|
2012-03-07 23:10:21 +01:00
|
|
|
const gchar *strv[] = { NULL };
|
|
|
|
gchar *str = mu_util_str_from_strv (strv);
|
|
|
|
g_assert_cmpstr (str, ==, "");
|
|
|
|
g_free (str);
|
2010-12-12 17:33:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_mu_util_get_dtype_with_lstat (void)
|
|
|
|
{
|
2012-03-07 23:10:21 +01:00
|
|
|
g_assert_cmpuint (
|
|
|
|
mu_util_get_dtype_with_lstat (MU_TESTMAILDIR), ==, DT_DIR);
|
|
|
|
g_assert_cmpuint (
|
|
|
|
mu_util_get_dtype_with_lstat (MU_TESTMAILDIR2), ==, DT_DIR);
|
|
|
|
g_assert_cmpuint (
|
2012-03-14 20:33:06 +01:00
|
|
|
mu_util_get_dtype_with_lstat (MU_TESTMAILDIR2 "/Foo/cur/mail5"),
|
2012-03-07 23:10:21 +01:00
|
|
|
==, DT_REG);
|
2010-02-04 21:48:13 +01:00
|
|
|
}
|
|
|
|
|
2010-01-25 21:21:11 +01:00
|
|
|
|
2012-10-18 11:11:43 +02:00
|
|
|
static void
|
|
|
|
test_mu_util_supports (void)
|
|
|
|
{
|
|
|
|
gboolean has_guile, has_crypto;
|
|
|
|
gchar *path;
|
|
|
|
|
|
|
|
has_guile = FALSE;
|
|
|
|
#ifdef BUILD_GUILE
|
|
|
|
has_guile = TRUE;
|
|
|
|
#endif /*BUILD_GUILE*/
|
|
|
|
|
|
|
|
g_assert_cmpuint (mu_util_supports (MU_FEATURE_GUILE),==,has_guile);
|
|
|
|
|
|
|
|
has_crypto = FALSE;
|
|
|
|
#ifdef BUILD_CRYPTO
|
|
|
|
has_crypto = TRUE;
|
|
|
|
#endif /*BUILD_CRYPTO*/
|
|
|
|
|
|
|
|
g_assert_cmpuint (mu_util_supports (MU_FEATURE_CRYPTO),==,has_crypto);
|
|
|
|
|
|
|
|
path = g_find_program_in_path ("gnuplot");
|
|
|
|
g_free (path);
|
|
|
|
|
|
|
|
g_assert_cmpuint (mu_util_supports (MU_FEATURE_GNUPLOT),==,path ? TRUE : FALSE);
|
|
|
|
|
|
|
|
g_assert_cmpuint (
|
|
|
|
mu_util_supports (MU_FEATURE_GNUPLOT|MU_FEATURE_GUILE|MU_FEATURE_CRYPTO),
|
|
|
|
==,
|
|
|
|
has_guile && has_crypto && path ? TRUE : FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_mu_util_program_in_path (void)
|
|
|
|
{
|
|
|
|
g_assert_cmpuint (mu_util_program_in_path("ls"),==,TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-09 10:56:55 +02:00
|
|
|
|
2010-01-25 09:24:33 +01:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
2012-03-07 23:10:21 +01:00
|
|
|
g_test_init (&argc, &argv, NULL);
|
|
|
|
|
|
|
|
/* mu_util_dir_expand */
|
|
|
|
g_test_add_func ("/mu-util/mu-util-dir-expand-00", test_mu_util_dir_expand_00);
|
|
|
|
g_test_add_func ("/mu-util/mu-util-dir-expand-01", test_mu_util_dir_expand_01);
|
|
|
|
|
|
|
|
/* mu_util_guess_maildir */
|
|
|
|
g_test_add_func ("/mu-util/mu-util-guess-maildir-01",
|
|
|
|
test_mu_util_guess_maildir_01);
|
|
|
|
g_test_add_func ("/mu-util/mu-util-guess-maildir-02",
|
|
|
|
test_mu_util_guess_maildir_02);
|
|
|
|
|
|
|
|
/* mu_util_check_dir */
|
|
|
|
g_test_add_func ("/mu-util/mu-util-check-dir-01", test_mu_util_check_dir_01);
|
|
|
|
g_test_add_func ("/mu-util/mu-util-check-dir-02", test_mu_util_check_dir_02);
|
|
|
|
g_test_add_func ("/mu-util/mu-util-check-dir-03", test_mu_util_check_dir_03);
|
|
|
|
g_test_add_func ("/mu-util/mu-util-check-dir-04", test_mu_util_check_dir_04);
|
|
|
|
|
|
|
|
/* test_mu_util_str_from_strv */
|
|
|
|
g_test_add_func ("/mu-util/mu-util-str-from-strv-01",
|
|
|
|
test_mu_util_str_from_strv_01);
|
|
|
|
g_test_add_func ("/mu-util/mu-util-str-from-strv-02",
|
|
|
|
test_mu_util_str_from_strv_02);
|
|
|
|
g_test_add_func ("/mu-util/mu-util-str-from-strv-03",
|
|
|
|
test_mu_util_str_from_strv_03);
|
|
|
|
|
|
|
|
g_test_add_func ("/mu-util/mu-util-get-dtype-with-lstat",
|
|
|
|
test_mu_util_get_dtype_with_lstat);
|
|
|
|
|
2012-10-18 11:11:43 +02:00
|
|
|
g_test_add_func ("/mu-util/mu-util-supports", test_mu_util_supports);
|
|
|
|
g_test_add_func ("/mu-util/mu-util-program-in-path", test_mu_util_program_in_path);
|
|
|
|
|
|
|
|
|
2012-03-07 23:10:21 +01:00
|
|
|
g_log_set_handler (NULL,
|
|
|
|
G_LOG_LEVEL_DEBUG|
|
|
|
|
G_LOG_LEVEL_MESSAGE|
|
|
|
|
G_LOG_LEVEL_INFO, (GLogFunc)black_hole, NULL);
|
|
|
|
|
|
|
|
return g_test_run ();
|
2010-01-25 09:24:33 +01:00
|
|
|
}
|