mirror of
https://github.com/clementine-player/Clementine
synced 2024-12-23 00:09:14 +01:00
43 lines
1.0 KiB
C++
43 lines
1.0 KiB
C++
|
#include "gtest/gtest.h"
|
||
|
|
||
|
#include "networkremote/zeroconf.h"
|
||
|
|
||
|
namespace {
|
||
|
|
||
|
static const char k64CharAscii[] =
|
||
|
"aaaaaaaaaaaaaaaa"
|
||
|
"aaaaaaaaaaaaaaaa"
|
||
|
"aaaaaaaaaaaaaaaa"
|
||
|
"aaaaaaaaaaaaaaaa";
|
||
|
|
||
|
static const char kShortMultiByteString[] =
|
||
|
"我会说一点汉语";
|
||
|
|
||
|
static const char kLongMultiByteString[] =
|
||
|
"我会说一点汉语"
|
||
|
"我会说一点汉语"
|
||
|
"我会说一点汉语"
|
||
|
"我会说一点汉语";
|
||
|
|
||
|
TEST(ZeroconfTest, TruncatesAscii) {
|
||
|
QByteArray truncated = Zeroconf::TruncateName(
|
||
|
QString::fromAscii(k64CharAscii));
|
||
|
EXPECT_EQ(63, truncated.size());
|
||
|
EXPECT_TRUE(truncated.endsWith('\0'));
|
||
|
}
|
||
|
|
||
|
TEST(ZeroconfTest, DoesNotTruncateShortMultiByteUTF8) {
|
||
|
EXPECT_EQ(
|
||
|
sizeof(kShortMultiByteString),
|
||
|
Zeroconf::TruncateName(QString::fromUtf8(kShortMultiByteString)).size());
|
||
|
}
|
||
|
|
||
|
TEST(ZeroconfTest, TruncatesLongMultiByteUTF8) {
|
||
|
QByteArray truncated = Zeroconf::TruncateName(
|
||
|
QString::fromAscii(kLongMultiByteString));
|
||
|
EXPECT_LE(63, truncated.size());
|
||
|
EXPECT_TRUE(truncated.endsWith('\0'));
|
||
|
}
|
||
|
|
||
|
} // namespace
|