Package totalcross.unit
Class ImageTester
- java.lang.Object
-
- totalcross.ui.gfx.GfxSurface
-
- totalcross.ui.image.Image
-
- totalcross.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.backColor = 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().getGraphics(); 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); } }
-
-
Field Summary
Fields Modifier and Type Field Description Graphicsgjava.lang.Stringnamejava.lang.Stringtitle-
Fields inherited from class totalcross.ui.image.Image
alphaMask, comment, FADE_VALUE, height, hwScaleH, hwScaleW, NO_TRANSPARENT_COLOR, surfaceType, transparentColor, useAlpha, width
-
-
Constructor Summary
Constructors Constructor Description ImageTester(int width, int height)ImageTester(java.lang.String name)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object originalObj)This testthod is the reason for the creation of this class.static voidhex2bytes(java.lang.String str, ByteArrayStream bas)java.lang.StringtoString()Converts this image to String, as a string of hexadecimal numbers.-
Methods inherited from class totalcross.ui.image.Image
applyChanges, applyColor, applyColor2, applyFade, changeColors, createJpg, createJpg4B, createPng, freeTexture, getAlphaInstance, getClippedInstance, getCopy, getCurrentFrame, getFadedInstance, getFadedInstance, getFrameCount, getFrameInstance, getGraphics, getHeight, getHwScaledInstance, getJpegBestFit, getJpegScaled, getPath, getPixelRow, getPixels, getRotatedScaledInstance, getScaledInstance, getSmoothScaledInstance, getSmoothScaledInstance, getTouchedUpInstance, getWidth, getX, getY, hashCode, hwScaledBy, hwScaledFixedAspectRatio, isSupported, loadFrom, lockChanges, nextFrame, prevFrame, resizeJpeg, saveTo, scaledBy, setCurrentFrame, setFrameCount, setHwScaleFixedAspectRatio, setTransparentColor, smoothScaledBy, smoothScaledBy, smoothScaledFixedAspectRatio, smoothScaledFixedAspectRatio, smoothScaledFromResolution, smoothScaledFromResolution, writeFrameCount
-
-
-
-
Field Detail
-
g
public Graphics g
-
title
public java.lang.String title
-
name
public java.lang.String name
-
-
Constructor Detail
-
ImageTester
public ImageTester(int width, int height) throws ImageException- Throws:
ImageException
-
ImageTester
public ImageTester(java.lang.String name) throws ImageException, IOException- Throws:
ImageExceptionIOException
-
-
Method Detail
-
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.
-
hex2bytes
public static void hex2bytes(java.lang.String str, ByteArrayStream bas)
-
toString
public java.lang.String toString()
Converts this image to String, as a string of hexadecimal numbers.- Overrides:
toStringin classjava.lang.Object
-
-