forked from qt-creator/qt-creator
Utils: Add constructor for character pointer
Change-Id: I12bd787caf911502a666de2c324bb74b8bd7b0aa Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
This commit is contained in:
@@ -114,6 +114,15 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
template<typename Type,
|
||||
typename = typename std::enable_if<std::is_pointer<Type>::value>::type
|
||||
>
|
||||
SmallString(Type characterPointer) noexcept
|
||||
: SmallString(characterPointer, std::strlen(characterPointer))
|
||||
{
|
||||
static_assert(!std::is_array<Type>::value, "Input type is array and not char pointer!");
|
||||
}
|
||||
|
||||
SmallString(const QString &qString)
|
||||
: SmallString(SmallString::fromQString(qString))
|
||||
{}
|
||||
|
||||
@@ -87,6 +87,14 @@ TEST(SmallString, ShortSmallStringIsReference)
|
||||
ASSERT_TRUE(longText.isReadOnlyReference());
|
||||
}
|
||||
|
||||
TEST(SmallString, SmallStringContructorIsNotReference)
|
||||
{
|
||||
const char *shortCSmallString = "short string";
|
||||
auto shortText = SmallString(shortCSmallString);
|
||||
|
||||
ASSERT_TRUE(shortText.isShortString());
|
||||
}
|
||||
|
||||
TEST(SmallString, ShortSmallStringIsNotReference)
|
||||
{
|
||||
const char *shortCSmallString = "short string";
|
||||
@@ -95,6 +103,14 @@ TEST(SmallString, ShortSmallStringIsNotReference)
|
||||
ASSERT_FALSE(shortText.isReadOnlyReference());
|
||||
}
|
||||
|
||||
TEST(SmallString, LongSmallStringConstrutorIsAllocated)
|
||||
{
|
||||
const char *longCSmallString = "very very very very very long text";
|
||||
auto longText = SmallString(longCSmallString);
|
||||
|
||||
ASSERT_TRUE(longText.hasAllocatedMemory());
|
||||
}
|
||||
|
||||
TEST(SmallString, MaximumShortSmallString)
|
||||
{
|
||||
SmallString maximumShortText("very very very very short text", 30);
|
||||
|
||||
Reference in New Issue
Block a user