Patrick Venture | cd8dab4 | 2019-01-15 19:57:38 -0800 | [diff] [blame] | 1 | #include "blob_mock.hpp" |
| 2 | #include "manager.hpp" |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 3 | |
| 4 | #include <gtest/gtest.h> |
| 5 | |
| 6 | namespace blobs |
| 7 | { |
| 8 | |
| 9 | using ::testing::_; |
| 10 | using ::testing::Return; |
| 11 | |
| 12 | TEST(ManagerCloseTest, CloseNoSessionReturnsFalse) |
| 13 | { |
| 14 | // Calling Close on a session that doesn't exist should return false. |
| 15 | |
| 16 | BlobManager mgr; |
| 17 | uint16_t sess = 1; |
| 18 | |
| 19 | EXPECT_FALSE(mgr.close(sess)); |
| 20 | } |
| 21 | |
| 22 | TEST(ManagerCloseTest, CloseSessionFoundButHandlerReturnsFalse) |
| 23 | { |
| 24 | // The handler was found but it returned failure. |
| 25 | |
| 26 | BlobManager mgr; |
| 27 | std::unique_ptr<BlobMock> m1 = std::make_unique<BlobMock>(); |
| 28 | auto m1ptr = m1.get(); |
| 29 | EXPECT_TRUE(mgr.registerHandler(std::move(m1))); |
| 30 | |
| 31 | uint16_t flags = OpenFlags::read, sess; |
| 32 | std::string path = "/asdf/asdf"; |
| 33 | |
| 34 | EXPECT_CALL(*m1ptr, canHandleBlob(path)).WillOnce(Return(true)); |
| 35 | EXPECT_CALL(*m1ptr, open(_, flags, path)).WillOnce(Return(true)); |
| 36 | EXPECT_TRUE(mgr.open(flags, path, &sess)); |
| 37 | |
| 38 | EXPECT_CALL(*m1ptr, close(sess)).WillOnce(Return(false)); |
| 39 | |
| 40 | EXPECT_FALSE(mgr.close(sess)); |
| 41 | |
| 42 | // TODO(venture): The session wasn't closed, need to verify. Could call |
| 43 | // public GetHandler method. |
| 44 | } |
| 45 | |
| 46 | TEST(ManagerCloseTest, CloseSessionFoundAndHandlerReturnsSuccess) |
| 47 | { |
| 48 | // The handler was found and returned success. |
| 49 | |
| 50 | BlobManager mgr; |
| 51 | std::unique_ptr<BlobMock> m1 = std::make_unique<BlobMock>(); |
| 52 | auto m1ptr = m1.get(); |
| 53 | EXPECT_TRUE(mgr.registerHandler(std::move(m1))); |
| 54 | |
| 55 | uint16_t flags = OpenFlags::read, sess; |
| 56 | std::string path = "/asdf/asdf"; |
| 57 | |
| 58 | EXPECT_CALL(*m1ptr, canHandleBlob(path)).WillOnce(Return(true)); |
| 59 | EXPECT_CALL(*m1ptr, open(_, flags, path)).WillOnce(Return(true)); |
| 60 | EXPECT_TRUE(mgr.open(flags, path, &sess)); |
| 61 | |
| 62 | EXPECT_CALL(*m1ptr, close(sess)).WillOnce(Return(true)); |
| 63 | |
| 64 | EXPECT_TRUE(mgr.close(sess)); |
| 65 | } |
| 66 | } // namespace blobs |