2
2
3
3
use uefi:: boot:: ScopedProtocol ;
4
4
use uefi:: proto:: shell:: Shell ;
5
- use uefi:: { CStr16 , boot } ;
5
+ use uefi:: { boot , cstr16 } ;
6
6
use uefi_raw:: Status ;
7
7
8
- /// Test `` get_env()`` , `` get_envs()`` , and `` set_env()` `
8
+ /// Test `get_env()`, `get_envs()`, and `set_env()`
9
9
pub fn test_env ( shell : & ScopedProtocol < Shell > ) {
10
- let mut test_buf = [ 0u16 ; 128 ] ;
11
-
12
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" ) , ) ;
13
15
let cur_env_vec = shell. get_envs ( ) ;
14
- assert_eq ! (
15
- * cur_env_vec. first( ) . unwrap( ) ,
16
- CStr16 :: from_str_with_buf( "path" , & mut test_buf) . unwrap( )
17
- ) ;
18
- assert_eq ! (
19
- * cur_env_vec. get( 1 ) . unwrap( ) ,
20
- CStr16 :: from_str_with_buf( "nonesting" , & mut test_buf) . unwrap( )
21
- ) ;
22
- let default_len = cur_env_vec. len ( ) ;
16
+ let default_len = cur_env_vec. count ( ) ;
23
17
24
18
/* Test setting and getting a specific environment variable */
25
- let mut test_env_buf = [ 0u16 ; 32 ] ;
26
- let test_var = CStr16 :: from_str_with_buf ( "test_var" , & mut test_env_buf) . unwrap ( ) ;
27
- let mut test_val_buf = [ 0u16 ; 32 ] ;
28
- let test_val = CStr16 :: from_str_with_buf ( "test_val" , & mut test_val_buf) . unwrap ( ) ;
19
+ let cur_env_vec = shell. get_envs ( ) ;
20
+ let test_var = cstr16 ! ( "test_var" ) ;
21
+ let test_val = cstr16 ! ( "test_val" ) ;
29
22
assert ! ( shell. get_env( test_var) . is_none( ) ) ;
30
23
let status = shell. set_env ( test_var, test_val, false ) ;
31
24
assert_eq ! ( status, Status :: SUCCESS ) ;
@@ -34,64 +27,81 @@ pub fn test_env(shell: &ScopedProtocol<Shell>) {
34
27
. expect ( "Could not get environment variable" ) ;
35
28
assert_eq ! ( cur_env_str, test_val) ;
36
29
37
- assert ! ( !cur_env_vec. contains( & test_var) ) ;
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
+
38
46
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 ) ;
47
+ assert_eq ! ( cur_env_vec. count( ) , default_len + 1 ) ;
41
48
42
49
/* Test deleting environment variable */
43
- let test_val = CStr16 :: from_str_with_buf ( "" , & mut test_val_buf ) . unwrap ( ) ;
50
+ let test_val = cstr16 ! ( "" ) ;
44
51
let status = shell. set_env ( test_var, test_val, false ) ;
45
52
assert_eq ! ( status, Status :: SUCCESS ) ;
46
53
assert ! ( shell. get_env( test_var) . is_none( ) ) ;
47
54
48
55
let cur_env_vec = shell. get_envs ( ) ;
49
- assert ! ( !cur_env_vec. contains( & test_var) ) ;
50
- assert_eq ! ( cur_env_vec. len( ) , default_len) ;
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) ;
51
65
}
52
66
53
- /// Test `` get_cur_dir()`` and `` set_cur_dir()` `
67
+ /// Test `get_cur_dir()` and `set_cur_dir()`
54
68
pub fn test_cur_dir ( shell : & ScopedProtocol < Shell > ) {
55
- let mut test_buf = [ 0u16 ; 128 ] ;
56
-
57
69
/* Test setting and getting current file system and current directory */
58
- let mut fs_buf = [ 0u16 ; 16 ] ;
59
- let fs_var = CStr16 :: from_str_with_buf ( "fs0:" , & mut fs_buf) . unwrap ( ) ;
60
- let mut dir_buf = [ 0u16 ; 32 ] ;
61
- let dir_var = CStr16 :: from_str_with_buf ( "/" , & mut dir_buf) . unwrap ( ) ;
70
+ let fs_var = cstr16 ! ( "fs0:" ) ;
71
+ let dir_var = cstr16 ! ( "/" ) ;
62
72
let status = shell. set_cur_dir ( Some ( fs_var) , Some ( dir_var) ) ;
63
73
assert_eq ! ( status, Status :: SUCCESS ) ;
64
74
65
75
let cur_fs_str = shell
66
76
. get_cur_dir ( Some ( fs_var) )
67
77
. expect ( "Could not get the current file system mapping" ) ;
68
- let expected_fs_str = CStr16 :: from_str_with_buf ( "FS0:\\ " , & mut test_buf ) . unwrap ( ) ;
78
+ let expected_fs_str = cstr16 ! ( "FS0:\\ " ) ;
69
79
assert_eq ! ( cur_fs_str, expected_fs_str) ;
70
80
71
81
// Changing current file system
72
- let fs_var = CStr16 :: from_str_with_buf ( "fs1:" , & mut fs_buf ) . unwrap ( ) ;
73
- let dir_var = CStr16 :: from_str_with_buf ( "/" , & mut dir_buf ) . unwrap ( ) ;
82
+ let fs_var = cstr16 ! ( "fs1:" ) ;
83
+ let dir_var = cstr16 ! ( "/" ) ;
74
84
let status = shell. set_cur_dir ( Some ( fs_var) , Some ( dir_var) ) ;
75
85
assert_eq ! ( status, Status :: SUCCESS ) ;
76
86
77
87
let cur_fs_str = shell
78
88
. get_cur_dir ( Some ( fs_var) )
79
89
. expect ( "Could not get the current file system mapping" ) ;
80
90
assert_ne ! ( cur_fs_str, expected_fs_str) ;
81
- let expected_fs_str = CStr16 :: from_str_with_buf ( "FS1:\\ " , & mut test_buf ) . unwrap ( ) ;
91
+ let expected_fs_str = cstr16 ! ( "FS1:\\ " ) ;
82
92
assert_eq ! ( cur_fs_str, expected_fs_str) ;
83
93
84
94
// Changing current file system and current directory
85
- let fs_var = CStr16 :: from_str_with_buf ( "fs0:" , & mut fs_buf ) . unwrap ( ) ;
86
- let dir_var = CStr16 :: from_str_with_buf ( "efi/" , & mut dir_buf ) . unwrap ( ) ;
95
+ let fs_var = cstr16 ! ( "fs0:" ) ;
96
+ let dir_var = cstr16 ! ( "efi/" ) ;
87
97
let status = shell. set_cur_dir ( Some ( fs_var) , Some ( dir_var) ) ;
88
98
assert_eq ! ( status, Status :: SUCCESS ) ;
89
99
90
100
let cur_fs_str = shell
91
101
. get_cur_dir ( Some ( fs_var) )
92
102
. expect ( "Could not get the current file system mapping" ) ;
93
103
assert_ne ! ( cur_fs_str, expected_fs_str) ;
94
- let expected_fs_str = CStr16 :: from_str_with_buf ( "FS0:\\ efi" , & mut test_buf ) . unwrap ( ) ;
104
+ let expected_fs_str = cstr16 ! ( "FS0:\\ efi" ) ;
95
105
assert_eq ! ( cur_fs_str, expected_fs_str) ;
96
106
97
107
/* Test current working directory cases */
@@ -101,13 +111,13 @@ pub fn test_cur_dir(shell: &ScopedProtocol<Shell>) {
101
111
assert ! ( shell. get_cur_dir( None ) . is_none( ) ) ;
102
112
103
113
// Setting the current working file system and current working directory
104
- let dir_var = CStr16 :: from_str_with_buf ( "fs0:/" , & mut dir_buf ) . unwrap ( ) ;
114
+ let dir_var = cstr16 ! ( "fs0:/" ) ;
105
115
let status = shell. set_cur_dir ( None , Some ( dir_var) ) ;
106
116
assert_eq ! ( status, Status :: SUCCESS ) ;
107
117
let cur_fs_str = shell
108
118
. get_cur_dir ( Some ( fs_var) )
109
119
. expect ( "Could not get the current file system mapping" ) ;
110
- let expected_fs_str = CStr16 :: from_str_with_buf ( "FS0:" , & mut test_buf ) . unwrap ( ) ;
120
+ let expected_fs_str = cstr16 ! ( "FS0:" ) ;
111
121
assert_eq ! ( cur_fs_str, expected_fs_str) ;
112
122
113
123
let cur_fs_str = shell
@@ -116,30 +126,30 @@ pub fn test_cur_dir(shell: &ScopedProtocol<Shell>) {
116
126
assert_eq ! ( cur_fs_str, expected_fs_str) ;
117
127
118
128
// Changing current working directory
119
- let dir_var = CStr16 :: from_str_with_buf ( "/efi" , & mut dir_buf ) . unwrap ( ) ;
129
+ let dir_var = cstr16 ! ( "/efi" ) ;
120
130
let status = shell. set_cur_dir ( None , Some ( dir_var) ) ;
121
131
assert_eq ! ( status, Status :: SUCCESS ) ;
122
132
let cur_fs_str = shell
123
133
. get_cur_dir ( Some ( fs_var) )
124
134
. expect ( "Could not get the current file system mapping" ) ;
125
- let expected_fs_str = CStr16 :: from_str_with_buf ( "FS0:\\ efi" , & mut test_buf ) . unwrap ( ) ;
135
+ let expected_fs_str = cstr16 ! ( "FS0:\\ efi" ) ;
126
136
assert_eq ! ( cur_fs_str, expected_fs_str) ;
127
137
let cur_fs_str = shell
128
138
. get_cur_dir ( None )
129
139
. expect ( "Could not get the current file system mapping" ) ;
130
140
assert_eq ! ( cur_fs_str, expected_fs_str) ;
131
141
132
142
// Changing current directory in a non-current working file system
133
- let fs_var = CStr16 :: from_str_with_buf ( "fs0:" , & mut fs_buf ) . unwrap ( ) ;
134
- let dir_var = CStr16 :: from_str_with_buf ( "efi/tools" , & mut dir_buf ) . unwrap ( ) ;
143
+ let fs_var = cstr16 ! ( "fs0:" ) ;
144
+ let dir_var = cstr16 ! ( "efi/tools" ) ;
135
145
let status = shell. set_cur_dir ( Some ( fs_var) , Some ( dir_var) ) ;
136
146
assert_eq ! ( status, Status :: SUCCESS ) ;
137
147
let cur_fs_str = shell
138
148
. get_cur_dir ( None )
139
149
. expect ( "Could not get the current file system mapping" ) ;
140
150
assert_ne ! ( cur_fs_str, expected_fs_str) ;
141
151
142
- let expected_fs_str = CStr16 :: from_str_with_buf ( "FS0:\\ efi\\ tools" , & mut test_buf ) . unwrap ( ) ;
152
+ let expected_fs_str = cstr16 ! ( "FS0:\\ efi\\ tools" ) ;
143
153
let cur_fs_str = shell
144
154
. get_cur_dir ( Some ( fs_var) )
145
155
. expect ( "Could not get the current file system mapping" ) ;
0 commit comments