1 #ifndef _VKTTESTCASEUTIL_HPP
2 #define _VKTTESTCASEUTIL_HPP
3 /*-------------------------------------------------------------------------
4 * Vulkan Conformance Tests
5 * ------------------------
7 * Copyright (c) 2015 Google Inc.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and/or associated documentation files (the
11 * "Materials"), to deal in the Materials without restriction, including
12 * without limitation the rights to use, copy, modify, merge, publish,
13 * distribute, sublicense, and/or sell copies of the Materials, and to
14 * permit persons to whom the Materials are furnished to do so, subject to
15 * the following conditions:
17 * The above copyright notice(s) and this permission notice shall be
18 * included in all copies or substantial portions of the Materials.
20 * The Materials are Confidential Information as defined by the
21 * Khronos Membership Agreement until designated non-confidential by
22 * Khronos, at which point this condition clause shall be removed.
24 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
27 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
28 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
29 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
30 * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
34 * \brief TestCase utilities
35 *//*--------------------------------------------------------------------*/
37 #include "tcuDefs.hpp"
38 #include "vktTestCase.hpp"
43 template<typename Arg0>
46 void init (vk::SourceCollections&, Arg0) const {}
49 template<typename Instance, typename Arg0, typename Programs = NoPrograms1<Arg0> >
50 class InstanceFactory1 : public TestCase
53 InstanceFactory1 (tcu::TestContext& testCtx, tcu::TestNodeType type, const std::string& name, const std::string& desc, const Arg0& arg0)
54 : TestCase (testCtx, type, name, desc)
59 InstanceFactory1 (tcu::TestContext& testCtx, tcu::TestNodeType type, const std::string& name, const std::string& desc, const Programs& progs, const Arg0& arg0)
60 : TestCase (testCtx, type, name, desc)
65 void initPrograms (vk::SourceCollections& dst) const { m_progs.init(dst, m_arg0); }
66 TestInstance* createInstance (Context& context) const { return new Instance(context, m_arg0); }
69 const Programs m_progs;
73 class FunctionInstance0 : public TestInstance
76 typedef tcu::TestStatus (*Function) (Context& context);
78 FunctionInstance0 (Context& context, Function function)
79 : TestInstance (context)
80 , m_function (function)
83 tcu::TestStatus iterate (void) { return m_function(m_context); }
86 const Function m_function;
89 template<typename Arg0>
90 class FunctionInstance1 : public TestInstance
93 typedef tcu::TestStatus (*Function) (Context& context, Arg0 arg0);
97 Args (Function func_, Arg0 arg0_) : func(func_), arg0(arg0_) {}
103 FunctionInstance1 (Context& context, const Args& args)
104 : TestInstance (context)
108 tcu::TestStatus iterate (void) { return m_args.func(m_context, m_args.arg0); }
114 class FunctionPrograms0
117 typedef void (*Function) (vk::SourceCollections& dst);
119 FunctionPrograms0 (Function func)
123 void init (vk::SourceCollections& dst, FunctionInstance0::Function) const { m_func(dst); }
126 const Function m_func;
129 template<typename Arg0>
130 class FunctionPrograms1
133 typedef void (*Function) (vk::SourceCollections& dst, Arg0 arg0);
135 FunctionPrograms1 (Function func)
139 void init (vk::SourceCollections& dst, const typename FunctionInstance1<Arg0>::Args& args) const { m_func(dst, args.arg0); }
142 const Function m_func;
145 // createFunctionCase
147 inline TestCase* createFunctionCase (tcu::TestContext& testCtx,
148 tcu::TestNodeType type,
149 const std::string& name,
150 const std::string& desc,
151 FunctionInstance0::Function testFunction)
153 return new InstanceFactory1<FunctionInstance0, FunctionInstance0::Function>(testCtx, type, name, desc, testFunction);
156 inline TestCase* createFunctionCaseWithPrograms (tcu::TestContext& testCtx,
157 tcu::TestNodeType type,
158 const std::string& name,
159 const std::string& desc,
160 FunctionPrograms0::Function initPrograms,
161 FunctionInstance0::Function testFunction)
163 return new InstanceFactory1<FunctionInstance0, FunctionInstance0::Function, FunctionPrograms0>(
164 testCtx, type, name, desc, FunctionPrograms0(initPrograms), testFunction);
167 template<typename Arg0>
168 TestCase* createFunctionCase (tcu::TestContext& testCtx,
169 tcu::TestNodeType type,
170 const std::string& name,
171 const std::string& desc,
172 typename FunctionInstance1<Arg0>::Function testFunction,
175 return new InstanceFactory1<FunctionInstance1<Arg0>, typename FunctionInstance1<Arg0>::Args>(
176 testCtx, type, name, desc, typename FunctionInstance1<Arg0>::Args(testFunction, arg0));
179 template<typename Arg0>
180 TestCase* createFunctionCaseWithPrograms (tcu::TestContext& testCtx,
181 tcu::TestNodeType type,
182 const std::string& name,
183 const std::string& desc,
184 typename FunctionPrograms1<Arg0>::Function initPrograms,
185 typename FunctionInstance1<Arg0>::Function testFunction,
188 return new InstanceFactory1<FunctionInstance1<Arg0>, typename FunctionInstance1<Arg0>::Args, FunctionPrograms1<Arg0> >(
189 testCtx, type, name, desc, FunctionPrograms1<Arg0>(initPrograms), typename FunctionInstance1<Arg0>::Args(testFunction, arg0));
194 inline void addFunctionCase (tcu::TestCaseGroup* group,
195 const std::string& name,
196 const std::string& desc,
197 FunctionInstance0::Function testFunc)
199 group->addChild(createFunctionCase(group->getTestContext(), tcu::NODETYPE_SELF_VALIDATE, name, desc, testFunc));
202 inline void addFunctionCaseWithPrograms (tcu::TestCaseGroup* group,
203 const std::string& name,
204 const std::string& desc,
205 FunctionPrograms0::Function initPrograms,
206 FunctionInstance0::Function testFunc)
208 group->addChild(createFunctionCaseWithPrograms(group->getTestContext(), tcu::NODETYPE_SELF_VALIDATE, name, desc, initPrograms, testFunc));
211 template<typename Arg0>
212 void addFunctionCase (tcu::TestCaseGroup* group,
213 const std::string& name,
214 const std::string& desc,
215 typename FunctionInstance1<Arg0>::Function testFunc,
218 group->addChild(createFunctionCase<Arg0>(group->getTestContext(), tcu::NODETYPE_SELF_VALIDATE, name, desc, testFunc, arg0));
221 template<typename Arg0>
222 void addFunctionCase (tcu::TestCaseGroup* group,
223 tcu::TestNodeType type,
224 const std::string& name,
225 const std::string& desc,
226 typename FunctionInstance1<Arg0>::Function testFunc,
229 group->addChild(createFunctionCase<Arg0>(group->getTestContext(), type, name, desc, testFunc, arg0));
232 template<typename Arg0>
233 void addFunctionCaseWithPrograms (tcu::TestCaseGroup* group,
234 const std::string& name,
235 const std::string& desc,
236 typename FunctionPrograms1<Arg0>::Function initPrograms,
237 typename FunctionInstance1<Arg0>::Function testFunc,
240 group->addChild(createFunctionCaseWithPrograms<Arg0>(group->getTestContext(), tcu::NODETYPE_SELF_VALIDATE, name, desc, initPrograms, testFunc, arg0));
243 template<typename Arg0>
244 void addFunctionCaseWithPrograms (tcu::TestCaseGroup* group,
245 tcu::TestNodeType type,
246 const std::string& name,
247 const std::string& desc,
248 typename FunctionPrograms1<Arg0>::Function initPrograms,
249 typename FunctionInstance1<Arg0>::Function testFunc,
252 group->addChild(createFunctionCaseWithPrograms<Arg0>(group->getTestContext(), type, name, desc, initPrograms, testFunc, arg0));
257 #endif // _VKTTESTCASEUTIL_HPP