| OLD | NEW |
| (Empty) |
| 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. | |
| 30 #include <google/protobuf/stubs/status.h> | |
| 31 | |
| 32 #include <stdio.h> | |
| 33 | |
| 34 #include <google/protobuf/testing/googletest.h> | |
| 35 #include <gtest/gtest.h> | |
| 36 | |
| 37 namespace google { | |
| 38 namespace protobuf { | |
| 39 namespace { | |
| 40 TEST(Status, Empty) { | |
| 41 util::Status status; | |
| 42 EXPECT_EQ(util::error::OK, util::Status::OK.error_code()); | |
| 43 EXPECT_EQ("OK", util::Status::OK.ToString()); | |
| 44 } | |
| 45 | |
| 46 TEST(Status, GenericCodes) { | |
| 47 EXPECT_EQ(util::error::OK, util::Status::OK.error_code()); | |
| 48 EXPECT_EQ(util::error::CANCELLED, util::Status::CANCELLED.error_code()); | |
| 49 EXPECT_EQ(util::error::UNKNOWN, util::Status::UNKNOWN.error_code()); | |
| 50 } | |
| 51 | |
| 52 TEST(Status, ConstructorZero) { | |
| 53 util::Status status(util::error::OK, "msg"); | |
| 54 EXPECT_TRUE(status.ok()); | |
| 55 EXPECT_EQ("OK", status.ToString()); | |
| 56 } | |
| 57 | |
| 58 TEST(Status, CheckOK) { | |
| 59 util::Status status; | |
| 60 GOOGLE_CHECK_OK(status); | |
| 61 GOOGLE_CHECK_OK(status) << "Failed"; | |
| 62 GOOGLE_DCHECK_OK(status) << "Failed"; | |
| 63 } | |
| 64 | |
| 65 TEST(Status, ErrorMessage) { | |
| 66 util::Status status(util::error::INVALID_ARGUMENT, ""); | |
| 67 EXPECT_FALSE(status.ok()); | |
| 68 EXPECT_EQ("", status.error_message().ToString()); | |
| 69 EXPECT_EQ("INVALID_ARGUMENT", status.ToString()); | |
| 70 status = util::Status(util::error::INVALID_ARGUMENT, "msg"); | |
| 71 EXPECT_FALSE(status.ok()); | |
| 72 EXPECT_EQ("msg", status.error_message().ToString()); | |
| 73 EXPECT_EQ("INVALID_ARGUMENT:msg", status.ToString()); | |
| 74 status = util::Status(util::error::OK, "msg"); | |
| 75 EXPECT_TRUE(status.ok()); | |
| 76 EXPECT_EQ("", status.error_message().ToString()); | |
| 77 EXPECT_EQ("OK", status.ToString()); | |
| 78 } | |
| 79 | |
| 80 TEST(Status, Copy) { | |
| 81 util::Status a(util::error::UNKNOWN, "message"); | |
| 82 util::Status b(a); | |
| 83 ASSERT_EQ(a.ToString(), b.ToString()); | |
| 84 } | |
| 85 | |
| 86 TEST(Status, Assign) { | |
| 87 util::Status a(util::error::UNKNOWN, "message"); | |
| 88 util::Status b; | |
| 89 b = a; | |
| 90 ASSERT_EQ(a.ToString(), b.ToString()); | |
| 91 } | |
| 92 | |
| 93 TEST(Status, AssignEmpty) { | |
| 94 util::Status a(util::error::UNKNOWN, "message"); | |
| 95 util::Status b; | |
| 96 a = b; | |
| 97 ASSERT_EQ(string("OK"), a.ToString()); | |
| 98 ASSERT_TRUE(b.ok()); | |
| 99 ASSERT_TRUE(a.ok()); | |
| 100 } | |
| 101 | |
| 102 TEST(Status, EqualsOK) { | |
| 103 ASSERT_EQ(util::Status::OK, util::Status()); | |
| 104 } | |
| 105 | |
| 106 TEST(Status, EqualsSame) { | |
| 107 const util::Status a = util::Status(util::error::CANCELLED, "message"); | |
| 108 const util::Status b = util::Status(util::error::CANCELLED, "message"); | |
| 109 ASSERT_EQ(a, b); | |
| 110 } | |
| 111 | |
| 112 TEST(Status, EqualsCopy) { | |
| 113 const util::Status a = util::Status(util::error::CANCELLED, "message"); | |
| 114 const util::Status b = a; | |
| 115 ASSERT_EQ(a, b); | |
| 116 } | |
| 117 | |
| 118 TEST(Status, EqualsDifferentCode) { | |
| 119 const util::Status a = util::Status(util::error::CANCELLED, "message"); | |
| 120 const util::Status b = util::Status(util::error::UNKNOWN, "message"); | |
| 121 ASSERT_NE(a, b); | |
| 122 } | |
| 123 | |
| 124 TEST(Status, EqualsDifferentMessage) { | |
| 125 const util::Status a = util::Status(util::error::CANCELLED, "message"); | |
| 126 const util::Status b = util::Status(util::error::CANCELLED, "another"); | |
| 127 ASSERT_NE(a, b); | |
| 128 } | |
| 129 } // namespace | |
| 130 } // namespace protobuf | |
| 131 } // namespace google | |
| OLD | NEW |