19 #include <gtest/gtest.h> 20 #include <gmock/gmock.h> 33 MOCK_METHOD0(start,
bool());
34 MOCK_METHOD0(shutdown,
bool());
36 MOCK_METHOD2(fileUploadCompleteStatus,
38 MOCK_METHOD1(addStatusMonitor,
39 void(std::shared_ptr<StatusMonitor> monitor));
40 MOCK_METHOD0(isDataAvailableToRead,
bool());
52 status_monitor_ = status_monitor;
64 public Sink<SharedFileUploadTask>
69 MOCK_METHOD2(tryEnqueue,
71 const std::chrono::microseconds &duration));
73 return enqueue_rvr(value);
77 const std::chrono::microseconds &duration)
override 79 return tryEnqueue(value, duration);
81 MOCK_METHOD0(clear,
void (
void));
90 file_manager = std::make_shared<::testing::StrictMock<MockDataReader>>();
91 file_upload_streamer = createFileUploadStreamer<std::string>(file_manager,
kFileManagerOptions);
92 mock_sink = std::make_shared<::testing::StrictMock<MockSink>>();
98 file_upload_streamer.reset();
111 file_upload_streamer->setSink(mock_sink);
114 file_manager->status_monitor_->setStatus(
AVAILABLE);
115 file_upload_streamer->onPublisherStateChange(
AVAILABLE);
120 EXPECT_CALL(*mock_sink, tryEnqueue(testing::_, testing::_))
121 .WillOnce(testing::Return(
true));
122 EXPECT_CALL(*file_manager, readBatch(testing::Eq(50u)))
123 .WillOnce(testing::Return(test_file_object));
125 file_upload_streamer->forceWork();
130 file_upload_streamer->setSink(mock_sink);
133 file_manager->status_monitor_->setStatus(
AVAILABLE);
134 file_upload_streamer->onPublisherStateChange(
AVAILABLE);
141 EXPECT_CALL(*mock_sink, tryEnqueue(testing::_, testing::_))
143 const std::chrono::microseconds&){
147 .WillOnce(testing::Return(
true));
148 EXPECT_CALL(*file_manager, readBatch(testing::Eq(50u)))
149 .WillOnce(testing::Return(test_file_object));
151 file_upload_streamer->forceWork();
152 file_upload_streamer->forceWork();
157 file_upload_streamer->setSink(mock_sink);
160 file_manager->status_monitor_->setStatus(
AVAILABLE);
161 file_upload_streamer->onPublisherStateChange(
AVAILABLE);
168 EXPECT_CALL(*mock_sink, tryEnqueue(testing::_, testing::_))
170 const std::chrono::microseconds&){
174 EXPECT_CALL(*file_manager, readBatch(testing::Eq(50u)))
175 .WillOnce(testing::Return(test_file_object));
176 EXPECT_CALL(*mock_sink, clear());
177 EXPECT_CALL(*file_manager, fileUploadCompleteStatus(
FAIL, testing::_));
179 file_upload_streamer->forceWork();
180 task->onComplete(
FAIL);
185 file_upload_streamer->setSink(mock_sink);
188 file_manager->status_monitor_->setStatus(
AVAILABLE);
189 file_upload_streamer->onPublisherStateChange(
AVAILABLE);
195 EXPECT_CALL(*mock_sink, tryEnqueue(testing::_, testing::_))
197 const std::chrono::microseconds&){
201 EXPECT_CALL(*file_manager, readBatch(testing::Eq(50u)))
202 .WillOnce(testing::Return(test_file_object));
203 EXPECT_CALL(*file_manager, fileUploadCompleteStatus(
SUCCESS, testing::_));
205 file_upload_streamer->forceWork();
std::shared_ptr< StatusMonitor > status_monitor_
void deleteStaleData() override
std::shared_ptr< Task< std::string >> SharedFileUploadTask
std::shared_ptr< MockSink > mock_sink
bool enqueue(SharedFileUploadTask &&value) override
TEST_F(FileStreamerTest, success_on_network_and_file)
bool tryEnqueue(SharedFileUploadTask &&value, const std::chrono::microseconds &duration) override
void setStatusMonitor(std::shared_ptr< StatusMonitor > status_monitor) override
std::shared_ptr<::testing::StrictMock< MockDataReader > > file_manager
std::shared_ptr< FileUploadStreamer< std::string > > file_upload_streamer
static const FileUploadStreamerOptions kFileManagerOptions