• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef _VKTTESTGROUPUTIL_HPP
2 #define _VKTTESTGROUPUTIL_HPP
3 /*-------------------------------------------------------------------------
4  * Vulkan Conformance Tests
5  * ------------------------
6  *
7  * Copyright (c) 2016 Google Inc.
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  *//*!
22  * \file
23  * \brief TestCaseGroup utilities
24  *//*--------------------------------------------------------------------*/
25 
26 #include "tcuDefs.hpp"
27 #include "tcuTestCase.hpp"
28 
29 namespace vkt
30 {
31 
32 class TestGroupHelper0 : public tcu::TestCaseGroup
33 {
34 public:
35 	typedef void (*CreateChildrenFunc) (tcu::TestCaseGroup* testGroup);
36 	typedef void (*CleanupGroupFunc) (tcu::TestCaseGroup* testGroup);
37 
TestGroupHelper0(tcu::TestContext & testCtx,const std::string & name,const std::string & description,CreateChildrenFunc createChildren,CleanupGroupFunc cleanupGroup)38 								TestGroupHelper0	(tcu::TestContext&		testCtx,
39 													 const std::string&		name,
40 													 const std::string&		description,
41 													 CreateChildrenFunc		createChildren,
42 													 CleanupGroupFunc		cleanupGroup)
43 									: tcu::TestCaseGroup(testCtx, name.c_str(), description.c_str())
44 									, m_createChildren(createChildren)
45 									, m_cleanupGroup(cleanupGroup)
46 								{
47 								}
48 
~TestGroupHelper0(void)49 								~TestGroupHelper0	(void)
50 								{
51 								}
52 
init(void)53 	void						init				(void)
54 								{
55 									m_createChildren(this);
56 								}
57 
deinit(void)58 	void						deinit				(void)
59 								{
60 									if (m_cleanupGroup)
61 										m_cleanupGroup(this);
62 								}
63 
64 private:
65 	const CreateChildrenFunc	m_createChildren;
66 	const CleanupGroupFunc		m_cleanupGroup;
67 };
68 
69 template<typename Arg0>
70 class TestGroupHelper1 : public tcu::TestCaseGroup
71 {
72 public:
73 	typedef void (*CreateChildrenFunc) (tcu::TestCaseGroup* testGroup, Arg0 arg0);
74 	typedef void (*CleanupGroupFunc) (tcu::TestCaseGroup* testGroup, Arg0 arg0);
75 
TestGroupHelper1(tcu::TestContext & testCtx,const std::string & name,const std::string & description,CreateChildrenFunc createChildren,const Arg0 & arg0,CleanupGroupFunc cleanupGroup)76 								TestGroupHelper1	(tcu::TestContext&		testCtx,
77 													 const std::string&		name,
78 													 const std::string&		description,
79 													 CreateChildrenFunc		createChildren,
80 													 const Arg0&			arg0,
81 													 CleanupGroupFunc		cleanupGroup)
82 									: tcu::TestCaseGroup	(testCtx, name.c_str(), description.c_str())
83 									, m_createChildren		(createChildren)
84 									, m_cleanupGroup		(cleanupGroup)
85 									, m_arg0				(arg0)
86 								{}
87 
init(void)88 	void						init				(void) { m_createChildren(this, m_arg0); }
deinit(void)89 	void						deinit				(void) { if (m_cleanupGroup) m_cleanupGroup(this, m_arg0); }
90 
91 private:
92 	const CreateChildrenFunc	m_createChildren;
93 	const CleanupGroupFunc		m_cleanupGroup;
94 	const Arg0					m_arg0;
95 };
96 
97 template<typename Arg0, typename Arg1>
98 class TestGroupHelper2 : public tcu::TestCaseGroup
99 {
100 public:
101 	typedef void(*CreateChildrenFunc) (tcu::TestCaseGroup* testGroup, Arg0 arg0, Arg1 arg1);
102 	typedef void(*CleanupGroupFunc) (tcu::TestCaseGroup* testGroup, Arg0 arg0, Arg1 arg1);
103 
TestGroupHelper2(tcu::TestContext & testCtx,const std::string & name,const std::string & description,CreateChildrenFunc createChildren,const Arg0 & arg0,const Arg1 & arg1,CleanupGroupFunc cleanupGroup)104 								TestGroupHelper2(tcu::TestContext&		testCtx,
105 												const std::string&		name,
106 												const std::string&		description,
107 												CreateChildrenFunc		createChildren,
108 												const Arg0&				arg0,
109 												const Arg1&				arg1,
110 												CleanupGroupFunc		cleanupGroup)
111 									: tcu::TestCaseGroup	(testCtx, name.c_str(), description.c_str())
112 									, m_createChildren		(createChildren)
113 									, m_cleanupGroup		(cleanupGroup)
114 									, m_arg0				(arg0)
115 									, m_arg1				(arg1)
116 								{}
117 
init(void)118 	void						init		(void) { m_createChildren(this, m_arg0, m_arg1); }
deinit(void)119 	void						deinit		(void) { if (m_cleanupGroup) m_cleanupGroup(this, m_arg0, m_arg1); }
120 
121 private:
122 	const CreateChildrenFunc	m_createChildren;
123 	const CleanupGroupFunc		m_cleanupGroup;
124 	const Arg0					m_arg0;
125 	const Arg1					m_arg1;
126 };
127 
createTestGroup(tcu::TestContext & testCtx,const std::string & name,const std::string & description,TestGroupHelper0::CreateChildrenFunc createChildren,TestGroupHelper0::CleanupGroupFunc cleanupGroup=DE_NULL)128 inline tcu::TestCaseGroup* createTestGroup (tcu::TestContext&										testCtx,
129 											const std::string&										name,
130 											const std::string&										description,
131 											TestGroupHelper0::CreateChildrenFunc					createChildren,
132 											TestGroupHelper0::CleanupGroupFunc						cleanupGroup = DE_NULL)
133 {
134 	return new TestGroupHelper0(testCtx, name, description, createChildren, cleanupGroup);
135 }
136 
137 template<typename Arg0>
createTestGroup(tcu::TestContext & testCtx,const std::string & name,const std::string & description,typename TestGroupHelper1<Arg0>::CreateChildrenFunc createChildren,Arg0 arg0,typename TestGroupHelper1<Arg0>::CleanupGroupFunc cleanupGroup=DE_NULL)138 tcu::TestCaseGroup* createTestGroup (tcu::TestContext&										testCtx,
139 									 const std::string&										name,
140 									 const std::string&										description,
141 									 typename TestGroupHelper1<Arg0>::CreateChildrenFunc	createChildren,
142 									 Arg0													arg0,
143 									 typename TestGroupHelper1<Arg0>::CleanupGroupFunc		cleanupGroup = DE_NULL)
144 {
145 	return new TestGroupHelper1<Arg0>(testCtx, name, description, createChildren, arg0, cleanupGroup);
146 }
147 template<typename Arg0, typename Arg1>
createTestGroup(tcu::TestContext & testCtx,const std::string & name,const std::string & description,typename TestGroupHelper2<Arg0,Arg1>::CreateChildrenFunc createChildren,Arg0 arg0,Arg1 arg1,typename TestGroupHelper2<Arg0,Arg1>::CleanupGroupFunc cleanupGroup=DE_NULL)148 tcu::TestCaseGroup* createTestGroup (tcu::TestContext&											testCtx,
149 									 const std::string&											name,
150 									 const std::string&											description,
151 									 typename TestGroupHelper2<Arg0, Arg1>::CreateChildrenFunc	createChildren,
152 									 Arg0														arg0,
153 									 Arg1														arg1,
154 									 typename TestGroupHelper2<Arg0, Arg1>::CleanupGroupFunc	cleanupGroup = DE_NULL)
155 {
156 	return new TestGroupHelper2<Arg0, Arg1>(testCtx, name, description, createChildren, arg0, arg1, cleanupGroup);
157 }
158 
addTestGroup(tcu::TestCaseGroup * parent,const std::string & name,const std::string & description,TestGroupHelper0::CreateChildrenFunc createChildren)159 inline void addTestGroup (tcu::TestCaseGroup*					parent,
160 						  const std::string&					name,
161 						  const std::string&					description,
162 						  TestGroupHelper0::CreateChildrenFunc	createChildren)
163 {
164 	parent->addChild(createTestGroup(parent->getTestContext(), name, description, createChildren));
165 }
166 
167 template<typename Arg0>
addTestGroup(tcu::TestCaseGroup * parent,const std::string & name,const std::string & description,typename TestGroupHelper1<Arg0>::CreateChildrenFunc createChildren,Arg0 arg0,typename TestGroupHelper1<Arg0>::CleanupGroupFunc cleanupGroup=DE_NULL)168 void addTestGroup (tcu::TestCaseGroup*									parent,
169 				   const std::string&									name,
170 				   const std::string&									description,
171 				   typename TestGroupHelper1<Arg0>::CreateChildrenFunc	createChildren,
172 				   Arg0													arg0,
173 				   typename TestGroupHelper1<Arg0>::CleanupGroupFunc	cleanupGroup = DE_NULL)
174 {
175 	parent->addChild(createTestGroup<Arg0>(parent->getTestContext(), name, description, createChildren, arg0, cleanupGroup));
176 }
177 
178 template<typename Arg0, typename Arg1>
addTestGroup(tcu::TestCaseGroup * parent,const std::string & name,const std::string & description,typename TestGroupHelper2<Arg0,Arg1>::CreateChildrenFunc createChildren,Arg0 arg0,Arg1 arg1,typename TestGroupHelper2<Arg0,Arg1>::CleanupGroupFunc cleanupGroup=DE_NULL)179 void addTestGroup(tcu::TestCaseGroup*					parent,
180 	const std::string&									name,
181 	const std::string&									description,
182 	typename TestGroupHelper2<Arg0,Arg1>::CreateChildrenFunc	createChildren,
183 	Arg0												arg0,
184 	Arg1												arg1,
185 	typename TestGroupHelper2<Arg0,Arg1>::CleanupGroupFunc	cleanupGroup = DE_NULL)
186 {
187 	parent->addChild(createTestGroup<Arg0,Arg1>(parent->getTestContext(), name, description, createChildren, arg0, arg1, cleanupGroup));
188 }
189 
190 } // vkt
191 
192 #endif // _VKTTESTGROUPUTIL_HPP
193