Merge branch 'quick_tests'
[yaffs2.git] / direct / timothy_tests / quick_tests / test_yaffs_rename_EEXISTS.c
1 /*
2  * YAFFS: Yet another FFS. A NAND-flash specific file system.
3  *
4  * Copyright (C) 2002-2010 Aleph One Ltd.
5  *   for Toby Churchill Ltd and Brightstar Engineering
6  *
7  * Created by Timothy Manning <timothy@yaffs.net>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2 as
11  * published by the Free Software Foundation.
12  */
13
14 #include "test_yaffs_rename_EEXISTS.h"
15
16
17 int test_yaffs_rename_EEXISTS(void)
18 {
19         int output=0;
20         int error_code =0;
21
22         if (0 !=  yaffs_access(DIR_PATH,0)) {
23                 output = yaffs_mkdir(DIR_PATH,S_IWRITE | S_IREAD);
24                 if (output < 0) {
25                         print_message("failed to create directory\n",2);
26                         return -1;
27                 }
28         }
29         if (0 !=  yaffs_access(RENAME_DIR_PATH,0)) {
30                 output = yaffs_mkdir(RENAME_DIR_PATH,S_IWRITE | S_IREAD);
31                 if (output < 0) {
32                         error_code=yaffs_get_error();
33                         if (abs(error_code)!=EEXIST){
34                                 print_message("failed to create second directory\n",2);
35                                 return -1;
36                         }
37                 }
38         }
39         output= yaffs_open("/yaffs2/dir2/file",O_CREAT | O_RDWR, FILE_MODE);
40         if (output<0){
41                 print_message("failed to open file in the second directory\n",2);
42                 return -1;
43         }
44         output = yaffs_rename(DIR_PATH , RENAME_DIR_PATH);
45         if (output<0){ 
46                 error_code=yaffs_get_error();
47                 if (abs(error_code)==ENOTEMPTY){
48                         return 1;
49                 } else {
50                         print_message("returned error does not match the the expected error\n",2);
51                         return -1;
52                 }
53         } else{
54                 print_message("removed /yaffs2/ directory (which is a bad thing)\n",2);
55                 return -1;
56         }       
57 }
58
59
60 int test_yaffs_rename_EEXISTS_clean(void)
61 {
62         int output = 0;
63         if (0 ==  yaffs_access("/yaffs2/dir2/file",0) ) {
64                 output = yaffs_unlink("/yaffs2/dir2/file");
65                 if (output < 0) {
66                         print_message("failed to remove the file\n",2);
67                         return -1;
68                 }
69         }
70         if (0 ==  yaffs_access(RENAME_PATH,0) && 0 != yaffs_access(DIR_PATH,0)) {
71                 output = yaffs_rename(RENAME_PATH,FILE_PATH);
72                 if (output < 0) {
73                         print_message("failed to remove the directory\n",2);
74                         return -1;
75                 }
76         }
77         
78         return 1;
79
80 }
81