blob: 7aa143ea488254991c9ac3d9d7a90bfc9e744ccc [file] [log] [blame]
Deepak Kodihallicb7f2d42019-06-19 13:25:31 +05301#include "libpldmresponder/bios_table.hpp"
2
Deepak Kodihallicb7f2d42019-06-19 13:25:31 +05303#include <algorithm>
Pavithra Barithayab3b84b42024-08-23 11:43:57 +05304#include <cstdlib>
Deepak Kodihallicb7f2d42019-06-19 13:25:31 +05305#include <vector>
6
7#include <gtest/gtest.h>
8
9using namespace pldm::responder::bios;
10
11class TestBIOSTable : public testing::Test
12{
13 public:
14 void SetUp() override
15 {
16 char tmpdir[] = "/tmp/pldm_bios_table.XXXXXX";
17 dir = fs::path(mkdtemp(tmpdir));
18 }
19
20 void TearDown() override
21 {
22 fs::remove_all(dir);
23 }
24
25 fs::path dir;
26};
27
28TEST_F(TestBIOSTable, testStoreLoad)
29{
30 std::vector<uint8_t> table{10, 34, 56, 100, 44, 55, 69, 21, 48, 2, 7, 82};
31 fs::path file(dir / "t1");
32 BIOSTable t(file.string().c_str());
33 std::vector<uint8_t> out{};
34
35 ASSERT_THROW(t.load(out), fs::filesystem_error);
36
37 ASSERT_EQ(true, t.isEmpty());
38
39 t.store(table);
40 t.load(out);
41 ASSERT_EQ(true, std::equal(table.begin(), table.end(), out.begin()));
42}
43
44TEST_F(TestBIOSTable, testLoadOntoExisting)
45{
46 std::vector<uint8_t> table{10, 34, 56, 100, 44, 55, 69, 21, 48, 2, 7, 82};
47 fs::path file(dir / "t1");
48 BIOSTable t(file.string().c_str());
49 std::vector<uint8_t> out{99, 99};
50
51 ASSERT_THROW(t.load(out), fs::filesystem_error);
52
53 ASSERT_EQ(true, t.isEmpty());
54
55 t.store(table);
56 t.load(out);
57 ASSERT_EQ(true, std::equal(table.begin(), table.end(), out.begin() + 2));
58 ASSERT_EQ(out[0], 99);
59 ASSERT_EQ(out[1], 99);
60}