1/* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16#include <sys/stat.h> 17#include <unistd.h> 18#include "functionalext.h" 19 20const int SUCCESS = 0; 21const int FAILED = -1; 22 23/** 24 * @tc.name : rmdir_0100 25 * @tc.desc : The parameter is valid, and the file directory can be deleted. 26 * @tc.level : Level 0 27 */ 28void rmdir_0100(void) 29{ 30 char *path = "testnormal"; 31 if (access(path, F_OK) != 0) { 32 int ret = mkdir(path, 0777); 33 EXPECT_EQ("rmdir_0100", ret, SUCCESS); 34 int rm = rmdir(path); 35 EXPECT_EQ("rmdir_0100", rm, SUCCESS); 36 } else { 37 remove(path); 38 int ret = mkdir(path, 0777); 39 EXPECT_EQ("rmdir_0100", ret, SUCCESS); 40 int rm = rmdir(path); 41 EXPECT_EQ("rmdir_0100", rm, SUCCESS); 42 } 43 path = NULL; 44} 45 46/** 47 * @tc.name : rmdir_0200 48 * @tc.desc : The parameter is invalid, the directory cannot be deleted. 49 * @tc.level : Level 2 50 */ 51void rmdir_0200(void) 52{ 53 char *path = "testerror"; 54 if (access(path, F_OK) != 0) { 55 int rm = rmdir(path); 56 EXPECT_EQ("rmdir_0200", rm, FAILED); 57 } else { 58 int rm = rmdir(path); 59 EXPECT_EQ("rmdir_0200", rm, SUCCESS); 60 rm = rmdir(path); 61 EXPECT_EQ("rmdir_0200", rm, FAILED); 62 } 63 path = NULL; 64} 65 66int main(int argc, char *argv[]) 67{ 68 rmdir_0100(); 69 rmdir_0200(); 70 71 return t_status; 72}