xref: /openbmc/phosphor-ipmi-blobs/test/manager_commit_unittest.cpp (revision cd8dab491d3f78124be800252186a32a90c884b8)
1*cd8dab49SPatrick Venture #include "blob_mock.hpp"
2*cd8dab49SPatrick Venture #include "manager.hpp"
3*cd8dab49SPatrick Venture 
4ef3aeadcSPatrick Venture #include <vector>
5ef3aeadcSPatrick Venture 
6ef3aeadcSPatrick Venture #include <gtest/gtest.h>
7ef3aeadcSPatrick Venture 
8ef3aeadcSPatrick Venture namespace blobs
9ef3aeadcSPatrick Venture {
10ef3aeadcSPatrick Venture 
11ef3aeadcSPatrick Venture using ::testing::_;
12ef3aeadcSPatrick Venture using ::testing::Return;
13ef3aeadcSPatrick Venture 
TEST(ManagerCommitTest,CommitNoSessionReturnsFalse)14ef3aeadcSPatrick Venture TEST(ManagerCommitTest, CommitNoSessionReturnsFalse)
15ef3aeadcSPatrick Venture {
16ef3aeadcSPatrick Venture     // Calling Commit on a session that doesn't exist should return false.
17ef3aeadcSPatrick Venture 
18ef3aeadcSPatrick Venture     BlobManager mgr;
19ef3aeadcSPatrick Venture     uint16_t sess = 1;
20ef3aeadcSPatrick Venture     std::vector<uint8_t> data;
21ef3aeadcSPatrick Venture 
22ef3aeadcSPatrick Venture     EXPECT_FALSE(mgr.commit(sess, data));
23ef3aeadcSPatrick Venture }
24ef3aeadcSPatrick Venture 
TEST(ManagerCommitTest,CommitSessionFoundButHandlerReturnsFalse)25ef3aeadcSPatrick Venture TEST(ManagerCommitTest, CommitSessionFoundButHandlerReturnsFalse)
26ef3aeadcSPatrick Venture {
27ef3aeadcSPatrick Venture     // The handler was found but it returned failure.
28ef3aeadcSPatrick Venture 
29ef3aeadcSPatrick Venture     BlobManager mgr;
30ef3aeadcSPatrick Venture     std::unique_ptr<BlobMock> m1 = std::make_unique<BlobMock>();
31ef3aeadcSPatrick Venture     auto m1ptr = m1.get();
32ef3aeadcSPatrick Venture     EXPECT_TRUE(mgr.registerHandler(std::move(m1)));
33ef3aeadcSPatrick Venture 
34ef3aeadcSPatrick Venture     uint16_t flags = OpenFlags::write, sess;
35ef3aeadcSPatrick Venture     std::string path = "/asdf/asdf";
36ef3aeadcSPatrick Venture 
37ef3aeadcSPatrick Venture     EXPECT_CALL(*m1ptr, canHandleBlob(path)).WillOnce(Return(true));
38ef3aeadcSPatrick Venture     EXPECT_CALL(*m1ptr, open(_, flags, path)).WillOnce(Return(true));
39ef3aeadcSPatrick Venture     EXPECT_TRUE(mgr.open(flags, path, &sess));
40ef3aeadcSPatrick Venture 
41ef3aeadcSPatrick Venture     std::vector<uint8_t> data;
42ef3aeadcSPatrick Venture     EXPECT_CALL(*m1ptr, commit(sess, data)).WillOnce(Return(false));
43ef3aeadcSPatrick Venture 
44ef3aeadcSPatrick Venture     EXPECT_FALSE(mgr.commit(sess, data));
45ef3aeadcSPatrick Venture }
46ef3aeadcSPatrick Venture 
TEST(ManagerCommitTest,CommitSessionFoundAndHandlerReturnsSuccess)47ef3aeadcSPatrick Venture TEST(ManagerCommitTest, CommitSessionFoundAndHandlerReturnsSuccess)
48ef3aeadcSPatrick Venture {
49ef3aeadcSPatrick Venture     // The handler was found and returned success.
50ef3aeadcSPatrick Venture 
51ef3aeadcSPatrick Venture     BlobManager mgr;
52ef3aeadcSPatrick Venture     std::unique_ptr<BlobMock> m1 = std::make_unique<BlobMock>();
53ef3aeadcSPatrick Venture     auto m1ptr = m1.get();
54ef3aeadcSPatrick Venture     EXPECT_TRUE(mgr.registerHandler(std::move(m1)));
55ef3aeadcSPatrick Venture 
56ef3aeadcSPatrick Venture     uint16_t flags = OpenFlags::write, sess;
57ef3aeadcSPatrick Venture     std::string path = "/asdf/asdf";
58ef3aeadcSPatrick Venture 
59ef3aeadcSPatrick Venture     EXPECT_CALL(*m1ptr, canHandleBlob(path)).WillOnce(Return(true));
60ef3aeadcSPatrick Venture     EXPECT_CALL(*m1ptr, open(_, flags, path)).WillOnce(Return(true));
61ef3aeadcSPatrick Venture     EXPECT_TRUE(mgr.open(flags, path, &sess));
62ef3aeadcSPatrick Venture 
63ef3aeadcSPatrick Venture     std::vector<uint8_t> data;
64ef3aeadcSPatrick Venture     EXPECT_CALL(*m1ptr, commit(sess, data)).WillOnce(Return(true));
65ef3aeadcSPatrick Venture 
66ef3aeadcSPatrick Venture     EXPECT_TRUE(mgr.commit(sess, data));
67ef3aeadcSPatrick Venture }
68ef3aeadcSPatrick Venture } // namespace blobs
69