mirror of
https://github.com/esphome/esphome.git
synced 2026-10-14 02:02:51 +00:00
[emontx] Test lines of exactly MAX_LINE_LENGTH bytes (#20517)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
7f7ae4c8fc
commit
c5cbc4a4e0
@@ -41,6 +41,25 @@ TEST_F(EmonTxTest, JsonLineParsed) {
|
||||
EXPECT_EQ(this->json_count_, 1);
|
||||
}
|
||||
|
||||
// The CR check must come before the overflow check, or a full line ending in CRLF would overflow.
|
||||
TEST_F(EmonTxTest, FullLengthLineWithCrLfDelivered) {
|
||||
this->uart_.push_rx(MAX_LINE_LENGTH, 'a');
|
||||
this->uart_.push_rx("\r\n");
|
||||
this->sut_.loop();
|
||||
|
||||
ASSERT_EQ(this->lines_.size(), 1u);
|
||||
EXPECT_EQ(this->lines_[0], std::string(MAX_LINE_LENGTH, 'a'));
|
||||
}
|
||||
|
||||
TEST_F(EmonTxTest, FullLengthLineWithLfDelivered) {
|
||||
this->uart_.push_rx(MAX_LINE_LENGTH, 'a');
|
||||
this->uart_.push_rx("\n");
|
||||
this->sut_.loop();
|
||||
|
||||
ASSERT_EQ(this->lines_.size(), 1u);
|
||||
EXPECT_EQ(this->lines_[0], std::string(MAX_LINE_LENGTH, 'a'));
|
||||
}
|
||||
|
||||
TEST_F(EmonTxTest, OverflowedLineDiscardedUntilLineFeed) {
|
||||
// One byte more than the buffer holds, then more of the same line.
|
||||
this->uart_.push_rx(MAX_LINE_LENGTH + 1, 'a');
|
||||
|
||||
Reference in New Issue
Block a user