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 PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
30 * \brief TestCase utilities
31 *//*--------------------------------------------------------------------*/
33 #include "tcuDefs.hpp"
34 #include "vktTestCase.hpp"
39 template<typename Arg0>
42 void init (vk::SourceCollections&, Arg0) const {}
45 template<typename Instance, typename Arg0, typename Programs = NoPrograms1<Arg0> >
46 class InstanceFactory1 : public TestCase
49 InstanceFactory1 (tcu::TestContext& testCtx, tcu::TestNodeType type, const std::string& name, const std::string& desc, const Arg0& arg0)
50 : TestCase (testCtx, type, name, desc)
55 InstanceFactory1 (tcu::TestContext& testCtx, tcu::TestNodeType type, const std::string& name, const std::string& desc, const Programs& progs, const Arg0& arg0)
56 : TestCase (testCtx, type, name, desc)
61 void initPrograms (vk::SourceCollections& dst) const { m_progs.init(dst, m_arg0); }
62 TestInstance* createInstance (Context& context) const { return new Instance(context, m_arg0); }
65 const Programs m_progs;
69 class FunctionInstance0 : public TestInstance
72 typedef tcu::TestStatus (*Function) (Context& context);
74 FunctionInstance0 (Context& context, Function function)
75 : TestInstance (context)
76 , m_function (function)
79 tcu::TestStatus iterate (void) { return m_function(m_context); }
82 const Function m_function;
85 template<typename Arg0>
86 class FunctionInstance1 : public TestInstance
89 typedef tcu::TestStatus (*Function) (Context& context, Arg0 arg0);
93 Args (Function func_, Arg0 arg0_) : func(func_), arg0(arg0_) {}
99 FunctionInstance1 (Context& context, const Args& args)
100 : TestInstance (context)
104 tcu::TestStatus iterate (void) { return m_args.func(m_context, m_args.arg0); }
110 class FunctionPrograms0
113 typedef void (*Function) (vk::SourceCollections& dst);
115 FunctionPrograms0 (Function func)
119 void init (vk::SourceCollections& dst, FunctionInstance0::Function) const { m_func(dst); }
122 const Function m_func;
125 template<typename Arg0>
126 class FunctionPrograms1
129 typedef void (*Function) (vk::SourceCollections& dst, Arg0 arg0);
131 FunctionPrograms1 (Function func)
135 void init (vk::SourceCollections& dst, const typename FunctionInstance1<Arg0>::Args& args) const { m_func(dst, args.arg0); }
138 const Function m_func;
141 // createFunctionCase
143 inline TestCase* createFunctionCase (tcu::TestContext& testCtx,
144 tcu::TestNodeType type,
145 const std::string& name,
146 const std::string& desc,
147 FunctionInstance0::Function testFunction)
149 return new InstanceFactory1<FunctionInstance0, FunctionInstance0::Function>(testCtx, type, name, desc, testFunction);
152 inline TestCase* createFunctionCaseWithPrograms (tcu::TestContext& testCtx,
153 tcu::TestNodeType type,
154 const std::string& name,
155 const std::string& desc,
156 FunctionPrograms0::Function initPrograms,
157 FunctionInstance0::Function testFunction)
159 return new InstanceFactory1<FunctionInstance0, FunctionInstance0::Function, FunctionPrograms0>(
160 testCtx, type, name, desc, FunctionPrograms0(initPrograms), testFunction);
163 template<typename Arg0>
164 TestCase* createFunctionCase (tcu::TestContext& testCtx,
165 tcu::TestNodeType type,
166 const std::string& name,
167 const std::string& desc,
168 typename FunctionInstance1<Arg0>::Function testFunction,
171 return new InstanceFactory1<FunctionInstance1<Arg0>, typename FunctionInstance1<Arg0>::Args>(
172 testCtx, type, name, desc, typename FunctionInstance1<Arg0>::Args(testFunction, arg0));
175 template<typename Arg0>
176 TestCase* createFunctionCaseWithPrograms (tcu::TestContext& testCtx,
177 tcu::TestNodeType type,
178 const std::string& name,
179 const std::string& desc,
180 typename FunctionPrograms1<Arg0>::Function initPrograms,
181 typename FunctionInstance1<Arg0>::Function testFunction,
184 return new InstanceFactory1<FunctionInstance1<Arg0>, typename FunctionInstance1<Arg0>::Args, FunctionPrograms1<Arg0> >(
185 testCtx, type, name, desc, FunctionPrograms1<Arg0>(initPrograms), typename FunctionInstance1<Arg0>::Args(testFunction, arg0));
190 inline void addFunctionCase (tcu::TestCaseGroup* group,
191 const std::string& name,
192 const std::string& desc,
193 FunctionInstance0::Function testFunc)
195 group->addChild(createFunctionCase(group->getTestContext(), tcu::NODETYPE_SELF_VALIDATE, name, desc, testFunc));
198 inline void addFunctionCaseWithPrograms (tcu::TestCaseGroup* group,
199 const std::string& name,
200 const std::string& desc,
201 FunctionPrograms0::Function initPrograms,
202 FunctionInstance0::Function testFunc)
204 group->addChild(createFunctionCaseWithPrograms(group->getTestContext(), tcu::NODETYPE_SELF_VALIDATE, name, desc, initPrograms, testFunc));
207 template<typename Arg0>
208 void addFunctionCase (tcu::TestCaseGroup* group,
209 const std::string& name,
210 const std::string& desc,
211 typename FunctionInstance1<Arg0>::Function testFunc,
214 group->addChild(createFunctionCase<Arg0>(group->getTestContext(), tcu::NODETYPE_SELF_VALIDATE, name, desc, testFunc, arg0));
217 template<typename Arg0>
218 void addFunctionCase (tcu::TestCaseGroup* group,
219 tcu::TestNodeType type,
220 const std::string& name,
221 const std::string& desc,
222 typename FunctionInstance1<Arg0>::Function testFunc,
225 group->addChild(createFunctionCase<Arg0>(group->getTestContext(), type, name, desc, testFunc, arg0));
228 template<typename Arg0>
229 void addFunctionCaseWithPrograms (tcu::TestCaseGroup* group,
230 const std::string& name,
231 const std::string& desc,
232 typename FunctionPrograms1<Arg0>::Function initPrograms,
233 typename FunctionInstance1<Arg0>::Function testFunc,
236 group->addChild(createFunctionCaseWithPrograms<Arg0>(group->getTestContext(), tcu::NODETYPE_SELF_VALIDATE, name, desc, initPrograms, testFunc, arg0));
239 template<typename Arg0>
240 void addFunctionCaseWithPrograms (tcu::TestCaseGroup* group,
241 tcu::TestNodeType type,
242 const std::string& name,
243 const std::string& desc,
244 typename FunctionPrograms1<Arg0>::Function initPrograms,
245 typename FunctionInstance1<Arg0>::Function testFunc,
248 group->addChild(createFunctionCaseWithPrograms<Arg0>(group->getTestContext(), type, name, desc, initPrograms, testFunc, arg0));
253 #endif // _VKTTESTCASEUTIL_HPP