yaffs More tests for quick tests.
[yaffs2.git] / direct / timothy_tests / quick_tests / test_yaffs_read_EINVAL.c
index 7e7d43ef2a0e82339bcbb5296fbb36f5a32372ec..46e11f78c2936f1e13540a6eb4ce71ab52af6327 100644 (file)
  * published by the Free Software Foundation.
  */
 
-#include "test_yaffs_read_EBADF.h"
+#include "test_yaffs_read_EINVAL.h"
 
 static int handle=0;
 
-int test_yaffs_read_EBADF(void){
+static char *file_name = NULL;
+int test_yaffs_read_EINVAL(void){
+       int error_code=0;
        handle=test_yaffs_open();
-       char text[20]="\0";
-       int output=0;
-       //printf("handle %d\n",handle);
+       char text[2000000]="\0";
+       int output=0;   
+       
+       if (handle<0){
+               printf("could not open file\n");
+               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");
+               return -1; 
+       }
+
        if (handle>=0){
-               output=yaffs_read(-1, text, FILE_TEXT_NBYTES);
-               //printf("yaffs_test_read output: %d\n",output);
-               //printf("text in file is: '%s' expected text is '%s'\n",text,FILE_TEXT);
+               output=yaffs_read(handle, text, -1);
+
                if (output<0){ 
-                       if (0==memcmp(text,FILE_TEXT,FILE_TEXT_NBYTES)){
+                       error_code=yaffs_get_error();
+                       if (abs(error_code)== EINVAL){
                                return 1;
                        }
                        else {
-                               printf("returned error does not match the the expected error\n");
+                               printf("different error than expected\n");
                                return -1;
                        }
                }
                else{
-                       printf("read a non-existing file (which is a bad thing)\n");
+                       printf("read a negative number of bytes (which is a bad thing)\n");
                        return -1;
                }
        }
@@ -45,6 +59,87 @@ int test_yaffs_read_EBADF(void){
        
 }
 
-int test_yaffs_read_EBADF_clean(void){
-       return yaffs_close(handle);
+int test_yaffs_read_EINVAL_clean(void){
+       int output=0;
+       if (handle>=0){
+               output=test_yaffs_read_EINVAL_init_clean();
+               if(output>=0){
+                       output=yaffs_close(handle);
+                       if (output>=0){
+                               return 1;
+                       } else {
+                               printf("could not close the handle\n");
+                               return -1;
+                       }
+               } else {
+                       printf("failed to fix the file\n");
+                       return -1;
+               }
+       }
+
 }
+
+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");
+               return -1;
+       }
+       
+       strcat(file_name,YAFFS_MOUNT_POINT);
+       for (x=strlen(YAFFS_MOUNT_POINT); x<file_name_length -1; x++){
+               file_name[x]='a';
+       }
+       file_name[file_name_length-2]='\0';
+
+
+
+       if (handle>=0){
+               output= yaffs_write(handle, file_name, file_name_length-1);
+               if (output<0){
+                       printf("could not write text to file\n");
+                       return -1;
+               } else {
+                       
+                       return 1;
+               }
+
+       } else {
+               printf("error opening file\n");
+               return -1;
+       }
+       
+}
+
+int test_yaffs_read_EINVAL_init_clean(void)
+{
+       int output=1;
+       if(file_name){
+               free(file_name);
+               file_name = NULL;
+       }
+
+       
+       output= yaffs_truncate(FILE_PATH,FILE_SIZE );   
+       if (output>=0){
+               output=test_yaffs_write();
+               if (output>=0){
+                       return 1;
+               } else {
+                       printf("failed to write to file\n");
+                       return -1;
+               }
+       } else {
+               printf("failed to truncate file\n");
+               return -1;
+       }
+
+}
+