1 #ifndef _VKTTESTCASEUTIL_HPP
2 #define _VKTTESTCASEUTIL_HPP
3 /*-------------------------------------------------------------------------
4 * Vulkan Conformance Tests
5 * ------------------------
7 * Copyright (c) 2015 Google Inc.
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 * \brief TestCase utilities
24 *//*--------------------------------------------------------------------*/
26 #include "tcuDefs.hpp"
27 #include "vktTestCase.hpp"
32 template<typename Arg0>
35 void init (vk::SourceCollections&, Arg0) const {}
38 template<typename Instance, typename Arg0, typename Programs = NoPrograms1<Arg0> >
39 class InstanceFactory1 : public TestCase
42 InstanceFactory1 (tcu::TestContext& testCtx, tcu::TestNodeType type, const std::string& name, const std::string& desc, const Arg0& arg0)
43 : TestCase (testCtx, type, name, desc)
48 InstanceFactory1 (tcu::TestContext& testCtx, tcu::TestNodeType type, const std::string& name, const std::string& desc, const Programs& progs, const Arg0& arg0)
49 : TestCase (testCtx, type, name, desc)
54 void initPrograms (vk::SourceCollections& dst) const { m_progs.init(dst, m_arg0); }
55 TestInstance* createInstance (Context& context) const { return new Instance(context, m_arg0); }
58 const Programs m_progs;
62 class FunctionInstance0 : public TestInstance
65 typedef tcu::TestStatus (*Function) (Context& context);
67 FunctionInstance0 (Context& context, Function function)
68 : TestInstance (context)
69 , m_function (function)
72 tcu::TestStatus iterate (void) { return m_function(m_context); }
75 const Function m_function;
78 template<typename Arg0>
79 class FunctionInstance1 : public TestInstance
82 typedef tcu::TestStatus (*Function) (Context& context, Arg0 arg0);
86 Args (Function func_, Arg0 arg0_) : func(func_), arg0(arg0_) {}
92 FunctionInstance1 (Context& context, const Args& args)
93 : TestInstance (context)
97 tcu::TestStatus iterate (void) { return m_args.func(m_context, m_args.arg0); }
103 class FunctionPrograms0
106 typedef void (*Function) (vk::SourceCollections& dst);
108 FunctionPrograms0 (Function func)
112 void init (vk::SourceCollections& dst, FunctionInstance0::Function) const { m_func(dst); }
115 const Function m_func;
118 template<typename Arg0>
119 class FunctionPrograms1
122 typedef void (*Function) (vk::SourceCollections& dst, Arg0 arg0);
124 FunctionPrograms1 (Function func)
128 void init (vk::SourceCollections& dst, const typename FunctionInstance1<Arg0>::Args& args) const { m_func(dst, args.arg0); }
131 const Function m_func;
134 // createFunctionCase
136 inline TestCase* createFunctionCase (tcu::TestContext& testCtx,
137 tcu::TestNodeType type,
138 const std::string& name,
139 const std::string& desc,
140 FunctionInstance0::Function testFunction)
142 return new InstanceFactory1<FunctionInstance0, FunctionInstance0::Function>(testCtx, type, name, desc, testFunction);
145 inline TestCase* createFunctionCaseWithPrograms (tcu::TestContext& testCtx,
146 tcu::TestNodeType type,
147 const std::string& name,
148 const std::string& desc,
149 FunctionPrograms0::Function initPrograms,
150 FunctionInstance0::Function testFunction)
152 return new InstanceFactory1<FunctionInstance0, FunctionInstance0::Function, FunctionPrograms0>(
153 testCtx, type, name, desc, FunctionPrograms0(initPrograms), testFunction);
156 template<typename Arg0>
157 TestCase* createFunctionCase (tcu::TestContext& testCtx,
158 tcu::TestNodeType type,
159 const std::string& name,
160 const std::string& desc,
161 typename FunctionInstance1<Arg0>::Function testFunction,
164 return new InstanceFactory1<FunctionInstance1<Arg0>, typename FunctionInstance1<Arg0>::Args>(
165 testCtx, type, name, desc, typename FunctionInstance1<Arg0>::Args(testFunction, arg0));
168 template<typename Arg0>
169 TestCase* createFunctionCaseWithPrograms (tcu::TestContext& testCtx,
170 tcu::TestNodeType type,
171 const std::string& name,
172 const std::string& desc,
173 typename FunctionPrograms1<Arg0>::Function initPrograms,
174 typename FunctionInstance1<Arg0>::Function testFunction,
177 return new InstanceFactory1<FunctionInstance1<Arg0>, typename FunctionInstance1<Arg0>::Args, FunctionPrograms1<Arg0> >(
178 testCtx, type, name, desc, FunctionPrograms1<Arg0>(initPrograms), typename FunctionInstance1<Arg0>::Args(testFunction, arg0));
183 inline void addFunctionCase (tcu::TestCaseGroup* group,
184 const std::string& name,
185 const std::string& desc,
186 FunctionInstance0::Function testFunc)
188 group->addChild(createFunctionCase(group->getTestContext(), tcu::NODETYPE_SELF_VALIDATE, name, desc, testFunc));
191 inline void addFunctionCaseWithPrograms (tcu::TestCaseGroup* group,
192 const std::string& name,
193 const std::string& desc,
194 FunctionPrograms0::Function initPrograms,
195 FunctionInstance0::Function testFunc)
197 group->addChild(createFunctionCaseWithPrograms(group->getTestContext(), tcu::NODETYPE_SELF_VALIDATE, name, desc, initPrograms, testFunc));
200 template<typename Arg0>
201 void addFunctionCase (tcu::TestCaseGroup* group,
202 const std::string& name,
203 const std::string& desc,
204 typename FunctionInstance1<Arg0>::Function testFunc,
207 group->addChild(createFunctionCase<Arg0>(group->getTestContext(), tcu::NODETYPE_SELF_VALIDATE, name, desc, testFunc, arg0));
210 template<typename Arg0>
211 void addFunctionCase (tcu::TestCaseGroup* group,
212 tcu::TestNodeType type,
213 const std::string& name,
214 const std::string& desc,
215 typename FunctionInstance1<Arg0>::Function testFunc,
218 group->addChild(createFunctionCase<Arg0>(group->getTestContext(), type, name, desc, testFunc, arg0));
221 template<typename Arg0>
222 void addFunctionCaseWithPrograms (tcu::TestCaseGroup* group,
223 const std::string& name,
224 const std::string& desc,
225 typename FunctionPrograms1<Arg0>::Function initPrograms,
226 typename FunctionInstance1<Arg0>::Function testFunc,
229 group->addChild(createFunctionCaseWithPrograms<Arg0>(group->getTestContext(), tcu::NODETYPE_SELF_VALIDATE, name, desc, initPrograms, testFunc, arg0));
232 template<typename Arg0>
233 void addFunctionCaseWithPrograms (tcu::TestCaseGroup* group,
234 tcu::TestNodeType type,
235 const std::string& name,
236 const std::string& desc,
237 typename FunctionPrograms1<Arg0>::Function initPrograms,
238 typename FunctionInstance1<Arg0>::Function testFunc,
241 group->addChild(createFunctionCaseWithPrograms<Arg0>(group->getTestContext(), type, name, desc, initPrograms, testFunc, arg0));
246 #endif // _VKTTESTCASEUTIL_HPP