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