summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormukesh agrawal <quiche@google.com>2016-11-15 00:10:47 +0000
committerandroid-build-merger <android-build-merger@google.com>2016-11-15 00:10:47 +0000
commit193b1b26fcf24ad1aabf92f40133ef7b3faf0923 (patch)
treea0321885ca8c8fc94daf77d6c88302a20fc776d9
parent14f24797c346d72a2fba0e10a411c31c09030355 (diff)
parentb7084fd5d5615c2a136cbb3a3ca2c239886deb52 (diff)
downloadwifilogd-193b1b26fcf24ad1aabf92f40133ef7b3faf0923.tar.gz
protocol: add setters for AsciiMessage am: 0df78aa33c am: 4302344df8
am: b7084fd5d5 Change-Id: I6c12afd1f012f03ef749859a7f77eea4c85b6da5
-rw-r--r--protocol.h15
-rw-r--r--tests/command_processor_unittest.cpp27
2 files changed, 30 insertions, 12 deletions
diff --git a/protocol.h b/protocol.h
index 527e5ff..d082850 100644
--- a/protocol.h
+++ b/protocol.h
@@ -73,6 +73,21 @@ struct Command {
};
struct AsciiMessage { // Old-style log messages.
+ AsciiMessage& set_data_len(uint16_t new_data_len) {
+ data_len = new_data_len;
+ return *this;
+ }
+
+ AsciiMessage& set_tag_len(uint8_t new_tag_len) {
+ tag_len = new_tag_len;
+ return *this;
+ }
+
+ AsciiMessage& set_severity(MessageSeverity new_severity) {
+ severity = new_severity;
+ return *this;
+ }
+
uint16_t data_len;
uint8_t tag_len;
MessageSeverity severity;
diff --git a/tests/command_processor_unittest.cpp b/tests/command_processor_unittest.cpp
index a4ec552..ede5cb0 100644
--- a/tests/command_processor_unittest.cpp
+++ b/tests/command_processor_unittest.cpp
@@ -84,18 +84,21 @@ class CommandProcessorTest : public ::testing::Test {
ssize_t command_payload_len_adjustment,
ssize_t ascii_message_tag_len_adjustment,
ssize_t ascii_message_data_len_adjustment) {
- protocol::AsciiMessage ascii_message_header;
- constexpr auto kMaxTagLength = GetMaxVal(ascii_message_header.tag_len);
- constexpr auto kMaxDataLength = GetMaxVal(ascii_message_header.data_len);
- EXPECT_TRUE(tag.length() <= kMaxTagLength);
- EXPECT_TRUE(message.length() <= kMaxDataLength);
- ascii_message_header.tag_len =
- SAFELY_CLAMP(tag.length() + ascii_message_tag_len_adjustment, uint8_t,
- 0, kMaxTagLength);
- ascii_message_header.data_len =
- SAFELY_CLAMP(message.length() + ascii_message_data_len_adjustment,
- uint16_t, 0, kMaxDataLength);
- ascii_message_header.severity = protocol::MessageSeverity::kError;
+ const size_t adjusted_tag_len =
+ tag.length() + ascii_message_tag_len_adjustment;
+ const size_t adjusted_data_len =
+ message.length() + ascii_message_data_len_adjustment;
+ const auto& ascii_message_header =
+ protocol::AsciiMessage()
+ .set_tag_len(SAFELY_CLAMP(
+ adjusted_tag_len, uint8_t, 0,
+ GetMaxVal<decltype(protocol::AsciiMessage::tag_len)>()))
+ .set_data_len(SAFELY_CLAMP(
+ adjusted_data_len, uint16_t, 0,
+ GetMaxVal<decltype(protocol::AsciiMessage::data_len)>()))
+ .set_severity(protocol::MessageSeverity::kError);
+ EXPECT_EQ(adjusted_tag_len, ascii_message_header.tag_len);
+ EXPECT_EQ(adjusted_data_len, ascii_message_header.data_len);
const size_t payload_len = sizeof(ascii_message_header) + tag.length() +
message.length() +