1 17 18 package org.apache.tools.ant.taskdefs.optional.image; 19 20 import org.apache.tools.ant.BuildFileTest; 21 import org.apache.tools.ant.taskdefs.condition.Os; 22 23 import java.io.IOException ; 24 import java.io.File ; 25 import java.io.InputStream ; 26 import java.io.BufferedInputStream ; 27 import java.io.FileInputStream ; 28 import java.io.FileReader ; 29 import java.io.BufferedReader ; 30 import java.util.Properties ; 31 32 37 public class ImageTest extends BuildFileTest { 38 39 private final static String TASKDEFS_DIR = "src/etc/testcases/taskdefs/optional/image/"; 40 private final static String LARGEIMAGE = "largeimage.jpg"; 41 42 public ImageTest(String name) { 43 super(name); 44 } 45 46 47 public void setUp() { 48 configureProject(TASKDEFS_DIR + "image.xml"); 49 } 50 51 52 public void tearDown() { 53 executeTarget("cleanup"); 54 } 55 56 public void testEchoToLog() { 57 expectLogContaining("testEchoToLog", "Processing File"); 58 } 59 60 public void testSimpleScale(){ 61 expectLogContaining("testSimpleScale", "Processing File"); 62 File f = createRelativeFile( "/dest/" + LARGEIMAGE ); 63 assertTrue( 64 "Did not create "+f.getAbsolutePath(), 65 f.exists() ); 66 67 } 68 69 public void testOverwriteTrue() { 70 expectLogContaining("testSimpleScale", "Processing File"); 71 File f = createRelativeFile( "/dest/" + LARGEIMAGE ); 72 long lastModified = f.lastModified(); 73 if (Os.isFamily("dos")) { 74 try { 75 Thread.sleep(2000); 76 } 77 catch (InterruptedException e) {} 78 } 79 expectLogContaining("testOverwriteTrue", "Processing File"); 80 f = createRelativeFile( "/dest/" + LARGEIMAGE ); 81 long overwrittenLastModified = f.lastModified(); 82 assertTrue("File was not overwritten.",lastModified < overwrittenLastModified); 83 } 84 85 public void testOverwriteFalse() { 86 expectLogContaining("testSimpleScale", "Processing File"); 87 File f = createRelativeFile( "/dest/" + LARGEIMAGE ); 88 long lastModified = f.lastModified(); 89 expectLogContaining("testOverwriteFalse", "Processing File"); 90 f = createRelativeFile( "/dest/" + LARGEIMAGE ); 91 long overwrittenLastModified = f.lastModified(); 92 assertTrue("File was overwritten.",lastModified == overwrittenLastModified); 93 } 94 95 96 public void off_testFailOnError() { 97 try { 98 expectLogContaining("testFailOnError", "Unable to process image stream"); 99 } 100 catch (RuntimeException re){ 101 assertTrue("Run time exception should say 'Unable to process image stream'. :" + re.toString(),re.toString().indexOf("Unable to process image stream") > -1); 102 } 103 } 104 105 106 107 protected File createRelativeFile( String filename ) { 108 if (filename.equals( "." )) { 109 return getProjectDir(); 110 } 111 return new File ( getProjectDir(), filename ); 113 } 114 } 115 116 | Popular Tags |