summaryrefslogtreecommitdiff
path: root/t/t_openpam_readlinev.c
diff options
context:
space:
mode:
Diffstat (limited to 't/t_openpam_readlinev.c')
-rw-r--r--t/t_openpam_readlinev.c134
1 files changed, 94 insertions, 40 deletions
diff --git a/t/t_openpam_readlinev.c b/t/t_openpam_readlinev.c
index 59f2b1071532..abc29e26cd55 100644
--- a/t/t_openpam_readlinev.c
+++ b/t/t_openpam_readlinev.c
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2012 Dag-Erling Smørgrav
+ * Copyright (c) 2012-2015 Dag-Erling Smørgrav
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: t_openpam_readlinev.c 648 2013-03-05 17:54:27Z des $
+ * $Id: t_openpam_readlinev.c 922 2017-02-19 19:28:30Z des $
*/
#ifdef HAVE_CONFIG_H
@@ -34,15 +34,25 @@
#endif
#include <err.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <cryb/test.h>
+
#include <security/pam_appl.h>
#include <security/openpam.h>
#include "openpam_impl.h"
-#include "t.h"
+
+#define T_FUNC(n, d) \
+ static const char *t_ ## n ## _desc = d; \
+ static int t_ ## n ## _func(OPENPAM_UNUSED(char **desc), \
+ OPENPAM_UNUSED(void *arg))
+
+#define T(n) \
+ t_add_test(&t_ ## n ## _func, NULL, t_ ## n ## _desc)
/*
* Read a line from the temp file and verify that the result matches our
@@ -55,7 +65,9 @@ orlv_expect(struct t_file *tf, const char **expectedv, int lines, int eof)
{
int expectedc, gotc, i, lineno = 0;
char **gotv;
+ int ret;
+ ret = 1;
expectedc = 0;
if (expectedv != NULL)
while (expectedv[expectedc] != NULL)
@@ -65,44 +77,38 @@ orlv_expect(struct t_file *tf, const char **expectedv, int lines, int eof)
err(1, "%s(): %s", __func__, tf->name);
if (expectedv != NULL && gotv == NULL) {
t_verbose("expected %d words, got nothing\n", expectedc);
- return (0);
- }
- if (expectedv == NULL && gotv != NULL) {
+ ret = 0;
+ } else if (expectedv == NULL && gotv != NULL) {
t_verbose("expected nothing, got %d words\n", gotc);
- FREEV(gotc, gotv);
- return (0);
- }
- if (expectedv != NULL && gotv != NULL) {
+ ret = 0;
+ } else if (expectedv != NULL && gotv != NULL) {
if (expectedc != gotc) {
t_verbose("expected %d words, got %d\n",
expectedc, gotc);
- FREEV(gotc, gotv);
- return (0);
+ ret = 0;
}
for (i = 0; i < gotc; ++i) {
if (strcmp(expectedv[i], gotv[i]) != 0) {
t_verbose("word %d: expected <<%s>>, "
"got <<%s>>\n", i, expectedv[i], gotv[i]);
- FREEV(gotc, gotv);
- return (0);
+ ret = 0;
}
}
- FREEV(gotc, gotv);
}
+ FREEV(gotc, gotv);
if (lineno != lines) {
t_verbose("expected to advance %d lines, advanced %d lines\n",
lines, lineno);
- return (0);
+ ret = 0;
}
if (eof && !t_feof(tf)) {
t_verbose("expected EOF, but didn't get it\n");
- return (0);
- }
- if (!eof && t_feof(tf)) {
+ ret = 0;
+ } else if (!eof && t_feof(tf)) {
t_verbose("didn't expect EOF, but got it anyway\n");
- return (0);
+ ret = 0;
}
- return (1);
+ return (ret);
}
@@ -125,6 +131,23 @@ static const char *hello_world[] = {
NULL
};
+static const char *numbers[] = {
+ "zero", "one", "two", "three", "four", "five", "six", "seven",
+ "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen",
+ "fifteen", "sixteen", "seventeen", "nineteen", "twenty",
+ "twenty-one", "twenty-two", "twenty-three", "twenty-four",
+ "twenty-five", "twenty-six", "twenty-seven", "twenty-eight",
+ "twenty-nine", "thirty", "thirty-one", "thirty-two", "thirty-three",
+ "thirty-four", "thirty-five", "thirty-six", "thirty-seven",
+ "thirty-eight", "thirty-nine", "fourty", "fourty-one", "fourty-two",
+ "fourty-three", "fourty-four", "fourty-five", "fourty-six",
+ "fourty-seven", "fourty-eight", "fourty-nine", "fifty", "fifty-one",
+ "fifty-two", "fifty-three", "fifty-four", "fifty-five", "fifty-six",
+ "fifty-seven", "fifty-eight", "fifty-nine", "sixty", "sixty-one",
+ "sixty-two", "sixty-three",
+ NULL
+};
+
/***************************************************************************
* Lines without words
@@ -206,6 +229,20 @@ T_FUNC(whitespace_before_comment, "whitespace before comment")
return (ret);
}
+T_FUNC(line_continuation_within_whitespace, "line continuation within whitespace")
+{
+ struct t_file *tf;
+ int ret;
+
+ tf = t_fopen(NULL);
+ t_fprintf(tf, "%s \\\n %s\n", hello_world[0], hello_world[1]);
+ t_frewind(tf);
+ ret = orlv_expect(tf, hello_world, 2 /*lines*/, 0 /*eof*/) &&
+ orlv_expect(tf, NULL, 0 /*lines*/, 1 /*eof*/);
+ t_fclose(tf);
+ return (ret);
+}
+
/***************************************************************************
* Simple words
@@ -237,6 +274,22 @@ T_FUNC(two_words, "two words")
return (ret);
}
+T_FUNC(many_words, "many words")
+{
+ struct t_file *tf;
+ const char **word;
+ int ret;
+
+ tf = t_fopen(NULL);
+ for (word = numbers; *word; ++word)
+ t_fprintf(tf, " %s", *word);
+ t_fprintf(tf, "\n");
+ t_frewind(tf);
+ ret = orlv_expect(tf, numbers, 1 /*lines*/, 0 /*eof*/);
+ t_fclose(tf);
+ return (ret);
+}
+
T_FUNC(unterminated_line, "unterminated line")
{
struct t_file *tf;
@@ -255,31 +308,32 @@ T_FUNC(unterminated_line, "unterminated line")
* Boilerplate
*/
-const struct t_test *t_plan[] = {
- T(empty_input),
- T(empty_line),
- T(unterminated_empty_line),
- T(whitespace),
- T(comment),
- T(whitespace_before_comment),
-
- T(one_word),
- T(two_words),
- T(unterminated_line),
-
- NULL
-};
-
-const struct t_test **
+static int
t_prepare(int argc, char *argv[])
{
(void)argc;
(void)argv;
- return (t_plan);
+
+ T(empty_input);
+ T(empty_line);
+ T(unterminated_empty_line);
+ T(whitespace);
+ T(comment);
+ T(whitespace_before_comment);
+ T(line_continuation_within_whitespace);
+
+ T(one_word);
+ T(two_words);
+ T(many_words);
+ T(unterminated_line);
+
+ return (0);
}
-void
-t_cleanup(void)
+int
+main(int argc, char *argv[])
{
+
+ t_main(t_prepare, NULL, argc, argv);
}