诸暨麻将添加redis
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

139 regels
4.9 KiB

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