1 /*
2 * Copyright (C) 2016 Intel Corporation. All Rights Reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sub license, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
14 * of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
19 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
20 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 #include "test_va_api_fixture.h"
26
27 #include <sstream>
28
29 namespace VAAPI
30 {
31
32 typedef VAAPIFixture VAAPICreateContextToFail;
33
TEST_F(VAAPICreateContextToFail,CreateContextWithNoConfig)34 TEST_F(VAAPICreateContextToFail, CreateContextWithNoConfig)
35 {
36 // There's no need to test all inputs for this to be a good test
37 // as long as there's no config the expected error should be
38 // returned
39 doInitialize();
40 ASSERT_FALSE(HasFailure());
41 doCreateContext({1920, 1080}, VA_STATUS_ERROR_INVALID_CONFIG);
42 doTerminate();
43 }
44
45 class VAAPICreateContext
46 : public VAAPIFixture
47 , public ::testing::WithParamInterface <
48 std::tuple<VAProfile, VAEntrypoint, Resolution> >
49 {
50 public:
VAAPICreateContext()51 VAAPICreateContext()
52 : profile(::testing::get<0>(GetParam()))
53 , entrypoint(::testing::get<1>(GetParam()))
54 , resolution(::testing::get<2>(GetParam()))
55 { }
56
57 protected:
58 const VAProfile& profile;
59 const VAEntrypoint& entrypoint;
60 const Resolution& resolution;
61
SetUp()62 virtual void SetUp()
63 {
64 VAAPIFixture::SetUp();
65 doInitialize();
66 ASSERT_FALSE(HasFailure());
67 }
68
TearDown()69 virtual void TearDown()
70 {
71 doTerminate();
72 VAAPIFixture::TearDown();
73 }
74 };
75
TEST_P(VAAPICreateContext,CreateContext)76 TEST_P(VAAPICreateContext, CreateContext)
77 {
78 // vaCreateContext requires a valid VAConfigID, vaCreateConfig requires a
79 // supported profile and entrypoint
80
81 if (!isSupported(profile, entrypoint)) {
82 skipTest(profile, entrypoint);
83 return;
84 }
85
86 // profile and entrypoint are supported
87 createConfig(profile, entrypoint);
88
89 Resolution minRes, maxRes;
90 getMinMaxSurfaceResolution(minRes, maxRes);
91
92 std::ostringstream oss;
93 oss << "resolution: min=" << minRes << "; max=" << maxRes
94 << "; current=" << resolution;
95 SCOPED_TRACE(oss.str());
96
97 if (!resolution.isWithin(minRes, maxRes)) {
98 doCreateContext(resolution, VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED);
99 doDestroyContext(VA_STATUS_ERROR_INVALID_CONTEXT);
100 } else {
101 doCreateContext(resolution);
102 doDestroyContext();
103 }
104
105 destroyConfig();
106 }
107
108 INSTANTIATE_TEST_SUITE_P(
109 CreateContext, VAAPICreateContext,
110 ::testing::Combine(::testing::ValuesIn(g_vaProfiles),
111 ::testing::ValuesIn(g_vaEntrypoints),
112 ::testing::ValuesIn(g_vaResolutions)));
113
114 } // namespace VAAPI
115