blob: fb632dc0eec164e356e3a3e031d2e57079adb096 [file] [log] [blame]
Chirag Sharma50427252020-08-11 12:11:38 -05001// SPDX-License-Identifier: Apache-2.0
Chirag Sharma50427252020-08-11 12:11:38 -05002#include <dump_serialize.hpp>
Jayanth Othayoth0af74a52021-04-08 03:55:21 -05003
4#include <cstdlib>
Chirag Sharma50427252020-08-11 12:11:38 -05005#include <exception>
6#include <filesystem>
7#include <set>
8#include <string>
9
10#include <gtest/gtest.h>
11
12namespace fs = std::filesystem;
13
14class TestDumpSerial : public ::testing::Test
15{
16 public:
Patrick Williams78e88402023-05-10 07:50:48 -050017 TestDumpSerial() {}
Chirag Sharma50427252020-08-11 12:11:38 -050018
19 void SetUp()
20 {
21 char tmpdir[] = "/tmp/dump.XXXXXX";
22 auto dirPtr = mkdtemp(tmpdir);
23 if (dirPtr == NULL)
24 {
25 throw std::bad_alloc();
26 }
27 dumpDir = std::string(dirPtr);
28 fs::create_directories(dumpDir);
29 dumpFile = dumpDir;
30 dumpFile /= "elogid";
31 }
32 void TearDown()
33 {
34 fs::remove_all(dumpDir);
35 }
36
37 std::string dumpDir;
38 fs::path dumpFile;
39};
40
41TEST_F(TestDumpSerial, Serialization)
42{
43 using ElogList = std::set<uint32_t>;
44 ElogList e;
45 e.insert(1);
46 e.insert(2);
47 e.insert(3);
48 phosphor::dump::elog::serialize(e, dumpFile.c_str());
49 bool value = phosphor::dump::elog::deserialize(dumpFile.c_str(), e);
50 EXPECT_EQ(value, true);
51}
52
53TEST_F(TestDumpSerial, DeserializationFalseCase)
54{
55 using ElogList = std::set<uint32_t>;
56 ElogList e;
57 e.insert(1);
58 bool value = phosphor::dump::elog::deserialize(dumpFile.c_str(), e);
59 EXPECT_EQ(value, false);
60}
61
62TEST(DumpDeSerialPath, DeserializationFalsePath)
63{
64 using ElogList = std::set<uint32_t>;
65 ElogList e;
66 e.insert(1);
67 // Providing dummy path
68 bool value = phosphor::dump::elog::deserialize("/tmp/Fake/serial", e);
69 EXPECT_EQ(value, false);
70}