Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 1315869 - gtestify security/manager/ssl/tests/compiled/*.cpp. r=c…
Browse files Browse the repository at this point in the history
…ykesiopka.
  • Loading branch information
nnethercote committed Nov 8, 2016
1 parent 6c5b24f commit e6b10a1
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 262 deletions.
189 changes: 0 additions & 189 deletions security/manager/ssl/tests/compiled/TestSTSParser.cpp

This file was deleted.

19 changes: 0 additions & 19 deletions security/manager/ssl/tests/compiled/moz.build

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* 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 "TestHarness.h"
#include "gtest/gtest.h"
#include "nsCOMPtr.h"
#include "nsIPrefService.h"
#include "nsISimpleEnumerator.h"
Expand All @@ -12,72 +12,49 @@
#include "nsIX509CertList.h"
#include "nsServiceManagerUtils.h"

int
main(int argc, char* argv[])
TEST(psm_CertDB, Test)
{
ScopedXPCOM xpcom("TestCertDB");
if (xpcom.failed()) {
fail("couldn't initialize XPCOM");
return 1;
}
{
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
if (!prefs) {
fail("couldn't get nsIPrefBranch");
return 1;
}
ASSERT_TRUE(prefs) << "couldn't get nsIPrefBranch";

// When PSM initializes, it attempts to get some localized strings.
// As a result, Android flips out if this isn't set.
nsresult rv = prefs->SetBoolPref("intl.locale.matchOS", true);
if (NS_FAILED(rv)) {
fail("couldn't set pref 'intl.locale.matchOS'");
return 1;
}
ASSERT_TRUE(NS_SUCCEEDED(rv)) << "couldn't set pref 'intl.locale.matchOS'";

nsCOMPtr<nsIX509CertDB> certdb(do_GetService(NS_X509CERTDB_CONTRACTID));
if (!certdb) {
fail("couldn't get certdb");
return 1;
}
ASSERT_TRUE(certdb) << "couldn't get certdb";

nsCOMPtr<nsIX509CertList> certList;
rv = certdb->GetCerts(getter_AddRefs(certList));
if (NS_FAILED(rv)) {
fail("couldn't get list of certificates");
return 1;
}
ASSERT_TRUE(NS_SUCCEEDED(rv)) << "couldn't get list of certificates";

nsCOMPtr<nsISimpleEnumerator> enumerator;
rv = certList->GetEnumerator(getter_AddRefs(enumerator));
if (NS_FAILED(rv)) {
fail("couldn't enumerate certificate list");
return 1;
}
ASSERT_TRUE(NS_SUCCEEDED(rv)) << "couldn't enumerate certificate list";

bool foundBuiltIn = false;
bool hasMore = false;
while (NS_SUCCEEDED(enumerator->HasMoreElements(&hasMore)) && hasMore) {
nsCOMPtr<nsISupports> supports;
if (NS_FAILED(enumerator->GetNext(getter_AddRefs(supports)))) {
fail("couldn't get next certificate");
return 1;
}
ASSERT_TRUE(NS_SUCCEEDED(enumerator->GetNext(getter_AddRefs(supports))))
<< "couldn't get next certificate";

nsCOMPtr<nsIX509Cert> cert(do_QueryInterface(supports));
if (!cert) {
fail("couldn't QI to nsIX509Cert");
return 1;
}
if (NS_FAILED(cert->GetIsBuiltInRoot(&foundBuiltIn))) {
fail("GetIsBuiltInRoot failed");
return 1;
}
ASSERT_TRUE(cert) << "couldn't QI to nsIX509Cert";

ASSERT_TRUE(NS_SUCCEEDED(cert->GetIsBuiltInRoot(&foundBuiltIn))) <<
"GetIsBuiltInRoot failed";

if (foundBuiltIn) {
break;
}
}
if (foundBuiltIn) {
passed("successfully loaded at least one built-in certificate");
} else {
fail("didn't load any built-in certificates");
return 1;
}

ASSERT_TRUE(foundBuiltIn) << "didn't load any built-in certificates";

printf("successfully loaded at least one built-in certificate\n");

} // this scopes the nsCOMPtrs
// no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM
return 0;
}
Loading

0 comments on commit e6b10a1

Please sign in to comment.