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 26 namespace common = mindspore::common; 27 28 using namespace mindspore::dataset; 29 using mindspore::MsLogLevel::ERROR; 30 using mindspore::ExceptionType::NoExceptionType; 31 using mindspore::LogStream; 32 33 class MindDataTestSchema : public UT::DatasetOpTesting { 34 protected: 35 }; 36 37 TEST_F(MindDataTestSchema, TestOldSchema) { 38 std::string schema_file = datasets_root_path_ + "/testDataset2/datasetSchema.json"; 39 std::unique_ptr<DataSchema> schema = std::make_unique<DataSchema>(); 40 Status rc = schema->LoadSchemaFile(schema_file, {}); 41 if (rc.IsError()) { 42 MS_LOG(ERROR) << "Return code error detected during schema load: " << common::SafeCStr(rc.ToString()) << "."; 43 EXPECT_TRUE(false); 44 } else { 45 int32_t num_cols = schema->NumColumns(); 46 EXPECT_TRUE(num_cols == 4); 47 } 48 } 49 50 TEST_F(MindDataTestSchema, TestAlbumSchema) { 51 std::string schema_file = datasets_root_path_ + "/testAlbum/fullSchema.json"; 52 std::unique_ptr<DataSchema> schema = std::make_unique<DataSchema>(); 53 Status rc = schema->LoadSchemaFile(schema_file, {}); 54 if (rc.IsError()) { 55 MS_LOG(ERROR) << "Return code error detected during schema load: " << common::SafeCStr(rc.ToString()) << "."; 56 EXPECT_TRUE(false); 57 } else { 58 int32_t num_cols = schema->NumColumns(); 59 MS_LOG(INFO) << "num_cols: " << num_cols << "."; 60 EXPECT_TRUE(num_cols == 8); 61 } 62 } 63 64