@@ -99,8 +99,32 @@ main(int argc, char **argv)
9999 assert (ftell (file ) == strlen (FILE_TEXT ));
100100 printf ("[Test] Reading at specified offset passed.\n" );
101101
102+ // Test: moving at the start of the file (fseek)
103+ printf ("Move at the start of the file (fseek)..\n" );
104+ printf ("File current offset: %ld\n" , ftell (file ));
105+ fseek (file , 0 , SEEK_SET );
106+ printf ("File current offset: %ld\n" , ftell (file ));
107+ assert (ftell (file ) == 0 );
108+
109+ // Test: moving at the end of the file (fseek)
110+ printf ("Move at the end of the file (fseek)..\n" );
111+ printf ("File current offset: %ld\n" , ftell (file ));
112+ fseek (file , 0 , SEEK_END );
113+ printf ("File current offset: %ld\n" , ftell (file ));
114+ assert (ftell (file ) == strlen (FILE_TEXT ));
115+ int end_position = ftell (file ) / 2 ;
116+
117+ // Test: moving at the middle of the file (fseek)
118+ printf ("Move at the middle of the file (fseek)..\n" );
119+ printf ("File current offset: %ld\n" , ftell (file ));
120+ fseek (file , 0 , SEEK_SET );
121+ fseek (file , end_position , SEEK_CUR );
122+ printf ("File current offset: %ld\n" , ftell (file ));
123+ assert (ftell (file ) == end_position );
124+
102125 // Test: allocate more space to the file (posix_fallocate)
103126 printf ("Allocate more space to the file (posix_fallocate)..\n" );
127+ fseek (file , 0 , SEEK_END );
104128 posix_fallocate (fileno (file ), ftell (file ), ADDITIONAL_SPACE );
105129 printf ("File current offset: %ld\n" , ftell (file ));
106130 printf ("Moving to the end..\n" );
@@ -120,23 +144,15 @@ main(int argc, char **argv)
120144 assert (ftell (file ) == strlen (text ) + 2 * ADDITIONAL_SPACE );
121145 printf ("[Test] Extension of the file size passed.\n" );
122146
123- // Test: allocate more space to the file (fseek)
147+ // Test: allocate more space to the file (fseek, from the start )
124148 printf ("Allocate more space to the file (fseek) from the start..\n" );
125149 printf ("File current offset: %ld\n" , ftell (file ));
126150 fseek (file , 3 * ADDITIONAL_SPACE , SEEK_SET );
127151 printf ("File current offset: %ld\n" , ftell (file ));
128152 assert (ftell (file ) == 3 * ADDITIONAL_SPACE );
129153 printf ("[Test] Extension of the file size passed.\n" );
130154
131- // Test: allocate more space to the file (fseek)
132- printf ("Allocate more space to the file (fseek) from the end..\n" );
133- printf ("File current offset: %ld\n" , ftell (file ));
134- fseek (file , ADDITIONAL_SPACE , SEEK_END );
135- printf ("File current offset: %ld\n" , ftell (file ));
136- assert (ftell (file ) == 4 * ADDITIONAL_SPACE );
137- printf ("[Test] Extension of the file size passed.\n" );
138-
139- // Test: allocate more space to the file (fseek)
155+ // Test: allocate more space to the file (fseek, from the middle)
140156 printf ("Allocate more space to the file (fseek) from the middle..\n" );
141157 fseek (file , 3 * ADDITIONAL_SPACE , SEEK_SET );
142158 printf ("File current offset: %ld\n" , ftell (file ));
0 commit comments