2013-02-22 14:39:29 +01:00
|
|
|
#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(
|
2015-04-16 18:54:42 +02:00
|
|
|
QString::fromLatin1(k64CharAscii));
|
2013-02-22 14:39:29 +01:00
|
|
|
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(
|
2015-04-16 18:54:42 +02:00
|
|
|
QString::fromLatin1(kLongMultiByteString));
|
2013-02-22 14:39:29 +01:00
|
|
|
EXPECT_LE(63, truncated.size());
|
|
|
|
EXPECT_TRUE(truncated.endsWith('\0'));
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|