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

solution_tests.cpp « tests « project « src - github.com/windirstat/premake-4.x-stable.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0078b006036112ca5618a93eb3304ec513c81a33 (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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/**
 * \file   solution_tests.cpp
 * \brief  Automated tests for the Solution class.
 * \author Copyright (c) 2008 Jason Perkins and the Premake project
 */

#include "premake.h"
#include "testing/testing.h"
extern "C" {
#include "project/solution.h"
#include "project/project.h"
#include "project/project_internal.h"
#include "base/strings.h"
}


struct FxSolution
{
	Solution sln;

	FxSolution()
	{
		sln = solution_create();
	}

	~FxSolution()
	{
		if (sln)
			solution_destroy(sln);
	}
};


SUITE(project)
{
	TEST_FIXTURE(FxSolution, Create_ReturnsObject_OnSuccess)
	{
		CHECK(sln != NULL);
	}


	/**********************************************************************
	 * Name tests
	 **********************************************************************/

	TEST_FIXTURE(FxSolution, GetName_ReturnsNull_OnStartup)
	{
		const char* name = solution_get_name(sln);
		CHECK(name == NULL);
	}

	TEST_FIXTURE(FxSolution, SetName_CanRoundtrip)
	{
		solution_set_name(sln, "MySolution");
		const char* name = solution_get_name(sln);
		CHECK_EQUAL("MySolution", name);
	}


	/**********************************************************************
	 * Base directory tests
	 **********************************************************************/

	TEST_FIXTURE(FxSolution, GetBaseDir_ReturnsNull_OnStartup)
	{
		const char* result = solution_get_base_dir(sln);
		CHECK(result == NULL);
	}

	TEST_FIXTURE(FxSolution, SetBaseDir_CanRoundtrip)
	{
		solution_set_base_dir(sln, "BaseDir");
		const char* result = solution_get_base_dir(sln);
		CHECK_EQUAL("BaseDir", result);
	}


	/**********************************************************************
	 * Configuration containment tests
	 **********************************************************************/

	TEST_FIXTURE(FxSolution, NumConfigs_IsZero_OnStartup)
	{
		int result = solution_num_configs(sln);
		CHECK(result == 0);
	}

	TEST_FIXTURE(FxSolution, AddConfig_IncrementsNumConfigs)
	{
		solution_add_config(sln, "Debug");
		int result = solution_num_configs(sln);
		CHECK(result == 1);
	}

	TEST_FIXTURE(FxSolution, AddConfig_CanRoundtrip)
	{
		solution_add_config(sln, "Debug");
		const char* result = solution_get_config(sln, 0);
		CHECK_EQUAL("Debug", result);
	}

	TEST_FIXTURE(FxSolution, GetConfigs_ReturnsEmptyList_OnStartup)
	{
		Strings result = solution_get_configs(sln);
		CHECK(strings_size(result) == 0);
	}

	TEST_FIXTURE(FxSolution, GetConfigs_ReturnsList_OnItemsAdded)
	{
		solution_add_config(sln, "Debug");
		Strings result = solution_get_configs(sln);
		CHECK_EQUAL("Debug", strings_item(result, 0));
	}


	/**********************************************************************
	 * Language tests
	 **********************************************************************/

	TEST_FIXTURE(FxSolution, GetLanguage_ReturnsNull_OnStartup)
	{
		const char* result = solution_get_language(sln);
		CHECK(result == NULL);
	}

	TEST_FIXTURE(FxSolution, SetLanguage_CanRoundtrip)
	{
		solution_set_language(sln, "c++");
		const char* result = solution_get_language(sln);
		CHECK_EQUAL("c++", result);
	}


	/**********************************************************************
	 * Location tests
	 **********************************************************************/

	TEST_FIXTURE(FxSolution, GetLocation_ReturnsNull_OnStartup)
	{
		const char* result = solution_get_location(sln);
		CHECK(result == NULL);
	}

	TEST_FIXTURE(FxSolution, SetLocation_CanRoundtrip)
	{
		solution_set_location(sln, "Location");
		const char* result = solution_get_location(sln);
		CHECK_EQUAL("Location", result);
	}


	/**********************************************************************
	 * Filename tests
	 **********************************************************************/

	TEST_FIXTURE(FxSolution, GetFilename_ReturnsFullPath_OnNoLocation)
	{
		solution_set_name(sln, "MySolution");
		solution_set_base_dir(sln, "/BaseDir");
		const char* filename = solution_get_filename(sln, NULL, ".xyz");
		CHECK_EQUAL("/BaseDir/MySolution.xyz", filename);
	}

	TEST_FIXTURE(FxSolution, GetFilename_ReturnsFullPath_OnLocation)
	{
		solution_set_name(sln, "MySolution");
		solution_set_base_dir(sln, "/BaseDir");
		solution_set_location(sln, "Location");
		const char* filename = solution_get_filename(sln, NULL, ".xyz");
		CHECK_EQUAL("/BaseDir/Location/MySolution.xyz", filename);
	}


	/**********************************************************************
	 * Project containment tests
	 **********************************************************************/

	TEST_FIXTURE(FxSolution, NumProjects_IsZero_OnStartup)
	{
		int result = solution_num_projects(sln);
		CHECK(result == 0);
	}

	TEST_FIXTURE(FxSolution, AddProject_IncrementsNumProjects)
	{
		Project prj = project_create();
		solution_add_project(sln, prj);
		int result = solution_num_projects(sln);
		CHECK(result == 1);
	}

	TEST_FIXTURE(FxSolution, AddProject_CanRoundtrip)
	{
		Project prj = project_create();
		solution_add_project(sln, prj);
		Project result = solution_get_project(sln, 0);
		CHECK(prj == result);
	}

	TEST_FIXTURE(FxSolution, AddProject_SetsProjectSolution)
	{
		Project prj = project_create();
		solution_add_project(sln, prj);
		CHECK(sln == project_get_solution(prj));
	}
}