Beispiel #1
0
  @Test
  public void fileStatNanoTime() throws Throwable {
    // Currently only linux file stat support nano time resolution
    jnr.ffi.Platform nativePlatform = jnr.ffi.Platform.getNativePlatform();
    if (nativePlatform.getOS() == jnr.ffi.Platform.OS.LINUX) {
      File f = File.createTempFile("stat", null);
      try {
        FileStat st = posix.stat(f.getAbsolutePath());
        assertNotNull("posix.stat failed", st);

        FileStat stat = posix.allocateStat();
        int result = posix.stat(f.getAbsolutePath(), stat);
        assertNotNull("posix.stat failed", st);
        assertEquals(0, result);

        if (Platform.IS_32_BIT) {
          LinuxFileStat32 fstat32 = (LinuxFileStat32) stat;
          assertTrue(fstat32.cTimeNanoSecs() > 0);
          assertTrue(fstat32.mTimeNanoSecs() > 0);
          assertTrue(fstat32.aTimeNanoSecs() > 0);
          assertEquals(fstat32.cTimeNanoSecs(), fstat32.mTimeNanoSecs());
        } else {
          LinuxFileStat64 fstat64 = (LinuxFileStat64) stat;
          assertTrue(fstat64.cTimeNanoSecs() > 0);
          assertTrue(fstat64.mTimeNanoSecs() > 0);
          assertTrue(fstat64.aTimeNanoSecs() > 0);

          assertEquals(fstat64.cTimeNanoSecs(), fstat64.mTimeNanoSecs());
        }
      } finally {
        f.delete();
      }
    }
  }
Beispiel #2
0
 @Test
 public void filestatInt() throws Throwable {
   // Windows does not store fd in FileDescriptor so this test wll not work
   if (jnr.ffi.Platform.getNativePlatform().isUnix()) {
     File f = File.createTempFile("stat", null);
     try {
       FileInputStream fis = new FileInputStream(f);
       FileDescriptor desc = fis.getFD();
       int fd = -1;
       try {
         Field fdField = FieldAccess.getProtectedField(FileDescriptor.class, "fd");
         fd = fdField.getInt(desc);
       } catch (SecurityException e) {
       } catch (IllegalArgumentException e) {
       } catch (IllegalAccessException e) {
       }
       FileStat stat = posix.allocateStat();
       int result = posix.fstat(fd, stat);
       assertTrue(fd > 2); // should not be stdin, stdout, stderr
       assertEquals(0, result);
     } finally {
       f.delete();
     }
   } else {
     FileStat stat = posix.fstat(0);
     assertTrue(stat != null);
   }
 }