From 4df63b1809a4df446ca7d8b5c2b75380aa3cf15f Mon Sep 17 00:00:00 2001 From: Eric Rahm Date: Mon, 9 Oct 2017 13:33:16 -0700 Subject: [PATCH] Bug 1403083 - Part 2: Test conditionaly enabling string functions. r=froydnj --HG-- extra : rebase_source : 01e852a2cf86a71fd1842fc852f1c2cdecb67b7b --- xpcom/tests/gtest/TestStrings.cpp | 40 +++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/xpcom/tests/gtest/TestStrings.cpp b/xpcom/tests/gtest/TestStrings.cpp index d28f53e2b8a0..45c63ce7e2f9 100644 --- a/xpcom/tests/gtest/TestStrings.cpp +++ b/xpcom/tests/gtest/TestStrings.cpp @@ -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 +struct EnableTest +{ + template > + bool IsChar16() { return true; } + + template > + bool IsChar16(int dummy = 42) { return false; } + + template > + bool IsChar() { return false; } + + template > + bool IsChar(int dummy = 42) { return true; } +}; + +TEST(Strings, IsChar) +{ + EnableTest charTest; + EXPECT_TRUE(charTest.IsChar()); + EXPECT_FALSE(charTest.IsChar16()); + + EnableTest 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;