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