1 #include "libpldmresponder/bios_table.hpp" 2 3 #include <algorithm> 4 #include <cstdlib> 5 #include <vector> 6 7 #include <gtest/gtest.h> 8 9 using namespace pldm::responder::bios; 10 11 class 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 28 TEST_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 44 TEST_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 } 61