2
2
3
3
use uefi:: boot:: ScopedProtocol ;
4
4
use uefi:: proto:: shell:: Shell ;
5
- use uefi:: { Error , Status , boot, cstr16, CStr16 } ;
5
+ use uefi:: { Error , Status , boot, cstr16} ;
6
6
7
7
/// Test `current_dir()` and `set_current_dir()`
8
8
pub fn test_current_dir ( shell : & ScopedProtocol < Shell > ) {
@@ -100,27 +100,20 @@ pub fn test_current_dir(shell: &ScopedProtocol<Shell>) {
100
100
assert_eq ! ( cur_fs_str, expected_fs_str) ;
101
101
}
102
102
103
- /// Test `` get_env()`` , `` get_envs()`` , and `` set_env()` `
103
+ /// Test `get_env()`, `get_envs()`, and `set_env()`
104
104
pub fn test_env ( shell : & ScopedProtocol < Shell > ) {
105
- let mut test_buf = [ 0u16 ; 128 ] ;
106
-
107
105
/* 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" ) , ) ;
108
110
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 ( ) ;
118
112
119
113
/* 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" ) ;
124
117
assert ! ( shell. get_env( test_var) . is_none( ) ) ;
125
118
let status = shell. set_env ( test_var, test_val, false ) ;
126
119
assert_eq ! ( status, Status :: SUCCESS ) ;
@@ -129,20 +122,41 @@ pub fn test_env(shell: &ScopedProtocol<Shell>) {
129
122
. expect ( "Could not get environment variable" ) ;
130
123
assert_eq ! ( cur_env_str, test_val) ;
131
124
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
+
133
141
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 ) ;
136
143
137
144
/* Test deleting environment variable */
138
- let test_val = CStr16 :: from_str_with_buf ( "" , & mut test_val_buf ) . unwrap ( ) ;
145
+ let test_val = cstr16 ! ( "" ) ;
139
146
let status = shell. set_env ( test_var, test_val, false ) ;
140
147
assert_eq ! ( status, Status :: SUCCESS ) ;
141
148
assert ! ( shell. get_env( test_var) . is_none( ) ) ;
142
149
143
150
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) ;
146
160
}
147
161
148
162
pub fn test ( ) {
0 commit comments