1 /* 2 * Copyright (c) 2016 Helmut Neemann 3 * Use of this source code is governed by the GPL v3 license 4 * that can be found in the LICENSE file. 5 */ 6 package de.neemann.digital.integration; 7 8 import de.neemann.digital.draw.elements.Circuit; 9 import de.neemann.digital.draw.graphics.Export; 10 import de.neemann.digital.draw.graphics.GraphicsImage; 11 import de.neemann.digital.draw.library.ElementLibrary; 12 import de.neemann.digital.draw.shapes.ShapeFactory; 13 import junit.framework.TestCase; 14 15 import java.io.ByteArrayOutputStream; 16 import java.io.File; 17 18 /** 19 */ 20 public class TestShapes extends TestCase { 21 22 /** 23 * Loads a circuit with all available elements and writes it 24 * to a PNG. 25 * 26 * @throws Exception 27 */ testShapes()28 public void testShapes() throws Exception { 29 useShapes(false); 30 } 31 testShapesIEEE()32 public void testShapesIEEE() throws Exception { 33 useShapes(true); 34 } 35 useShapes(boolean ieee)36 private void useShapes(boolean ieee) throws Exception { 37 File filename = new File(Resources.getRoot(), "dig/shapes.dig"); 38 ElementLibrary library = new ElementLibrary(); 39 library.setRootFilePath(new File(Resources.getRoot(), "dig")); 40 ShapeFactory shapeFactory = new ShapeFactory(library, ieee); 41 Circuit circuit = Circuit.loadCircuit(filename, shapeFactory); 42 43 // try to write circuit to graphics instance 44 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 45 new Export(circuit, 46 (out) -> new GraphicsImage(out, "PNG", 1)) 47 .export(baos); 48 49 assertTrue(baos.size() > 30000); 50 51 } 52 } 53