superwaba.ext.xplat.unit
Class ImageTester
java.lang.Object
|
+--waba.fx.Image
|
+--superwaba.ext.xplat.unit.ImageTester
- public class ImageTester
- extends Image
This class is a helper to test if two images are equal, ie,
their width and height are the satest and their pixel values
are the satest.
There's first a learning stage where the images are generated
and the compressed strings are created.
Then the test should run again to do the effective comparision
at a pda.
Here's a sample:
public class GraphicsTest extends TestCase
{
private Graphics g;
private boolean learning = false; // change this to true to generate the strings
// generated string during learning stage
private String drawLine = "58C3AD94510EC2300CC5DEFD0FEA73C0186C0335892791DF7956DB240F6485CCB571027CCAC80C6E2E32822F1599C0DD4406F02D223DF8F190163C34A4034F0B69C08B84D4E0D5414AF04BD17C4ACDA5BA16D5997EFFA778FF4C5C9613B4E0B21A5DDA2EFCC527CFD7DE17F77EDCED87ECAF9C17397FF33C73633FE4BEC9FD957920F345E695CC3F99A7329F0DB683AA1EE9F8D157";
private ImageTester testDrawLine()
{
int w = 40, h = 40;
ImageTester it = new ImageTester(w,h);
Graphics g = it.g;
g.setBackColor(Color.WHITE);
g.fillRect(0,0,w,h);
g.drawLine(0,0,w,h);
g.drawLine(0,0,w,0);
g.drawLine(0,0,0,h);
g.drawLine(w-1,0,w-1,h);
g.drawLine(0,h-1,w,h-1);
g.drawLine(w,0,0,h);
g.drawLine(5,10,5,10); // a single pixel
g.drawLine(5,15,6,16); // two pixels
return it;
}
public void testRun()
{
g = MainWindow.getMainWindow().createGraphics();
test(testDrawLine(), drawLine, "drawLine");
}
private void test(ImageTester it, String compressedResults, String title)
{
if (learning)
{
g.drawImage(it,0,0);
Vm.debug("private String "+title+" = \""+it.toString()+"\";");
}
else
assertEquals(it, compressedResults);
}
}
|
Method Summary |
boolean |
equals(java.lang.Object originalObj)
This testthod is the reason for the creation of this class.
|
protected void |
getPixelRow(byte[] fillIn,
int y)
used in saveTo method. fill in the y row into the fillIn array.
there must be enough space for the full line be filled. |
java.lang.String |
toString()
Converts this image to String, as a string of hexadecimal numbers. |
| Methods inherited from class waba.fx.Image |
applyPalette,
changeColors,
createBmp,
free,
getGraphics,
getHeight,
getPalette,
getRotatedScaledInstance,
getScaledInstance,
getTouchedUpInstance,
getTransparentColor,
getWidth,
load,
saveTo,
scaledBy,
setPalette,
setTransparentColor |
| Methods inherited from class java.lang.Object |
clone,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
g
public Graphics g
title
public java.lang.String title
name
public java.lang.String name
ImageTester
public ImageTester(int width,
int height)
ImageTester
public ImageTester(java.lang.String name)
throws ImageError
getPixelRow
protected void getPixelRow(byte[] fillIn,
int y)
- Description copied from class: Image
- used in saveTo method. fill in the y row into the fillIn array.
there must be enough space for the full line be filled.
- Overrides:
- getPixelRow in class Image
equals
public boolean equals(java.lang.Object originalObj)
- This testthod is the reason for the creation of this class.
It compares two images byte per byte.
- Overrides:
- equals in class java.lang.Object
toString
public java.lang.String toString()
- Converts this image to String, as a string of hexadecimal numbers.
- Overrides:
- toString in class java.lang.Object