summaryrefslogtreecommitdiffstats
path: root/tdecore/tdeconfig_compiler/tests/tdeconfigcompiler_test.cpp
blob: 158d008a025d5171ccb75ca548eeabe4a41d1b1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
    Tests for TDEConfig Compiler

    Copyright (c) 2005      by Duncan Mac-Vicar       <duncan@kde.org>

    *************************************************************************
    *                                                                       *
    * This library is free software; you can redistribute it and/or         *
    * modify it under the terms of the GNU Lesser General Public            *
    * License as published by the Free Software Foundation; either          *
    * version 2 of the License, or (at your option) any later version.      *
    *                                                                       *
    *************************************************************************
*/

#include <tqfile.h>
#include <tqstring.h>
#include <kdebug.h>
#include <tdeunittest/module.h>
#include "tdeconfigcompiler_test.h"

using namespace KUnitTest;

TDEUNITTEST_MODULE( tdeunittest_tdeconfigcompiler_test, "TDEConfigXT")
TDEUNITTEST_MODULE_REGISTER_TESTER( TDEConfigCompiler_Test )

typedef const char * CompilerTestSet[];

static CompilerTestSet testCases =
{
	"test1.cpp", "test1.h",
	"test2.cpp", "test2.h",
	"test3.cpp", "test3.h",
	"test4.cpp", "test4.h",
	"test5.cpp", "test5.h",
	"test6.cpp", "test6.h",
	"test7.cpp", "test7.h",
	"test8a.cpp", "test8a.h",
	"test8b.cpp", "test8b.h",
	"test9.h", "test9.cpp", 
	"test_dpointer.cpp", "test_dpointer.h",	 
	NULL
};

static CompilerTestSet willFailCases =
{
	// where is that TQDir comming from?
	//"test9.cpp", NULL
	NULL
};


void TDEConfigCompiler_Test::allTests()
{
	testExpectedOutput();
}

void TDEConfigCompiler_Test::testExpectedOutput()
{
	uint i = 0;
	// Known to pass test cases
	while (testCases[ i ])
	{
		performCompare(TQString::fromLatin1(testCases[ i ]));
		++i;
	}

	// broken test cases
	i= 0;
	while (willFailCases[ i ])
	{
		performCompare(TQString::fromLatin1(willFailCases[ i ]), true);
		++i;
	}
}

void TDEConfigCompiler_Test::performCompare(const TQString &fileName, bool fail)
{
	TQFile file(fileName);
	TQFile fileRef(TQString::fromLatin1(SRCDIR) + TQString::fromLatin1("/") + fileName + TQString::fromLatin1(".ref"));
	
	if ( file.open(IO_ReadOnly) && fileRef.open(IO_ReadOnly) )
	{
		TQString content = file.readAll();
		TQString contentRef = fileRef.readAll();
		
		if (!fail)
			CHECK( content, contentRef);
		else
			XFAIL( content, contentRef);
	}
	else
	{
		SKIP("Can't open file for comparision");
	}
}