Kaydet (Commit) 943e06d4 authored tarafından Lei De Bin's avatar Lei De Bin

#119998# copy the VCLAuto from Symphony code base to AOO trunk.

More info, check here
http://wiki.services.openoffice.org/wiki/QA/vclauto
http://wiki.services.openoffice.org/wiki/Test_Refactor
Copy the testcommon
üst 4964a13d
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="source"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="output/class"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>testcommon</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
<?xml version="1.0"?>
<!--************************************************************************
*
* Licensed Materials - Property of IBM.
* (C) Copyright IBM Corporation 2003, 2012. All Rights Reserved.
* U.S. Government Users Restricted Rights:
* Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
*
************************************************************************ -->
<project basedir="." default="dist">
<property name="src" value="./source" />
<property name="out" value="output" />
<property name="classes" value="${out}/class" />
<property name="dist" value="${out}/class" />
<property name="jar.name" value="testcommon.jar" />
<target name="init">
<mkdir dir="${classes}" />
<mkdir dir="${dist}" />
<copy includeemptydirs="false" todir="${classes}">
<fileset dir="${src}">
<exclude name="**/*.java" />
</fileset>
</copy>
</target>
<target name="clean" description="Clean all output">
<delete dir="${classes}" />
<delete dir="${dist}" />
</target>
<target name="compile" depends="init">
<javac srcdir="${src}" destdir="${classes}" debug="on" source="1.6">
</javac>
</target>
<target name="dist" depends="compile">
<jar destfile="${dist}/${jar.name}" basedir="${classes}" excludes="*.jar"/>
</target>
</project>
#*************************************************************************
#
# Licensed Materials - Property of IBM.
# (C) Copyright IBM Corporation 2003, 2012. All Rights Reserved.
# U.S. Government Users Restricted Rights:
# Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
#
#*************************************************************************
#**************************************************************
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
#**************************************************************
PRJ=.
PRJNAME=testcommon
TARGET=testcommon
.INCLUDE : ant.mk
ALLTAR : ANTBUILD
\ No newline at end of file
tcomm testcommon : NULL
tcomm testcommon nmake - all tcomm_mkout NULL
..\%__SRC%\class\testcommon.jar %_DEST%\bin%_EXT%\testcommon.jar
/************************************************************************
*
* Licensed Materials - Property of IBM.
* (C) Copyright IBM Corporation 2003, 2012. All Rights Reserved.
* U.S. Government Users Restricted Rights:
* Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
*
************************************************************************/
package org.openoffice.test.common;
public abstract class Condition {
/**
*
* @return true, if the condition is true. false, if it's not true.
*/
public abstract boolean value();
public boolean test(double iTimeout, double interval) {
long startTime = System.currentTimeMillis();
while (System.currentTimeMillis() - startTime < iTimeout * 1000) {
if (value())
return true;
try {
Thread.sleep((long) (interval * 1000));
} catch (InterruptedException e) {
}
}
return value();
}
public void waitForTrue(String message, double iTimeout, double interval) {
if (!test(iTimeout, interval)) {
throw new RuntimeException(message);
}
}
}
/************************************************************************
*
* Licensed Materials - Property of IBM.
* (C) Copyright IBM Corporation 2003, 2012. All Rights Reserved.
* U.S. Government Users Restricted Rights:
* Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
*
************************************************************************/
package org.openoffice.test.common;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.imageio.ImageIO;
/**
* Utilities related to graphics
*
*/
public class GraphicsUtil {
/**
* Error tolerance for rectangle
*/
static final double ERR_RANGLE_RECTANGLE = 0.0;
/**
* Error tolerance for ellipse
*/
static final double ERR_RANGLE_ELLIPSE = 1;
/**
* Load a image file as buffered image
* @param file
* @return
*/
public static BufferedImage loadImage(String file) {
BufferedImage image = null;
FileInputStream in = null;
try {
in = new FileInputStream(file);
image = ImageIO.read(in);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (in != null)
in.close();
} catch (IOException e) {
// ignore
}
}
return image;
}
/**
* Store a buffered image in the given file
*
* @param image
* @param imgFile
*/
public static void storeImage(BufferedImage image, String imgFile) {
File file = new File(imgFile);
if (!file.getParentFile().exists())
file.getParentFile().mkdirs();
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
ImageIO.write(image, FileUtil.getFileExtName(imgFile), fos);
} catch (Exception e) {
//
e.printStackTrace();
} finally {
try {
if (fos != null)
fos.close();
} catch (IOException e) {
//ignore
}
}
}
/**
* Get a BufferedImage including the full current screen shot
* @return
*/
public static BufferedImage screenshot() {
return screenshot(null, null);
}
/**
* Get a BufferedImage including the area of current screen shot
* @param area
* @return
*/
public static BufferedImage screenshot(Rectangle area) {
return screenshot(null, area);
}
/**
* Store the screen shot as a image file
* @param filename
*/
public static BufferedImage screenShot(String filename) {
return screenshot(filename, null);
}
/**
* Store the specified area of the screen as a image file
* @param filename
* @param area
*/
public static BufferedImage screenshot(String filename, Rectangle area) {
// screen capture
try {
Robot robot = new Robot();
if (area == null)
area = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
BufferedImage capture = robot.createScreenCapture(area);
if (filename != null)
storeImage(capture, filename);
return capture;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* Find a rectangle in the screen.
* Note: The rectangle must be filled with solid color and the color must be different from the background color
*
* @param rect the area in the screen to search
* @param color the rectangle color.
* @return The found rectangle's location and size. If no rectangle is
* found, return null
*/
public static Rectangle findRectangle(Rectangle rect, int color) {
return findRectangle(screenshot(rect), color);
}
/**
* find a rectangle in an image
* Note: The rectangle must be filled with solid color and the color must be different from the background color
* @param src
* @param color
* the rectangle color.
* @return The found rectangle's location and size. If no rectangle is
* found, return null
*/
public static Rectangle findRectangle(BufferedImage src, int color) {
Rectangle re = new Rectangle();
BufferedImage dst = new BufferedImage(src.getWidth(), src.getHeight(),
BufferedImage.TYPE_INT_ARGB);
for (int x = 0; x < dst.getWidth(); x++) {
for (int y = 0; y < dst.getHeight(); y++) {
dst.setRGB(x, y, 0xFFFFFFFF);
}
}
Graphics g = dst.getGraphics();
g.setColor(Color.black);
int sx = -1, sy = 0, ex = 0, ey = 0;
for (int x = 0; x < src.getWidth(); x++) {
for (int y = 0; y < src.getHeight(); y++) {
int rgbSrc = src.getRGB(x, y);
if (rgbSrc == color) {
if (sx == -1) {
sx = x;
sy = y;
}
ex = x;
ey = y;
}
}
}
g.fillRect(sx, sy, ex - sx + 1, ey - sy + 1);
// g.fillRect(0, 0, dst.getWidth(), dst.getHeight());
int perimeter = 2 * (ex - sx + ey - sy);
int errMax = (int)(perimeter * ERR_RANGLE_RECTANGLE);
if (!(detect(src, color, dst, 0xff000000, errMax) && detect(dst, 0xff000000,
src, color, errMax)))
return null;
re.setBounds(sx, sy, ex - sx, ey - sy);
if (re.width < 2 || re.height < 2) {
return null;
}
return re;
}
protected static boolean detect(BufferedImage src, int colorSrc,
BufferedImage dst, int colorDst, double errMax) {
int errCount = 0;
for (int x = 0; x < src.getWidth(); x++) {
for (int y = 0; y < src.getHeight(); y++) {
int rgbSrc = src.getRGB(x, y);
if (rgbSrc == colorSrc) {
int rgbDst = dst.getRGB(x, y);
if (!(rgbDst == colorDst)) {
errCount++;
}
}
} // end for y
}// end for x
// System.out.println(errCount);
if (errCount <= errMax)
return true;
return false;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment