package com.jogamp.opengl.test.junit.jogl.util.texture;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.ByteBuffer;

import javax.media.opengl.GL;
import javax.media.opengl.GLProfile;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import com.jogamp.common.util.IOUtil;
import com.jogamp.opengl.util.texture.spi.DDSImage;
import com.jogamp.opengl.util.texture.spi.TGAImage;
import com.jogamp.opengl.util.texture.spi.DDSImage.ImageInfo;

public class TestBug982TGAImageReadFromFile {
	
	File testTGAImage01;
	static GLProfile glp = GLProfile.getDefault();
	
	@Before
    public void setup() throws Throwable {
		testTGAImage01 = initFile("notloaded.tga");
    }
	
    @After
    public void teardown() {
    	testTGAImage01 = null;
    }
    
    private File initFile(String filename) throws URISyntaxException {
    	URLConnection connection = IOUtil.getResource(getClass(), filename);
    	Assert.assertNotNull(connection);
    	URL url = connection.getURL();
    	File file = new File(url.toURI());
    	Assert.assertTrue(file.exists());
    	return file;
    }
    
    private void testImpl(File file) throws IOException {
    	TGAImage tgaImage = TGAImage.read(glp, new FileInputStream(testTGAImage01));
    	Assert.assertNotNull(tgaImage);
    }
    
    
    @Test
    public void test00_TGAImage_ReadFromFile () throws IOException {
    	testImpl(testTGAImage01);
    }
    
	public static void main(String[] args) {
		org.junit.runner.JUnitCore.main(TestBug982TGAImageReadFromFile.class.getName());
	}
}