1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-29 11:01:37 +01:00
Clementine-audio-player-Mac.../tests/zeroconf_test.cpp
2015-04-16 18:54:42 +02:00

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::fromLatin1(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::fromLatin1(kLongMultiByteString));
EXPECT_LE(63, truncated.size());
EXPECT_TRUE(truncated.endsWith('\0'));
}
} // namespace