Exemple #1
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();
      }
    }
  }
Exemple #2
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();
    }
  }
Exemple #3
0
  @Test
  public void filestatDescriptor() throws Throwable {
    File f = File.createTempFile("stat", null);

    try {
      FileInputStream fis = new FileInputStream(f);
      FileStat stat = posix.allocateStat();
      int result = posix.fstat(fis.getFD(), stat);
      assertEquals(0, result);
      assertEquals(0, stat.st_size());
    } finally {
      f.delete();
    }
  }
Exemple #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();
    }
  }