summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMatt Spinler <spinler@us.ibm.com>2019-10-29 11:34:03 -0500
committerMatt Spinler <spinler@us.ibm.com>2019-11-04 16:18:29 -0600
commit97d19b4806101161c5a97c1cc4daab6b95c89984 (patch)
tree4205a872c25082902a25cec74524aae58b7cf7de /test
parentda031717543b48a75e193d5e4d846a80279ca90b (diff)
downloadphosphor-logging-97d19b4806101161c5a97c1cc4daab6b95c89984.tar.gz
phosphor-logging-97d19b4806101161c5a97c1cc4daab6b95c89984.zip
PEL: Const accessors for Private/UserHeader
Change the combined non-const accessor/setter functions for the PrivateHeader and UserHeader fields to the standard const accessors, and have separate setters for the fields that need to be modified. In addition, make the 'get PrivateHeader' and 'get UserHeader' functions on the PEL class return a const reference. This allows const enforcement on the PEL class, for things like: void func(const PEL& pel) { auto id = pel.privateHeader().id(); } Signed-off-by: Matt Spinler <spinler@us.ibm.com> Change-Id: I840170e72b41e9e2465f716617500269244de6d9
Diffstat (limited to 'test')
-rw-r--r--test/openpower-pels/pel_test.cpp22
-rw-r--r--test/openpower-pels/private_header_test.cpp8
-rw-r--r--test/openpower-pels/real_pel_test.cpp2
-rw-r--r--test/openpower-pels/repository_test.cpp2
-rw-r--r--test/openpower-pels/user_header_test.cpp14
5 files changed, 17 insertions, 31 deletions
diff --git a/test/openpower-pels/pel_test.cpp b/test/openpower-pels/pel_test.cpp
index 6494c52..c83b54f 100644
--- a/test/openpower-pels/pel_test.cpp
+++ b/test/openpower-pels/pel_test.cpp
@@ -26,8 +26,8 @@ TEST_F(PELTest, FlattenTest)
EXPECT_TRUE(pel->valid());
EXPECT_EQ(pel->id(), 0x80818283);
EXPECT_EQ(pel->plid(), 0x50515253);
- EXPECT_EQ(pel->userHeader()->subsystem(), 0x10);
- EXPECT_EQ(pel->userHeader()->actionFlags(), 0x80C0);
+ EXPECT_EQ(pel->userHeader().subsystem(), 0x10);
+ EXPECT_EQ(pel->userHeader().actionFlags(), 0x80C0);
// Test that data in == data out
auto flattenedData = pel->data();
@@ -86,8 +86,8 @@ TEST_F(PELTest, InvalidPELTest)
auto pel = std::make_unique<PEL>(data);
- EXPECT_TRUE(pel->privateHeader()->valid());
- EXPECT_FALSE(pel->userHeader()->valid());
+ EXPECT_TRUE(pel->privateHeader().valid());
+ EXPECT_FALSE(pel->userHeader().valid());
EXPECT_FALSE(pel->valid());
// Now corrupt the private header
@@ -95,8 +95,8 @@ TEST_F(PELTest, InvalidPELTest)
data.at(0) = 0;
pel = std::make_unique<PEL>(data);
- EXPECT_FALSE(pel->privateHeader()->valid());
- EXPECT_TRUE(pel->userHeader()->valid());
+ EXPECT_FALSE(pel->privateHeader().valid());
+ EXPECT_TRUE(pel->userHeader().valid());
EXPECT_FALSE(pel->valid());
}
@@ -105,8 +105,8 @@ TEST_F(PELTest, EmptyDataTest)
std::vector<uint8_t> data;
auto pel = std::make_unique<PEL>(data);
- EXPECT_FALSE(pel->privateHeader()->valid());
- EXPECT_FALSE(pel->userHeader()->valid());
+ EXPECT_FALSE(pel->privateHeader().valid());
+ EXPECT_FALSE(pel->userHeader().valid());
EXPECT_FALSE(pel->valid());
}
@@ -128,8 +128,8 @@ TEST_F(PELTest, CreateFromRegistryTest)
dataIface};
EXPECT_TRUE(pel.valid());
- EXPECT_EQ(pel.privateHeader()->obmcLogID(), 42);
- EXPECT_EQ(pel.userHeader()->severity(), 0x40);
+ EXPECT_EQ(pel.privateHeader().obmcLogID(), 42);
+ EXPECT_EQ(pel.userHeader().severity(), 0x40);
EXPECT_EQ(pel.primarySRC().value()->asciiString(),
"BD051234 ");
@@ -259,4 +259,4 @@ TEST_F(PELTest, MakeUDSectionTest)
EXPECT_EQ(newJSON["KEY1"], "VALUE1");
EXPECT_EQ(newJSON["KEY2"], "VALUE2");
EXPECT_EQ(newJSON["KEY3"], "VALUE3");
-} \ No newline at end of file
+}
diff --git a/test/openpower-pels/private_header_test.cpp b/test/openpower-pels/private_header_test.cpp
index 07746b3..4eb052b 100644
--- a/test/openpower-pels/private_header_test.cpp
+++ b/test/openpower-pels/private_header_test.cpp
@@ -28,7 +28,7 @@ TEST_F(PrivateHeaderTest, UnflattenFlattenTest)
EXPECT_EQ(ph.header().subType, 0x02);
EXPECT_EQ(ph.header().componentID, 0x0304);
- auto& ct = ph.createTimestamp();
+ auto ct = ph.createTimestamp();
EXPECT_EQ(ct.yearMSB, 0x20);
EXPECT_EQ(ct.yearLSB, 0x30);
EXPECT_EQ(ct.month, 0x05);
@@ -38,7 +38,7 @@ TEST_F(PrivateHeaderTest, UnflattenFlattenTest)
EXPECT_EQ(ct.seconds, 0x01);
EXPECT_EQ(ct.hundredths, 0x63);
- auto& mt = ph.commitTimestamp();
+ auto mt = ph.commitTimestamp();
EXPECT_EQ(mt.yearMSB, 0x20);
EXPECT_EQ(mt.yearLSB, 0x31);
EXPECT_EQ(mt.month, 0x06);
@@ -68,7 +68,7 @@ TEST_F(PrivateHeaderTest, UnflattenFlattenTest)
EXPECT_EQ(data, newData);
// Change a field, then flatten and unflatten again
- ph.creatorID() = 0x55;
+ ph.setID(0x55);
newStream.offset(0);
newData.clear();
@@ -79,7 +79,7 @@ TEST_F(PrivateHeaderTest, UnflattenFlattenTest)
PrivateHeader newPH(newStream);
EXPECT_TRUE(newPH.valid());
- EXPECT_EQ(newPH.creatorID(), 0x55);
+ EXPECT_EQ(newPH.id(), 0x55);
}
TEST_F(PrivateHeaderTest, ShortDataTest)
diff --git a/test/openpower-pels/real_pel_test.cpp b/test/openpower-pels/real_pel_test.cpp
index ec5282d..59cc84e 100644
--- a/test/openpower-pels/real_pel_test.cpp
+++ b/test/openpower-pels/real_pel_test.cpp
@@ -537,7 +537,7 @@ TEST_F(PELTest, RealPELTest)
// Check that the code can extract an object for every section.
//(The PrivateHeader and UserHeader account for the + 2 below.)
const auto& sections = pel.optionalSections();
- EXPECT_EQ(pel.privateHeader()->sectionCount(), sections.size() + 2);
+ EXPECT_EQ(pel.privateHeader().sectionCount(), sections.size() + 2);
auto src = pel.primarySRC();
EXPECT_EQ(src.value()->asciiString(), "B181A80E ");
diff --git a/test/openpower-pels/repository_test.cpp b/test/openpower-pels/repository_test.cpp
index 85ceab6..bd1953f 100644
--- a/test/openpower-pels/repository_test.cpp
+++ b/test/openpower-pels/repository_test.cpp
@@ -61,7 +61,7 @@ TEST_F(RepositoryTest, AddTest)
// Check that the PEL was stored where it was supposed to be,
// and that it wrote the PEL data.
- const auto& ts = pel->privateHeader()->commitTimestamp();
+ const auto ts = pel->privateHeader().commitTimestamp();
auto name = Repository::getPELFilename(pel->id(), ts);
fs::path file = repoPath / "logs" / name;
diff --git a/test/openpower-pels/user_header_test.cpp b/test/openpower-pels/user_header_test.cpp
index 88ac9a5..ab8b7d6 100644
--- a/test/openpower-pels/user_header_test.cpp
+++ b/test/openpower-pels/user_header_test.cpp
@@ -42,20 +42,6 @@ TEST(UserHeaderTest, UnflattenFlattenTest)
uh.flatten(newStream);
EXPECT_EQ(data, newData);
-
- // Change a field, then flatten and unflatten again
- uh.subsystem() = 0x44;
-
- newStream.offset(0);
- newData.clear();
- uh.flatten(newStream);
- EXPECT_NE(data, newData);
-
- newStream.offset(0);
- UserHeader newUH(newStream);
-
- EXPECT_TRUE(newUH.valid());
- EXPECT_EQ(newUH.subsystem(), 0x44);
}
TEST(UserHeaderTest, ShortDataTest)
OpenPOWER on IntegriCloud