package net.lecousin.framework.core.tests.io.util;

import java.io.File;
import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.file.Path;

import net.lecousin.framework.adapter.AdapterRegistry;
import net.lecousin.framework.concurrent.Task;
import net.lecousin.framework.concurrent.tasks.drives.GetFileInfoTask;
import net.lecousin.framework.core.test.LCCoreAbstractTest;
import net.lecousin.framework.io.IO;
import net.lecousin.framework.io.util.FileInfo;

import org.junit.Assert;
import org.junit.Test;

public class TestFileInfo extends LCCoreAbstractTest {

	@Test
	public void test() throws Exception {
		File f = File.createTempFile("test", "fileinfo");
		f.deleteOnExit();
		FileOutputStream out = new FileOutputStream(f);
		out.write(new byte[] { 1, 2, 3 });
		out.close();
		GetFileInfoTask task = new GetFileInfoTask(f, Task.PRIORITY_NORMAL);
		FileInfo info = task.start().getOutput().blockResult(0);
		Assert.assertFalse(info.isDirectory);
		Assert.assertEquals(3, info.size);
		Assert.assertEquals(f, info.file);
		Assert.assertEquals(f, AdapterRegistry.get().adapt(info, File.class));
		Assert.assertEquals(f, AdapterRegistry.get().adapt(info, Path.class).toFile());
		IO.Readable in = AdapterRegistry.get().adapt(info, IO.Readable.class);
		in.close();
		byte[] buf = new byte[5];
		Assert.assertEquals(3, in.readFullySync(ByteBuffer.wrap(buf)));
		Assert.assertEquals(1, buf[0]);
		Assert.assertEquals(2, buf[1]);
		Assert.assertEquals(3, buf[2]);
		f.delete();
	}
	
}

@@ -604,16 +604,32 @@
 %0D%0A%09@Test
+(timeout=120000)
 %0D%0A%09publi
@@ -1325,23 +1325,8 @@
 );%0D%0A
-%09%09in.close();%0D%0A
 %09%09by
@@ -1518,24 +1518,39 @@
 , buf%5B2%5D);%0D%0A
+%09%09in.close();%0D%0A
 %09%09f.delete()

add timeout to TestFileInfo