Rename write_unsigned_{long,short} to write_uint{16,32}
This commit is contained in:
parent
dd21e8fa1d
commit
e73ea080c4
4 changed files with 26 additions and 26 deletions
|
|
@ -60,18 +60,18 @@ std::size_t IpConfigBuilder::write(common::BinaryWriter &writer) {
|
|||
// See http://androidxref.com/7.1.1_r6/xref/frameworks/base/services/core/java/com/android/server/net/IpConfigStore.java
|
||||
// for more details on the binary file format used here.
|
||||
|
||||
writer.write_unsigned_long(static_cast<std::uint32_t>(version_));
|
||||
writer.write_uint32(static_cast<std::uint32_t>(version_));
|
||||
|
||||
writer.write_string_with_size(assignment_key);
|
||||
writer.write_string_with_size(assignment_to_string(assignment_));
|
||||
|
||||
writer.write_string_with_size(link_address_key);
|
||||
writer.write_string_with_size(link_.address);
|
||||
writer.write_unsigned_long(link_.prefix_length);
|
||||
writer.write_uint32(link_.prefix_length);
|
||||
|
||||
writer.write_string_with_size(gateway_key);
|
||||
writer.write_unsigned_long(is_default_gateway);
|
||||
writer.write_unsigned_long(gateway_is_present);
|
||||
writer.write_uint32(is_default_gateway);
|
||||
writer.write_uint32(gateway_is_present);
|
||||
writer.write_string_with_size(gateway_);
|
||||
|
||||
writer.write_string_with_size(dns_key);
|
||||
|
|
@ -79,7 +79,7 @@ std::size_t IpConfigBuilder::write(common::BinaryWriter &writer) {
|
|||
writer.write_string_with_size(server);
|
||||
|
||||
writer.write_string_with_size(id_key);
|
||||
writer.write_unsigned_long(id_);
|
||||
writer.write_uint32(id_);
|
||||
|
||||
writer.write_string_with_size(eos_key);
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ void BinaryWriter::set_byte_order(Order order) {
|
|||
byte_order_ = order;
|
||||
}
|
||||
|
||||
void BinaryWriter::write_unsigned_short(std::uint16_t value) {
|
||||
void BinaryWriter::write_uint16(std::uint16_t value) {
|
||||
if (current_ + sizeof(value) > end_)
|
||||
throw std::out_of_range{"Write buffer exhausted"};
|
||||
|
||||
|
|
@ -62,7 +62,7 @@ void BinaryWriter::write_unsigned_short(std::uint16_t value) {
|
|||
current_ += sizeof(v);
|
||||
}
|
||||
|
||||
void BinaryWriter::write_unsigned_long(std::uint32_t value) {
|
||||
void BinaryWriter::write_uint32(std::uint32_t value) {
|
||||
if (current_ + sizeof(value) > end_)
|
||||
throw std::out_of_range{"Write buffer exhausted"};
|
||||
|
||||
|
|
@ -95,7 +95,7 @@ void BinaryWriter::write_string_with_size(const std::string &str) {
|
|||
}
|
||||
|
||||
void BinaryWriter::write_string_with_size(const char *s, std::size_t size) {
|
||||
write_unsigned_short(size);
|
||||
write_uint16(size);
|
||||
write_string(s, size);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,8 +37,8 @@ class BinaryWriter {
|
|||
|
||||
void set_byte_order(Order order);
|
||||
|
||||
void write_unsigned_short(std::uint16_t value);
|
||||
void write_unsigned_long(std::uint32_t value);
|
||||
void write_uint16(std::uint16_t value);
|
||||
void write_uint32(std::uint32_t value);
|
||||
void write_string(const char *s, std::size_t size);
|
||||
void write_string_with_size(const std::string &str);
|
||||
void write_string_with_size(const char *s, std::size_t size);
|
||||
|
|
|
|||
|
|
@ -23,31 +23,31 @@ namespace ac = anbox::common;
|
|||
|
||||
using namespace ::testing;
|
||||
|
||||
TEST(BinaryWriter, WritesUnsignedLong) {
|
||||
TEST(BinaryWriter, WriteUint32) {
|
||||
std::vector<std::uint8_t> buffer;
|
||||
buffer.resize(sizeof(std::uint32_t) * 2);
|
||||
ac::BinaryWriter writer(buffer.begin(), buffer.end());
|
||||
|
||||
writer.write_unsigned_long(0x10);
|
||||
writer.write_unsigned_long(0x3322);
|
||||
writer.write_uint32(0x10);
|
||||
writer.write_uint32(0x3322);
|
||||
|
||||
ASSERT_EQ(writer.bytes_written(), 8);
|
||||
ASSERT_THAT(buffer, ElementsAre(0x10, 0x00, 0x00, 0x00, 0x22, 0x33, 0x00, 0x00));
|
||||
}
|
||||
|
||||
TEST(BinaryWriter, WriteUnsignedLongFailsWithExhaustedError) {
|
||||
TEST(BinaryWriter, WriteUint32FailsWithExhaustedError) {
|
||||
std::vector<std::uint8_t> buffer;
|
||||
ac::BinaryWriter writer(buffer.begin(), buffer.end());
|
||||
EXPECT_THROW(writer.write_unsigned_long(0x11), std::out_of_range);
|
||||
EXPECT_THROW(writer.write_uint32(0x11), std::out_of_range);
|
||||
}
|
||||
|
||||
TEST(BinaryWriter, WriteUnsignedLongWithChangedBinaryOrder) {
|
||||
TEST(BinaryWriter, WriteUint32WithChangedBinaryOrder) {
|
||||
std::vector<std::uint8_t> buffer;
|
||||
buffer.resize(sizeof(std::uint32_t));
|
||||
ac::BinaryWriter writer(buffer.begin(), buffer.end());
|
||||
|
||||
writer.set_byte_order(ac::BinaryWriter::Order::Big);
|
||||
writer.write_unsigned_long(0x11223344);
|
||||
writer.write_uint32(0x11223344);
|
||||
|
||||
ASSERT_EQ(writer.bytes_written(), 4);
|
||||
ASSERT_THAT(buffer, ElementsAre(0x11, 0x22, 0x33, 0x44));
|
||||
|
|
@ -58,37 +58,37 @@ TEST(BinaryWriter, WriteUnsignedLongWithChangedBinaryOrder) {
|
|||
writer = ac::BinaryWriter(buffer.begin(), buffer.end());
|
||||
|
||||
writer.set_byte_order(ac::BinaryWriter::Order::Little);
|
||||
writer.write_unsigned_long(0x11223344);
|
||||
writer.write_uint32(0x11223344);
|
||||
|
||||
ASSERT_EQ(writer.bytes_written(), 4);
|
||||
ASSERT_THAT(buffer, ElementsAre(0x44, 0x33, 0x22, 0x11));
|
||||
}
|
||||
|
||||
TEST(BinaryWriter, WriteUnsignedShort) {
|
||||
TEST(BinaryWriter, WriteUint16) {
|
||||
std::vector<std::uint8_t> buffer;
|
||||
buffer.resize(sizeof(std::uint16_t) * 2);
|
||||
ac::BinaryWriter writer(buffer.begin(), buffer.end());
|
||||
|
||||
writer.write_unsigned_short(0x10);
|
||||
writer.write_unsigned_short(0x3322);
|
||||
writer.write_uint16(0x10);
|
||||
writer.write_uint16(0x3322);
|
||||
|
||||
ASSERT_EQ(writer.bytes_written(), 4);
|
||||
ASSERT_THAT(buffer, ElementsAre(0x10, 0x00, 0x22, 0x33));
|
||||
}
|
||||
|
||||
TEST(BinaryWriter, WriteUnsignedShortFailsWithExhaustedError) {
|
||||
TEST(BinaryWriter, WriteUint16FailsWithExhaustedError) {
|
||||
std::vector<std::uint8_t> buffer;
|
||||
ac::BinaryWriter writer(buffer.begin(), buffer.end());
|
||||
EXPECT_THROW(writer.write_unsigned_short(0x11), std::out_of_range);
|
||||
EXPECT_THROW(writer.write_uint16(0x11), std::out_of_range);
|
||||
}
|
||||
|
||||
TEST(BinaryWriter, WriteUnsignedShortWithChangedBinaryOrder) {
|
||||
TEST(BinaryWriter, WriteUint16WithChangedBinaryOrder) {
|
||||
std::vector<std::uint8_t> buffer;
|
||||
buffer.resize(sizeof(std::uint16_t));
|
||||
ac::BinaryWriter writer(buffer.begin(), buffer.end());
|
||||
|
||||
writer.set_byte_order(ac::BinaryWriter::Order::Big);
|
||||
writer.write_unsigned_short(0x1122);
|
||||
writer.write_uint16(0x1122);
|
||||
|
||||
ASSERT_EQ(writer.bytes_written(), 2);
|
||||
ASSERT_THAT(buffer, ElementsAre(0x11, 0x22));
|
||||
|
|
@ -99,7 +99,7 @@ TEST(BinaryWriter, WriteUnsignedShortWithChangedBinaryOrder) {
|
|||
writer = ac::BinaryWriter(buffer.begin(), buffer.end());
|
||||
|
||||
writer.set_byte_order(ac::BinaryWriter::Order::Little);
|
||||
writer.write_unsigned_short(0x1122);
|
||||
writer.write_uint16(0x1122);
|
||||
|
||||
ASSERT_EQ(writer.bytes_written(), 2);
|
||||
ASSERT_THAT(buffer, ElementsAre(0x22, 0x11));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue