@@ -5,14 +5,12 @@ use uefi::proto::shell::Shell;
5
5
use uefi:: { CStr16 , boot} ;
6
6
use uefi_raw:: Status ;
7
7
8
- /// Test ``get_env()`` and ``set_env()``
8
+ /// Test ``get_env()``, ``get_envs()``, and ``set_env()``
9
9
pub fn test_env ( shell : & ScopedProtocol < Shell > ) {
10
10
let mut test_buf = [ 0u16 ; 128 ] ;
11
11
12
- /* Test retrieving list of environment variable names (null input) */
13
- let cur_env_vec = shell
14
- . get_env ( None )
15
- . expect ( "Could not get environment variable" ) ;
12
+ /* Test retrieving list of environment variable names */
13
+ let cur_env_vec = shell. get_envs ( ) ;
16
14
assert_eq ! (
17
15
* cur_env_vec. first( ) . unwrap( ) ,
18
16
CStr16 :: from_str_with_buf( "path" , & mut test_buf) . unwrap( )
@@ -21,27 +19,35 @@ pub fn test_env(shell: &ScopedProtocol<Shell>) {
21
19
* cur_env_vec. get( 1 ) . unwrap( ) ,
22
20
CStr16 :: from_str_with_buf( "nonesting" , & mut test_buf) . unwrap( )
23
21
) ;
22
+ let default_len = cur_env_vec. len ( ) ;
24
23
25
24
/* Test setting and getting a specific environment variable */
26
25
let mut test_env_buf = [ 0u16 ; 32 ] ;
27
26
let test_var = CStr16 :: from_str_with_buf ( "test_var" , & mut test_env_buf) . unwrap ( ) ;
28
27
let mut test_val_buf = [ 0u16 ; 32 ] ;
29
28
let test_val = CStr16 :: from_str_with_buf ( "test_val" , & mut test_val_buf) . unwrap ( ) ;
30
- assert ! ( shell. get_env( Some ( test_var) ) . is_none( ) ) ;
29
+ assert ! ( shell. get_env( test_var) . is_none( ) ) ;
31
30
let status = shell. set_env ( test_var, test_val, false ) ;
32
31
assert_eq ! ( status, Status :: SUCCESS ) ;
33
- let cur_env_str = * shell
34
- . get_env ( Some ( test_var) )
35
- . expect ( "Could not get environment variable" )
36
- . first ( )
37
- . unwrap ( ) ;
32
+ let cur_env_str = shell
33
+ . get_env ( test_var)
34
+ . expect ( "Could not get environment variable" ) ;
38
35
assert_eq ! ( cur_env_str, test_val) ;
39
36
37
+ assert ! ( !cur_env_vec. contains( & test_var) ) ;
38
+ let cur_env_vec = shell. get_envs ( ) ;
39
+ assert ! ( cur_env_vec. contains( & test_var) ) ;
40
+ assert_eq ! ( cur_env_vec. len( ) , default_len + 1 ) ;
41
+
40
42
/* Test deleting environment variable */
41
43
let test_val = CStr16 :: from_str_with_buf ( "" , & mut test_val_buf) . unwrap ( ) ;
42
44
let status = shell. set_env ( test_var, test_val, false ) ;
43
45
assert_eq ! ( status, Status :: SUCCESS ) ;
44
- assert ! ( shell. get_env( Some ( test_var) ) . is_none( ) ) ;
46
+ assert ! ( shell. get_env( test_var) . is_none( ) ) ;
47
+
48
+ let cur_env_vec = shell. get_envs ( ) ;
49
+ assert ! ( !cur_env_vec. contains( & test_var) ) ;
50
+ assert_eq ! ( cur_env_vec. len( ) , default_len) ;
45
51
}
46
52
47
53
/// Test ``get_cur_dir()`` and ``set_cur_dir()``
0 commit comments