1 /* vim: set ts=8 sts=4 sw=4 tw=80 noet: */
2 /*======================================================================
3 Copyright (C) 2004,2005,2009,2013 Walter Doekes <walter+tthsum@wjd.nu>
4 This file is part of tthsum.
5 
6 tthsum is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10 
11 tthsum is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License
17 along with tthsum.  If not, see <http://www.gnu.org/licenses/>.
18 ======================================================================*/
19 #include "texts.h"
20 
21 #include "test.h"
22 #include <sys/stat.h>
23 #include <fcntl.h>
24 #include <string.h>
25 
26 
test_texts_initial()27 static int test_texts_initial() {
28     const char* err;
29     set_error("some context", ERROR_FIRST); /* reset errors */
30     err = get_error();
31     TEST_PASS1(strcmp(err, "some context: No error yet") == 0,
32 	    "Unexpected \"No-error-yet\" text, got: \"%s\"", err);
33     return 0;
34 }
35 
test_texts_enum()36 static int test_texts_enum() {
37     const char* err;
38     int tid;
39     for (tid = ERROR_FIRST; tid != ERROR_LAST; ++tid) {
40 	set_error("another context", tid);
41 	err = get_error();
42 	TEST_PASS1(strncmp(err, "another context", 15) == 0,
43 		"Error text context mismatch, got: \"%s\"", err);
44 	TEST_PASS2(strcmp(err + 17, get_text((enum text_id)tid)) == 0,
45 		"Error text mismatch for text id %i, got: \"%s\"", tid, err);
46     }
47     return 0;
48 }
49 
test_texts_oserror()50 static int test_texts_oserror() {
51     const char* err;
52     open("", O_RDONLY);
53     set_error("yet another context", ERROR_FROM_OS);
54     err = get_error();
55 #ifdef _WIN32
56     TEST_PASS1(strcmp(err, "yet another context: "
57 	    "The system cannot find the path specified. (0x3)") == 0,
58 	    "Unexpected OS error text, got: \"%s\"", err);
59 #else /* !_WIN32 */
60     TEST_PASS1(strcmp(err, "yet another context: "
61 	    "No such file or directory (2)") == 0,
62 	    "Unexpected OS error text, got: \"%s\"", err);
63 #endif /* !_WIN32 */
64     return 0;
65 }
66 
67 
68 TESTS(texts_test)
69     TEST(test_texts_initial);
70     TEST(test_texts_enum);
71     TEST_WARN(test_texts_oserror);
72 ENDTESTS
73