Alexander Hansen | e1d49f1 | 2025-07-18 15:10:37 +0200 | [diff] [blame] | 1 | |
| 2 | #include "common/include/software_config.hpp" |
| 3 | |
| 4 | #include <fcntl.h> |
| 5 | #include <inttypes.h> |
| 6 | #include <unistd.h> |
| 7 | |
| 8 | #include <phosphor-logging/lg2.hpp> |
| 9 | |
| 10 | #include <gtest/gtest.h> |
| 11 | |
| 12 | using namespace phosphor::software; |
| 13 | using namespace phosphor::software::config; |
| 14 | |
| 15 | constexpr uint32_t vendorIANA = 0x0324; |
| 16 | |
| 17 | constexpr const char* compatibleHardware = |
| 18 | "com.ExampleCorp.Hardware.ExamplePlatform.ExampleDevice"; |
| 19 | constexpr const char* exampleConfigName = "ExampleConfigName"; |
| 20 | constexpr const char* exampleConfigType = "ExampleConfigType"; |
| 21 | |
| 22 | const std::string objPath = |
| 23 | "/xyz/openbmc_project/inventory/system/board/ExampleBoard/ExampleDevice"; |
| 24 | |
| 25 | TEST(SoftwareConfig, ConfigCreate) |
| 26 | { |
| 27 | SoftwareConfig config(objPath, vendorIANA, compatibleHardware, |
| 28 | exampleConfigType, exampleConfigName); |
| 29 | |
| 30 | ASSERT_EQ(config.configName, exampleConfigName); |
| 31 | ASSERT_EQ(config.configType, exampleConfigType); |
| 32 | } |
| 33 | |
| 34 | TEST(SoftwareConfig, FailureCompatibleNoDot) |
| 35 | { |
| 36 | try |
| 37 | { |
| 38 | SoftwareConfig config(objPath, vendorIANA, "comexamplesamplecorp", |
| 39 | exampleConfigType, exampleConfigName); |
| 40 | ASSERT_FALSE(true); |
| 41 | } |
| 42 | catch (std::exception& /*unused*/) |
| 43 | {} |
| 44 | } |
| 45 | |
| 46 | TEST(SoftwareConfig, FailureCompatibleInvalidChar) |
| 47 | { |
| 48 | try |
| 49 | { |
| 50 | SoftwareConfig config(objPath, vendorIANA, |
| 51 | std::string(compatibleHardware) + "#", |
| 52 | exampleConfigType, exampleConfigName); |
| 53 | ASSERT_FALSE(true); |
| 54 | } |
| 55 | catch (std::exception& /*unused*/) |
| 56 | {} |
| 57 | } |