17c804472Sopenharmony_ci/* 27c804472Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 37c804472Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 47c804472Sopenharmony_ci * you may not use this file except in compliance with the License. 57c804472Sopenharmony_ci * You may obtain a copy of the License at 67c804472Sopenharmony_ci * 77c804472Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 87c804472Sopenharmony_ci * 97c804472Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 107c804472Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 117c804472Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 127c804472Sopenharmony_ci * See the License for the specific language governing permissions and 137c804472Sopenharmony_ci * limitations under the License. 147c804472Sopenharmony_ci */ 157c804472Sopenharmony_ci 167c804472Sopenharmony_ci#include <filesystem> 177c804472Sopenharmony_ci#include <unistd.h> 187c804472Sopenharmony_ci#include <sys/stat.h> 197c804472Sopenharmony_ci#include <sys/types.h> 207c804472Sopenharmony_ci#include "gtest/gtest.h" 217c804472Sopenharmony_ci#include "NativeFileSystem.h" 227c804472Sopenharmony_ci 237c804472Sopenharmony_cinamespace { 247c804472Sopenharmony_ci class NativeFileSystemTest : public ::testing::Test { 257c804472Sopenharmony_ci public: 267c804472Sopenharmony_ci NativeFileSystemTest() {} 277c804472Sopenharmony_ci ~NativeFileSystemTest() {} 287c804472Sopenharmony_ci protected: 297c804472Sopenharmony_ci // 在整个测试夹具类执行前执行一次初始化操作 307c804472Sopenharmony_ci static void SetUpTestCase() 317c804472Sopenharmony_ci { 327c804472Sopenharmony_ci char buffer[FILENAME_MAX]; 337c804472Sopenharmony_ci if (getcwd(buffer, FILENAME_MAX) != nullptr) { 347c804472Sopenharmony_ci currDir = std::string(buffer); 357c804472Sopenharmony_ci childDir = currDir + "/mytestdirname"; 367c804472Sopenharmony_ci int status = mkdir(childDir.c_str(), 0777); // 0777 表示所有用户有读、写、执行权限 377c804472Sopenharmony_ci if (status != 0) { 387c804472Sopenharmony_ci printf("Error creating folder!\n"); 397c804472Sopenharmony_ci } 407c804472Sopenharmony_ci } else { 417c804472Sopenharmony_ci printf("error: getcwd failed"); 427c804472Sopenharmony_ci } 437c804472Sopenharmony_ci } 447c804472Sopenharmony_ci // 在整个测试夹具类执行后执行一次清理操作 457c804472Sopenharmony_ci static void TearDownTestCase() 467c804472Sopenharmony_ci { 477c804472Sopenharmony_ci std::filesystem::remove(childDir.c_str()); 487c804472Sopenharmony_ci } 497c804472Sopenharmony_ci 507c804472Sopenharmony_ci static std::string currDir; 517c804472Sopenharmony_ci static std::string childDir; 527c804472Sopenharmony_ci }; 537c804472Sopenharmony_ci 547c804472Sopenharmony_ci std::string NativeFileSystemTest::currDir = ""; 557c804472Sopenharmony_ci std::string NativeFileSystemTest::childDir = ""; 567c804472Sopenharmony_ci 577c804472Sopenharmony_ci TEST_F(NativeFileSystemTest, FindSubfolderByNameTest) 587c804472Sopenharmony_ci { 597c804472Sopenharmony_ci std::string filePath = OHOS::Ide::NativeFileSystem::FindSubfolderByName(currDir, "mytestdirname"); 607c804472Sopenharmony_ci EXPECT_EQ(filePath, childDir); 617c804472Sopenharmony_ci } 627c804472Sopenharmony_ci}