You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

status_test.cc 2.0 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /**
  2. * Copyright 2021 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <memory>
  17. #include "common/common_test.h"
  18. #define private public
  19. #include "include/api/status.h"
  20. #undef private
  21. namespace mindspore {
  22. class TestCxxApiStatus : public UT::Common {
  23. public:
  24. TestCxxApiStatus() = default;
  25. };
  26. TEST_F(TestCxxApiStatus, test_status_base_SUCCESS) {
  27. Status status_1;
  28. ASSERT_TRUE(status_1 == kSuccess);
  29. ASSERT_TRUE(status_1 == Status(kSuccess));
  30. ASSERT_EQ(status_1.operator bool(), true);
  31. ASSERT_EQ(status_1.operator int(), kSuccess);
  32. ASSERT_EQ(status_1.StatusCode(), kSuccess);
  33. ASSERT_EQ(status_1.IsOk(), true);
  34. ASSERT_EQ(status_1.IsError(), false);
  35. }
  36. TEST_F(TestCxxApiStatus, test_status_msg_SUCCESS) {
  37. std::string message = "2333";
  38. Status status_1(kMDSyntaxError, message);
  39. ASSERT_EQ(status_1.IsError(), true);
  40. ASSERT_EQ(status_1.ToString(), message);
  41. }
  42. TEST_F(TestCxxApiStatus, test_status_ctor_SUCCESS) {
  43. Status status_1;
  44. Status status_2(kSuccess);
  45. Status status_3(kSuccess, "2333");
  46. Status status_4(kSuccess, 1, "file", "2333");
  47. Status status_5 = Status::OK();
  48. ASSERT_TRUE(status_1 == status_2);
  49. ASSERT_TRUE(status_1 == status_3);
  50. ASSERT_TRUE(status_1 == status_4);
  51. ASSERT_TRUE(status_1 == status_5);
  52. }
  53. TEST_F(TestCxxApiStatus, test_status_string_SUCCESS) {
  54. Status status_1(kMDSyntaxError);
  55. ASSERT_EQ(Status::CodeAsString(status_1.StatusCode()), "Syntax error");
  56. }
  57. } // namespace mindspore