33use uefi:: boot:: ScopedProtocol ;
44use uefi:: proto:: shell:: Shell ;
55use uefi:: { boot, cstr16} ;
6- use uefi_raw:: Status ;
7-
8- /// Test `get_env()`, `get_envs()`, and `set_env()`
9- pub fn test_env ( shell : & ScopedProtocol < Shell > ) {
10- /* Test retrieving list of environment variable names */
11- let mut cur_env_vec = shell. get_envs ( ) ;
12- assert_eq ! ( cur_env_vec. next( ) . unwrap( ) , cstr16!( "path" ) , ) ;
13- // check pre-defined shell variables; see UEFI Shell spec
14- assert_eq ! ( cur_env_vec. next( ) . unwrap( ) , cstr16!( "nonesting" ) , ) ;
15- let cur_env_vec = shell. get_envs ( ) ;
16- let default_len = cur_env_vec. count ( ) ;
17-
18- /* Test setting and getting a specific environment variable */
19- let cur_env_vec = shell. get_envs ( ) ;
20- let test_var = cstr16 ! ( "test_var" ) ;
21- let test_val = cstr16 ! ( "test_val" ) ;
22- assert ! ( shell. get_env( test_var) . is_none( ) ) ;
23- let status = shell. set_env ( test_var, test_val, false ) ;
24- assert_eq ! ( status, Status :: SUCCESS ) ;
25- let cur_env_str = shell
26- . get_env ( test_var)
27- . expect ( "Could not get environment variable" ) ;
28- assert_eq ! ( cur_env_str, test_val) ;
29-
30- let mut found_var = false ;
31- for env_var in cur_env_vec {
32- if env_var == test_var {
33- found_var = true ;
34- }
35- }
36- assert ! ( !found_var) ;
37- let cur_env_vec = shell. get_envs ( ) ;
38- let mut found_var = false ;
39- for env_var in cur_env_vec {
40- if env_var == test_var {
41- found_var = true ;
42- }
43- }
44- assert ! ( found_var) ;
45-
46- let cur_env_vec = shell. get_envs ( ) ;
47- assert_eq ! ( cur_env_vec. count( ) , default_len + 1 ) ;
48-
49- /* Test deleting environment variable */
50- let test_val = cstr16 ! ( "" ) ;
51- let status = shell. set_env ( test_var, test_val, false ) ;
52- assert_eq ! ( status, Status :: SUCCESS ) ;
53- assert ! ( shell. get_env( test_var) . is_none( ) ) ;
54-
55- let cur_env_vec = shell. get_envs ( ) ;
56- let mut found_var = false ;
57- for env_var in cur_env_vec {
58- if env_var == test_var {
59- found_var = true ;
60- }
61- }
62- assert ! ( !found_var) ;
63- let cur_env_vec = shell. get_envs ( ) ;
64- assert_eq ! ( cur_env_vec. count( ) , default_len) ;
65- }
666
67- /// Test `get_cur_dir ()` and `set_cur_dir ()`
7+ /// Test `current_dir ()` and `set_current_dir ()`
688pub fn test_cur_dir ( shell : & ScopedProtocol < Shell > ) {
699 /* Test setting and getting current file system and current directory */
7010 let fs_var = cstr16 ! ( "fs0:" ) ;
7111 let dir_var = cstr16 ! ( "/" ) ;
72- let status = shell. set_cur_dir ( Some ( fs_var) , Some ( dir_var) ) ;
73- assert_eq ! ( status, Status :: SUCCESS ) ;
12+ let status = shell. set_current_dir ( Some ( fs_var) , Some ( dir_var) ) ;
13+ assert ! ( status. is_ok ( ) ) ;
7414
7515 let cur_fs_str = shell
76- . get_cur_dir ( Some ( fs_var) )
16+ . current_dir ( Some ( fs_var) )
7717 . expect ( "Could not get the current file system mapping" ) ;
7818 let expected_fs_str = cstr16 ! ( "FS0:\\ " ) ;
7919 assert_eq ! ( cur_fs_str, expected_fs_str) ;
8020
8121 // Changing current file system
8222 let fs_var = cstr16 ! ( "fs1:" ) ;
8323 let dir_var = cstr16 ! ( "/" ) ;
84- let status = shell. set_cur_dir ( Some ( fs_var) , Some ( dir_var) ) ;
85- assert_eq ! ( status, Status :: SUCCESS ) ;
24+ let status = shell. set_current_dir ( Some ( fs_var) , Some ( dir_var) ) ;
25+ assert ! ( status. is_ok ( ) ) ;
8626
8727 let cur_fs_str = shell
88- . get_cur_dir ( Some ( fs_var) )
28+ . current_dir ( Some ( fs_var) )
8929 . expect ( "Could not get the current file system mapping" ) ;
9030 assert_ne ! ( cur_fs_str, expected_fs_str) ;
9131 let expected_fs_str = cstr16 ! ( "FS1:\\ " ) ;
@@ -94,11 +34,11 @@ pub fn test_cur_dir(shell: &ScopedProtocol<Shell>) {
9434 // Changing current file system and current directory
9535 let fs_var = cstr16 ! ( "fs0:" ) ;
9636 let dir_var = cstr16 ! ( "efi/" ) ;
97- let status = shell. set_cur_dir ( Some ( fs_var) , Some ( dir_var) ) ;
98- assert_eq ! ( status, Status :: SUCCESS ) ;
37+ let status = shell. set_current_dir ( Some ( fs_var) , Some ( dir_var) ) ;
38+ assert ! ( status. is_ok ( ) ) ;
9939
10040 let cur_fs_str = shell
101- . get_cur_dir ( Some ( fs_var) )
41+ . current_dir ( Some ( fs_var) )
10242 . expect ( "Could not get the current file system mapping" ) ;
10343 assert_ne ! ( cur_fs_str, expected_fs_str) ;
10444 let expected_fs_str = cstr16 ! ( "FS0:\\ efi" ) ;
@@ -108,50 +48,50 @@ pub fn test_cur_dir(shell: &ScopedProtocol<Shell>) {
10848
10949 // At this point, the current working file system has not been set
11050 // So we expect a NULL output
111- assert ! ( shell. get_cur_dir ( None ) . is_none( ) ) ;
51+ assert ! ( shell. current_dir ( None ) . is_none( ) ) ;
11252
11353 // Setting the current working file system and current working directory
11454 let dir_var = cstr16 ! ( "fs0:/" ) ;
115- let status = shell. set_cur_dir ( None , Some ( dir_var) ) ;
116- assert_eq ! ( status, Status :: SUCCESS ) ;
55+ let status = shell. set_current_dir ( None , Some ( dir_var) ) ;
56+ assert ! ( status. is_ok ( ) ) ;
11757 let cur_fs_str = shell
118- . get_cur_dir ( Some ( fs_var) )
58+ . current_dir ( Some ( fs_var) )
11959 . expect ( "Could not get the current file system mapping" ) ;
12060 let expected_fs_str = cstr16 ! ( "FS0:" ) ;
12161 assert_eq ! ( cur_fs_str, expected_fs_str) ;
12262
12363 let cur_fs_str = shell
124- . get_cur_dir ( None )
64+ . current_dir ( None )
12565 . expect ( "Could not get the current file system mapping" ) ;
12666 assert_eq ! ( cur_fs_str, expected_fs_str) ;
12767
12868 // Changing current working directory
12969 let dir_var = cstr16 ! ( "/efi" ) ;
130- let status = shell. set_cur_dir ( None , Some ( dir_var) ) ;
131- assert_eq ! ( status, Status :: SUCCESS ) ;
70+ let status = shell. set_current_dir ( None , Some ( dir_var) ) ;
71+ assert ! ( status. is_ok ( ) ) ;
13272 let cur_fs_str = shell
133- . get_cur_dir ( Some ( fs_var) )
73+ . current_dir ( Some ( fs_var) )
13474 . expect ( "Could not get the current file system mapping" ) ;
13575 let expected_fs_str = cstr16 ! ( "FS0:\\ efi" ) ;
13676 assert_eq ! ( cur_fs_str, expected_fs_str) ;
13777 let cur_fs_str = shell
138- . get_cur_dir ( None )
78+ . current_dir ( None )
13979 . expect ( "Could not get the current file system mapping" ) ;
14080 assert_eq ! ( cur_fs_str, expected_fs_str) ;
14181
14282 // Changing current directory in a non-current working file system
14383 let fs_var = cstr16 ! ( "fs0:" ) ;
14484 let dir_var = cstr16 ! ( "efi/tools" ) ;
145- let status = shell. set_cur_dir ( Some ( fs_var) , Some ( dir_var) ) ;
146- assert_eq ! ( status, Status :: SUCCESS ) ;
85+ let status = shell. set_current_dir ( Some ( fs_var) , Some ( dir_var) ) ;
86+ assert ! ( status. is_ok ( ) ) ;
14787 let cur_fs_str = shell
148- . get_cur_dir ( None )
88+ . current_dir ( None )
14989 . expect ( "Could not get the current file system mapping" ) ;
15090 assert_ne ! ( cur_fs_str, expected_fs_str) ;
15191
15292 let expected_fs_str = cstr16 ! ( "FS0:\\ efi\\ tools" ) ;
15393 let cur_fs_str = shell
154- . get_cur_dir ( Some ( fs_var) )
94+ . current_dir ( Some ( fs_var) )
15595 . expect ( "Could not get the current file system mapping" ) ;
15696 assert_eq ! ( cur_fs_str, expected_fs_str) ;
15797}
@@ -164,6 +104,5 @@ pub fn test() {
164104 let shell =
165105 boot:: open_protocol_exclusive :: < Shell > ( handle) . expect ( "Failed to open Shell protocol" ) ;
166106
167- test_env ( & shell) ;
168107 test_cur_dir ( & shell) ;
169108}
0 commit comments