Class 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 Detail

      • title

        public java.lang.String title
      • name

        public java.lang.String name
    • 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.
        Overrides:
        equals in class Image
      • 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:
        toString in class java.lang.Object