| 1 | /* |
| 2 | * Copyright (c) 2017, Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice shall be included |
| 12 | * in all copies or substantial portions of the Software. |
| 13 | * |
| 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 20 | * OTHER DEALINGS IN THE SOFTWARE. |
| 21 | */ |
| 22 | |
| 23 | #include "cm_test.h" |
| 24 | |
| 25 | class Surface3DTest: public CmTest |
| 26 | { |
| 27 | public: |
| 28 | static const uint32_t WIDTH = 16; |
| 29 | static const uint32_t HEIGHT = 16; |
| 30 | static const uint32_t DEPTH = 16; |
| 31 | |
| 32 | Surface3DTest(): m_surface(nullptr) {} |
| 33 | |
| 34 | ~Surface3DTest() {} |
| 35 | |
| 36 | int32_t CreateDestroy(CM_SURFACE_FORMAT format, |
| 37 | uint32_t width, |
| 38 | uint32_t height, |
| 39 | uint32_t depth) |
| 40 | { |
| 41 | int32_t result = m_mockDevice->CreateSurface3D(width, height, depth, |
| 42 | format, m_surface); |
| 43 | if (result != CM_SUCCESS) |
| 44 | { |
| 45 | return result; |
| 46 | } |
| 47 | SurfaceIndex *surface_index = nullptr; |
| 48 | result = m_surface->GetIndex(surface_index); |
| 49 | EXPECT_EQ(CM_SUCCESS, result); |
| 50 | EXPECT_GT(surface_index->get_data(), static_cast<uint32_t>(0)); |
| 51 | return m_mockDevice->DestroySurface(m_surface); |
| 52 | }//================================================ |
| 53 | |
| 54 | int32_t ReadWrite() |
| 55 | { |
| 56 | uint8_t to_surface[4*WIDTH*HEIGHT*DEPTH] = {1}; |
| 57 | uint8_t from_surface[4*WIDTH*HEIGHT*DEPTH] = {2}; |
| 58 | for (uint32_t i = 0; i < WIDTH*HEIGHT*DEPTH; ++i) |
| 59 | { |
| 60 | to_surface[4*i] = to_surface[4*i + 1] = to_surface[4*i + 2] |
| 61 | = to_surface[4*i + 3] = i%255; |
| 62 | } |
| 63 | |
| 64 | int32_t result = m_mockDevice->CreateSurface3D( |
| 65 | WIDTH, HEIGHT, DEPTH, CM_SURFACE_FORMAT_A8R8G8B8, m_surface); |
| 66 | EXPECT_EQ(CM_SUCCESS, result); |
| 67 | |
| 68 | result = m_surface->WriteSurface(to_surface, nullptr); |
| 69 | EXPECT_EQ(CM_SUCCESS, result); |
| 70 | |
| 71 | result = m_surface->ReadSurface(from_surface, nullptr); |
| 72 | EXPECT_EQ(CM_SUCCESS, result); |
| 73 | |
| 74 | result = memcmp(to_surface, from_surface, sizeof(to_surface)); |
| 75 | EXPECT_EQ(0, result); |
| 76 | |
| 77 | return m_mockDevice->DestroySurface(m_surface); |
| 78 | }//================================================ |
| 79 | |
| 80 | int32_t Initialize() |
| 81 | { |
| 82 | int32_t result |
| 83 | = m_mockDevice->CreateSurface3D(WIDTH, HEIGHT, DEPTH, |
| 84 | CM_SURFACE_FORMAT_A8R8G8B8, |
| 85 | m_surface); |
| 86 | EXPECT_EQ(CM_SUCCESS, result); |
| 87 | |
| 88 | result = m_surface->InitSurface(0x42424242, nullptr); |
| 89 | EXPECT_EQ(CM_SUCCESS, result); |
| 90 | |
| 91 | uint8_t data[4*WIDTH*HEIGHT*DEPTH] = {0}; |
| 92 | result = m_surface->ReadSurface(data, nullptr); |
| 93 | EXPECT_EQ(CM_SUCCESS, result); |
| 94 | EXPECT_EQ(0x42, data[0]); |
| 95 | EXPECT_EQ(0x42, data[4*WIDTH*HEIGHT*DEPTH - 1]); |
| 96 | return m_mockDevice->DestroySurface(m_surface); |
| 97 | }//================================================ |
| 98 | |
| 99 | private: |
| 100 | CMRT_UMD::CmSurface3D *m_surface; |
| 101 | };//================================= |
| 102 | |
| 103 | TEST_F(Surface3DTest, MultipleSizes) |
| 104 | { |
| 105 | RunEach<int32_t>(CM_SUCCESS, |
| 106 | [this]() { return CreateDestroy(CM_SURFACE_FORMAT_A8R8G8B8, |
| 107 | WIDTH, HEIGHT, DEPTH); }); |
| 108 | |
| 109 | RunEach<int32_t>(CM_SUCCESS, |
| 110 | [this]() { return CreateDestroy(CM_SURFACE_FORMAT_A8R8G8B8, |
| 111 | CM_MIN_SURF_WIDTH, |
| 112 | CM_MIN_SURF_HEIGHT, |
| 113 | CM_MIN_SURF_DEPTH); }); |
| 114 | |
| 115 | RunEach<int32_t>( |
| 116 | CM_SUCCESS, |
| 117 | [this]() { return CreateDestroy(CM_SURFACE_FORMAT_A8R8G8B8, |
| 118 | CM_MAX_3D_SURF_WIDTH, HEIGHT, |
| 119 | DEPTH); }); |
| 120 | |
| 121 | RunEach<int32_t>( |
| 122 | CM_SUCCESS, |
| 123 | [this]() { return CreateDestroy(CM_SURFACE_FORMAT_A8R8G8B8, |
| 124 | WIDTH, CM_MAX_3D_SURF_HEIGHT, |
| 125 | DEPTH); }); |
| 126 | |
| 127 | RunEach<int32_t>(CM_SUCCESS, |
| 128 | [this]() { return CreateDestroy(CM_SURFACE_FORMAT_A8R8G8B8, |
| 129 | WIDTH, HEIGHT, |
| 130 | CM_MAX_3D_SURF_DEPTH); }); |
| 131 | |
| 132 | RunEach<int32_t>( |
| 133 | CM_INVALID_WIDTH, |
| 134 | [this]() { return CreateDestroy(CM_SURFACE_FORMAT_A8R8G8B8, 0, |
| 135 | HEIGHT, DEPTH); }); |
| 136 | |
| 137 | RunEach<int32_t>( |
| 138 | CM_INVALID_HEIGHT, |
| 139 | [this]() { return CreateDestroy(CM_SURFACE_FORMAT_A8R8G8B8, WIDTH, |
| 140 | 0, DEPTH); }); |
| 141 | |
| 142 | RunEach<int32_t>( |
| 143 | CM_INVALID_DEPTH, |
| 144 | [this]() { return CreateDestroy(CM_SURFACE_FORMAT_A8R8G8B8, WIDTH, |
| 145 | HEIGHT, 0); }); |
| 146 | |
| 147 | RunEach<int32_t>( |
| 148 | CM_INVALID_DEPTH, |
| 149 | [this]() { return CreateDestroy(CM_SURFACE_FORMAT_A8R8G8B8, WIDTH, |
| 150 | HEIGHT, |
| 151 | CM_MAX_3D_SURF_DEPTH + 1); }); |
| 152 | |
| 153 | // Tests size in odd numbers. |
| 154 | RunEach<int32_t>(CM_SUCCESS, |
| 155 | [this]() { return CreateDestroy(CM_SURFACE_FORMAT_A8R8G8B8, |
| 156 | WIDTH + 1, HEIGHT + 3, |
| 157 | DEPTH + 5); }); |
| 158 | |
| 159 | return; |
| 160 | }//======== |
| 161 | |
| 162 | TEST_F(Surface3DTest, Abgr16Format) |
| 163 | { |
| 164 | RunEach<int32_t>( |
| 165 | CM_SUCCESS, |
| 166 | [this]() { return CreateDestroy(CM_SURFACE_FORMAT_A16B16G16R16, |
| 167 | WIDTH, HEIGHT, DEPTH); }); |
| 168 | |
| 169 | RunEach<int32_t>( |
| 170 | CM_SUCCESS, |
| 171 | [this]() { return CreateDestroy(CM_SURFACE_FORMAT_A16B16G16R16, |
| 172 | WIDTH + 1, HEIGHT + 3, |
| 173 | DEPTH + 5); }); |
| 174 | return; |
| 175 | }//======== |
| 176 | |
| 177 | TEST_F(Surface3DTest, ReadWrite) |
| 178 | { |
| 179 | RunEach<int32_t>(CM_SUCCESS, |
| 180 | [this]() { return ReadWrite(); }); |
| 181 | return; |
| 182 | }//======== |
| 183 | |
| 184 | TEST_F(Surface3DTest, Initialization) |
| 185 | { |
| 186 | RunEach<int32_t>(CM_SUCCESS, |
| 187 | [this]() { return Initialize(); }); |
| 188 | return; |
| 189 | }//======== |