| 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/stringdatasourcestub.h" |
| 7 | #include "core/info/common/swinfokernel.h" |
| 8 | |
| 9 | namespace Tests::SWInfoKernel { |
| 10 | |
| 11 | TEST_CASE("SWInfoKernel tests", "[Info][SWInfo][SWInfoKernel]") |
| 12 | { |
| 13 | SECTION("Provides kernel version when /proc/version has a known format") |
| 14 | { |
| 15 | std::string const infoData("Linux version 1.2.3_other_info ..."); |
| 16 | |
| 17 | ::SWInfoKernel ts( |
| 18 | std::make_unique<StringDataSourceStub>("/proc/version", infoData)); |
| 19 | auto output = ts.provideInfo(); |
| 20 | |
| 21 | auto kernelVersion = std::make_pair( |
| 22 | std::string(ISWInfo::Keys::kernelVersion), std::string("1.2.3")); |
| 23 | REQUIRE_THAT(output, Catch::Matchers::VectorContains(kernelVersion)); |
| 24 | } |
| 25 | |
| 26 | SECTION("Provides fake kernel version (0.0.0) when...") |
| 27 | { |
| 28 | SECTION("Cannot read /proc/version") |
| 29 | { |
| 30 | ::SWInfoKernel ts( |
| 31 | std::make_unique<StringDataSourceStub>("/proc/version", "", false)); |
| 32 | auto output = ts.provideInfo(); |
| 33 | |
| 34 | auto kernelVersion = std::make_pair( |
| 35 | std::string(ISWInfo::Keys::kernelVersion), std::string("0.0.0")); |
| 36 | REQUIRE_THAT(output, Catch::Matchers::VectorContains(kernelVersion)); |
| 37 | } |
| 38 | |
| 39 | SECTION("/proc/version data has an unknown format") |
| 40 | { |
| 41 | std::string const infoData("Other format ..."); |
| 42 | |
| 43 | ::SWInfoKernel ts( |
| 44 | std::make_unique<StringDataSourceStub>("/proc/version", infoData)); |
| 45 | auto output = ts.provideInfo(); |
| 46 | |
| 47 | auto kernelVersion = std::make_pair( |
| 48 | std::string(ISWInfo::Keys::kernelVersion), std::string("0.0.0")); |
| 49 | REQUIRE_THAT(output, Catch::Matchers::VectorContains(kernelVersion)); |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | } // namespace Tests::SWInfoKernel |