|
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 code is made available to you under your choice of the following sets |
|
4 * of licensing terms: |
|
5 */ |
|
6 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
7 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
8 * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
|
9 */ |
|
10 /* Copyright 2014 Mozilla Contributors |
|
11 * |
|
12 * Licensed under the Apache License, Version 2.0 (the "License"); |
|
13 * you may not use this file except in compliance with the License. |
|
14 * You may obtain a copy of the License at |
|
15 * |
|
16 * http://www.apache.org/licenses/LICENSE-2.0 |
|
17 * |
|
18 * Unless required by applicable law or agreed to in writing, software |
|
19 * distributed under the License is distributed on an "AS IS" BASIS, |
|
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
21 * See the License for the specific language governing permissions and |
|
22 * limitations under the License. |
|
23 */ |
|
24 #ifndef mozilla_pkix__pkixgtest_h |
|
25 #define mozilla_pkix__pkixgtest_h |
|
26 |
|
27 #include <ostream> |
|
28 |
|
29 #include "gtest/gtest.h" |
|
30 #include "pkixutil.h" |
|
31 #include "prerror.h" |
|
32 #include "stdint.h" |
|
33 |
|
34 namespace mozilla { namespace pkix { namespace test { |
|
35 |
|
36 class ResultWithPRErrorCode |
|
37 { |
|
38 public: |
|
39 ResultWithPRErrorCode(Result rv, PRErrorCode errorCode) |
|
40 : mRv(rv) |
|
41 , mErrorCode(errorCode) |
|
42 { |
|
43 } |
|
44 |
|
45 explicit ResultWithPRErrorCode(Result rv) |
|
46 : mRv(rv) |
|
47 , mErrorCode(rv == Success ? 0 : PR_GetError()) |
|
48 { |
|
49 } |
|
50 |
|
51 bool operator==(const ResultWithPRErrorCode& other) const |
|
52 { |
|
53 return mRv == other.mRv && mErrorCode == other.mErrorCode; |
|
54 } |
|
55 |
|
56 private: |
|
57 const Result mRv; |
|
58 const PRErrorCode mErrorCode; |
|
59 |
|
60 friend std::ostream& operator<<(std::ostream& os, |
|
61 const ResultWithPRErrorCode & value); |
|
62 |
|
63 void operator=(const ResultWithPRErrorCode&) /*= delete*/; |
|
64 }; |
|
65 |
|
66 ::std::ostream& operator<<(::std::ostream&, const ResultWithPRErrorCode &); |
|
67 |
|
68 #define ASSERT_Success(rv) \ |
|
69 ASSERT_EQ(::mozilla::pkix::test::ResultWithPRErrorCode( \ |
|
70 ::mozilla::pkix::Success, 0), \ |
|
71 ::mozilla::pkix::test::ResultWithPRErrorCode(rv)) |
|
72 #define EXPECT_Success(rv) \ |
|
73 EXPECT_EQ(::mozilla::pkix::test::ResultWithPRErrorCode( \ |
|
74 ::mozilla::pkix::Success, 0), \ |
|
75 ::mozilla::pkix::test::ResultWithPRErrorCode(rv)) |
|
76 |
|
77 #define ASSERT_RecoverableError(expectedError, rv) \ |
|
78 ASSERT_EQ(::mozilla::pkix::test::ResultWithPRErrorCode( \ |
|
79 ::mozilla::pkix::RecoverableError, expectedError), \ |
|
80 ::mozilla::pkix::test::ResultWithPRErrorCode(rv)) |
|
81 #define EXPECT_RecoverableError(expectedError, rv) \ |
|
82 EXPECT_EQ(::mozilla::pkix::test::ResultWithPRErrorCode( \ |
|
83 ::mozilla::pkix::RecoverableError, expectedError), \ |
|
84 ::mozilla::pkix::test::ResultWithPRErrorCode(rv)) |
|
85 |
|
86 #define ASSERT_FatalError(expectedError, rv) \ |
|
87 ASSERT_EQ(::mozilla::pkix::test::ResultWithPRErrorCode( \ |
|
88 ::mozilla::pkix::FatalError, expectedError), \ |
|
89 ::mozilla::pkix::test::ResultWithPRErrorCode(rv)) |
|
90 #define EXPECT_FatalError(expectedError, rv) \ |
|
91 EXPECT_EQ(::mozilla::pkix::test::ResultWithPRErrorCode( \ |
|
92 ::mozilla::pkix::FatalError, expectedError), \ |
|
93 ::mozilla::pkix::test::ResultWithPRErrorCode(rv)) |
|
94 |
|
95 } } } // namespace mozilla::pkix::test |
|
96 |
|
97 #endif // mozilla_pkix__pkixgtest_h |