1 /** 2 * Copyright 2019 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 "minddata/dataset/util/status.h" 17 #include "common/common.h" 18 #include "gtest/gtest.h" 19 #include "utils/log_adapter.h" 20 21 using namespace mindspore::dataset; 22 23 class MindDataTestStatus : public UT::Common { 24 public: 25 MindDataTestStatus() {} 26 }; 27 28 // This function returns Status 29 Status f1() { 30 Status rc(StatusCode::kMDUnexpectedError, "Testing macro"); 31 RETURN_IF_NOT_OK(rc); 32 // We shouldn't get here 33 return Status::OK(); 34 } 35 36 Status f3() { 37 RETURN_STATUS_UNEXPECTED("Testing macro3"); 38 } 39 40 TEST_F(MindDataTestStatus, Test1) { 41 // Test default constructor which should be OK 42 Status rc; 43 ASSERT_TRUE(rc.IsOk()); 44 Status err1(StatusCode::kMDOutOfMemory, __LINE__, __FILE__); 45 MS_LOG(DEBUG) << err1; 46 ASSERT_TRUE(err1 == StatusCode::kMDOutOfMemory); 47 ASSERT_TRUE(err1.IsError()); 48 Status err2(StatusCode::kMDUnexpectedError, __LINE__, __FILE__, "Oops"); 49 MS_LOG(DEBUG) << err2; 50 } 51 52 TEST_F(MindDataTestStatus, Test2) { 53 Status rc = f1(); 54 MS_LOG(DEBUG) << rc; 55 } 56 57 TEST_F(MindDataTestStatus, Test3) { 58 Status rc = f3(); 59 MS_LOG(DEBUG) << rc; 60 } 61