xref: /netbsd-src/external/bsd/openpam/dist/t/t_openpam_readword.c (revision 4391d5e9d4f291db41e3b3ba26a01b5e51364aae)
1 /*	$NetBSD: t_openpam_readword.c,v 1.1.1.1 2013/04/06 01:23:33 christos Exp $	*/
2 
3 /*-
4  * Copyright (c) 2012 Dag-Erling Smørgrav
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer
12  *    in this position and unchanged.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. The name of the author may not be used to endorse or promote
17  *    products derived from this software without specific prior written
18  *    permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  *
32  * Id: t_openpam_readword.c 584 2012-04-07 22:47:16Z des
33  */
34 
35 #ifdef HAVE_CONFIG_H
36 # include "config.h"
37 #endif
38 
39 #include <err.h>
40 #include <errno.h>
41 #include <fcntl.h>
42 #include <stdio.h>
43 #include <stdlib.h>
44 #include <string.h>
45 #include <unistd.h>
46 
47 #include <security/pam_appl.h>
48 #include <security/openpam.h>
49 
50 #include "t.h"
51 
52 static char filename[1024];
53 static FILE *f;
54 
55 /*
56  * Open the temp file and immediately unlink it so it doesn't leak in case
57  * of premature exit.
58  */
59 static void
60 orw_open(void)
61 {
62 	int fd;
63 
64 	if ((fd = open(filename, O_RDWR|O_CREAT|O_TRUNC, 0600)) < 0)
65 		err(1, "%s(): %s", __func__, filename);
66 	if ((f = fdopen(fd, "r+")) == NULL)
67 		err(1, "%s(): %s", __func__, filename);
68 	if (unlink(filename) < 0)
69 		err(1, "%s(): %s", __func__, filename);
70 }
71 
72 /*
73  * Write text to the temp file.
74  */
75 static void
76 orw_output(const char *fmt, ...)
77 {
78 	va_list ap;
79 
80 	va_start(ap, fmt);
81 	vfprintf(f, fmt, ap);
82 	va_end(ap);
83 	if (ferror(f))
84 		err(1, "%s", filename);
85 }
86 
87 /*
88  * Rewind the temp file.
89  */
90 static void
91 orw_rewind(void)
92 {
93 
94 	errno = 0;
95 	rewind(f);
96 	if (errno != 0)
97 		err(1, "%s(): %s", __func__, filename);
98 }
99 
100 /*
101  * Read a word from the temp file and verify that the result matches our
102  * expectations: whether a word was read at all, how many lines were read
103  * (in case of quoted or escaped newlines), whether we reached the end of
104  * the file and whether we reached the end of the line.
105  */
106 static int
107 orw_expect(const char *expected, int lines, int eof, int eol)
108 {
109 	int ch, lineno = 0;
110 	char *got;
111 	size_t len;
112 
113 	got = openpam_readword(f, &lineno, &len);
114 	if (ferror(f))
115 		err(1, "%s(): %s", __func__, filename);
116 	if (expected != NULL && got == NULL) {
117 		t_verbose("expected <<%s>>, got nothing\n", expected);
118 		return (0);
119 	}
120 	if (expected == NULL && got != NULL) {
121 		t_verbose("expected nothing, got <<%s>>\n", got);
122 		return (0);
123 	}
124 	if (expected != NULL && got != NULL && strcmp(expected, got) != 0) {
125 		t_verbose("expected <<%s>>, got <<%s>>\n", expected, got);
126 		return (0);
127 	}
128 	if (lineno != lines) {
129 		t_verbose("expected to advance %d lines, advanced %d lines\n",
130 		    lines, lineno);
131 		return (0);
132 	}
133 	if (eof && !feof(f)) {
134 		t_verbose("expected EOF, but didn't get it\n");
135 		return (0);
136 	}
137 	if (!eof && feof(f)) {
138 		t_verbose("didn't expect EOF, but got it anyway\n");
139 		return (0);
140 	}
141 	ch = fgetc(f);
142 	if (ferror(f))
143 		err(1, "%s(): %s", __func__, filename);
144 	if (eol && ch != '\n') {
145 		t_verbose("expected EOL, but didn't get it\n");
146 		return (0);
147 	}
148 	if (!eol && ch == '\n') {
149 		t_verbose("didn't expect EOL, but got it anyway\n");
150 		return (0);
151 	}
152 	if (ch != EOF)
153 		ungetc(ch, f);
154 	return (1);
155 }
156 
157 /*
158  * Close the temp file.
159  */
160 void
161 orw_close(void)
162 {
163 
164 	if (fclose(f) != 0)
165 		err(1, "%s(): %s", __func__, filename);
166 	f = NULL;
167 }
168 
169 
170 /***************************************************************************
171  * Lines without words
172  */
173 
174 T_FUNC(empty_input, "empty input")
175 {
176 	int ret;
177 
178 	orw_open();
179 	ret = orw_expect(NULL, 0 /*lines*/, 1 /*eof*/, 0 /*eol*/);
180 	orw_close();
181 	return (ret);
182 }
183 
184 T_FUNC(empty_line, "empty line")
185 {
186 	int ret;
187 
188 	orw_open();
189 	orw_output("\n");
190 	orw_rewind();
191 	ret = orw_expect(NULL, 0 /*lines*/, 0 /*eof*/, 1 /*eol*/);
192 	orw_close();
193 	return (ret);
194 }
195 
196 T_FUNC(unterminated_line, "unterminated line")
197 {
198 	int ret;
199 
200 	orw_open();
201 	orw_output(" ");
202 	orw_rewind();
203 	ret = orw_expect(NULL, 0 /*lines*/, 1 /*eof*/, 0 /*eol*/);
204 	orw_close();
205 	return (ret);
206 }
207 
208 T_FUNC(single_whitespace, "single whitespace")
209 {
210 	int ret;
211 
212 	orw_open();
213 	orw_output(" \n");
214 	orw_rewind();
215 	ret = orw_expect(NULL, 0 /*lines*/, 0 /*eof*/, 1 /*eol*/);
216 	orw_close();
217 	return (ret);
218 }
219 
220 T_FUNC(multiple_whitespace, "multiple whitespace")
221 {
222 	int ret;
223 
224 	orw_open();
225 	orw_output(" \t\r\n");
226 	orw_rewind();
227 	ret = orw_expect(NULL, 0 /*lines*/, 0 /*eof*/, 1 /*eol*/);
228 	orw_close();
229 	return (ret);
230 }
231 
232 T_FUNC(comment, "comment")
233 {
234 	int ret;
235 
236 	orw_open();
237 	orw_output("# comment\n");
238 	orw_rewind();
239 	ret = orw_expect(NULL, 0 /*lines*/, 0 /*eof*/, 1 /*eol*/);
240 	orw_close();
241 	return (ret);
242 }
243 
244 T_FUNC(whitespace_before_comment, "whitespace before comment")
245 {
246 	int ret;
247 
248 	orw_open();
249 	orw_output(" # comment\n");
250 	orw_rewind();
251 	ret = orw_expect(NULL, 0 /*lines*/, 0 /*eof*/, 1 /*eol*/);
252 	orw_close();
253 	return (ret);
254 }
255 
256 
257 /***************************************************************************
258  * Simple cases - no quotes or escapes
259  */
260 
261 T_FUNC(single_word, "single word")
262 {
263 	const char *word = "hello";
264 	int ret;
265 
266 	orw_open();
267 	orw_output("%s\n", word);
268 	orw_rewind();
269 	ret = orw_expect(word, 0 /*lines*/, 0 /*eof*/, 1 /*eol*/);
270 	orw_close();
271 	return (ret);
272 }
273 
274 T_FUNC(single_whitespace_before_word, "single whitespace before word")
275 {
276 	const char *word = "hello";
277 	int ret;
278 
279 	orw_open();
280 	orw_output(" %s\n", word);
281 	orw_rewind();
282 	ret = orw_expect(word, 0 /*lines*/, 0 /*eof*/, 1 /*eol*/);
283 	orw_close();
284 	return (ret);
285 }
286 
287 T_FUNC(double_whitespace_before_word, "double whitespace before word")
288 {
289 	const char *word = "hello";
290 	int ret;
291 
292 	orw_open();
293 	orw_output("  %s\n", word);
294 	orw_rewind();
295 	ret = orw_expect(word, 0 /*lines*/, 0 /*eof*/, 1 /*eol*/);
296 	orw_close();
297 	return (ret);
298 }
299 
300 T_FUNC(single_whitespace_after_word, "single whitespace after word")
301 {
302 	const char *word = "hello";
303 	int ret;
304 
305 	orw_open();
306 	orw_output("%s \n", word);
307 	orw_rewind();
308 	ret = orw_expect(word, 0 /*lines*/, 0 /*eof*/, 0 /*eol*/);
309 	orw_close();
310 	return (ret);
311 }
312 
313 T_FUNC(double_whitespace_after_word, "double whitespace after word")
314 {
315 	const char *word = "hello";
316 	int ret;
317 
318 	orw_open();
319 	orw_output("%s  \n", word);
320 	orw_rewind();
321 	ret = orw_expect(word, 0 /*lines*/, 0 /*eof*/, 0 /*eol*/);
322 	orw_close();
323 	return (ret);
324 }
325 
326 T_FUNC(comment_after_word, "comment after word")
327 {
328 	const char *word = "hello";
329 	int ret;
330 
331 	orw_open();
332 	orw_output("%s # comment\n", word);
333 	orw_rewind();
334 	ret = orw_expect(word, 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) &&
335 	    orw_expect(NULL, 0 /*lines*/, 0 /*eof*/, 1 /*eol*/);
336 	orw_close();
337 	return (ret);
338 }
339 
340 T_FUNC(word_containing_hash, "word containing hash")
341 {
342 	const char *word = "hello#world";
343 	int ret;
344 
345 	orw_open();
346 	orw_output("%s\n", word);
347 	orw_rewind();
348 	ret = orw_expect(word, 0 /*lines*/, 0 /*eof*/, 1 /*eol*/);
349 	orw_close();
350 	return (ret);
351 }
352 
353 T_FUNC(two_words, "two words")
354 {
355 	const char *word[] = { "hello", "world" };
356 	int ret;
357 
358 	orw_open();
359 	orw_output("%s %s\n", word[0], word[1]);
360 	orw_rewind();
361 	ret = orw_expect(word[0], 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) &&
362 	    orw_expect(word[1], 0 /*lines*/, 0 /*eof*/, 1 /*eol*/);
363 	orw_close();
364 	return (ret);
365 }
366 
367 
368 /***************************************************************************
369  * Escapes
370  */
371 
372 T_FUNC(naked_escape, "naked escape")
373 {
374 	int ret;
375 
376 	orw_open();
377 	orw_output("\\");
378 	orw_rewind();
379 	ret = orw_expect(NULL, 0 /*lines*/, 1 /*eof*/, 0 /*eol*/);
380 	orw_close();
381 	return (ret);
382 }
383 
384 T_FUNC(escaped_escape, "escaped escape")
385 {
386 	int ret;
387 
388 	orw_open();
389 	orw_output("\\\\\n");
390 	orw_rewind();
391 	ret = orw_expect("\\", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/);
392 	orw_close();
393 	return (ret);
394 }
395 
396 T_FUNC(escaped_whitespace, "escaped whitespace")
397 {
398 	int ret;
399 
400 	orw_open();
401 	orw_output("\\  \\\t \\\r \\\n\n");
402 	orw_rewind();
403 	ret = orw_expect(" ", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) &&
404 	    orw_expect("\t", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) &&
405 	    orw_expect("\r", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) &&
406 	    /* this last one is a line continuation */
407 	    orw_expect(NULL, 1 /*lines*/, 0 /*eof*/, 1 /*eol*/);
408 	orw_close();
409 	return (ret);
410 }
411 
412 T_FUNC(escaped_newline_before_word, "escaped newline before word")
413 {
414 	int ret;
415 
416 	orw_open();
417 	orw_output("\\\nhello world\n");
418 	orw_rewind();
419 	ret = orw_expect("hello", 1 /*lines*/, 0 /*eof*/, 0 /*eol*/);
420 	orw_close();
421 	return (ret);
422 }
423 
424 T_FUNC(escaped_newline_within_word, "escaped newline within word")
425 {
426 	int ret;
427 
428 	orw_open();
429 	orw_output("hello\\\nworld\n");
430 	orw_rewind();
431 	ret = orw_expect("helloworld", 1 /*lines*/, 0 /*eof*/, 1 /*eol*/);
432 	orw_close();
433 	return (ret);
434 }
435 
436 T_FUNC(escaped_newline_after_word, "escaped newline after word")
437 {
438 	int ret;
439 
440 	orw_open();
441 	orw_output("hello\\\n world\n");
442 	orw_rewind();
443 	ret = orw_expect("hello", 1 /*lines*/, 0 /*eof*/, 0 /*eol*/);
444 	orw_close();
445 	return (ret);
446 }
447 
448 T_FUNC(escaped_letter, "escaped letter")
449 {
450 	int ret;
451 
452 	orw_open();
453 	orw_output("\\z\n");
454 	orw_rewind();
455 	ret = orw_expect("z", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/);
456 	orw_close();
457 	return (ret);
458 }
459 
460 
461 /***************************************************************************
462  * Quotes
463  */
464 
465 T_FUNC(naked_single_quote, "naked single quote")
466 {
467 	int ret;
468 
469 	orw_open();
470 	orw_output("'");
471 	orw_rewind();
472 	ret = orw_expect(NULL, 0 /*lines*/, 1 /*eof*/, 0 /*eol*/);
473 	orw_close();
474 	return (ret);
475 }
476 
477 T_FUNC(naked_double_quote, "naked double quote")
478 {
479 	int ret;
480 
481 	orw_open();
482 	orw_output("\"");
483 	orw_rewind();
484 	ret = orw_expect(NULL, 0 /*lines*/, 1 /*eof*/, 0 /*eol*/);
485 	orw_close();
486 	return (ret);
487 }
488 
489 T_FUNC(empty_single_quotes, "empty single quotes")
490 {
491 	int ret;
492 
493 	orw_open();
494 	orw_output("''\n");
495 	orw_rewind();
496 	ret = orw_expect("", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/);
497 	orw_close();
498 	return (ret);
499 }
500 
501 T_FUNC(empty_double_quotes, "empty double quotes")
502 {
503 	int ret;
504 
505 	orw_open();
506 	orw_output("\"\"\n");
507 	orw_rewind();
508 	ret = orw_expect("", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/);
509 	orw_close();
510 	return (ret);
511 }
512 
513 T_FUNC(single_quotes_within_double_quotes, "single quotes within double quotes")
514 {
515 	int ret;
516 
517 	orw_open();
518 	orw_output("\"' '\"\n");
519 	orw_rewind();
520 	ret = orw_expect("' '", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/);
521 	orw_close();
522 	return (ret);
523 }
524 
525 T_FUNC(double_quotes_within_single_quotes, "double quotes within single quotes")
526 {
527 	int ret;
528 
529 	orw_open();
530 	orw_output("'\" \"'\n");
531 	orw_rewind();
532 	ret = orw_expect("\" \"", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/);
533 	orw_close();
534 	return (ret);
535 }
536 
537 T_FUNC(single_quoted_whitespace, "single-quoted whitespace")
538 {
539 	int ret;
540 
541 	orw_open();
542 	orw_output("' ' '\t' '\r' '\n'\n");
543 	orw_rewind();
544 	ret = orw_expect(" ", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) &&
545 	    orw_expect("\t", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) &&
546 	    orw_expect("\r", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) &&
547 	    orw_expect("\n", 1 /*lines*/, 0 /*eof*/, 1 /*eol*/);
548 	orw_close();
549 	return (ret);
550 }
551 
552 T_FUNC(double_quoted_whitespace, "double-quoted whitespace")
553 {
554 	int ret;
555 
556 	orw_open();
557 	orw_output("\" \" \"\t\" \"\r\" \"\n\"\n");
558 	orw_rewind();
559 	ret = orw_expect(" ", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) &&
560 	    orw_expect("\t", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) &&
561 	    orw_expect("\r", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) &&
562 	    orw_expect("\n", 1 /*lines*/, 0 /*eof*/, 1 /*eol*/);
563 	orw_close();
564 	return (ret);
565 }
566 
567 T_FUNC(single_quoted_words, "single-quoted words")
568 {
569 	int ret;
570 
571 	orw_open();
572 	orw_output("'hello world'\n");
573 	orw_rewind();
574 	ret = orw_expect("hello world", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/);
575 	orw_close();
576 	return (ret);
577 }
578 
579 T_FUNC(double_quoted_words, "double-quoted words")
580 {
581 	int ret;
582 
583 	orw_open();
584 	orw_output("\"hello world\"\n");
585 	orw_rewind();
586 	ret = orw_expect("hello world", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/);
587 	orw_close();
588 	return (ret);
589 }
590 
591 
592 /***************************************************************************
593  * Combinations of escape and quotes
594  */
595 
596 T_FUNC(escaped_single_quote,
597     "escaped single quote")
598 {
599 	int ret;
600 
601 	orw_open();
602 	orw_output("\\'\n");
603 	orw_rewind();
604 	ret = orw_expect("'", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/);
605 	orw_close();
606 	return (ret);
607 }
608 
609 T_FUNC(escaped_double_quote,
610     "escaped double quote")
611 {
612 	int ret;
613 
614 	orw_open();
615 	orw_output("\\\"\n");
616 	orw_rewind();
617 	ret = orw_expect("\"", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/);
618 	orw_close();
619 	return (ret);
620 }
621 
622 T_FUNC(escaped_whitespace_within_single_quotes,
623     "escaped whitespace within single quotes")
624 {
625 	int ret;
626 
627 	orw_open();
628 	orw_output("'\\ ' '\\\t' '\\\r' '\\\n'\n");
629 	orw_rewind();
630 	ret = orw_expect("\\ ", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) &&
631 	    orw_expect("\\\t", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) &&
632 	    orw_expect("\\\r", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) &&
633 	    orw_expect("\\\n", 1 /*lines*/, 0 /*eof*/, 1 /*eol*/);
634 	orw_close();
635 	return (ret);
636 }
637 
638 T_FUNC(escaped_whitespace_within_double_quotes,
639     "escaped whitespace within double quotes")
640 {
641 	int ret;
642 
643 	orw_open();
644 	orw_output("\"\\ \" \"\\\t\" \"\\\r\" \"\\\n\"\n");
645 	orw_rewind();
646 	ret = orw_expect("\\ ", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) &&
647 	    orw_expect("\\\t", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) &&
648 	    orw_expect("\\\r", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) &&
649 	    /* this last one is a line continuation */
650 	    orw_expect("", 1 /*lines*/, 0 /*eof*/, 1 /*eol*/);
651 	orw_close();
652 	return (ret);
653 }
654 
655 T_FUNC(escaped_letter_within_single_quotes,
656     "escaped letter within single quotes")
657 {
658 	int ret;
659 
660 	orw_open();
661 	orw_output("'\\z'\n");
662 	orw_rewind();
663 	ret = orw_expect("\\z", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/);
664 	orw_close();
665 	return (ret);
666 }
667 
668 T_FUNC(escaped_letter_within_double_quotes,
669     "escaped letter within double quotes")
670 {
671 	int ret;
672 
673 	orw_open();
674 	orw_output("\"\\z\"\n");
675 	orw_rewind();
676 	ret = orw_expect("\\z", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/);
677 	orw_close();
678 	return (ret);
679 }
680 
681 T_FUNC(escaped_escape_within_single_quotes,
682     "escaped escape within single quotes")
683 {
684 	int ret;
685 
686 	orw_open();
687 	orw_output("'\\\\'\n");
688 	orw_rewind();
689 	ret = orw_expect("\\\\", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/);
690 	orw_close();
691 	return (ret);
692 }
693 
694 T_FUNC(escaped_escape_within_double_quotes,
695     "escaped escape within double quotes")
696 {
697 	int ret;
698 
699 	orw_open();
700 	orw_output("\"\\\\\"\n");
701 	orw_rewind();
702 	ret = orw_expect("\\", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/);
703 	orw_close();
704 	return (ret);
705 }
706 
707 T_FUNC(escaped_single_quote_within_single_quotes,
708     "escaped single quote within single quotes")
709 {
710 	int ret;
711 
712 	orw_open();
713 	orw_output("'\\''\n");
714 	orw_rewind();
715 	ret = orw_expect(NULL, 1 /*lines*/, 1 /*eof*/, 0 /*eol*/);
716 	orw_close();
717 	return (ret);
718 }
719 
720 T_FUNC(escaped_double_quote_within_single_quotes,
721     "escaped double quote within single quotes")
722 {
723 	int ret;
724 
725 	orw_open();
726 	orw_output("'\\\"'\n");
727 	orw_rewind();
728 	ret = orw_expect("\\\"", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/);
729 	orw_close();
730 	return (ret);
731 }
732 
733 T_FUNC(escaped_single_quote_within_double_quotes,
734     "escaped single quote within double quotes")
735 {
736 	int ret;
737 
738 	orw_open();
739 	orw_output("\"\\'\"\n");
740 	orw_rewind();
741 	ret = orw_expect("\\'", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/);
742 	orw_close();
743 	return (ret);
744 }
745 
746 T_FUNC(escaped_double_quote_within_double_quotes,
747     "escaped double quote within double quotes")
748 {
749 	int ret;
750 
751 	orw_open();
752 	orw_output("\"\\\"\"\n");
753 	orw_rewind();
754 	ret = orw_expect("\"", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/);
755 	orw_close();
756 	return (ret);
757 }
758 
759 
760 /***************************************************************************
761  * Boilerplate
762  */
763 
764 const struct t_test *t_plan[] = {
765 	T(empty_input),
766 	T(empty_line),
767 	T(single_whitespace),
768 	T(multiple_whitespace),
769 	T(comment),
770 	T(whitespace_before_comment),
771 
772 	T(single_word),
773 	T(single_whitespace_before_word),
774 	T(double_whitespace_before_word),
775 	T(single_whitespace_after_word),
776 	T(double_whitespace_after_word),
777 	T(comment_after_word),
778 	T(word_containing_hash),
779 	T(two_words),
780 
781 	T(naked_escape),
782 	T(escaped_escape),
783 	T(escaped_whitespace),
784 	T(escaped_newline_before_word),
785 	T(escaped_newline_within_word),
786 	T(escaped_newline_after_word),
787 	T(escaped_letter),
788 
789 	T(naked_single_quote),
790 	T(naked_double_quote),
791 	T(empty_single_quotes),
792 	T(empty_double_quotes),
793 	T(single_quotes_within_double_quotes),
794 	T(double_quotes_within_single_quotes),
795 	T(single_quoted_whitespace),
796 	T(double_quoted_whitespace),
797 	T(single_quoted_words),
798 	T(double_quoted_words),
799 
800 	T(escaped_single_quote),
801 	T(escaped_double_quote),
802 	T(escaped_whitespace_within_single_quotes),
803 	T(escaped_whitespace_within_double_quotes),
804 	T(escaped_letter_within_single_quotes),
805 	T(escaped_letter_within_double_quotes),
806 	T(escaped_escape_within_single_quotes),
807 	T(escaped_escape_within_double_quotes),
808 	T(escaped_single_quote_within_single_quotes),
809 	T(escaped_double_quote_within_single_quotes),
810 	T(escaped_single_quote_within_double_quotes),
811 	T(escaped_double_quote_within_double_quotes),
812 
813 	NULL
814 };
815 
816 const struct t_test **
817 t_prepare(int argc, char *argv[])
818 {
819 
820 	(void)argc;
821 	(void)argv;
822 	snprintf(filename, sizeof filename, "%s.%d.tmp", t_progname, getpid());
823 	if (filename == NULL)
824 		err(1, "asprintf()");
825 	return (t_plan);
826 }
827 
828 void
829 t_cleanup(void)
830 {
831 }
832