22
33use uefi:: boot:: ScopedProtocol ;
44use uefi:: proto:: shell:: Shell ;
5- use uefi:: { CStr16 , boot } ;
5+ use uefi:: { boot , cstr16 } ;
66use uefi_raw:: Status ;
77
8- /// Test `` get_env()`` , `` get_envs()`` , and `` set_env()` `
8+ /// Test `get_env()`, `get_envs()`, and `set_env()`
99pub fn test_env ( shell : & ScopedProtocol < Shell > ) {
10- let mut test_buf = [ 0u16 ; 128 ] ;
11-
1210 /* Test retrieving list of environment variable names */
1311 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" ) , ) ;
2214 let cur_env_vec = shell. get_envs ( ) ;
2315 let default_len = cur_env_vec. count ( ) ;
2416
2517 /* Test setting and getting a specific environment variable */
2618 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" ) ;
3121 assert ! ( shell. get_env( test_var) . is_none( ) ) ;
3222 let status = shell. set_env ( test_var, test_val, false ) ;
3323 assert_eq ! ( status, Status :: SUCCESS ) ;
@@ -56,7 +46,7 @@ pub fn test_env(shell: &ScopedProtocol<Shell>) {
5646 assert_eq ! ( cur_env_vec. count( ) , default_len + 1 ) ;
5747
5848 /* Test deleting environment variable */
59- let test_val = CStr16 :: from_str_with_buf ( "" , & mut test_val_buf ) . unwrap ( ) ;
49+ let test_val = cstr16 ! ( "" ) ;
6050 let status = shell. set_env ( test_var, test_val, false ) ;
6151 assert_eq ! ( status, Status :: SUCCESS ) ;
6252 assert ! ( shell. get_env( test_var) . is_none( ) ) ;
@@ -73,48 +63,44 @@ pub fn test_env(shell: &ScopedProtocol<Shell>) {
7363 assert_eq ! ( cur_env_vec. count( ) , default_len) ;
7464}
7565
76- /// Test `` get_cur_dir()`` and `` set_cur_dir()` `
66+ /// Test `get_cur_dir()` and `set_cur_dir()`
7767pub fn test_cur_dir ( shell : & ScopedProtocol < Shell > ) {
78- let mut test_buf = [ 0u16 ; 128 ] ;
79-
8068 /* 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 ! ( "/" ) ;
8571 let status = shell. set_cur_dir ( Some ( fs_var) , Some ( dir_var) ) ;
8672 assert_eq ! ( status, Status :: SUCCESS ) ;
8773
8874 let cur_fs_str = shell
8975 . get_cur_dir ( Some ( fs_var) )
9076 . 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:\\ " ) ;
9278 assert_eq ! ( cur_fs_str, expected_fs_str) ;
9379
9480 // 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 ! ( "/" ) ;
9783 let status = shell. set_cur_dir ( Some ( fs_var) , Some ( dir_var) ) ;
9884 assert_eq ! ( status, Status :: SUCCESS ) ;
9985
10086 let cur_fs_str = shell
10187 . get_cur_dir ( Some ( fs_var) )
10288 . expect ( "Could not get the current file system mapping" ) ;
10389 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:\\ " ) ;
10591 assert_eq ! ( cur_fs_str, expected_fs_str) ;
10692
10793 // 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/" ) ;
11096 let status = shell. set_cur_dir ( Some ( fs_var) , Some ( dir_var) ) ;
11197 assert_eq ! ( status, Status :: SUCCESS ) ;
11298
11399 let cur_fs_str = shell
114100 . get_cur_dir ( Some ( fs_var) )
115101 . expect ( "Could not get the current file system mapping" ) ;
116102 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" ) ;
118104 assert_eq ! ( cur_fs_str, expected_fs_str) ;
119105
120106 /* Test current working directory cases */
@@ -124,13 +110,13 @@ pub fn test_cur_dir(shell: &ScopedProtocol<Shell>) {
124110 assert ! ( shell. get_cur_dir( None ) . is_none( ) ) ;
125111
126112 // 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:/" ) ;
128114 let status = shell. set_cur_dir ( None , Some ( dir_var) ) ;
129115 assert_eq ! ( status, Status :: SUCCESS ) ;
130116 let cur_fs_str = shell
131117 . get_cur_dir ( Some ( fs_var) )
132118 . 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:" ) ;
134120 assert_eq ! ( cur_fs_str, expected_fs_str) ;
135121
136122 let cur_fs_str = shell
@@ -139,30 +125,30 @@ pub fn test_cur_dir(shell: &ScopedProtocol<Shell>) {
139125 assert_eq ! ( cur_fs_str, expected_fs_str) ;
140126
141127 // Changing current working directory
142- let dir_var = CStr16 :: from_str_with_buf ( "/efi" , & mut dir_buf ) . unwrap ( ) ;
128+ let dir_var = cstr16 ! ( "/efi" ) ;
143129 let status = shell. set_cur_dir ( None , Some ( dir_var) ) ;
144130 assert_eq ! ( status, Status :: SUCCESS ) ;
145131 let cur_fs_str = shell
146132 . get_cur_dir ( Some ( fs_var) )
147133 . 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" ) ;
149135 assert_eq ! ( cur_fs_str, expected_fs_str) ;
150136 let cur_fs_str = shell
151137 . get_cur_dir ( None )
152138 . expect ( "Could not get the current file system mapping" ) ;
153139 assert_eq ! ( cur_fs_str, expected_fs_str) ;
154140
155141 // 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" ) ;
158144 let status = shell. set_cur_dir ( Some ( fs_var) , Some ( dir_var) ) ;
159145 assert_eq ! ( status, Status :: SUCCESS ) ;
160146 let cur_fs_str = shell
161147 . get_cur_dir ( None )
162148 . expect ( "Could not get the current file system mapping" ) ;
163149 assert_ne ! ( cur_fs_str, expected_fs_str) ;
164150
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" ) ;
166152 let cur_fs_str = shell
167153 . get_cur_dir ( Some ( fs_var) )
168154 . expect ( "Could not get the current file system mapping" ) ;
0 commit comments