• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
22 namespace mindspore {
23 class TestCxxApiStatus : public UT::Common {
24  public:
25   TestCxxApiStatus() = default;
26 };
27 
TEST_F(TestCxxApiStatus,test_status_base_SUCCESS)28 TEST_F(TestCxxApiStatus, test_status_base_SUCCESS) {
29   Status status_1;
30   ASSERT_TRUE(status_1 == kSuccess);
31   ASSERT_TRUE(status_1 == Status(kSuccess));
32   ASSERT_EQ(status_1.operator bool(), true);
33   ASSERT_EQ(status_1.operator int(), kSuccess);
34   ASSERT_EQ(status_1.StatusCode(), kSuccess);
35   ASSERT_EQ(status_1.IsOk(), true);
36   ASSERT_EQ(status_1.IsError(), false);
37 }
38 
TEST_F(TestCxxApiStatus,test_status_msg_SUCCESS)39 TEST_F(TestCxxApiStatus, test_status_msg_SUCCESS) {
40   std::string message = "2333";
41   Status status_1(kMDSyntaxError, message);
42   ASSERT_EQ(status_1.IsError(), true);
43   ASSERT_EQ(status_1.ToString(), message);
44 }
45 
TEST_F(TestCxxApiStatus,test_status_ctor_SUCCESS)46 TEST_F(TestCxxApiStatus, test_status_ctor_SUCCESS) {
47   Status status_1;
48   Status status_2(kSuccess);
49   Status status_3(kSuccess, "2333");
50   Status status_4(kSuccess, 1, "file", "2333");
51   Status status_5 = Status::OK();
52   ASSERT_TRUE(status_1 == status_2);
53   ASSERT_TRUE(status_1 == status_3);
54   ASSERT_TRUE(status_1 == status_4);
55   ASSERT_TRUE(status_1 == status_5);
56 }
57 
TEST_F(TestCxxApiStatus,test_status_string_SUCCESS)58 TEST_F(TestCxxApiStatus, test_status_string_SUCCESS) {
59   Status status_1(kMDSyntaxError);
60   ASSERT_EQ(Status::CodeAsString(status_1.StatusCode()), "Syntax error");
61 }
62 }  // namespace mindspore
63