This source file includes following definitions.
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
#include "remoting/base/typed_buffer.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace remoting {
namespace {
struct Data {
int data[1];
};
}
TEST(TypedBufferTest, Empty) {
TypedBuffer<Data> buffer;
EXPECT_FALSE(buffer.get());
EXPECT_FALSE(buffer);
EXPECT_EQ(buffer.length(), 0u);
}
TEST(TypedBufferTest, ZeroSize) {
TypedBuffer<Data> buffer(0);
EXPECT_FALSE(buffer.get());
EXPECT_FALSE(buffer);
EXPECT_EQ(buffer.length(), 0u);
}
TEST(TypedBufferTest, Basic) {
TypedBuffer<Data> buffer(sizeof(int) * 10);
EXPECT_TRUE(buffer.get());
EXPECT_TRUE(buffer);
EXPECT_EQ(buffer.length(), sizeof(int) * 10);
(*buffer).data[9] = 0x12345678;
EXPECT_EQ(buffer->data[9], 0x12345678);
}
TEST(TypedBufferTest, Pass) {
TypedBuffer<Data> left;
TypedBuffer<Data> right(sizeof(int));
EXPECT_FALSE(left.get());
EXPECT_EQ(left.length(), 0u);
EXPECT_TRUE(right.get());
EXPECT_EQ(right.length(), sizeof(int));
Data* raw_ptr = right.get();
left = right.Pass();
EXPECT_EQ(left.get(), raw_ptr);
EXPECT_EQ(left.length(), sizeof(int));
EXPECT_FALSE(right.get());
EXPECT_EQ(right.length(), 0u);
}
TEST(TypedBufferTest, Swap) {
TypedBuffer<Data> left(sizeof(int));
TypedBuffer<Data> right(sizeof(int) * 2);
EXPECT_TRUE(left.get());
EXPECT_EQ(left.length(), sizeof(int));
EXPECT_TRUE(right.get());
EXPECT_EQ(right.length(), sizeof(int) * 2);
Data* raw_left = left.get();
Data* raw_right = right.get();
left.Swap(right);
EXPECT_EQ(left.get(), raw_right);
EXPECT_EQ(left.length(), sizeof(int) * 2);
EXPECT_EQ(right.get(), raw_left);
EXPECT_EQ(right.length(), sizeof(int));
}
TEST(TypedBufferTest, GetAtOffset) {
TypedBuffer<Data> buffer(sizeof(int) * 10);
EXPECT_EQ(buffer.get(), buffer.GetAtOffset(0));
EXPECT_EQ(reinterpret_cast<Data*>(&buffer->data[9]),
buffer.GetAtOffset(sizeof(int) * 9));
}
}