source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/testcases/org/apache/tools/ant/taskdefs/optional/image/ImageTest.java@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

File size: 3.6 KB
Line 
1/*
2 * Copyright 2000-2004 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18package org.apache.tools.ant.taskdefs.optional.image;
19
20import org.apache.tools.ant.BuildFileTest;
21import org.apache.tools.ant.taskdefs.condition.Os;
22
23import java.io.IOException;
24import java.io.File;
25import java.io.InputStream;
26import java.io.BufferedInputStream;
27import java.io.FileInputStream;
28import java.io.FileReader;
29import java.io.BufferedReader;
30import java.util.Properties;
31
32/**
33 * Tests the Image task.
34 *
35 * @since Ant 1.5
36 */
37public 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 // else
112 return new File( getProjectDir(), filename );
113 }
114}
115
Note: See TracBrowser for help on using the repository browser.