yaffs Have revised and checked each test in quick tests.
[yaffs2.git] / direct / timothy_tests / quick_tests / test_yaffs_read_EINVAL.c
index 46e11f78c2936f1e13540a6eb4ce71ab52af6327..e3ce96667c53ac0113d892cb88f4ee3752c9515e 100644 (file)
 
 #include "test_yaffs_read_EINVAL.h"
 
-static int handle=0;
-
+static int handle = -1;
 static char *file_name = NULL;
-int test_yaffs_read_EINVAL(void){
-       int error_code=0;
+
+int test_yaffs_read_EINVAL(void)
+{
+       int error_code = 0;
        handle=test_yaffs_open();
        char text[2000000]="\0";
        int output=0;   
        
        if (handle<0){
-               printf("could not open file\n");
+               print_message("could not open file\n",2);
                return -1;
        }       
 
        /*there needs a large amout of test in the file in order to trigger EINVAL */
        output=test_yaffs_read_EINVAL_init();
        if (output<0){
-               printf("could not write text to the file\n");
+               print_message("could not write text to the file\n",2);
                return -1; 
        }
 
        if (handle>=0){
                output=yaffs_read(handle, text, -1);
-
                if (output<0){ 
                        error_code=yaffs_get_error();
                        if (abs(error_code)== EINVAL){
                                return 1;
-                       }
-                       else {
-                               printf("different error than expected\n");
+                       } else {
+                               print_message("different error than expected\n",2);
                                return -1;
                        }
-               }
-               else{
-                       printf("read a negative number of bytes (which is a bad thing)\n");
+               } else{
+                       print_message("read a negative number of bytes (which is a bad thing)\n",2);
                        return -1;
                }
-       }
-       else {
-               printf("error opening file\n");
+       } else {
+               print_message("error opening file\n",2);
                return -1;
        }
-       
 }
 
-int test_yaffs_read_EINVAL_clean(void){
+int test_yaffs_read_EINVAL_clean(void)
+{
        int output=0;
        if (handle>=0){
                output=test_yaffs_read_EINVAL_init_clean();
@@ -68,28 +65,28 @@ int test_yaffs_read_EINVAL_clean(void){
                        if (output>=0){
                                return 1;
                        } else {
-                               printf("could not close the handle\n");
+                               print_message("could not close the handle\n",2);
                                return -1;
                        }
                } else {
-                       printf("failed to fix the file\n");
+                       print_message("failed to fix the file\n",2);
                        return -1;
                }
+       } else {
+               print_message("no open handle\n",2);
        }
-
 }
 
 int test_yaffs_read_EINVAL_init(void)
 {
        int output=0;
-       int error_code=0;
        int x=0;
        
        int file_name_length=1000000;
 
        file_name = malloc(file_name_length);
        if(!file_name){
-               printf("unable to create file text\n");
+               print_message("unable to create file text\n",2);
                return -1;
        }
        
@@ -104,7 +101,7 @@ int test_yaffs_read_EINVAL_init(void)
        if (handle>=0){
                output= yaffs_write(handle, file_name, file_name_length-1);
                if (output<0){
-                       printf("could not write text to file\n");
+                       print_message("could not write text to file\n",2);
                        return -1;
                } else {
                        
@@ -112,7 +109,7 @@ int test_yaffs_read_EINVAL_init(void)
                }
 
        } else {
-               printf("error opening file\n");
+               print_message("error opening file\n",2);
                return -1;
        }
        
@@ -133,11 +130,11 @@ int test_yaffs_read_EINVAL_init_clean(void)
                if (output>=0){
                        return 1;
                } else {
-                       printf("failed to write to file\n");
+                       print_message("failed to write to file\n",2);
                        return -1;
                }
        } else {
-               printf("failed to truncate file\n");
+               print_message("failed to truncate file\n",2);
                return -1;
        }