Welcome to mirror list, hosted at ThFree Co, Russian Federation.

unload_tests.cpp « tests « script « src - github.com/windirstat/premake-4.x-stable.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cb8b3bcb8bf1b9621b11f04506a8fd64d2d5fa2f (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/**
 * \file   unload_tests.cpp
 * \brief  Automated tests for project object enumeration from the script environment.
 * \author Copyright (c) 2007-2008 Jason Perkins and the Premake project
 */

#include "premake.h"
#include "testing/testing.h"
extern "C" {
#include "script/script_internal.h"
}

/* mock interface to object loaders */

static int num_solution_calls;
static int num_project_calls;

static int stub_solution_func(lua_State* L, Solution sln)
{
	UNUSED(L);  UNUSED(sln);
	num_solution_calls++;
	return OKAY;
}

static int stub_solution_fail_func(lua_State* L, Solution sln)
{
	UNUSED(L);  UNUSED(sln);
	num_solution_calls++;
	return !OKAY;
}

static int stub_project_func(lua_State* L, Project prj)
{
	UNUSED(L);  UNUSED(prj);
	num_project_calls++;
	return OKAY;
}

static int stub_project_fail_func(lua_State* L, Project prj)
{
	UNUSED(L);  UNUSED(prj);
	num_project_calls++;
	return !OKAY;
}


struct FxUnload
{
	Script      script;
	lua_State*  L;
	Array       slns;
	UnloadFuncs funcs;

	FxUnload()
	{
		script = script_create();
		L = script_get_lua(script);
	
		slns = array_create();

		funcs.unload_solution = stub_solution_func;
		funcs.unload_project  = stub_project_func;
		num_solution_calls = 0;
		num_project_calls = 0;
	}

	~FxUnload()
	{
		array_destroy(slns);
		script_destroy(script);
	}
};


struct FxUnload2 : FxUnload
{
	FxUnload2()
	{
		script_run_string(script,
			"solution 'MySolution';"
			"  configurations{'Debug','Release'};"
			"  project 'MyProject';"
			"  project 'MyProject2';"
			"solution 'MySolution2';");
	}
};


SUITE(unload)
{
	TEST_FIXTURE(FxUnload, Unload_ReturnsOkay_OnEmptySession)
	{
		int result = unload_all(L, slns, &funcs);
		CHECK(result == OKAY);
	}

	TEST_FIXTURE(FxUnload, Unload_ReturnsEmptySession_OnEmptySession)
	{
		unload_all(L, slns, &funcs);
		int n = array_size(slns);
		CHECK(n == 0);
	}

	TEST_FIXTURE(FxUnload2, Unload_ReturnsOkay_OnNonEmptySession)
	{
		int result = unload_all(L, slns, &funcs);
		CHECK(result == OKAY);
	}


	/**********************************************************************
	 * Solution enumeration tests
	 **********************************************************************/

	TEST_FIXTURE(FxUnload2, Unload_AddsSolutions_OnNonEmptySession)
	{
		unload_all(L, slns, &funcs);
		int n = array_size(slns);
		CHECK(n == 2);
	}

	TEST_FIXTURE(FxUnload2, Unload_CallsSolutionFunc_OnEachSolution)
	{
		unload_all(L, slns, &funcs);
		CHECK(num_solution_calls == 2);
	}

	TEST_FIXTURE(FxUnload2, Unload_ReturnsNotOkay_OnSolutionFailure)
	{
		funcs.unload_solution = stub_solution_fail_func;
		int result = unload_all(L, slns, &funcs);
		CHECK(result != OKAY);
	}

	TEST_FIXTURE(FxUnload2, Unload_AbortsSolutionLoop_OnNotOkay)
	{
		funcs.unload_solution = stub_solution_fail_func;
		unload_all(L, slns, &funcs);
		CHECK(num_solution_calls == 1);
	}


	/**********************************************************************
	 * Project enumeration tests
	 **********************************************************************/

	TEST_FIXTURE(FxUnload2, Unload_AddsProjects_OnNonEmptySession)
	{
		unload_all(L, slns, &funcs);
		Solution sln = (Solution)array_item(slns, 0);
		int n = solution_num_projects(sln);
		CHECK(n == 2);
	}

	TEST_FIXTURE(FxUnload2, Unload_CallsProjectFunc_OnEachProject)
	{
		unload_all(L, slns, &funcs);
		CHECK(num_project_calls == 2);
	}

	TEST_FIXTURE(FxUnload2, Unload_ReturnsNotOkay_OnProjectFailure)
	{
		funcs.unload_project = stub_project_fail_func;
		int result = unload_all(L, slns, &funcs);
		CHECK(result != OKAY);
	}

	TEST_FIXTURE(FxUnload2, Unload_AbortsProjectLoop_OnNotOkay)
	{
		funcs.unload_project = stub_project_fail_func;
		unload_all(L, slns, &funcs);
		CHECK(num_project_calls == 1);
	}

}