test/md5.o \
test/rfc2047.o \
test/address.o \
- test/url.o \
- test/file.o
+ test/url.o
ADDRESS_OBJS = test/address/main.o \
test/address/mutt_addr_append.o \
test/envlist/mutt_envlist_unset.o
FILE_OBJS = test/file/main.o \
+ test/file/common.o \
test/file/mutt_file_check_empty.o \
test/file/mutt_file_chmod_add.o \
test/file/mutt_file_chmod_add_stat.o \
+++ /dev/null
-/**
- * @file
- * Test code for the file operations
- *
- * @authors
- * Copyright (C) 2018 Ian Zimmerman
- *
- * @copyright
- * 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 2 of the License, 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, see <http://www.gnu.org/licenses/>.
- */
-
-#define TEST_NO_MAIN
-#include "acutest.h"
-#include <stdbool.h>
-#include <stdio.h>
-#include <string.h>
-#include "mutt/file.h"
-
-static const char *lines[] = {
- "This is the first line.",
- "The second line.",
- "And the third line",
- NULL,
-};
-
-#define NUM_TEST_LINES (sizeof(lines) / sizeof(const char *) - 1)
-#define BOOLIFY(x) ((x) ? "true" : "false")
-#define SET_UP() (set_up(__func__))
-#define TEAR_DOWN(fp) (tear_down((fp), __func__))
-
-static FILE *set_up(const char *funcname)
-{
- int res = 0;
- FILE *fp = tmpfile();
- const char **linep = NULL;
- if (!fp)
- goto err1;
- for (linep = lines; *linep; linep++)
- {
- res = fputs(*linep, fp);
- if (res == EOF)
- goto err2;
- res = fputc('\n', fp);
- if (res == EOF)
- goto err2;
- }
- rewind(fp);
- return fp;
-err2:
- fclose(fp);
-err1:
- TEST_MSG("Failed to set up test %s", funcname);
- return NULL;
-}
-
-static void tear_down(FILE *fp, const char *funcname)
-{
- int res = fclose(fp);
- if (res == EOF)
- TEST_MSG("Failed to tear down test %s", funcname);
-}
-
-void test_file_iter_line(void)
-{
- FILE *fp = SET_UP();
- if (!fp)
- return;
- struct MuttFileIter iter = { 0 };
- bool res;
- for (int i = 0; i < NUM_TEST_LINES; i++)
- {
- res = mutt_file_iter_line(&iter, fp, 0);
- if (!TEST_CHECK(res))
- {
- TEST_MSG("Expected: true");
- TEST_MSG("Actual: false");
- }
- if (!TEST_CHECK(strcmp(iter.line, lines[i]) == 0))
- {
- TEST_MSG("Expected: %s", lines[i]);
- TEST_MSG("Actual: %s", iter.line);
- }
- if (!TEST_CHECK(iter.line_num == i + 1))
- {
- TEST_MSG("Expected: %d", i + 1);
- TEST_MSG("Actual: %d", iter.line_num);
- }
- }
- res = mutt_file_iter_line(&iter, fp, 0);
- if (!TEST_CHECK(!res))
- {
- TEST_MSG("Expected: false");
- TEST_MSG("Actual: true");
- }
- TEAR_DOWN(fp);
-}
-
-static bool mapping_func(char *line, int line_num, void *user_data)
-{
- const int *p_last_line_num = (const int *) (user_data);
- if (!TEST_CHECK(strcmp(line, lines[line_num - 1]) == 0))
- {
- TEST_MSG("Expected: %s", lines[line_num - 1]);
- TEST_MSG("Actual: %s", line);
- }
- return (line_num < *p_last_line_num);
-}
-
-static void test_file_map_lines_breaking_after(int last_line, bool expected)
-{
- FILE *fp = SET_UP();
- if (!fp)
- return;
- bool res = mutt_file_map_lines(mapping_func, &last_line, fp, 0);
- if (!TEST_CHECK(res == expected))
- {
- TEST_MSG("Expected: %s", BOOLIFY(expected));
- TEST_MSG("Actual: %s", BOOLIFY(res));
- }
- TEAR_DOWN(fp);
-}
-
-void test_file_map_lines(void)
-{
- test_file_map_lines_breaking_after(NUM_TEST_LINES + 1, true);
- test_file_map_lines_breaking_after(0, false);
- test_file_map_lines_breaking_after(1, false);
- test_file_map_lines_breaking_after(NUM_TEST_LINES, false);
-}
--- /dev/null
+/**
+ * @file
+ * Common code for file tests
+ *
+ * @authors
+ * Copyright (C) 2019 Richard Russon <rich@flatcap.org>
+ *
+ * @copyright
+ * 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 2 of the License, 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#define TEST_NO_MAIN
+#include "acutest.h"
+#include "config.h"
+#include "mutt/mutt.h"
+
+const char *file_lines[] = {
+ "This is the first line.",
+ "The second line.",
+ "And the third line",
+ NULL,
+};
+
+size_t file_num_test_lines(void)
+{
+ return (sizeof(file_lines) / sizeof(const char *) - 1);
+}
+
+FILE *file_set_up(const char *funcname)
+{
+ int res = 0;
+ const char **linep = NULL;
+ FILE *fp = tmpfile();
+ if (!fp)
+ goto err1;
+ for (linep = file_lines; *linep; linep++)
+ {
+ res = fputs(*linep, fp);
+ if (res == EOF)
+ goto err2;
+ res = fputc('\n', fp);
+ if (res == EOF)
+ goto err2;
+ }
+ rewind(fp);
+ return fp;
+err2:
+ fclose(fp);
+err1:
+ TEST_MSG("Failed to set up test %s", funcname);
+ return NULL;
+}
+
+void file_tear_down(FILE *fp, const char *funcname)
+{
+ int res = fclose(fp);
+ if (res == EOF)
+ TEST_MSG("Failed to tear down test %s", funcname);
+}
--- /dev/null
+/**
+ * @file
+ * Common code for file tests
+ *
+ * @authors
+ * Copyright (C) 2019 Richard Russon <rich@flatcap.org>
+ *
+ * @copyright
+ * 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 2 of the License, 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "acutest.h"
+#include "config.h"
+#include <stdio.h>
+#include "mutt/mutt.h"
+
+extern const char *file_lines[];
+
+FILE *file_set_up(const char *funcname);
+void file_tear_down(FILE *fp, const char *funcname);
+size_t file_num_test_lines(void);
+
+#define SET_UP() (file_set_up(__func__))
+#define TEAR_DOWN(fp) (file_tear_down((fp), __func__))
+
#include "acutest.h"
#include "config.h"
#include "mutt/mutt.h"
+#include "common.h"
void test_mutt_file_iter_line(void)
{
struct MuttFileIter muttfileiter = { 0 };
TEST_CHECK(!mutt_file_iter_line(&muttfileiter, NULL, 0));
}
+
+ {
+ FILE *fp = SET_UP();
+ if (!fp)
+ return;
+ struct MuttFileIter iter = { 0 };
+ bool res;
+ for (int i = 0; file_lines[i]; i++)
+ {
+ res = mutt_file_iter_line(&iter, fp, 0);
+ if (!TEST_CHECK(res))
+ {
+ TEST_MSG("Expected: true");
+ TEST_MSG("Actual: false");
+ }
+ if (!TEST_CHECK(strcmp(iter.line, file_lines[i]) == 0))
+ {
+ TEST_MSG("Expected: %s", file_lines[i]);
+ TEST_MSG("Actual: %s", iter.line);
+ }
+ if (!TEST_CHECK(iter.line_num == (i + 1)))
+ {
+ TEST_MSG("Expected: %d", i + 1);
+ TEST_MSG("Actual: %d", iter.line_num);
+ }
+ }
+ res = mutt_file_iter_line(&iter, fp, 0);
+ if (!TEST_CHECK(!res))
+ {
+ TEST_MSG("Expected: false");
+ TEST_MSG("Actual: true");
+ }
+ TEAR_DOWN(fp);
+ }
}
#include "acutest.h"
#include "config.h"
#include "mutt/mutt.h"
+#include "common.h"
+
+#define BOOLIFY(x) ((x) ? "true" : "false")
bool map_dummy(char *line, int line_num, void *user_data)
{
return false;
}
+static bool mapping_func(char *line, int line_num, void *user_data)
+{
+ const int *p_last_line_num = (const int *) (user_data);
+ if (!TEST_CHECK(strcmp(line, file_lines[line_num - 1]) == 0))
+ {
+ TEST_MSG("Expected: %s", file_lines[line_num - 1]);
+ TEST_MSG("Actual: %s", line);
+ }
+ return (line_num < *p_last_line_num);
+}
+
+static void test_file_map_lines_breaking_after(int last_line, bool expected)
+{
+ FILE *fp = SET_UP();
+ if (!fp)
+ return;
+ bool res = mutt_file_map_lines(mapping_func, &last_line, fp, 0);
+ if (!TEST_CHECK(res == expected))
+ {
+ TEST_MSG("Expected: %s", BOOLIFY(expected));
+ TEST_MSG("Actual: %s", BOOLIFY(res));
+ }
+ TEAR_DOWN(fp);
+}
+
void test_mutt_file_map_lines(void)
{
// bool mutt_file_map_lines(mutt_file_map_t func, void *user_data, FILE *fp, int flags);
mutt_file_map_t map = map_dummy;
TEST_CHECK(!mutt_file_map_lines(map, "apple", NULL, 0));
}
+
+ {
+ const size_t num = file_num_test_lines();
+ test_file_map_lines_breaking_after(num + 1, true);
+ test_file_map_lines_breaking_after(0, false);
+ test_file_map_lines_breaking_after(1, false);
+ test_file_map_lines_breaking_after(num, false);
+ }
}
* Add your test cases to this list.
*****************************************************************************/
#define NEOMUTT_TEST_LIST \
- NEOMUTT_TEST_ITEM(test_file_iter_line) \
- NEOMUTT_TEST_ITEM(test_file_map_lines) \
NEOMUTT_TEST_ITEM(test_rfc2047) \
NEOMUTT_TEST_ITEM(test_md5) \
NEOMUTT_TEST_ITEM(test_md5_ctx) \