* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <filesystem>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "gtest/gtest.h"
#include "NativeFileSystem.h"
namespace {
class NativeFileSystemTest : public ::testing::Test {
public:
NativeFileSystemTest() {}
~NativeFileSystemTest() {}
protected:
static void SetUpTestCase()
{
char buffer[FILENAME_MAX];
if (getcwd(buffer, FILENAME_MAX) != nullptr) {
currDir = std::string(buffer);
childDir = currDir + "/mytestdirname";
int status = mkdir(childDir.c_str(), 0777);
if (status != 0) {
printf("Error creating folder!\n");
}
} else {
printf("error: getcwd failed");
}
}
static void TearDownTestCase()
{
std::filesystem::remove(childDir.c_str());
}
static std::string currDir;
static std::string childDir;
};
std::string NativeFileSystemTest::currDir = "";
std::string NativeFileSystemTest::childDir = "";
TEST_F(NativeFileSystemTest, FindSubfolderByNameTest)
{
std::string filePath = OHOS::Ide::NativeFileSystem::FindSubfolderByName(currDir, "mytestdirname");
EXPECT_EQ(filePath, childDir);
}
}