Bug 1403083 - Part 2: Test conditionaly enabling string functions. r=froydnj

--HG--
extra : rebase_source : 01e852a2cf86a71fd1842fc852f1c2cdecb67b7b
This commit is contained in:
Eric Rahm 2017-10-09 13:33:16 -07:00
parent e0bdf23b2e
commit 4df63b1809

View File

@ -26,6 +26,46 @@ void test_assign_helper(const nsACString& in, nsACString &_retval)
_retval = in;
}
// Simple helper struct to test if conditionally enabled string functions are
// working.
template <typename T>
struct EnableTest
{
template <typename Q = T, typename EnableIfChar16 = mozilla::Char16OnlyT<Q>>
bool IsChar16() { return true; }
template <typename Q = T, typename EnableIfChar = mozilla::CharOnlyT<Q>>
bool IsChar16(int dummy = 42) { return false; }
template <typename Q = T, typename EnableIfChar16 = mozilla::Char16OnlyT<Q>>
bool IsChar() { return false; }
template <typename Q = T, typename EnableIfChar = mozilla::CharOnlyT<Q>>
bool IsChar(int dummy = 42) { return true; }
};
TEST(Strings, IsChar)
{
EnableTest<char> charTest;
EXPECT_TRUE(charTest.IsChar());
EXPECT_FALSE(charTest.IsChar16());
EnableTest<char16_t> char16Test;
EXPECT_TRUE(char16Test.IsChar16());
EXPECT_FALSE(char16Test.IsChar());
#ifdef COMPILATION_FAILURE_TEST
nsAutoCString a_ctest;
nsAutoString a_test;
a_ctest.AssignLiteral("hello");
// This should cause a compilation failure.
a_ctest.AssignLiteral(u"hello");
a_test.AssignLiteral(u"hello");
a_test.AssignLiteral("hello");
#endif
}
TEST(Strings, assign)
{
nsCString result;