+#include "common.h"
+#include "filesys.h"
+#include <errno.h>
+
+static void test_read_open();
+static void test_write_open();
+static void test_append_open();
+static void test_close_stream();
+static void test_file_read();
+static void test_file_unlink();
+static void test_file_rename();
+
+
+int main()
+{
+ fprintf( stderr, "Running all tests for filesys.c\n" );
+
+ test_read_open();
+ test_write_open();
+ test_append_open();
+ test_close_stream();
+ test_file_read();
+ test_file_unlink();
+ test_file_rename();
+
+ fprintf( stderr, "Done\n\n" );
+
+ return EXIT_SUCCESS;
+}
+
+
+void test_read_open()
+{
+ FILE *fp;
+
+ fprintf( stderr, " Testing read_open ... " );
+
+ // fp = read_open( "/tmp/asdf" );
+ // fp = read_open( "/private/etc/ssh_host_rsa_key" );
+ fp = read_open( "/dev/null" );
+
+ close_stream( fp );
+
+ fprintf( stderr, "OK\n" );
+}
+
+
+void test_write_open()
+{
+ FILE *fp;
+
+ fprintf( stderr, " Testing write_open ... " );
+
+ // fp = write_open( "/tmp/asdf" );
+ // fp = write_open( "/private/etc/ssh_host_rsa_key" );
+ fp = write_open( "/dev/null" );
+
+ close_stream( fp );
+
+ fprintf( stderr, "OK\n" );
+}
+
+
+void test_append_open()
+{
+ FILE *fp;
+
+ fprintf( stderr, " Testing append_open ... " );
+
+ //fp = append_open( "/tmp/asdf" );
+ //fp = append_open( "/private/etc/ssh_host_rsa_key" );
+ fp = append_open( "/dev/null" );
+
+ close_stream( fp );
+
+ fprintf( stderr, "OK\n" );
+}
+
+
+void test_close_stream()
+{
+ FILE *fp;
+
+ fprintf( stderr, " Testing close_stream ... " );
+
+ fp = read_open( "/dev/null" );
+
+ close_stream( fp );
+
+ fprintf( stderr, "OK\n" );
+}
+
+
+void test_file_read()
+{
+ char *test_file = "/etc/passwd";
+ char *buffer;
+ FILE *fp;
+ size_t len = 1000;
+
+ fprintf( stderr, " Testing file_read ... " );
+
+ fp = read_open( test_file );
+
+ buffer = file_read( fp, len );
+
+ close_stream( fp );
+
+ assert( strlen( buffer ) == len );
+ assert( buffer[ len ] == '\0' );
+
+ fprintf( stderr, "OK\n" );
+}
+
+
+void test_file_unlink()
+{
+ char *test_file = "/tmp/test";
+ FILE *fp;
+
+ fprintf( stderr, " Testing file_unlink ... " );
+
+ fp = write_open( test_file );
+
+ close_stream( fp );
+
+ //file_unlink( "" );
+ //file_unlink( "/dev/null" );
+ //file_unlink( "/tmp/" );
+ //file_unlink( "/private/etc/ssh_host_rsa_key" );
+ file_unlink( test_file );
+
+ fprintf( stderr, "OK\n" );
+}
+
+
+void test_file_rename()
+{
+ char *file_before = "/tmp/before";
+ char *file_after = "/tmp/after";
+
+ FILE *fp;
+
+ fprintf( stderr, " Testing file_rename ... " );
+
+ fp = write_open( file_before );
+
+ close_stream( fp );
+
+ //file_rename( file_after, file_after );
+ file_rename( file_before, file_before );
+ file_rename( file_before, file_after );
+
+ //file_unlink( file_before );
+ file_unlink( file_after );
+
+ fprintf( stderr, "OK\n" );
+}