/* vim: set ts=8 sts=4 sw=4 tw=80 noet: */
/*======================================================================
Copyright (C) 2004,2005,2009 Walter Doekes <walter+tthsum@wjd.nu>
This file is part of tthsum.

tthsum 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 of the License, or
(at your option) any later version.

tthsum 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 tthsum.  If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
#include "texts.h"

#include "test.h"
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>


static int test_texts_initial() {
    set_error("some context", ERROR_FIRST); /* reset errors */
    TEST_PASS(strcmp(get_error(), "No error yet") == 0,
	    "No-error-yet text is wrong");
    return 0;
}

static int test_texts_enum() {
    int tid;
    for (tid = ERROR_FIRST; tid != ERROR_LAST; ++tid) {
	set_error("another context", tid);
	TEST_PASS1(strcmp(get_error(), get_text((enum text_id)tid)) == 0,
		"Error text mismatch for text id %i", tid);
    }
    return 0;
}

static int test_texts_oserror() {
    open("", O_RDONLY);
    set_error("yet another context", -1);
#ifdef _WIN32
    TEST_PASS1(strcmp(get_error(), "yet another context: "
	    "The system cannot find the path specified. (0x3)") == 0,
	    "OS error text mismatch, got: \"%s\"", get_error());
#else /* !_WIN32 */
    TEST_PASS1(strcmp(get_error(), "yet another context: "
	    "No such file or directory (2)") == 0,
	    "OS error text mismatch, got: \"%s\"", get_error());
#endif /* !_WIN32 */
    return 0;
}


TESTS(texts_test)
    TEST(test_texts_initial);
    TEST(test_texts_enum);
    TEST(test_texts_oserror);
ENDTESTS
