25
25
26
26
import static org .junit .Assert .assertNotEquals ;
27
27
28
+ import java .util .Date ;
29
+ import java .util .Map ;
30
+
28
31
import com .sun .jna .Memory ;
29
32
import com .sun .jna .Native ;
30
33
import com .sun .jna .Platform ;
@@ -167,6 +170,31 @@ public void testHostProcessorInfo() {
167
170
procInfoCount .getValue ());
168
171
}
169
172
173
+ // From Unix LibCAPI
174
+ public void testGetenv () {
175
+ Map <String , String > env = System .getenv ();
176
+ for (Map .Entry <String , String > ee : env .entrySet ()) {
177
+ String name = ee .getKey ();
178
+ String expected = ee .getValue ();
179
+ String actual = SystemB .INSTANCE .getenv (name );
180
+ assertEquals (name , expected , actual );
181
+ }
182
+ }
183
+
184
+ // From Unix LibCAPI
185
+ public void testSetenv () {
186
+ String name = "SystemBTestEnv" ;
187
+ try {
188
+ String expected = new Date (System .currentTimeMillis ()).toString ();
189
+ assertEquals ("setenv" , 0 , SystemB .INSTANCE .setenv (name , expected , 1 ));
190
+ assertEquals ("Mismatched values" , expected , SystemB .INSTANCE .getenv (name ));
191
+ assertEquals ("unsetenv" , 0 , SystemB .INSTANCE .unsetenv (name ));
192
+ } finally {
193
+ SystemB .INSTANCE .unsetenv (name );
194
+ }
195
+ }
196
+
197
+ // From Unix LibCAPI
170
198
public void testGetLoadAvg () {
171
199
double [] loadavg = new double [3 ];
172
200
int retval = SystemB .INSTANCE .getloadavg (loadavg , 3 );
@@ -176,6 +204,16 @@ public void testGetLoadAvg() {
176
204
assertTrue (loadavg [2 ] >= 0 );
177
205
}
178
206
207
+ // From Unix LibCAPI
208
+ public void testGethostnameGetdomainname () {
209
+ byte [] buffer = new byte [256 ];
210
+ assertEquals ("gethostname" , 0 , SystemB .INSTANCE .gethostname (buffer , buffer .length ));
211
+ String hostname = Native .toString (buffer );
212
+ assertTrue (hostname .length () > 0 );
213
+ assertEquals ("getdomainname" , 0 , SystemB .INSTANCE .getdomainname (buffer , buffer .length ));
214
+ // May have length 0
215
+ }
216
+
179
217
public void testTimeofDay () {
180
218
Timeval tp = new Timeval ();
181
219
long before = System .currentTimeMillis ();
0 commit comments