Esempio n. 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();
      }
    }
  }
Esempio n. 2
0
  @Test
  public void structStatSize() throws Throwable {
    if (Platform.IS_SOLARIS) {
      jnr.ffi.Runtime runtime = jnr.ffi.Runtime.getSystemRuntime();
      if (Platform.IS_32_BIT) {
        assertEquals("struct size is wrong", 144, new SolarisFileStat32.Layout(runtime).size());
      } else {
        assertEquals("struct size is wrong", 128, new SolarisFileStat64.Layout(runtime).size());
      }
    }

    if (Platform.IS_SOLARIS) {
      File f = File.createTempFile("stat", null);
      try {
        FileStat st = posix.stat(f.getAbsolutePath());

        if (Platform.IS_32_BIT) {
          assertSame("incorrect stat instance returned", SolarisFileStat32.class, st.getClass());
        } else {
          assertSame("incorrect stat instance returned", SolarisFileStat64.class, st.getClass());
        }
      } finally {
        f.delete();
      }
    }
  }
Esempio n. 3
0
  @Test
  public void filestatDirectory() throws Throwable {
    File f = File.createTempFile("stat", null).getParentFile();
    try {
      FileStat stat = posix.stat(f.getAbsolutePath());

      assertTrue(stat.isDirectory());
    } finally {
      f.delete();
    }
  }
Esempio n. 4
0
  @Test
  public void filestat() throws Throwable {
    File f = File.createTempFile("stat", null);
    int size = 1567;
    // Thread.sleep(2000);
    addNBytes(f, size);
    try {
      FileStat stat = posix.stat(f.getAbsolutePath());
      assertNotNull("posix.stat failed", stat);
      assertEquals(size, stat.st_size());
      // assertNotEquals(stat.mtime(), stat.ctime());

      stat = posix.allocateStat();
      int result = posix.stat(f.getAbsolutePath(), stat);
      assertNotNull("posix.stat failed", stat);
      assertEquals(0, result);
      assertEquals(size, stat.st_size());
    } finally {
      f.delete();
    }
  }
Esempio n. 5
0
  @Test
  public void filestatFailed() throws Throwable {
    FileStat stat = null;

    // A little wonky without adding a new posixhandler but we are using dummy so this is ok for now
    // the default handler raises on a problem in stat so we are only verifying this at the moment.
    try {
      stat = posix.stat(NON_EXISTENT_FILENAME);
    } catch (UnsupportedOperationException e) {
    }

    assertTrue(stat == null);
  }