d379944d769b4e27d61c1411b71a86edb4fd8aa0
[yaffs2.git] / direct / timothy_tests / quick_tests / test_yaffs_stat.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_stat.h"
15
16 int test_yaffs_stat(void){
17         int mode=0;
18         int size=0;
19         mode =yaffs_test_stat_mode();
20         
21         if (mode>=0){
22         
23                 if (FILE_MODE == (FILE_MODE & mode)){
24                         mode=1;
25                 }
26                 else {
27                         printf("mode did not match expected file mode\n");
28                         return -1;
29                 }
30         }
31         else {
32                 mode =-1;
33         }
34
35         size=yaffs_test_stat_size();
36         if (size >=0){
37                 if (size==FILE_SIZE){
38                         size=1;
39                 }
40                 else {
41                         printf("file size %d, expected file size %d\n",size,FILE_SIZE);
42                         printf("mode did not match expected file mode\n");
43                         return -1;
44                 }
45         }
46         else {
47                 size =-1;
48         }       
49
50
51         if ((mode>0) && (size>0)){
52                 return 1;
53         }
54         else {
55                 /* a test failed*/
56                 return -1;
57         }
58
59 }
60
61 int test_yaffs_stat_clean(void){
62         return 1;
63 }
64
65 int yaffs_test_stat_mode(void){
66         struct yaffs_stat stat;
67         int output=0;
68         output=yaffs_stat(FILE_PATH, &stat);
69         //printf("output: %d\n",output);
70         if (output>=0){
71                 return stat.st_mode;    
72         }
73         else {
74                 printf("failed to stat file mode\n") ;
75                 return -1;
76         }
77 }
78
79 int yaffs_test_stat_size(void){
80         struct yaffs_stat stat;
81         int output=0;
82         output=yaffs_stat(FILE_PATH, &stat); 
83         if (output>=0){
84                 return stat.st_size;    
85         }
86         else {
87                 printf("failed to stat file size\n") ;
88                 return -1;
89         }
90 }
91
92