Andrew Jeffery | 7c1dc7e | 2023-04-28 14:52:16 +0930 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "instance_id.hpp" |
| 4 | |
| 5 | static constexpr uintmax_t pldmMaxInstanceIds = 32; |
| 6 | |
| 7 | class TestInstanceIdDb : public pldm::InstanceIdDb |
| 8 | { |
| 9 | public: |
| 10 | TestInstanceIdDb() : TestInstanceIdDb(createDb()) {} |
| 11 | |
| 12 | ~TestInstanceIdDb() |
| 13 | { |
| 14 | std::filesystem::remove(dbPath); |
| 15 | }; |
| 16 | |
| 17 | private: |
| 18 | static std::filesystem::path createDb() |
| 19 | { |
| 20 | static const char dbTmpl[] = "/tmp/db.XXXXXX"; |
| 21 | char dbName[sizeof(dbTmpl)] = {}; |
| 22 | |
| 23 | ::strncpy(dbName, dbTmpl, sizeof(dbName)); |
| 24 | ::close(::mkstemp(dbName)); |
| 25 | |
| 26 | std::filesystem::path dbPath(dbName); |
| 27 | std::filesystem::resize_file( |
| 28 | dbPath, static_cast<uintmax_t>(PLDM_MAX_TIDS) * pldmMaxInstanceIds); |
| 29 | |
| 30 | return dbPath; |
| 31 | }; |
| 32 | |
| 33 | TestInstanceIdDb(std::filesystem::path dbPath) : |
| 34 | InstanceIdDb(dbPath), dbPath(dbPath) |
| 35 | {} |
| 36 | |
| 37 | std::filesystem::path dbPath; |
| 38 | }; |