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 <stdio.h> 17#include <string.h> 18#include <unistd.h> 19#include "test.h" 20 21/** 22 * @tc.name : symlink_0100 23 * @tc.desc : Test the symlink function to create a new file link 24 * @tc.level : Level 0 25 */ 26void symlink_0100(void) 27{ 28 char *file_name = "/data/temp.txt"; 29 char *link_name = "/data/linktemp.txt"; 30 FILE *f = fopen(file_name, "w"); 31 fclose(f); 32 int result = symlink(file_name, link_name); 33 if (result != 0) { 34 t_error("%s symlink get result is %d are not 0\n", __func__, result); 35 } 36 if (access(link_name, 0) != 0) { 37 t_error("%s symlink error link not exist\n", __func__); 38 } 39 unlink(file_name); 40 unlink(link_name); 41} 42 43/** 44 * @tc.name : symlink_0200 45 * @tc.desc : old file does not exist 46 * @tc.level : Level 1 47 */ 48void symlink_0200(void) 49{ 50 char *file_name = "/data/temp.txt"; 51 char *link_name = "/data/linktemp.txt"; 52 int result = symlink(file_name, link_name); 53 if (result != 0) { 54 t_error("%s symlink get result is %d are not 0\n", __func__, result); 55 } 56 if (access(link_name, 0) == 0) { 57 t_error("%s symlink error link exist\n", __func__); 58 } 59 unlink(link_name); 60} 61 62int main(int argc, char *argv[]) 63{ 64 symlink_0100(); 65 symlink_0200(); 66 return t_status; 67}