22
33use uefi:: boot:: ScopedProtocol ;
44use uefi:: proto:: shell:: Shell ;
5- use uefi:: { Error , Status , boot, cstr16, CStr16 } ;
5+ use uefi:: { Error , Status , boot, cstr16} ;
66
77/// Test `current_dir()` and `set_current_dir()`
88pub fn test_current_dir ( shell : & ScopedProtocol < Shell > ) {
@@ -100,27 +100,20 @@ pub fn test_current_dir(shell: &ScopedProtocol<Shell>) {
100100 assert_eq ! ( cur_fs_str, expected_fs_str) ;
101101}
102102
103- /// Test `` get_env()`` , `` get_envs()`` , and `` set_env()` `
103+ /// Test `get_env()`, `get_envs()`, and `set_env()`
104104pub fn test_env ( shell : & ScopedProtocol < Shell > ) {
105- let mut test_buf = [ 0u16 ; 128 ] ;
106-
107105 /* Test retrieving list of environment variable names */
106+ let mut cur_env_vec = shell. get_envs ( ) ;
107+ assert_eq ! ( cur_env_vec. next( ) . unwrap( ) , cstr16!( "path" ) , ) ;
108+ // check pre-defined shell variables; see UEFI Shell spec
109+ assert_eq ! ( cur_env_vec. next( ) . unwrap( ) , cstr16!( "nonesting" ) , ) ;
108110 let cur_env_vec = shell. get_envs ( ) ;
109- assert_eq ! (
110- * cur_env_vec. first( ) . unwrap( ) ,
111- CStr16 :: from_str_with_buf( "path" , & mut test_buf) . unwrap( )
112- ) ;
113- assert_eq ! (
114- * cur_env_vec. get( 1 ) . unwrap( ) ,
115- CStr16 :: from_str_with_buf( "nonesting" , & mut test_buf) . unwrap( )
116- ) ;
117- let default_len = cur_env_vec. len ( ) ;
111+ let default_len = cur_env_vec. count ( ) ;
118112
119113 /* Test setting and getting a specific environment variable */
120- let mut test_env_buf = [ 0u16 ; 32 ] ;
121- let test_var = CStr16 :: from_str_with_buf ( "test_var" , & mut test_env_buf) . unwrap ( ) ;
122- let mut test_val_buf = [ 0u16 ; 32 ] ;
123- let test_val = CStr16 :: from_str_with_buf ( "test_val" , & mut test_val_buf) . unwrap ( ) ;
114+ let cur_env_vec = shell. get_envs ( ) ;
115+ let test_var = cstr16 ! ( "test_var" ) ;
116+ let test_val = cstr16 ! ( "test_val" ) ;
124117 assert ! ( shell. get_env( test_var) . is_none( ) ) ;
125118 let status = shell. set_env ( test_var, test_val, false ) ;
126119 assert_eq ! ( status, Status :: SUCCESS ) ;
@@ -129,20 +122,41 @@ pub fn test_env(shell: &ScopedProtocol<Shell>) {
129122 . expect ( "Could not get environment variable" ) ;
130123 assert_eq ! ( cur_env_str, test_val) ;
131124
132- assert ! ( !cur_env_vec. contains( & test_var) ) ;
125+ let mut found_var = false ;
126+ for env_var in cur_env_vec {
127+ if env_var == test_var {
128+ found_var = true ;
129+ }
130+ }
131+ assert ! ( !found_var) ;
132+ let cur_env_vec = shell. get_envs ( ) ;
133+ let mut found_var = false ;
134+ for env_var in cur_env_vec {
135+ if env_var == test_var {
136+ found_var = true ;
137+ }
138+ }
139+ assert ! ( found_var) ;
140+
133141 let cur_env_vec = shell. get_envs ( ) ;
134- assert ! ( cur_env_vec. contains( & test_var) ) ;
135- assert_eq ! ( cur_env_vec. len( ) , default_len + 1 ) ;
142+ assert_eq ! ( cur_env_vec. count( ) , default_len + 1 ) ;
136143
137144 /* Test deleting environment variable */
138- let test_val = CStr16 :: from_str_with_buf ( "" , & mut test_val_buf ) . unwrap ( ) ;
145+ let test_val = cstr16 ! ( "" ) ;
139146 let status = shell. set_env ( test_var, test_val, false ) ;
140147 assert_eq ! ( status, Status :: SUCCESS ) ;
141148 assert ! ( shell. get_env( test_var) . is_none( ) ) ;
142149
143150 let cur_env_vec = shell. get_envs ( ) ;
144- assert ! ( !cur_env_vec. contains( & test_var) ) ;
145- assert_eq ! ( cur_env_vec. len( ) , default_len) ;
151+ let mut found_var = false ;
152+ for env_var in cur_env_vec {
153+ if env_var == test_var {
154+ found_var = true ;
155+ }
156+ }
157+ assert ! ( !found_var) ;
158+ let cur_env_vec = shell. get_envs ( ) ;
159+ assert_eq ! ( cur_env_vec. count( ) , default_len) ;
146160}
147161
148162pub fn test ( ) {
0 commit comments