]> git.donarmstrong.com Git - biopieces.git/blob - code_c/Maasha/src/test/test_filesys.c
update of c libs
[biopieces.git] / code_c / Maasha / src / test / test_filesys.c
1 #include "common.h"
2 #include "filesys.h"
3 #include <errno.h>
4
5 static void test_read_open();
6 static void test_write_open();
7 static void test_append_open();
8 static void test_close_stream();
9 static void test_file_read();
10 static void test_file_unlink();
11 static void test_file_rename();
12
13
14 int main()
15 {
16     fprintf( stderr, "Running all tests for filesys.c\n" );
17
18     test_read_open();
19     test_write_open();
20     test_append_open();
21     test_close_stream();
22     test_file_read();
23     test_file_unlink();
24     test_file_rename();
25
26     fprintf( stderr, "Done\n\n" );
27
28     return EXIT_SUCCESS;
29 }
30
31
32 void test_read_open()
33 {
34     FILE *fp;
35
36     fprintf( stderr, "   Testing read_open ... " );
37
38     // fp = read_open( "/tmp/asdf" );
39     // fp = read_open( "/private/etc/ssh_host_rsa_key" );
40     fp = read_open( "/dev/null" );
41
42     close_stream( fp );
43
44     fprintf( stderr, "OK\n" );
45 }
46
47
48 void test_write_open()
49 {
50     FILE *fp;
51
52     fprintf( stderr, "   Testing write_open ... " );
53
54     // fp = write_open( "/tmp/asdf" );
55     // fp = write_open( "/private/etc/ssh_host_rsa_key" );
56     fp = write_open( "/dev/null" );
57
58     close_stream( fp );
59
60     fprintf( stderr, "OK\n" );
61 }
62
63
64 void test_append_open()
65 {
66     FILE *fp;
67
68     fprintf( stderr, "   Testing append_open ... " );
69
70     //fp = append_open( "/tmp/asdf" );
71     //fp = append_open( "/private/etc/ssh_host_rsa_key" );
72     fp = append_open( "/dev/null" );
73
74     close_stream( fp );
75
76     fprintf( stderr, "OK\n" );
77 }
78
79
80 void test_close_stream()
81 {
82     FILE *fp;
83
84     fprintf( stderr, "   Testing close_stream ... " );
85
86     fp = read_open( "/dev/null" );
87
88     close_stream( fp );
89
90     fprintf( stderr, "OK\n" );
91 }
92
93
94 void test_file_read()
95 {
96     char   *test_file = "/etc/passwd";
97     char   *buffer;
98     FILE   *fp;
99     size_t  len = 1000;
100
101     fprintf( stderr, "   Testing file_read ... " );
102
103     fp = read_open( test_file );
104
105     buffer = file_read( fp, len );
106
107     close_stream( fp );
108
109     assert( strlen( buffer ) == len );
110     assert( buffer[ len ] == '\0' );
111
112     fprintf( stderr, "OK\n" );
113 }
114
115
116 void test_file_unlink()
117 {
118     char *test_file = "/tmp/test";
119     FILE *fp;
120
121     fprintf( stderr, "   Testing file_unlink ... " );
122
123     fp = write_open( test_file );
124
125     close_stream( fp );
126
127     //file_unlink( "" );
128     //file_unlink( "/dev/null" );
129     //file_unlink( "/tmp/" );
130     //file_unlink( "/private/etc/ssh_host_rsa_key" );
131     file_unlink( test_file );
132
133     fprintf( stderr, "OK\n" );
134 }
135
136
137 void test_file_rename()
138 {
139     char *file_before = "/tmp/before";
140     char *file_after  = "/tmp/after";
141
142     FILE *fp;
143
144     fprintf( stderr, "   Testing file_rename ... " );
145     
146     fp = write_open( file_before );
147
148     close_stream( fp );
149
150     //file_rename( file_after, file_after );
151     file_rename( file_before, file_before );
152     file_rename( file_before, file_after );
153
154     //file_unlink( file_before );
155     file_unlink( file_after );
156
157     fprintf( stderr, "OK\n" );
158 }