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