blob: 23df9d46fcc6b57e1e21184b504ecca9c88bc2b3 [file] [log] [blame]
Patrick Ventureaceb4ba2018-09-27 14:50:37 -07001#include <blobs-ipmid/manager.hpp>
Patrick Venture7210b312018-10-03 14:01:35 -07002#include <blobs-ipmid/test/blob_mock.hpp>
Patrick Ventureef3aead2018-09-12 08:53:29 -07003#include <vector>
4
5#include <gtest/gtest.h>
6
7namespace blobs
8{
9
10using ::testing::_;
11using ::testing::Return;
12
13TEST(ManagerReadTest, ReadNoSessionReturnsFalse)
14{
15 // Calling Read on a session that doesn't exist should return false.
16
17 BlobManager mgr;
18 uint16_t sess = 1;
19 uint32_t ofs = 0x54;
20 uint32_t requested = 0x100;
21
22 std::vector<uint8_t> result = mgr.read(sess, ofs, requested);
23 EXPECT_EQ(0, result.size());
24}
25
26TEST(ManagerReadTest, ReadFromWriteOnlyFails)
27{
28 // The session manager will not route a Read call to a blob if the session
29 // was opened as write-only.
30
31 BlobManager mgr;
32 std::unique_ptr<BlobMock> m1 = std::make_unique<BlobMock>();
33 auto m1ptr = m1.get();
34 EXPECT_TRUE(mgr.registerHandler(std::move(m1)));
35
36 uint16_t sess = 1;
37 uint32_t ofs = 0x54;
38 uint32_t requested = 0x100;
39 uint16_t flags = OpenFlags::write;
40 std::string path = "/asdf/asdf";
41
42 EXPECT_CALL(*m1ptr, canHandleBlob(path)).WillOnce(Return(true));
43 EXPECT_CALL(*m1ptr, open(_, flags, path)).WillOnce(Return(true));
44 EXPECT_TRUE(mgr.open(flags, path, &sess));
45
46 std::vector<uint8_t> result = mgr.read(sess, ofs, requested);
47 EXPECT_EQ(0, result.size());
48}
49
50TEST(ManagerReadTest, ReadFromHandlerReturnsData)
51{
52 // There is no logic in this as it's just as a pass-thru command, however
53 // we want to verify this behavior doesn't change.
54
55 BlobManager mgr;
56 std::unique_ptr<BlobMock> m1 = std::make_unique<BlobMock>();
57 auto m1ptr = m1.get();
58 EXPECT_TRUE(mgr.registerHandler(std::move(m1)));
59
60 uint16_t sess = 1;
61 uint32_t ofs = 0x54;
62 uint32_t requested = 0x100;
63 uint16_t flags = OpenFlags::read;
64 std::string path = "/asdf/asdf";
65 std::vector<uint8_t> data = {0x12, 0x14, 0x15, 0x16};
66
67 EXPECT_CALL(*m1ptr, canHandleBlob(path)).WillOnce(Return(true));
68 EXPECT_CALL(*m1ptr, open(_, flags, path)).WillOnce(Return(true));
69 EXPECT_TRUE(mgr.open(flags, path, &sess));
70
71 EXPECT_CALL(*m1ptr, read(sess, ofs, requested)).WillOnce(Return(data));
72
73 std::vector<uint8_t> result = mgr.read(sess, ofs, requested);
74 EXPECT_EQ(data.size(), result.size());
75 EXPECT_EQ(result, data);
76}
77} // namespace blobs