1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/pkix/test/gtest/pkixgtest.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,97 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ 1.6 +/* This code is made available to you under your choice of the following sets 1.7 + * of licensing terms: 1.8 + */ 1.9 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.10 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.11 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 1.12 + */ 1.13 +/* Copyright 2014 Mozilla Contributors 1.14 + * 1.15 + * Licensed under the Apache License, Version 2.0 (the "License"); 1.16 + * you may not use this file except in compliance with the License. 1.17 + * You may obtain a copy of the License at 1.18 + * 1.19 + * http://www.apache.org/licenses/LICENSE-2.0 1.20 + * 1.21 + * Unless required by applicable law or agreed to in writing, software 1.22 + * distributed under the License is distributed on an "AS IS" BASIS, 1.23 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1.24 + * See the License for the specific language governing permissions and 1.25 + * limitations under the License. 1.26 + */ 1.27 +#ifndef mozilla_pkix__pkixgtest_h 1.28 +#define mozilla_pkix__pkixgtest_h 1.29 + 1.30 +#include <ostream> 1.31 + 1.32 +#include "gtest/gtest.h" 1.33 +#include "pkixutil.h" 1.34 +#include "prerror.h" 1.35 +#include "stdint.h" 1.36 + 1.37 +namespace mozilla { namespace pkix { namespace test { 1.38 + 1.39 +class ResultWithPRErrorCode 1.40 +{ 1.41 +public: 1.42 + ResultWithPRErrorCode(Result rv, PRErrorCode errorCode) 1.43 + : mRv(rv) 1.44 + , mErrorCode(errorCode) 1.45 + { 1.46 + } 1.47 + 1.48 + explicit ResultWithPRErrorCode(Result rv) 1.49 + : mRv(rv) 1.50 + , mErrorCode(rv == Success ? 0 : PR_GetError()) 1.51 + { 1.52 + } 1.53 + 1.54 + bool operator==(const ResultWithPRErrorCode& other) const 1.55 + { 1.56 + return mRv == other.mRv && mErrorCode == other.mErrorCode; 1.57 + } 1.58 + 1.59 +private: 1.60 + const Result mRv; 1.61 + const PRErrorCode mErrorCode; 1.62 + 1.63 + friend std::ostream& operator<<(std::ostream& os, 1.64 + const ResultWithPRErrorCode & value); 1.65 + 1.66 + void operator=(const ResultWithPRErrorCode&) /*= delete*/; 1.67 +}; 1.68 + 1.69 +::std::ostream& operator<<(::std::ostream&, const ResultWithPRErrorCode &); 1.70 + 1.71 +#define ASSERT_Success(rv) \ 1.72 + ASSERT_EQ(::mozilla::pkix::test::ResultWithPRErrorCode( \ 1.73 + ::mozilla::pkix::Success, 0), \ 1.74 + ::mozilla::pkix::test::ResultWithPRErrorCode(rv)) 1.75 +#define EXPECT_Success(rv) \ 1.76 + EXPECT_EQ(::mozilla::pkix::test::ResultWithPRErrorCode( \ 1.77 + ::mozilla::pkix::Success, 0), \ 1.78 + ::mozilla::pkix::test::ResultWithPRErrorCode(rv)) 1.79 + 1.80 +#define ASSERT_RecoverableError(expectedError, rv) \ 1.81 + ASSERT_EQ(::mozilla::pkix::test::ResultWithPRErrorCode( \ 1.82 + ::mozilla::pkix::RecoverableError, expectedError), \ 1.83 + ::mozilla::pkix::test::ResultWithPRErrorCode(rv)) 1.84 +#define EXPECT_RecoverableError(expectedError, rv) \ 1.85 + EXPECT_EQ(::mozilla::pkix::test::ResultWithPRErrorCode( \ 1.86 + ::mozilla::pkix::RecoverableError, expectedError), \ 1.87 + ::mozilla::pkix::test::ResultWithPRErrorCode(rv)) 1.88 + 1.89 +#define ASSERT_FatalError(expectedError, rv) \ 1.90 + ASSERT_EQ(::mozilla::pkix::test::ResultWithPRErrorCode( \ 1.91 + ::mozilla::pkix::FatalError, expectedError), \ 1.92 + ::mozilla::pkix::test::ResultWithPRErrorCode(rv)) 1.93 +#define EXPECT_FatalError(expectedError, rv) \ 1.94 + EXPECT_EQ(::mozilla::pkix::test::ResultWithPRErrorCode( \ 1.95 + ::mozilla::pkix::FatalError, expectedError), \ 1.96 + ::mozilla::pkix::test::ResultWithPRErrorCode(rv)) 1.97 + 1.98 +} } } // namespace mozilla::pkix::test 1.99 + 1.100 +#endif // mozilla_pkix__pkixgtest_h