19 #include <gtest/gtest.h>
74 const int block_size = 1024;
95 void BufferWriterTest(
int block_size,
int total_size,
int backup_size) {
102 bool backed_up_entire_slice =
false;
104 while (written_size < total_size) {
108 int write_size =
size;
109 bool should_backup =
false;
110 if (backup_size > 0 &&
size > backup_size) {
111 write_size =
size - backup_size;
112 should_backup =
true;
113 }
else if (
size == backup_size && !backed_up_entire_slice) {
115 backed_up_entire_slice =
true;
116 should_backup =
true;
120 if (write_size + written_size > total_size) {
121 write_size = total_size - written_size;
122 should_backup =
true;
123 backup_size =
size - write_size;
126 for (
int i = 0;
i < write_size;
i++) {
131 writer.BackUp(backup_size);
137 GrpcByteBufferPeer peer(&bb);
155 static void SetUpTestCase() {
166 TEST_F(WriterTest, TinyBlockTinyBackup) {
168 BufferWriterTest(i, 256, 1);
172 TEST_F(WriterTest, SmallBlockTinyBackup) { BufferWriterTest(64, 256, 1); }
174 TEST_F(WriterTest, SmallBlockNoBackup) { BufferWriterTest(64, 256, 0); }
176 TEST_F(WriterTest, SmallBlockFullBackup) { BufferWriterTest(64, 256, 64); }
178 TEST_F(WriterTest, LargeBlockTinyBackup) { BufferWriterTest(4096, 8192, 1); }
180 TEST_F(WriterTest, LargeBlockNoBackup) { BufferWriterTest(4096, 8192, 0); }
182 TEST_F(WriterTest, LargeBlockFullBackup) { BufferWriterTest(4096, 8192, 4096); }
184 TEST_F(WriterTest, LargeBlockLargeBackup) {
185 BufferWriterTest(4096, 8192, 4095);
192 int main(
int argc,
char** argv) {