michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=8 sts=2 et sw=2 tw=80: */ michael@0: /* This code is made available to you under your choice of the following sets michael@0: * of licensing terms: michael@0: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: */ michael@0: /* Copyright 2014 Mozilla Contributors michael@0: * michael@0: * Licensed under the Apache License, Version 2.0 (the "License"); michael@0: * you may not use this file except in compliance with the License. michael@0: * You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, software michael@0: * distributed under the License is distributed on an "AS IS" BASIS, michael@0: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. michael@0: * See the License for the specific language governing permissions and michael@0: * limitations under the License. michael@0: */ michael@0: #ifndef mozilla_pkix__pkixgtest_h michael@0: #define mozilla_pkix__pkixgtest_h michael@0: michael@0: #include michael@0: michael@0: #include "gtest/gtest.h" michael@0: #include "pkixutil.h" michael@0: #include "prerror.h" michael@0: #include "stdint.h" michael@0: michael@0: namespace mozilla { namespace pkix { namespace test { michael@0: michael@0: class ResultWithPRErrorCode michael@0: { michael@0: public: michael@0: ResultWithPRErrorCode(Result rv, PRErrorCode errorCode) michael@0: : mRv(rv) michael@0: , mErrorCode(errorCode) michael@0: { michael@0: } michael@0: michael@0: explicit ResultWithPRErrorCode(Result rv) michael@0: : mRv(rv) michael@0: , mErrorCode(rv == Success ? 0 : PR_GetError()) michael@0: { michael@0: } michael@0: michael@0: bool operator==(const ResultWithPRErrorCode& other) const michael@0: { michael@0: return mRv == other.mRv && mErrorCode == other.mErrorCode; michael@0: } michael@0: michael@0: private: michael@0: const Result mRv; michael@0: const PRErrorCode mErrorCode; michael@0: michael@0: friend std::ostream& operator<<(std::ostream& os, michael@0: const ResultWithPRErrorCode & value); michael@0: michael@0: void operator=(const ResultWithPRErrorCode&) /*= delete*/; michael@0: }; michael@0: michael@0: ::std::ostream& operator<<(::std::ostream&, const ResultWithPRErrorCode &); michael@0: michael@0: #define ASSERT_Success(rv) \ michael@0: ASSERT_EQ(::mozilla::pkix::test::ResultWithPRErrorCode( \ michael@0: ::mozilla::pkix::Success, 0), \ michael@0: ::mozilla::pkix::test::ResultWithPRErrorCode(rv)) michael@0: #define EXPECT_Success(rv) \ michael@0: EXPECT_EQ(::mozilla::pkix::test::ResultWithPRErrorCode( \ michael@0: ::mozilla::pkix::Success, 0), \ michael@0: ::mozilla::pkix::test::ResultWithPRErrorCode(rv)) michael@0: michael@0: #define ASSERT_RecoverableError(expectedError, rv) \ michael@0: ASSERT_EQ(::mozilla::pkix::test::ResultWithPRErrorCode( \ michael@0: ::mozilla::pkix::RecoverableError, expectedError), \ michael@0: ::mozilla::pkix::test::ResultWithPRErrorCode(rv)) michael@0: #define EXPECT_RecoverableError(expectedError, rv) \ michael@0: EXPECT_EQ(::mozilla::pkix::test::ResultWithPRErrorCode( \ michael@0: ::mozilla::pkix::RecoverableError, expectedError), \ michael@0: ::mozilla::pkix::test::ResultWithPRErrorCode(rv)) michael@0: michael@0: #define ASSERT_FatalError(expectedError, rv) \ michael@0: ASSERT_EQ(::mozilla::pkix::test::ResultWithPRErrorCode( \ michael@0: ::mozilla::pkix::FatalError, expectedError), \ michael@0: ::mozilla::pkix::test::ResultWithPRErrorCode(rv)) michael@0: #define EXPECT_FatalError(expectedError, rv) \ michael@0: EXPECT_EQ(::mozilla::pkix::test::ResultWithPRErrorCode( \ michael@0: ::mozilla::pkix::FatalError, expectedError), \ michael@0: ::mozilla::pkix::test::ResultWithPRErrorCode(rv)) michael@0: michael@0: } } } // namespace mozilla::pkix::test michael@0: michael@0: #endif // mozilla_pkix__pkixgtest_h