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.

schema_test.cc 2.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * Copyright 2020 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 <string>
  18. #include "common/common.h"
  19. #include "utils/ms_utils.h"
  20. #include "minddata/dataset/engine/data_schema.h"
  21. #include "minddata/dataset/util/status.h"
  22. #include "gtest/gtest.h"
  23. #include "utils/log_adapter.h"
  24. #include "securec.h"
  25. namespace common = mindspore::common;
  26. using namespace mindspore::dataset;
  27. using mindspore::MsLogLevel::ERROR;
  28. using mindspore::ExceptionType::NoExceptionType;
  29. using mindspore::LogStream;
  30. class MindDataTestSchema : public UT::DatasetOpTesting {
  31. protected:
  32. };
  33. TEST_F(MindDataTestSchema, TestOldSchema) {
  34. std::string schema_file = datasets_root_path_ + "/testDataset2/datasetSchema.json";
  35. std::unique_ptr<DataSchema> schema = std::make_unique<DataSchema>();
  36. Status rc = schema->LoadSchemaFile(schema_file, {});
  37. if (rc.IsError()) {
  38. MS_LOG(ERROR) << "Return code error detected during schema load: " << common::SafeCStr(rc.ToString()) << ".";
  39. EXPECT_TRUE(false);
  40. } else {
  41. int32_t num_cols = schema->NumColumns();
  42. EXPECT_TRUE(num_cols == 4);
  43. }
  44. }
  45. TEST_F(MindDataTestSchema, TestAlbumSchema) {
  46. std::string schema_file = datasets_root_path_ + "/testAlbum/fullSchema.json";
  47. std::unique_ptr<DataSchema> schema = std::make_unique<DataSchema>();
  48. Status rc = schema->LoadSchemaFile(schema_file, {});
  49. if (rc.IsError()) {
  50. MS_LOG(ERROR) << "Return code error detected during schema load: " << common::SafeCStr(rc.ToString()) << ".";
  51. EXPECT_TRUE(false);
  52. } else {
  53. int32_t num_cols = schema->NumColumns();
  54. MS_LOG(INFO) << "num_cols: " << num_cols << ".";
  55. EXPECT_TRUE(num_cols == 8);
  56. }
  57. }