2019-11-13 06:40:17 +00:00
|
|
|
// Copyright 2019 The Pigweed Authors
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
2019-11-26 22:13:38 +00:00
|
|
|
// use this file except in compliance with the License. You may obtain a copy of
|
|
|
|
// the License at
|
2019-11-13 06:40:17 +00:00
|
|
|
//
|
|
|
|
// 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
|
2019-11-26 22:13:38 +00:00
|
|
|
// License for the specific language governing permissions and limitations under
|
|
|
|
// the License.
|
2019-11-13 06:40:17 +00:00
|
|
|
|
|
|
|
#include "pw_status/status.h"
|
|
|
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
2019-11-14 01:04:21 +00:00
|
|
|
namespace pw {
|
2019-11-13 06:40:17 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
constexpr Status::Code kInvalidCode = static_cast<Status::Code>(30);
|
|
|
|
|
|
|
|
TEST(Status, Default) {
|
|
|
|
Status status;
|
|
|
|
EXPECT_TRUE(status.ok());
|
|
|
|
EXPECT_EQ(Status(), status);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Status, ConstructWithStatusCode) {
|
|
|
|
Status status(Status::ABORTED);
|
|
|
|
EXPECT_EQ(Status::ABORTED, status.code());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Status, AssignFromStatusCode) {
|
|
|
|
Status status;
|
|
|
|
status = Status::INTERNAL;
|
|
|
|
EXPECT_EQ(Status::INTERNAL, status.code());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Status, CompareToStatusCode) {
|
|
|
|
EXPECT_EQ(Status(), Status::OK);
|
|
|
|
EXPECT_EQ(Status::ABORTED, Status(Status::ABORTED));
|
|
|
|
EXPECT_NE(Status(), Status::ABORTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Status, Ok_OkIsTrue) {
|
|
|
|
EXPECT_TRUE(Status().ok());
|
|
|
|
EXPECT_TRUE(Status(Status::OK).ok());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Status, NotOk_OkIsFalse) {
|
|
|
|
EXPECT_FALSE(Status(Status::DATA_LOSS).ok());
|
|
|
|
EXPECT_FALSE(Status(kInvalidCode).ok());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Status, KnownString) {
|
2019-11-14 18:43:51 +00:00
|
|
|
EXPECT_STREQ("OK", Status(Status::OK).str());
|
|
|
|
EXPECT_STREQ("CANCELLED", Status(Status::CANCELLED).str());
|
|
|
|
EXPECT_STREQ("DEADLINE_EXCEEDED", Status(Status::DEADLINE_EXCEEDED).str());
|
|
|
|
EXPECT_STREQ("NOT_FOUND", Status(Status::NOT_FOUND).str());
|
|
|
|
EXPECT_STREQ("ALREADY_EXISTS", Status(Status::ALREADY_EXISTS).str());
|
|
|
|
EXPECT_STREQ("PERMISSION_DENIED", Status(Status::PERMISSION_DENIED).str());
|
|
|
|
EXPECT_STREQ("UNAUTHENTICATED", Status(Status::UNAUTHENTICATED).str());
|
|
|
|
EXPECT_STREQ("RESOURCE_EXHAUSTED", Status(Status::RESOURCE_EXHAUSTED).str());
|
|
|
|
EXPECT_STREQ("FAILED_PRECONDITION",
|
|
|
|
Status(Status::FAILED_PRECONDITION).str());
|
|
|
|
EXPECT_STREQ("ABORTED", Status(Status::ABORTED).str());
|
|
|
|
EXPECT_STREQ("OUT_OF_RANGE", Status(Status::OUT_OF_RANGE).str());
|
|
|
|
EXPECT_STREQ("UNIMPLEMENTED", Status(Status::UNIMPLEMENTED).str());
|
|
|
|
EXPECT_STREQ("INTERNAL", Status(Status::INTERNAL).str());
|
|
|
|
EXPECT_STREQ("UNAVAILABLE", Status(Status::UNAVAILABLE).str());
|
|
|
|
EXPECT_STREQ("DATA_LOSS", Status(Status::DATA_LOSS).str());
|
2019-11-13 06:40:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Status, UnknownString) {
|
2019-11-14 18:43:51 +00:00
|
|
|
EXPECT_STREQ("INVALID STATUS", Status(static_cast<Status::Code>(30)).str());
|
2019-11-13 06:40:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
2019-11-14 01:04:21 +00:00
|
|
|
} // namespace pw
|