3
3
use uefi:: boot:: ScopedProtocol ;
4
4
use uefi:: proto:: shell:: Shell ;
5
5
use 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
- }
66
6
67
- /// Test `get_cur_dir ()` and `set_cur_dir ()`
7
+ /// Test `current_dir ()` and `set_current_dir ()`
68
8
pub fn test_cur_dir ( shell : & ScopedProtocol < Shell > ) {
69
9
/* Test setting and getting current file system and current directory */
70
10
let fs_var = cstr16 ! ( "fs0:" ) ;
71
11
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 ( ) ) ;
74
14
75
15
let cur_fs_str = shell
76
- . get_cur_dir ( Some ( fs_var) )
16
+ . current_dir ( Some ( fs_var) )
77
17
. expect ( "Could not get the current file system mapping" ) ;
78
18
let expected_fs_str = cstr16 ! ( "FS0:\\ " ) ;
79
19
assert_eq ! ( cur_fs_str, expected_fs_str) ;
80
20
81
21
// Changing current file system
82
22
let fs_var = cstr16 ! ( "fs1:" ) ;
83
23
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 ( ) ) ;
86
26
87
27
let cur_fs_str = shell
88
- . get_cur_dir ( Some ( fs_var) )
28
+ . current_dir ( Some ( fs_var) )
89
29
. expect ( "Could not get the current file system mapping" ) ;
90
30
assert_ne ! ( cur_fs_str, expected_fs_str) ;
91
31
let expected_fs_str = cstr16 ! ( "FS1:\\ " ) ;
@@ -94,11 +34,11 @@ pub fn test_cur_dir(shell: &ScopedProtocol<Shell>) {
94
34
// Changing current file system and current directory
95
35
let fs_var = cstr16 ! ( "fs0:" ) ;
96
36
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 ( ) ) ;
99
39
100
40
let cur_fs_str = shell
101
- . get_cur_dir ( Some ( fs_var) )
41
+ . current_dir ( Some ( fs_var) )
102
42
. expect ( "Could not get the current file system mapping" ) ;
103
43
assert_ne ! ( cur_fs_str, expected_fs_str) ;
104
44
let expected_fs_str = cstr16 ! ( "FS0:\\ efi" ) ;
@@ -108,50 +48,50 @@ pub fn test_cur_dir(shell: &ScopedProtocol<Shell>) {
108
48
109
49
// At this point, the current working file system has not been set
110
50
// So we expect a NULL output
111
- assert ! ( shell. get_cur_dir ( None ) . is_none( ) ) ;
51
+ assert ! ( shell. current_dir ( None ) . is_none( ) ) ;
112
52
113
53
// Setting the current working file system and current working directory
114
54
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 ( ) ) ;
117
57
let cur_fs_str = shell
118
- . get_cur_dir ( Some ( fs_var) )
58
+ . current_dir ( Some ( fs_var) )
119
59
. expect ( "Could not get the current file system mapping" ) ;
120
60
let expected_fs_str = cstr16 ! ( "FS0:" ) ;
121
61
assert_eq ! ( cur_fs_str, expected_fs_str) ;
122
62
123
63
let cur_fs_str = shell
124
- . get_cur_dir ( None )
64
+ . current_dir ( None )
125
65
. expect ( "Could not get the current file system mapping" ) ;
126
66
assert_eq ! ( cur_fs_str, expected_fs_str) ;
127
67
128
68
// Changing current working directory
129
69
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 ( ) ) ;
132
72
let cur_fs_str = shell
133
- . get_cur_dir ( Some ( fs_var) )
73
+ . current_dir ( Some ( fs_var) )
134
74
. expect ( "Could not get the current file system mapping" ) ;
135
75
let expected_fs_str = cstr16 ! ( "FS0:\\ efi" ) ;
136
76
assert_eq ! ( cur_fs_str, expected_fs_str) ;
137
77
let cur_fs_str = shell
138
- . get_cur_dir ( None )
78
+ . current_dir ( None )
139
79
. expect ( "Could not get the current file system mapping" ) ;
140
80
assert_eq ! ( cur_fs_str, expected_fs_str) ;
141
81
142
82
// Changing current directory in a non-current working file system
143
83
let fs_var = cstr16 ! ( "fs0:" ) ;
144
84
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 ( ) ) ;
147
87
let cur_fs_str = shell
148
- . get_cur_dir ( None )
88
+ . current_dir ( None )
149
89
. expect ( "Could not get the current file system mapping" ) ;
150
90
assert_ne ! ( cur_fs_str, expected_fs_str) ;
151
91
152
92
let expected_fs_str = cstr16 ! ( "FS0:\\ efi\\ tools" ) ;
153
93
let cur_fs_str = shell
154
- . get_cur_dir ( Some ( fs_var) )
94
+ . current_dir ( Some ( fs_var) )
155
95
. expect ( "Could not get the current file system mapping" ) ;
156
96
assert_eq ! ( cur_fs_str, expected_fs_str) ;
157
97
}
@@ -164,6 +104,5 @@ pub fn test() {
164
104
let shell =
165
105
boot:: open_protocol_exclusive :: < Shell > ( handle) . expect ( "Failed to open Shell protocol" ) ;
166
106
167
- test_env ( & shell) ;
168
107
test_cur_dir ( & shell) ;
169
108
}
0 commit comments