diff --git a/mailnews/base/test/TestMailCookie.cpp b/mailnews/base/test/TestMailCookie.cpp index 7427eb6c40..b23f15eba8 100644 --- a/mailnews/base/test/TestMailCookie.cpp +++ b/mailnews/base/test/TestMailCookie.cpp @@ -3,7 +3,6 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "TestCommon.h" #include "gtest/gtest.h" #include "nsIServiceManager.h" #include "nsICookieService.h" @@ -34,7 +33,7 @@ static const char kCookiesAskPermission[] = "network.cookie.warnAboutCookies"; static const char kCookiesMaxPerHost[] = "network.cookie.maxPerHost"; void -SetACookie(nsICookieService *aCookieService, const char *aSpec1, const char *aSpec2, const char* aCookieString, const char *aServerTime) +SetACookieMail(nsICookieService *aCookieService, const char *aSpec1, const char *aSpec2, const char* aCookieString, const char *aServerTime) { nsCOMPtr uri1, uri2; NS_NewURI(getter_AddRefs(uri1), aSpec1); @@ -45,20 +44,10 @@ SetACookie(nsICookieService *aCookieService, const char *aSpec1, const char *aSp EXPECT_TRUE(NS_SUCCEEDED(rv)); } -void -SetACookieNoHttp(nsICookieService *aCookieService, const char *aSpec, const char* aCookieString) -{ - nsCOMPtr uri; - NS_NewURI(getter_AddRefs(uri), aSpec); - - nsresult rv = aCookieService->SetCookieString(uri, nullptr, (char *)aCookieString, nullptr); - EXPECT_TRUE(NS_SUCCEEDED(rv)); -} - // returns true if cookie(s) for the given host were found; else false. // the cookie string is returned via aCookie. bool -GetACookie(nsICookieService *aCookieService, const char *aSpec1, const char *aSpec2, char **aCookie) +GetACookieMail(nsICookieService *aCookieService, const char *aSpec1, const char *aSpec2, char **aCookie) { nsCOMPtr uri1, uri2; NS_NewURI(getter_AddRefs(uri1), aSpec1); @@ -69,18 +58,6 @@ GetACookie(nsICookieService *aCookieService, const char *aSpec1, const char *aSp return *aCookie != nullptr; } -// returns true if cookie(s) for the given host were found; else false. -// the cookie string is returned via aCookie. -bool -GetACookieNoHttp(nsICookieService *aCookieService, const char *aSpec, char **aCookie) -{ - nsCOMPtr uri; - NS_NewURI(getter_AddRefs(uri), aSpec); - - Unused << aCookieService->GetCookieString(uri, nullptr, aCookie); - return *aCookie != nullptr; -} - // some #defines for comparison rules #define MUST_BE_NULL 0 #define MUST_EQUAL 1 @@ -116,7 +93,7 @@ CheckResult(const char *aLhs, uint32_t aRule, const char *aRhs = nullptr) } void -InitPrefs(nsIPrefBranch *aPrefBranch) +InitPrefsMail(nsIPrefBranch *aPrefBranch) { // init some relevant prefs, so the tests don't go awry. // we use the most restrictive set of prefs we can; @@ -130,7 +107,6 @@ InitPrefs(nsIPrefBranch *aPrefBranch) aPrefBranch->SetIntPref(kCookiesMaxPerHost, 50); } - TEST(TestMailCookie,TestMailCookieMain) { nsresult rv0; @@ -143,7 +119,7 @@ TEST(TestMailCookie,TestMailCookieMain) do_GetService(kPrefServiceCID, &rv0); ASSERT_TRUE(NS_SUCCEEDED(rv0)); - InitPrefs(prefBranch); + InitPrefsMail(prefBranch); nsCString cookie; @@ -175,17 +151,17 @@ TEST(TestMailCookie,TestMailCookieMain) // test some mailnews cookies to ensure blockage. // we use null firstURI's deliberately, since we have hacks to deal with // this situation... - SetACookie(cookieService, "mailbox://mail.co.uk/", nullptr, "test=mailnews", nullptr); - GetACookie(cookieService, "mailbox://mail.co.uk/", nullptr, getter_Copies(cookie)); + SetACookieMail(cookieService, "mailbox://mail.co.uk/", nullptr, "test=mailnews", nullptr); + GetACookieMail(cookieService, "mailbox://mail.co.uk/", nullptr, getter_Copies(cookie)); EXPECT_TRUE(CheckResult(cookie.get(), MUST_BE_NULL)); - GetACookie(cookieService, "http://mail.co.uk/", nullptr, getter_Copies(cookie)); + GetACookieMail(cookieService, "http://mail.co.uk/", nullptr, getter_Copies(cookie)); EXPECT_TRUE(CheckResult(cookie.get(), MUST_BE_NULL)); - SetACookie(cookieService, "http://mail.co.uk/", nullptr, "test=mailnews", nullptr); - GetACookie(cookieService, "mailbox://mail.co.uk/", nullptr, getter_Copies(cookie)); + SetACookieMail(cookieService, "http://mail.co.uk/", nullptr, "test=mailnews", nullptr); + GetACookieMail(cookieService, "mailbox://mail.co.uk/", nullptr, getter_Copies(cookie)); EXPECT_TRUE(CheckResult(cookie.get(), MUST_BE_NULL)); - GetACookie(cookieService, "http://mail.co.uk/", nullptr, getter_Copies(cookie)); + GetACookieMail(cookieService, "http://mail.co.uk/", nullptr, getter_Copies(cookie)); EXPECT_TRUE(CheckResult(cookie.get(), MUST_EQUAL, "test=mailnews")); - SetACookie(cookieService, "http://mail.co.uk/", nullptr, "test=mailnews; max-age=0", nullptr); - GetACookie(cookieService, "http://mail.co.uk/", nullptr, getter_Copies(cookie)); + SetACookieMail(cookieService, "http://mail.co.uk/", nullptr, "test=mailnews; max-age=0", nullptr); + GetACookieMail(cookieService, "http://mail.co.uk/", nullptr, getter_Copies(cookie)); EXPECT_TRUE(CheckResult(cookie.get(), MUST_BE_NULL)); } diff --git a/mailnews/base/test/TestMsgStripRE.cpp b/mailnews/base/test/TestMsgStripRE.cpp index 4914a045b1..0a09a666df 100644 --- a/mailnews/base/test/TestMsgStripRE.cpp +++ b/mailnews/base/test/TestMsgStripRE.cpp @@ -2,8 +2,8 @@ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include -#include "TestHarness.h" + +#include "gtest/gtest.h" #include "mozilla/ArrayUtils.h" #include "nsCOMPtr.h" #include "nsMsgUtils.h" @@ -24,21 +24,19 @@ testStripRe(const char *encodedInput, char *expectedOutput, bool expectedDidModify) { // call NS_StripRE with the appropriate args - char *modifiedSubject; + nsCString modifiedSubject; bool didModify; - const char *encodedInout = encodedInput; - uint32_t length = strlen(encodedInout); - didModify = NS_MsgStripRE(&encodedInout, &length, &modifiedSubject); + didModify = NS_MsgStripRE(nsDependentCString(encodedInput), modifiedSubject); // make sure we got the right results if (didModify != expectedDidModify) return 2; if (didModify) { - if (strcmp(expectedOutput, modifiedSubject)) { + if (strcmp(expectedOutput, modifiedSubject.get())) { return 3; } - } else if (strcmp(expectedOutput, encodedInout)) { + } else if (strcmp(expectedOutput, encodedInput)) { return 4; } @@ -46,31 +44,26 @@ testStripRe(const char *encodedInput, char *expectedOutput, return 0; } -// General note about return values: -// return 1 for a setup or xpcom type failure, return 2 for a real test failure -int main(int argc, char** argv) +// int main(int argc, char** argv) +TEST(TestMsgStripRE,TestMsgStripREMain) { - - ScopedXPCOM xpcom("TestMsgStripRE.cpp"); - if (xpcom.failed()) - return 1; - nsresult rv; nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); - NS_ENSURE_SUCCESS(rv, 1); + EXPECT_TRUE(NS_SUCCEEDED(rv)); // set localizedRe pref, value "SV,ÆØÅ", // \xC3\x86, \xC3\x98 and \xC3\x85 are the UTF-8 encodings of Æ, Ø and Å. rv = prefBranch->SetStringPref("mailnews.localizedRe", NS_LITERAL_CSTRING("SV,\xC3\x86\xC3\x98\xC3\x85")); - NS_ENSURE_SUCCESS(rv, 1); + EXPECT_TRUE(NS_SUCCEEDED(rv)); // run our tests struct testInfo testInfoStructs[] = { - {"SV: =?ISO-8859-1?Q?=C6blegr=F8d?=", "=?ISO-8859-1?Q?=C6blegr=F8d?=", + // Note that re-encoding always happens in UTF-8. + {"SV: =?ISO-8859-1?Q?=C6blegr=F8d?=", "=?UTF-8?B?w4ZibGVncsO4ZA==?=", true}, - {"=?ISO-8859-1?Q?SV=3A=C6blegr=F8d?=", "=?ISO-8859-1?Q?=C6blegr=F8d?=", + {"=?ISO-8859-1?Q?SV=3A=C6blegr=F8d?=", "=?UTF-8?B?w4ZibGVncsO4ZA==?=", true}, // Note that in the next two tests, the only ISO-8859-1 chars are in the @@ -89,14 +82,14 @@ int main(int argc, char** argv) testInfoStructs[i].expectedDidModify); if (result) { - fail("%s, i=%d | result=%d\n", __FILE__, i, result); + printf("Failed: %s, i=%d | result=%d\n", __FILE__, i, result); allTestsPassed = false; } + EXPECT_TRUE(result == 0); } if (allTestsPassed) { - passed("all tests passed\n"); + printf("all tests passed\n"); } - - return allTestsPassed ? 0 : 2; + EXPECT_TRUE(allTestsPassed); } diff --git a/mailnews/base/test/moz.build b/mailnews/base/test/moz.build index 738ba664d7..74f40f7a66 100644 --- a/mailnews/base/test/moz.build +++ b/mailnews/base/test/moz.build @@ -9,6 +9,7 @@ FINAL_LIBRARY = 'xul-gtest' UNIFIED_SOURCES += [ 'TestMailCookie.cpp', + 'TestMsgStripRE.cpp', ] LOCAL_INCLUDES += [