status_test.cc
Go to the documentation of this file.
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the
14 // distribution.
15 // * Neither the name of Google Inc. nor the names of its
16 // contributors may be used to endorse or promote products derived from
17 // this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 
32 #include <stdio.h>
33 
35 #include <gtest/gtest.h>
36 
37 namespace google {
38 namespace protobuf {
39 namespace {
40 TEST(Status, Empty) {
41  util::Status status;
44  EXPECT_EQ("OK", util::Status::OK.ToString());
45 }
46 
47 TEST(Status, GenericCodes) {
54 }
55 
56 TEST(Status, ConstructorZero) {
57  util::Status status(util::error::OK, "msg");
58  EXPECT_TRUE(status.ok());
59  EXPECT_EQ("OK", status.ToString());
60 }
61 
62 TEST(Status, CheckOK) {
63  util::Status status;
64  GOOGLE_CHECK_OK(status);
65  GOOGLE_CHECK_OK(status) << "Failed";
66  GOOGLE_DCHECK_OK(status) << "Failed";
67 }
68 
69 TEST(Status, ErrorMessage) {
71  EXPECT_FALSE(status.ok());
72  EXPECT_EQ("", status.error_message().ToString());
73  EXPECT_EQ("", status.message().ToString());
74  EXPECT_EQ("INVALID_ARGUMENT", status.ToString());
76  EXPECT_FALSE(status.ok());
77  EXPECT_EQ("msg", status.error_message().ToString());
78  EXPECT_EQ("msg", status.message().ToString());
79  EXPECT_EQ("INVALID_ARGUMENT:msg", status.ToString());
80  status = util::Status(util::error::OK, "msg");
81  EXPECT_TRUE(status.ok());
82  EXPECT_EQ("", status.error_message().ToString());
83  EXPECT_EQ("", status.message().ToString());
84  EXPECT_EQ("OK", status.ToString());
85 }
86 
87 TEST(Status, Copy) {
89  util::Status b(a);
90  ASSERT_EQ(a.ToString(), b.ToString());
91 }
92 
93 TEST(Status, Assign) {
96  b = a;
97  ASSERT_EQ(a.ToString(), b.ToString());
98 }
99 
100 TEST(Status, AssignEmpty) {
101  util::Status a(util::error::UNKNOWN, "message");
102  util::Status b;
103  a = b;
104  ASSERT_EQ(string("OK"), a.ToString());
105  ASSERT_TRUE(b.ok());
106  ASSERT_TRUE(a.ok());
107 }
108 
109 TEST(Status, EqualsOK) {
111 }
112 
113 TEST(Status, EqualsSame) {
116  ASSERT_EQ(a, b);
117 }
118 
119 TEST(Status, EqualsCopy) {
121  const util::Status b = a;
122  ASSERT_EQ(a, b);
123 }
124 
125 TEST(Status, EqualsDifferentCode) {
127  const util::Status b = util::Status(util::error::UNKNOWN, "message");
128  ASSERT_NE(a, b);
129 }
130 
131 TEST(Status, EqualsDifferentMessage) {
134  ASSERT_NE(a, b);
135 }
136 } // namespace
137 } // namespace protobuf
138 } // namespace google
google::protobuf::util::Status::OK
static const Status OK
Definition: status.h:82
ASSERT_NE
#define ASSERT_NE(val1, val2)
Definition: gtest.h:2086
google::protobuf::util::error::CANCELLED
@ CANCELLED
Definition: status.h:48
GOOGLE_DCHECK_OK
#define GOOGLE_DCHECK_OK
Definition: logging.h:195
gtest.h
testing::Assign
PolymorphicAction< internal::AssignAction< T1, T2 > > Assign(T1 *ptr, T2 val)
Definition: gmock-actions.h:1122
EXPECT_EQ
#define EXPECT_EQ(val1, val2)
Definition: glog/src/googletest.h:155
google::protobuf::util::error::UNKNOWN
@ UNKNOWN
Definition: status.h:49
ASSERT_EQ
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:2082
b
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:3228
google::protobuf::util::Status::UNKNOWN
static const Status UNKNOWN
Definition: status.h:84
google::protobuf::util::error::OK
@ OK
Definition: status.h:47
google::protobuf::TEST
TEST(ArenaTest, ArenaConstructable)
Definition: arena_unittest.cc:156
EXPECT_TRUE
#define EXPECT_TRUE(cond)
Definition: glog/src/googletest.h:137
ASSERT_TRUE
#define ASSERT_TRUE(condition)
Definition: gtest.h:1995
google::protobuf::util::error::INVALID_ARGUMENT
@ INVALID_ARGUMENT
Definition: status.h:50
google::protobuf::util::Status::CANCELLED
static const Status CANCELLED
Definition: status.h:83
aditof::Status
Status
Status of any operation that the TOF sdk performs.
Definition: status_definitions.h:48
Empty
Definition: empty.pb.h:69
GOOGLE_CHECK_OK
#define GOOGLE_CHECK_OK(A)
Definition: logging.h:155
googletest.h
EXPECT_FALSE
#define EXPECT_FALSE(cond)
Definition: glog/src/googletest.h:145
a
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:3228
status.h
google
Definition: data_proto2_to_proto3_util.h:11


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:59