@@ -55,34 +55,52 @@ fn escape_namespace_root() {
5555}
5656
5757fn iterating ( location : Location ) {
58- client:: get ( |client| {
59- syscall ! ( client. write_file(
60- location,
61- PathBuf :: from( "foo" ) ,
62- Bytes :: from_slice( b"foo" ) . unwrap( ) ,
63- None
64- ) ) ;
65- syscall ! ( client. write_file(
66- location,
67- PathBuf :: from( "bar" ) ,
68- Bytes :: from_slice( b"bar" ) . unwrap( ) ,
69- None
70- ) ) ;
71- let first_entry = syscall ! ( client. read_dir_first( location, PathBuf :: from( "" ) , None ) )
72- . entry
73- . unwrap ( ) ;
74- assert_eq ! ( first_entry. file_name( ) , "bar" ) ;
58+ for count in [ 0 , 1 , 10 , 20 ] {
59+ let files: Vec < _ > = ( 0 ..count) . map ( |i| format ! ( "file{i:04}" ) ) . collect ( ) ;
60+ client:: get ( |client| {
61+ // Setup filesystem
62+ for file in & files {
63+ syscall ! ( client. write_file(
64+ location,
65+ PathBuf :: from( & * * file) ,
66+ Bytes :: from_slice( file. as_bytes( ) ) . unwrap( ) ,
67+ None
68+ ) ) ;
69+ }
70+
71+ // Iteration over entries (filenames)
72+ for i in 0 ..count {
73+ if let Some ( f) = files. get ( i) {
74+ let entry = syscall ! ( client. read_dir_nth( location, PathBuf :: new( ) , i) )
75+ . entry
76+ . unwrap ( ) ;
77+ assert_eq ! ( entry. path( ) . as_ref( ) , f) ;
78+ }
79+
80+ for j in i + 1 ..count {
81+ let entry = syscall ! ( client. read_dir_next( ) ) . entry . unwrap ( ) ;
82+ assert_eq ! ( entry. path( ) . as_ref( ) , & files[ j] ) ;
83+ }
84+ assert ! ( syscall!( client. read_dir_next( ) ) . entry. is_none( ) ) ;
85+ }
7586
76- let next_entry = syscall ! ( client. read_dir_next( ) ) . entry . unwrap ( ) ;
77- assert_eq ! ( next_entry. file_name( ) , "foo" ) ;
87+ for i in 0 ..count {
88+ if let Some ( f) = files. get ( i) {
89+ let data =
90+ syscall ! ( client. read_dir_files_nth( location, PathBuf :: new( ) , i, None ) )
91+ . data
92+ . unwrap ( ) ;
93+ assert_eq ! ( data, f. as_bytes( ) ) ;
94+ }
7895
79- let first_data = syscall ! ( client. read_dir_files_first( location, PathBuf :: from( "" ) , None ) )
80- . data
81- . unwrap ( ) ;
82- assert_eq ! ( first_data, b"bar" ) ;
83- let next_data = syscall ! ( client. read_dir_files_next( ) ) . data . unwrap ( ) ;
84- assert_eq ! ( next_data, b"foo" ) ;
85- } ) ;
96+ for j in i + 1 ..count {
97+ let data = syscall ! ( client. read_dir_files_next( ) ) . data . unwrap ( ) ;
98+ assert_eq ! ( data, files[ j] . as_bytes( ) ) ;
99+ }
100+ assert ! ( syscall!( client. read_dir_files_next( ) ) . data. is_none( ) ) ;
101+ }
102+ } ) ;
103+ }
86104}
87105
88106#[ test]
0 commit comments