| // Copyright 2026 Google LLC | |
| // | |
| // Licensed under the Apache License, Version 2.0 (the "License"); | |
| // you may not use this file except in compliance with the License. | |
| // You may obtain a copy of the License at | |
| // | |
| // https://www.apache.org/licenses/LICENSE-2.0 | |
| // | |
| // Unless required by applicable law or agreed to in writing, software | |
| // distributed under the License is distributed on an "AS IS" BASIS, | |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| // See the License for the specific language governing permissions and | |
| // limitations under the License. | |
| // | |
| #include "tsp/status_codes.h" | |
| #include <string> | |
| #include "absl/status/status.h" | |
| #include "absl/status/status_matchers.h" | |
| #include "absl/strings/str_cat.h" | |
| #include "gmock/gmock.h" | |
| #include "gtest/gtest.h" | |
| namespace credentio { | |
| namespace { | |
| using ::absl_testing::IsOkAndHolds; | |
| using ::absl_testing::StatusIs; | |
| TEST(StatusCodesTest, GetTspPkiStatusTest) { | |
| EXPECT_THAT(GetTspPkiStatus(0), IsOkAndHolds(TspPkiStatus::kGranted)); | |
| EXPECT_THAT(GetTspPkiStatus(1), IsOkAndHolds(TspPkiStatus::kGrantedWithMods)); | |
| EXPECT_THAT(GetTspPkiStatus(2), IsOkAndHolds(TspPkiStatus::kRejection)); | |
| EXPECT_THAT(GetTspPkiStatus(3), IsOkAndHolds(TspPkiStatus::kWaiting)); | |
| EXPECT_THAT(GetTspPkiStatus(4), | |
| IsOkAndHolds(TspPkiStatus::kRevocationWarning)); | |
| EXPECT_THAT(GetTspPkiStatus(5), | |
| IsOkAndHolds(TspPkiStatus::kRevocationNotification)); | |
| EXPECT_THAT(GetTspPkiStatus(6), StatusIs(absl::StatusCode::kInvalidArgument, | |
| "unknown TspPkiStatus code: 6")); | |
| EXPECT_THAT(GetTspPkiStatus(-1), StatusIs(absl::StatusCode::kInvalidArgument, | |
| "unknown TspPkiStatus code: -1")); | |
| } | |
| TEST(StatusCodesTest, AbslStringifyTspPkiStatus) { | |
| EXPECT_EQ(absl::StrCat(TspPkiStatus::kGranted), "granted"); | |
| EXPECT_EQ(absl::StrCat(TspPkiStatus::kGrantedWithMods), "grantedWithMods"); | |
| EXPECT_EQ(absl::StrCat(TspPkiStatus::kRejection), "rejection"); | |
| EXPECT_EQ(absl::StrCat(TspPkiStatus::kWaiting), "waiting"); | |
| EXPECT_EQ(absl::StrCat(TspPkiStatus::kRevocationWarning), | |
| "revocationWarning"); | |
| EXPECT_EQ(absl::StrCat(TspPkiStatus::kRevocationNotification), | |
| "revocationNotification"); | |
| } | |
| TEST(StatusCodesTest, AbslStringifyInvalidTspPkiStatus) { | |
| EXPECT_DEBUG_DEATH( | |
| { std::string result = absl::StrCat(static_cast<TspPkiStatus>(100)); }, | |
| "unknown TspPkiStatus enum: 100"); | |
| } | |
| } // namespace | |
| } // namespace credentio |