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 1.7 kB

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