2022-10-19 16:42:08 +00:00
|
|
|
// This file Copyright (C) 2013-2022 Mnemosyne LLC.
|
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
|
|
|
|
// or any future license endorsed by Mnemosyne LLC.
|
|
|
|
// License text can be found in the licenses/ folder.
|
|
|
|
|
2023-01-02 16:23:51 +00:00
|
|
|
#include <libtransmission/transmission.h>
|
2022-10-19 16:42:08 +00:00
|
|
|
|
2023-01-02 16:23:51 +00:00
|
|
|
#include <libtransmission/tr-buffer.h>
|
2022-10-19 16:42:08 +00:00
|
|
|
|
|
|
|
#include "test-fixtures.h"
|
|
|
|
|
|
|
|
using BufferTest = ::testing::Test;
|
|
|
|
using namespace std::literals;
|
|
|
|
using Buffer = libtransmission::Buffer;
|
|
|
|
|
|
|
|
TEST_F(BufferTest, startsWithInSingleSegment)
|
|
|
|
{
|
|
|
|
auto constexpr Hello = "Hello, "sv;
|
|
|
|
auto constexpr World = "World"sv;
|
|
|
|
auto constexpr Bang = "!"sv;
|
|
|
|
|
|
|
|
auto buf = Buffer{};
|
|
|
|
buf.add(Hello);
|
2023-01-28 02:12:09 +00:00
|
|
|
EXPECT_TRUE(buf.starts_with(Hello));
|
2022-10-19 16:42:08 +00:00
|
|
|
|
|
|
|
buf.add(World);
|
2023-01-28 02:12:09 +00:00
|
|
|
EXPECT_TRUE(buf.starts_with(Hello));
|
|
|
|
EXPECT_TRUE(buf.starts_with("Hello, Worl"sv));
|
|
|
|
EXPECT_TRUE(buf.starts_with("Hello, World"sv));
|
|
|
|
EXPECT_FALSE(buf.starts_with("Hello, World!"sv));
|
|
|
|
EXPECT_FALSE(buf.starts_with("Hello!"sv));
|
2022-10-19 16:42:08 +00:00
|
|
|
|
|
|
|
buf.add(Bang);
|
2023-01-28 02:12:09 +00:00
|
|
|
EXPECT_FALSE(buf.starts_with("Hello!"));
|
|
|
|
EXPECT_TRUE(buf.starts_with(Hello));
|
|
|
|
EXPECT_TRUE(buf.starts_with("Hello, Worl"sv));
|
|
|
|
EXPECT_TRUE(buf.starts_with("Hello, World"sv));
|
|
|
|
EXPECT_TRUE(buf.starts_with("Hello, World!"sv));
|
2022-10-19 16:42:08 +00:00
|
|
|
}
|
|
|
|
TEST_F(BufferTest, startsWithInMultiSegment)
|
|
|
|
{
|
|
|
|
auto constexpr Hello = "Hello, "sv;
|
|
|
|
auto constexpr World = "World"sv;
|
|
|
|
auto constexpr Bang = "!"sv;
|
|
|
|
|
|
|
|
auto buf = std::make_unique<Buffer>();
|
|
|
|
buf->add(Buffer{ Hello });
|
2023-01-28 02:12:09 +00:00
|
|
|
EXPECT_TRUE(buf->starts_with(Hello));
|
2022-10-19 16:42:08 +00:00
|
|
|
|
|
|
|
buf->add(Buffer{ World });
|
2023-01-28 02:12:09 +00:00
|
|
|
EXPECT_TRUE(buf->starts_with(Hello));
|
|
|
|
EXPECT_TRUE(buf->starts_with("Hello, Worl"sv));
|
|
|
|
EXPECT_TRUE(buf->starts_with("Hello, World"sv));
|
|
|
|
EXPECT_FALSE(buf->starts_with("Hello, World!"sv));
|
|
|
|
EXPECT_FALSE(buf->starts_with("Hello!"sv));
|
2022-10-19 16:42:08 +00:00
|
|
|
|
|
|
|
buf->add(Buffer{ Bang });
|
2023-01-28 02:12:09 +00:00
|
|
|
EXPECT_FALSE(buf->starts_with("Hello!"));
|
|
|
|
EXPECT_TRUE(buf->starts_with(Hello));
|
|
|
|
EXPECT_TRUE(buf->starts_with("Hello, Worl"sv));
|
|
|
|
EXPECT_TRUE(buf->starts_with("Hello, World"sv));
|
|
|
|
EXPECT_TRUE(buf->starts_with("Hello, World!"sv));
|
2022-10-19 16:42:08 +00:00
|
|
|
}
|