Merge branch 'quick_tests'
[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 {
18         char message[100];
19         int mode=0;
20         int size=0;
21         message[0]='\0';
22
23         mode =yaffs_test_stat_mode();   
24         if (mode>=0){
25                 if (FILE_MODE == (FILE_MODE & mode)){
26                         mode=1;
27                 } else {
28                         print_message("mode did not match expected file mode\n",2);
29                         return -1;
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                 } else {
40                         sprintf(message,"file size %d, expected file size %d\n",size,FILE_SIZE);
41                         print_message(message,2);
42                         print_message("mode did not match expected file mode\n",2);
43                         return -1;
44                 }
45         } else {
46                 size =-1;
47         }       
48
49
50         if ((mode>0) && (size>0)){
51                 return 1;
52         } else {
53                 /* one of the tests failed*/
54                 return -1;
55         }
56 }
57
58 int test_yaffs_stat_clean(void)
59 {
60         return 1;
61 }
62
63 int yaffs_test_stat_mode(void)
64 {
65         struct yaffs_stat stat;
66         int output=0;
67         output=yaffs_stat(FILE_PATH, &stat);
68         //printf("output: %d\n",output);
69         if (output>=0){
70                 return stat.st_mode;    
71         } else {
72                 print_message("failed to stat file mode\n",2) ;
73                 return -1;
74         }
75 }
76
77 int yaffs_test_stat_size(void){
78         struct yaffs_stat stat;
79         int output=0;
80         output=yaffs_stat(FILE_PATH, &stat); 
81         if (output>=0){
82                 return stat.st_size;    
83         } else {
84                 print_message("failed to stat file size\n",2) ;
85                 return -1;
86         }
87 }
88
89