Add operator<< for TopicPartition

This commit is contained in:
Matias Fontanini
2016-06-15 07:44:28 -07:00
parent 6877c4be03
commit 9e79321a1f
5 changed files with 49 additions and 0 deletions

View File

@@ -1,7 +1,10 @@
#include <sstream>
#include <gtest/gtest.h>
#include "cppkafka/topic_partition_list.h"
#include "cppkafka/topic_partition.h"
using std::ostringstream;
using namespace cppkafka;
class TopicPartitionListTest : public testing::Test {
@@ -26,3 +29,20 @@ TEST_F(TopicPartitionListTest, Conversion) {
EXPECT_EQ(item1.get_offset(), item2.get_offset());
}
}
TEST_F(TopicPartitionListTest, AsString) {
ostringstream output;
TopicPartition topic_partition("foo", 5);
output << topic_partition;
EXPECT_EQ("foo[5]", output.str());
}
TEST_F(TopicPartitionListTest, ListAsString) {
ostringstream output;
TopicPartitionList list;
list.push_back("foo");
list.push_back({ "bar", 2 });
output << list;
EXPECT_EQ("[ foo[-1], bar[2] ]", output.str());
}