| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | // Copyright 2019 Juan Palacios <[email protected]> |
| 3 | |
| 4 | #include <catch2/catch_all.hpp> |
| 5 | |
| 6 | #include "common/hwidtranslatorstub.h" |
| 7 | #include "core/idatasource.h" |
| 8 | #include "core/info/common/gpuinfoopengl.h" |
| 9 | |
| 10 | namespace Tests::GPUInfoOpenGL { |
| 11 | |
| 12 | class GPUInfoOpenGLDataSourceStub : public IDataSource<std::string, int const> |
| 13 | { |
| 14 | public: |
| 15 | GPUInfoOpenGLDataSourceStub(std::string source = "", std::string data = "") |
| 16 | : source_(std::move(source)) |
| 17 | , data_(std::move(data)) |
| 18 | { |
| 19 | } |
| 20 | |
| 21 | std::string source() const override |
| 22 | { |
| 23 | return source_; |
| 24 | } |
| 25 | |
| 26 | bool read(std::string &data, int const &) override |
| 27 | { |
| 28 | data = data_; |
| 29 | return true; |
| 30 | } |
| 31 | |
| 32 | private: |
| 33 | std::string const source_; |
| 34 | std::string const data_; |
| 35 | }; |
| 36 | |
| 37 | TEST_CASE("GPUInfoOpenGL tests", "[Info][GPUInfo][GPUInfoOpenGL]") |
| 38 | { |
| 39 | std::string const infoData( |
| 40 | // clang-format off |
| 41 | "...\n\ |
| 42 | Extended renderer info (GLX_MESA_query_renderer):\n\ |
| 43 | ...\n\ |
| 44 | Max core profile version: 1.1\n\ |
| 45 | Max compat profile version: 2.2\n\ |
| 46 | ..."); // clang-format on |
| 47 | |
| 48 | Vendor vendor(Vendor::AMD); |
| 49 | int const gpuIndex = 0; |
| 50 | IGPUInfo::Path path("_sys_", "_dev_"); |
| 51 | HWIDTranslatorStub hwIDTranslator; |
| 52 | |
| 53 | ::GPUInfoOpenGL ts( |
| 54 | std::make_unique<GPUInfoOpenGLDataSourceStub>("glxinfo", infoData)); |
| 55 | |
| 56 | auto output = ts.provideInfo(vendor, gpuIndex, path, hwIDTranslator); |
| 57 | |
| 58 | SECTION("Provides core version") |
| 59 | { |
| 60 | auto coreVersion = std::make_pair( |
| 61 | std::string(::GPUInfoOpenGL::Keys::coreVersion), std::string("1.1")); |
| 62 | REQUIRE_THAT(output, Catch::Matchers::VectorContains(coreVersion)); |
| 63 | } |
| 64 | |
| 65 | SECTION("Provides compat version") |
| 66 | { |
| 67 | auto compatVersion = std::make_pair( |
| 68 | std::string(::GPUInfoOpenGL::Keys::compatVersion), std::string("2.2")); |
| 69 | REQUIRE_THAT(output, Catch::Matchers::VectorContains(compatVersion)); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | } // namespace Tests::GPUInfoOpenGL |