MozAssertions.cpp (1278B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 5 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #include "MozAssertions.h" 8 #include "mozilla/ErrorNames.h" 9 #include "nsString.h" 10 11 namespace mozilla::gtest { 12 13 static testing::AssertionResult NsresultFailureHelper(const char* expr, 14 const char* expected, 15 nsresult rv) { 16 nsAutoCString name; 17 GetErrorName(rv, name); 18 19 return testing::AssertionFailure() 20 << "Expected: " << expr << " " << expected << ".\n" 21 << " Actual: " << name << "\n"; 22 } 23 24 testing::AssertionResult IsNsresultSuccess(const char* expr, nsresult rv) { 25 if (NS_SUCCEEDED(rv)) { 26 return testing::AssertionSuccess(); 27 } 28 return NsresultFailureHelper(expr, "succeeds", rv); 29 } 30 31 testing::AssertionResult IsNsresultFailure(const char* expr, nsresult rv) { 32 if (NS_FAILED(rv)) { 33 return testing::AssertionSuccess(); 34 } 35 return NsresultFailureHelper(expr, "failed", rv); 36 } 37 38 } // namespace mozilla::gtest