Hello, im making a processing library in java that makes possible to create presentation without limitations.
I’m having a lot of problems, first of all i dont know how could i add JUnit to the properties.xml, furthermore i want in a test to get an IMG of my sketch, the images and text are appearing in the SlideShow draw() that calls other classes to make it possible, as im triying i’m only getting a small black screen as a saved img.
package test;
import static org.junit.Assert.fail;
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import org.junit.;
import SlideShow.library.;
import processing.core.*;
public class TestSlideShow extends PApplet {
private static SlideShow theSlideShow;
private static PApplet sketch;
private static Writer testWriter;
private static Style textStyle;
private static float width;
private static float height;
private static Theme theme;
class MySlide extends ThemedSlide {
Writer textArea1;
MySlide(int width_, int height_, Theme theme_, PApplet sketch) {
super(width_, height_, theme_,sketch);
setTitle("Hello");
Style textStyle = new Style(theme.textStyle);
textStyle.setSize(20);
textArea1 = new Writer(textStyle, (float)0.2*width_, (float)0.2*height_, (float)0.6*width_, (float)0.2*height_,sketch);
textArea1.addTextLine("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi faucibus interdum elit, molestie dictum tortor consectetur nec. Nam dignissim efficitur mi vel sagittis. Duis iaculis egestas ante. Vestibulum varius, dui vitae maximus euismod, nunc nisl volutpat diam, vel sodales ex lacus vel eros. Sed ac nisi at enim accumsan dignissim vel a arcu. Duis sodales aliquet eros sed facilisis. Phasellus aliquam lacus non urna imperdiet, eu efficitur purus auctor. Praesent eget dignissim dolor, at lacinia diam. Donec ac gravida justo. Quisque maximus mattis est at vestibulum. Ut lectus sem, ultrices quis dapibus eu, hendrerit ultricies libero. Suspendisse at feugiat elit. Aenean viverra eros eget lorem semper, a consequat ex vulputate. Cras congue nisl erat, non convallis velit egestas ac. Donec vulputate posuere dolor, sit amet dapibus mi tincidunt blandit.");
addItem(textArea1);
}
}
public void saveSketch() {
sketch.save("prueba.jpg");
}
@BeforeClass
public static void InitializeTest() {
width = 1080;
height = 1920;
sketch = new PApplet();
theSlideShow = new SlideShow(sketch);
theme = new Theme();
theme.textStyle = new Style(
null,null,null,null,
(float)120.0,0xffc5d492);
textStyle = theme.textStyle;
testWriter = new Writer(textStyle, (float)0.2*width, (float)0.4*height, (float)0.6*width, (float)0.2*height,sketch);
theSlideShow = new SlideShow(sketch);
}
@Test
public void addSlideText() {
theSlideShow.addSlide(new MySlide((int)width, (int)height, theme,sketch));
if(theSlideShow.getSlides().size() != 1) {
//fail("Error en el metodo addSlide");
}
}
public double checkDifference() {
BufferedImage img1=null,img2 = null;
double percentage = 0;
try {
img1 = ImageIO.read(new File("C:\\Users\\medio\\OneDrive\\Escritorio\\uni\\cuarto\\tfg\\Libreria\\processingslideshow\\Library-processing-master\\data"));
img2 = ImageIO.read(new File("C:\\Users\\medio\\OneDrive\\Escritorio\\uni\\cuarto\\tfg\\Libreria\\processingslideshow\\Library-processing-master\\data"));
} catch (IOException e) {
e.printStackTrace();
}
int w1 = img1.getWidth();
int w2 = img2.getWidth();
int h1 = img1.getHeight();
int h2 = img2.getHeight();
if ((w1!=w2)||(h1!=h2)) {
System.out.println("Both images should have same dimwnsions");
} else {
long diff = 0;
for (int j = 0; j < h1; j++) {
for (int i = 0; i < w1; i++) {
int pixel1 = img1.getRGB(i, j);
Color color1 = new Color(pixel1, true);
int r1 = color1.getRed();
int g1 = color1.getGreen();
int b1 = color1.getBlue();
int pixel2 = img2.getRGB(i, j);
Color color2 = new Color(pixel2, true);
int r2 = color2.getRed();
int g2 = color2.getGreen();
int b2= color2.getBlue();
long data = Math.abs(r1-r2)+Math.abs(g1-g2)+ Math.abs(b1-b2);
diff = diff+data;
}
}
double avg = diff/(w1*h1*3);
percentage = (avg/255)*100;
System.out.println("Difference: "+percentage);
}
return percentage;
}
@Test
public void checkOutput() {
PApplet.runSketch(new String[] {"theSlideShow"}, sketch);
saveSketch();
}
@BeforeClass
public static void main() {
SlideShow sketch1 = new SlideShow(sketch);
PApplet.runSketch(new String[]{"--location=0,0", ""}, sketch1);
}
}