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 
38 								TestGroupHelper0	(tcu::TestContext&		testCtx,
39 													 const std::string&		name,
40 													 const std::string&		description,
41 													 CreateChildrenFunc		createChildren,
42 													 CleanupGroupFunc		cleanupGroup);
43 								~TestGroupHelper0	(void);
44 
45 	void						init				(void);
46 	void						deinit				(void);
47 
48 private:
49 	const CreateChildrenFunc	m_createChildren;
50 	const CleanupGroupFunc		m_cleanupGroup;
51 };
52 
53 template<typename Arg0>
54 class TestGroupHelper1 : public tcu::TestCaseGroup
55 {
56 public:
57 	typedef void (*CreateChildrenFunc) (tcu::TestCaseGroup* testGroup, Arg0 arg0);
58 	typedef void (*CleanupGroupFunc) (tcu::TestCaseGroup* testGroup, Arg0 arg0);
59 
TestGroupHelper1(tcu::TestContext & testCtx,const std::string & name,const std::string & description,CreateChildrenFunc createChildren,const Arg0 & arg0,CleanupGroupFunc cleanupGroup)60 								TestGroupHelper1	(tcu::TestContext&		testCtx,
61 													 const std::string&		name,
62 													 const std::string&		description,
63 													 CreateChildrenFunc		createChildren,
64 													 const Arg0&			arg0,
65 													 CleanupGroupFunc		cleanupGroup)
66 									: tcu::TestCaseGroup	(testCtx, name.c_str(), description.c_str())
67 									, m_createChildren		(createChildren)
68 									, m_cleanupGroup		(cleanupGroup)
69 									, m_arg0				(arg0)
70 								{}
71 
init(void)72 	void						init				(void) { m_createChildren(this, m_arg0); }
deinit(void)73 	void						deinit				(void) { if (m_cleanupGroup) m_cleanupGroup(this, m_arg0); }
74 
75 private:
76 	const CreateChildrenFunc	m_createChildren;
77 	const CleanupGroupFunc		m_cleanupGroup;
78 	const Arg0					m_arg0;
79 };
80 
81 template<typename Arg0, typename Arg1>
82 class TestGroupHelper2 : public tcu::TestCaseGroup
83 {
84 public:
85 	typedef void(*CreateChildrenFunc) (tcu::TestCaseGroup* testGroup, Arg0 arg0, Arg1 arg1);
86 	typedef void(*CleanupGroupFunc) (tcu::TestCaseGroup* testGroup, Arg0 arg0, Arg1 arg1);
87 
TestGroupHelper2(tcu::TestContext & testCtx,const std::string & name,const std::string & description,CreateChildrenFunc createChildren,const Arg0 & arg0,const Arg1 & arg1,CleanupGroupFunc cleanupGroup)88 								TestGroupHelper2(tcu::TestContext&		testCtx,
89 												const std::string&		name,
90 												const std::string&		description,
91 												CreateChildrenFunc		createChildren,
92 												const Arg0&				arg0,
93 												const Arg1&				arg1,
94 												CleanupGroupFunc		cleanupGroup)
95 									: tcu::TestCaseGroup	(testCtx, name.c_str(), description.c_str())
96 									, m_createChildren		(createChildren)
97 									, m_cleanupGroup		(cleanupGroup)
98 									, m_arg0				(arg0)
99 									, m_arg1				(arg1)
100 								{}
101 
init(void)102 	void						init		(void) { m_createChildren(this, m_arg0, m_arg1); }
deinit(void)103 	void						deinit		(void) { if (m_cleanupGroup) m_cleanupGroup(this, m_arg0, m_arg1); }
104 
105 private:
106 	const CreateChildrenFunc	m_createChildren;
107 	const CleanupGroupFunc		m_cleanupGroup;
108 	const Arg0					m_arg0;
109 	const Arg1					m_arg1;
110 };
111 
createTestGroup(tcu::TestContext & testCtx,const std::string & name,const std::string & description,TestGroupHelper0::CreateChildrenFunc createChildren,TestGroupHelper0::CleanupGroupFunc cleanupGroup=DE_NULL)112 inline tcu::TestCaseGroup* createTestGroup (tcu::TestContext&										testCtx,
113 											const std::string&										name,
114 											const std::string&										description,
115 											TestGroupHelper0::CreateChildrenFunc					createChildren,
116 											TestGroupHelper0::CleanupGroupFunc						cleanupGroup = DE_NULL)
117 {
118 	return new TestGroupHelper0(testCtx, name, description, createChildren, cleanupGroup);
119 }
120 
121 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)122 tcu::TestCaseGroup* createTestGroup (tcu::TestContext&										testCtx,
123 									 const std::string&										name,
124 									 const std::string&										description,
125 									 typename TestGroupHelper1<Arg0>::CreateChildrenFunc	createChildren,
126 									 Arg0													arg0,
127 									 typename TestGroupHelper1<Arg0>::CleanupGroupFunc		cleanupGroup = DE_NULL)
128 {
129 	return new TestGroupHelper1<Arg0>(testCtx, name, description, createChildren, arg0, cleanupGroup);
130 }
131 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)132 tcu::TestCaseGroup* createTestGroup (tcu::TestContext&											testCtx,
133 									 const std::string&											name,
134 									 const std::string&											description,
135 									 typename TestGroupHelper2<Arg0, Arg1>::CreateChildrenFunc	createChildren,
136 									 Arg0														arg0,
137 									 Arg1														arg1,
138 									 typename TestGroupHelper2<Arg0, Arg1>::CleanupGroupFunc	cleanupGroup = DE_NULL)
139 {
140 	return new TestGroupHelper2<Arg0, Arg1>(testCtx, name, description, createChildren, arg0, arg1, cleanupGroup);
141 }
142 
addTestGroup(tcu::TestCaseGroup * parent,const std::string & name,const std::string & description,TestGroupHelper0::CreateChildrenFunc createChildren)143 inline void addTestGroup (tcu::TestCaseGroup*					parent,
144 						  const std::string&					name,
145 						  const std::string&					description,
146 						  TestGroupHelper0::CreateChildrenFunc	createChildren)
147 {
148 	parent->addChild(createTestGroup(parent->getTestContext(), name, description, createChildren));
149 }
150 
151 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)152 void addTestGroup (tcu::TestCaseGroup*									parent,
153 				   const std::string&									name,
154 				   const std::string&									description,
155 				   typename TestGroupHelper1<Arg0>::CreateChildrenFunc	createChildren,
156 				   Arg0													arg0,
157 				   typename TestGroupHelper1<Arg0>::CleanupGroupFunc	cleanupGroup = DE_NULL)
158 {
159 	parent->addChild(createTestGroup<Arg0>(parent->getTestContext(), name, description, createChildren, arg0, cleanupGroup));
160 }
161 
162 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)163 void addTestGroup(tcu::TestCaseGroup*					parent,
164 	const std::string&									name,
165 	const std::string&									description,
166 	typename TestGroupHelper2<Arg0,Arg1>::CreateChildrenFunc	createChildren,
167 	Arg0												arg0,
168 	Arg1												arg1,
169 	typename TestGroupHelper2<Arg0,Arg1>::CleanupGroupFunc	cleanupGroup = DE_NULL)
170 {
171 	parent->addChild(createTestGroup<Arg0,Arg1>(parent->getTestContext(), name, description, createChildren, arg0, arg1, cleanupGroup));
172 }
173 
174 } // vkt
175 
176 #endif // _VKTTESTGROUPUTIL_HPP
177