Package org.apache.batik.test

Examples of org.apache.batik.test.DefaultTestReport


    /**
     * This method will only throw exceptions if some aspect
     * of the test's internal operation fails.
     */
    public TestReport runImpl() throws Exception {
        DefaultTestReport report
            = new DefaultTestReport(this);

        InputStream inIS;

        try {
            inIS = in.openStream();
        } catch(Exception e) {
            StringWriter trace = new StringWriter();
            e.printStackTrace(new PrintWriter(trace));
            report.setErrorCode(ERROR_CANNOT_READ_IN_URL);
            report.setDescription(new TestReport.Entry[] {
                new TestReport.Entry
                    (TestMessages.formatMessage
                     (ENTRY_KEY_ERROR_DESCRIPTION, null),
                     TestMessages.formatMessage
                     (ERROR_CANNOT_READ_IN_URL,
                      new String[]{in.toString(), trace.toString()}))
                    });
            report.setPassed(false);
            return report;
        }

        if (action.equals("ROUND"))
            this.ref = in;
        else if (!action.equals("ENCODE") &&
                 !action.equals("DECODE")) {
            report.setErrorCode(ERROR_BAD_ACTION_STRING);
            report.setDescription(new TestReport.Entry[] {
                new TestReport.Entry
                    (TestMessages.formatMessage
                     (ENTRY_KEY_ERROR_DESCRIPTION, null),
                     TestMessages.formatMessage(ERROR_BAD_ACTION_STRING,
                                            new String[]{action}))
                    });
            report.setPassed(false);
            return report;
        }

        InputStream refIS;
        try {
            refIS = ref.openStream();
        } catch(Exception e) {
            StringWriter trace = new StringWriter();
            e.printStackTrace(new PrintWriter(trace));
            report.setErrorCode(ERROR_CANNOT_READ_REF_URL);
            report.setDescription(new TestReport.Entry[] {
                new TestReport.Entry
                    (TestMessages.formatMessage
                     (ENTRY_KEY_ERROR_DESCRIPTION, null),
                     TestMessages.formatMessage
                     (ERROR_CANNOT_READ_REF_URL,
                      new String[]{ref.toString(), trace.toString()}))
                    });
            report.setPassed(false);
            return report;
        }

        if (action.equals("ENCODE") ||
            action.equals("ROUND")) {
          // We need to encode the incomming data
          PipedOutputStream pos = new PipedOutputStream();
          OutputStream os = new Base64EncoderStream(pos);

          // Copy the input to the Base64 Encoder (in a seperate thread).
          Thread t = new StreamCopier(inIS, os);
         
          // Read that from the piped output stream.
          inIS = new PipedInputStream(pos);
          t.start();
        }

        if (action.equals("DECODE")||
            action.equals("ROUND")) {
            inIS = new Base64DecodeStream(inIS);
        }


        int mismatch = compareStreams(inIS, refIS, action.equals("ENCODE"));
       
        if (mismatch == -1) {
          report.setPassed(true);
          return report;
        }

        report.setErrorCode(ERROR_WRONG_RESULT);
        report.setDescription(new TestReport.Entry[] {
          new TestReport.Entry
            (TestMessages.formatMessage(ENTRY_KEY_ERROR_DESCRIPTION, null),
             TestMessages.formatMessage(ERROR_WRONG_RESULT,
                                    new String[]{""+mismatch}))
            });
        report.setPassed(false);
        return report;
    }
View Full Code Here


    /**
     * Runs this test. This method will only throw exceptions if some aspect of
     * the test's internal operation fails.
     */
    public TestReport runImpl() throws Exception {
  report = new DefaultTestReport(this);

  try {
      DiffImageTranscoder transcoder =
    new DiffImageTranscoder(getReferenceImageData());

View Full Code Here

    /**
     * This method will only throw exceptions if some aspect
     * of the test's internal operation fails.
     */
    public TestReport runImpl() throws Exception {
        DefaultTestReport report
            = new DefaultTestReport(this);

        ParsedURL url;
        try {
            url = new ParsedURL(base);
            if (sub != null) {
                url  = new ParsedURL(url, sub);
            }
        } catch(Exception e) {
            StringWriter trace = new StringWriter();
            e.printStackTrace(new PrintWriter(trace));
            report.setErrorCode(ERROR_CANNOT_PARSE_URL);
            report.setDescription(new TestReport.Entry[] {
                new TestReport.Entry
                    (TestMessages.formatMessage
                     (ENTRY_KEY_ERROR_DESCRIPTION, null),
                     TestMessages.formatMessage
                     (ERROR_CANNOT_PARSE_URL,
                      new String[]{base,
                                   (sub == null) ? "null" : sub,
                                   trace.toString()}))
                    });
            report.setPassed(false);
            return report;
        }

        if (ref.equals(url.toString())) {
            report.setPassed(true);
            return report;
        }

        report.setErrorCode(ERROR_WRONG_RESULT);
        report.setDescription(new TestReport.Entry[] {
          new TestReport.Entry
            (TestMessages.formatMessage(ENTRY_KEY_ERROR_DESCRIPTION, null),
             TestMessages.formatMessage
             (ERROR_WRONG_RESULT, new String[]{url.toString(), ref }))
            });
        report.setPassed(false);
        return report;
    }
View Full Code Here

    /**
     * This method will only throw exceptions if some aspect
     * of the test's internal operation fails.
     */
    public TestReport runImpl() throws Exception {
        DefaultTestReport report
            = new DefaultTestReport(this);

        ParsedURL purl;
        try {
            purl  = new ParsedURL(base);
        } catch(Exception e) {
            StringWriter trace = new StringWriter();
            e.printStackTrace(new PrintWriter(trace));
            report.setErrorCode(ERROR_CANNOT_PARSE_URL);
            report.setDescription(new TestReport.Entry[] {
                new TestReport.Entry
                    (TestMessages.formatMessage
                     (ENTRY_KEY_ERROR_DESCRIPTION, null),
                     TestMessages.formatMessage
                     (ERROR_CANNOT_PARSE_URL,
                      new String[]{"null",
                                   base,
                                   trace.toString()}))
                    });
            report.setPassed(false);
            return report;
        }

        byte[] data = new byte[5];
        int num = 0;
        try {
            InputStream is = purl.openStream();
            num = is.read(data);
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
        StringBuffer sb = new StringBuffer();
        for (int i=0; i<num; i++) {
            int val = ((int)data[i])&0xFF;
            if (val < 16) {
                sb.append("0");
            }
            sb.append(Integer.toHexString(val) + " ");
        }
       
        String info = ( "CT: " + purl.getContentType() +
                       " CE: " + purl.getContentEncoding() +
                       " DATA: " + sb +
                       "URL: " + purl);

        if (ref.equals(info)) {
            report.setPassed(true);
            return report;
        }

        report.setErrorCode(ERROR_WRONG_RESULT);
        report.setDescription(new TestReport.Entry[] {
          new TestReport.Entry
            (TestMessages.formatMessage(ENTRY_KEY_ERROR_DESCRIPTION, null),
             TestMessages.formatMessage
             (ERROR_WRONG_RESULT, new String[]{info, ref }))
            });
        report.setPassed(false);
        return report;
    }
View Full Code Here

    /**
     * Runs this test. This method will only throw exceptions if some aspect of
     * the test's internal operation fails.
     */
    public TestReport runImpl() throws Exception {
        DefaultTestReport report = new DefaultTestReport(this);

        ValueManager manager;
        try {
            manager = createValueManager();
        } catch (Exception ex) {
            report.setErrorCode(ERROR_INSTANTIATION);
            report.setPassed(false);
            report.addDescriptionEntry(ERROR_INSTANTIATION, ex.getMessage());
            return report;
        }

        // test default value if any
        if (!defaultValue.equals("__USER_AGENT__")) {
            String s = manager.getDefaultValue().getCssText();
            if (!defaultValue.equalsIgnoreCase(s)) {
                report.setErrorCode(ERROR_INVALID_DEFAULT_VALUE);
                report.setPassed(false);
                report.addDescriptionEntry(ERROR_INVALID_DEFAULT_VALUE,
                                           "should be: "+defaultValue);
            }
        }

        // test if the property is inherited or not
        if (isInherited.booleanValue() != manager.isInheritedProperty()) {
            report.setErrorCode(ERROR_IS_INHERITED);
            report.setPassed(false);
            report.addDescriptionEntry(ERROR_IS_INHERITED, "");
        }

        Parser cssParser = new Parser();
        // see if the property supports the value 'inherit'
        try {
            LexicalUnit lu = cssParser.parsePropertyValue("inherit");
            Value v = manager.createValue(lu, null);
            String s = v.getCssText();
            if (!"inherit".equalsIgnoreCase(s)) {
                report.setErrorCode(ERROR_INHERIT_VALUE);
                report.setPassed(false);
                report.addDescriptionEntry(ERROR_INHERIT_VALUE, "inherit");
            }
        } catch (Exception ex) {
            report.setErrorCode(ERROR_INHERIT_VALUE);
            report.setPassed(false);
            report.addDescriptionEntry(ERROR_INHERIT_VALUE, ex.getMessage());
        }

        // test all possible identifiers
        if (identValues != null) {
            try {
                for (int i=0; i < identValues.length; ++i) {
                    LexicalUnit lu = cssParser.parsePropertyValue(identValues[i]);
                    Value v = manager.createValue(lu, null);
                    String s = v.getCssText();
                    if (!identValues[i].equalsIgnoreCase(s)) {
                        report.setErrorCode(ERROR_INVALID_VALUE);
                        report.setPassed(false);
                        report.addDescriptionEntry(ERROR_INVALID_VALUE,
                                                   identValues[i]+"/"+s);
                    }
                }
            } catch (Exception ex) {
                report.setErrorCode(ERROR_INVALID_VALUE);
                report.setPassed(false);
                report.addDescriptionEntry(ERROR_INVALID_VALUE,
                                           ex.getMessage());
            }
        }
        return report;
    }
View Full Code Here

                missingIds += "[" + publicId + "]  -- ";
            }
        }
       
        if (!"".equals(missingIds)) {
            DefaultTestReport report = new DefaultTestReport(this);
            report.setErrorCode(ERROR_MISSING_SYSTEM_ID);
            report.addDescriptionEntry(KEY_MISSING_IDS, missingIds);
            report.setPassed(false);
            return report;
        }

        return reportSuccess();
    }
View Full Code Here

     * Requests this <tt>Test</tt> to run and produce a
     * report.
     *
     */
    public TestReport run(){
        DefaultTestReport report
            = new DefaultTestReport(this);

        //
        // First, do clean-up
        //
        if (candidateReference != null){
            if (candidateReference.exists()){
                candidateReference.delete();
            }
        }
                   

        //
        // Render the SVG image into a raster. We use the
        // ImageTranscoder to convert the SVG into a raster in
        // a temporary file.
        //
        File tmpFile = null;

        try{
            if (candidateReference != null)
                tmpFile = candidateReference;
            else
                tmpFile = File.createTempFile(TEMP_FILE_PREFIX,
                                              TEMP_FILE_SUFFIX,
                                              null);
        }catch(IOException e){
            report.setErrorCode(ERROR_CANNOT_CREATE_TEMP_FILE);
            report.setDescription(new TestReport.Entry[] {
                new TestReport.Entry(Messages.formatMessage(ENTRY_KEY_ERROR_DESCRIPTION, null),
                          Messages.formatMessage(ERROR_CANNOT_CREATE_TEMP_FILE,
                                                 new Object[]{e.getMessage()}))
                    });
            report.setPassed(false);
            return report;
        }


        FileOutputStream tmpFileOS = null;

        try{
            tmpFileOS = new FileOutputStream(tmpFile);
        }catch(IOException e){
            report.setErrorCode(ERROR_CANNOT_CREATE_TEMP_FILE_STREAM);
            report.setDescription(new TestReport.Entry[] {
                new TestReport.Entry(Messages.formatMessage(ENTRY_KEY_ERROR_DESCRIPTION, null),
                          Messages.formatMessage(ERROR_CANNOT_CREATE_TEMP_FILE_STREAM,
                                                 new String[]{tmpFile.getAbsolutePath(),
                                                              e.getMessage()})) });
            report.setPassed(false);
            tmpFile.deleteOnExit();
            return report;
        }

        ImageTranscoder transcoder = getTestImageTranscoder();
        TranscoderInput src = new TranscoderInput(svgURL.toString());
        TranscoderOutput dst = new TranscoderOutput(tmpFileOS);
       
        try{
            transcoder.transcode(src, dst);
        }catch(TranscoderException e){
            StringWriter trace = new StringWriter();
            e.printStackTrace(new PrintWriter(trace));
               
            report.setErrorCode(ERROR_CANNOT_TRANSCODE_SVG);
            report.setDescription(new TestReport.Entry[]{
                new TestReport.Entry(Messages.formatMessage(ENTRY_KEY_ERROR_DESCRIPTION, null),
                          Messages.formatMessage(ERROR_CANNOT_TRANSCODE_SVG,
                                                 new String[]{svgURL.toString(),
                                                              e.getClass().getName(),
                                                              e.getMessage(),
                                                              trace.toString()
                                                 })) });
            report.setPassed(false);
            tmpFile.deleteOnExit();
            return report;
        }catch(Exception e){
            StringWriter trace = new StringWriter();
            e.printStackTrace(new PrintWriter(trace));

            report.setErrorCode(ERROR_CANNOT_TRANSCODE_SVG);
            report.setDescription(new TestReport.Entry[]{
                new TestReport.Entry(Messages.formatMessage(ENTRY_KEY_ERROR_DESCRIPTION, null),
                          Messages.formatMessage(ERROR_CANNOT_TRANSCODE_SVG,
                                                 new String[]{svgURL.toString(),
                                                              e.getClass().getName(),
                                                              e.getMessage(),
                                                              trace.toString()
                                                 })) });
            report.setPassed(false);
            tmpFile.deleteOnExit();
            return report;
        }

        //
        // Do a binary comparison of the encoded images.
        //
        InputStream refStream = null;
        InputStream newStream = null;
        try {
            refStream =
                new BufferedInputStream(refImgURL.openStream());
        }catch(IOException e){
            report.setErrorCode(ERROR_CANNOT_OPEN_REFERENCE_IMAGE);
            report.setDescription( new TestReport.Entry[]{
                new TestReport.Entry(Messages.formatMessage(ENTRY_KEY_ERROR_DESCRIPTION, null),
                          Messages.formatMessage(ERROR_CANNOT_OPEN_REFERENCE_IMAGE,
                                                 new Object[]{refImgURL.toString(),
                                                              e.getMessage()})) });
            report.setPassed(false);
            // Try and save tmp file as a candidate variation
            if (candidateReference == null){
                tmpFile.delete();
            }
            return report;
        }

        try{
            newStream =
                new BufferedInputStream(new FileInputStream(tmpFile));
        }catch(IOException e){
            report.setErrorCode(ERROR_CANNOT_OPEN_GENERATED_IMAGE);
            report.setDescription(new TestReport.Entry[]{
                new TestReport.Entry(Messages.formatMessage(ENTRY_KEY_ERROR_DESCRIPTION, null),
                          Messages.formatMessage(ERROR_CANNOT_OPEN_GENERATED_IMAGE,
                                                 new Object[]{tmpFile.getAbsolutePath(),
                                                              e.getMessage()}))});
            report.setPassed(false);
            tmpFile.delete();
            return report;
        }


        boolean accurate = false;
        try{
            accurate = compare(refStream, newStream);
        } catch(IOException e) {
            report.setErrorCode(ERROR_ERROR_WHILE_COMPARING_FILES);
            report.setDescription(new TestReport.Entry[]{
                new TestReport.Entry(Messages.formatMessage(ENTRY_KEY_ERROR_DESCRIPTION, null),
                          Messages.formatMessage(ERROR_ERROR_WHILE_COMPARING_FILES,
                                                 new Object[]{refImgURL.toString(),
                                                              tmpFile.getAbsolutePath(),
                                                              e.getMessage()}))});
            report.setPassed(false);
            if (candidateReference == null){
                tmpFile.delete();
            }
            return report;
        }


        //
        // If the files differ here, it means that even the variation does
        // not account for the difference return an error
        //
        if(!accurate){
            try{
                BufferedImage ref = getImage(refImgURL);
                BufferedImage gen = getImage(tmpFile);
                BufferedImage diff = buildDiffImage(ref, gen);

                //
                // If there is an accepted variation, check if it equals the
                // computed difference.
                //
                if(variationURL != null){
                    File tmpDiff = imageToFile(diff, IMAGE_TYPE_DIFF);

                    InputStream variationURLStream = null;
                    try{
                        variationURLStream = variationURL.openStream();
                    }catch(IOException e){
                        // Could not open variationURL stream. Just trace that
                        System.err.println(Messages.formatMessage(COULD_NOT_OPEN_VARIATION_URL,
                                                                  new Object[]{variationURL.toString()}));
                    }

                    if(variationURLStream != null){
                        InputStream refDiffStream =
                            new BufferedInputStream(variationURLStream);
                       
                        InputStream tmpDiffStream =
                            new BufferedInputStream(new FileInputStream(tmpDiff));
                       
                        if(compare(refDiffStream, tmpDiffStream)){
                            // We accept the generated result.
                            accurate = true;
                        }
                    }
                }

                if(!accurate){
                    System.err.println(">>>>>>>>>>>>>>>>>>>>>> Rendering is not accurate");
                    if(saveVariation != null){
                        // There is a computed variation different from the
                        // referenced variation and there is a place where the new
                        // variation should be saved.
                        saveImage(diff, saveVariation);
                    }
                   
                    // Build two images:
                    // a. One with the reference image and the newly generated image
                    // b. One with the difference between the two images and the set of
                    //    different pixels.
                    BufferedImage cmp = makeCompareImage(ref, gen);
                    File cmpFile = imageToFile(cmp, IMAGE_TYPE_COMPARISON);
                    File diffFile = imageToFile(diff, IMAGE_TYPE_DIFF);
                   
                    report.setErrorCode(ERROR_SVG_RENDERING_NOT_ACCURATE);
                   
                    report.setDescription(new TestReport.Entry[]{
                        new TestReport.Entry(Messages.formatMessage(ENTRY_KEY_ERROR_DESCRIPTION, null),
                                             Messages.formatMessage(ERROR_SVG_RENDERING_NOT_ACCURATE, null)),
                        new TestReport.Entry(Messages.formatMessage(ENTRY_KEY_REFERENCE_GENERATED_IMAGE_URI, null),
                                             cmpFile),
                        new TestReport.Entry(Messages.formatMessage(ENTRY_KEY_DIFFERENCE_IMAGE, null),
                                             diffFile) });

                    if (candidateReference == null){
                        tmpFile.delete();
                    }
                   
                    report.setPassed(false);
                    return report;
                }
            }catch(Exception e){
                report.setErrorCode(ERROR_SVG_RENDERING_NOT_ACCURATE);
                StringWriter trace = new StringWriter();
                e.printStackTrace(new PrintWriter(trace));
               
                report.setDescription(new TestReport.Entry[]{
                    new TestReport.Entry(Messages.formatMessage(ENTRY_KEY_ERROR_DESCRIPTION, null),
                                         Messages.formatMessage(ERROR_SVG_RENDERING_NOT_ACCURATE, null)),
                    new TestReport.Entry(Messages.formatMessage(ENTRY_KEY_INTERNAL_ERROR, null),
                                         Messages.formatMessage(COULD_NOT_GENERATE_COMPARISON_IMAGES,
                                                                new Object[]{e.getClass().getName(),
                                                                             e.getMessage(),
                                                                             trace.toString()})) });

                if (candidateReference == null){
                    tmpFile.delete();
                }
               
                report.setPassed(false);
                return report;
            }
        }


        //
        // Yahooooooo! everything worked out well.
        //
        report.setPassed(true);
        tmpFile.delete();
        return report;
    }
View Full Code Here

     * Requests this <tt>Test</tt> to run and produce a
     * report.
     *
     */
    public TestReport run(){
        DefaultTestReport report
            = new DefaultTestReport(this);

        //
        // First, do clean-up
        //
        if (candidateReference != null){
            if (candidateReference.exists()){
                candidateReference.delete();
            }
        }
                   

        //
        // Render the SVG image into a raster. We use the
        // ImageTranscoder to convert the SVG into a raster in
        // a temporary file.
        //
        File tmpFile = null;

        try{
            if (candidateReference != null)
                tmpFile = candidateReference;
            else
                tmpFile = File.createTempFile(TEMP_FILE_PREFIX,
                                              TEMP_FILE_SUFFIX,
                                              null);
        }catch(IOException e){
            report.setErrorCode(ERROR_CANNOT_CREATE_TEMP_FILE);
            report.setDescription(new TestReport.Entry[] {
                new TestReport.Entry(Messages.formatMessage(ENTRY_KEY_ERROR_DESCRIPTION, null),
                          Messages.formatMessage(ERROR_CANNOT_CREATE_TEMP_FILE,
                                                 new Object[]{e.getMessage()}))
                    });
            report.setPassed(false);
            return report;
        }


        FileOutputStream tmpFileOS = null;

        try{
            tmpFileOS = new FileOutputStream(tmpFile);
        }catch(IOException e){
            report.setErrorCode(ERROR_CANNOT_CREATE_TEMP_FILE_STREAM);
            report.setDescription(new TestReport.Entry[] {
                new TestReport.Entry(Messages.formatMessage(ENTRY_KEY_ERROR_DESCRIPTION, null),
                          Messages.formatMessage(ERROR_CANNOT_CREATE_TEMP_FILE_STREAM,
                                                 new String[]{tmpFile.getAbsolutePath(),
                                                              e.getMessage()})) });
            report.setPassed(false);
            tmpFile.deleteOnExit();
            return report;
        }

        ImageTranscoder transcoder = getTestImageTranscoder();
        TranscoderInput src = new TranscoderInput(svgURL.toString());
        TranscoderOutput dst = new TranscoderOutput(tmpFileOS);
       
        try{
            transcoder.transcode(src, dst);
        }catch(TranscoderException e){
            StringWriter trace = new StringWriter();
            e.printStackTrace(new PrintWriter(trace));
               
            report.setErrorCode(ERROR_CANNOT_TRANSCODE_SVG);
            report.setDescription(new TestReport.Entry[]{
                new TestReport.Entry(Messages.formatMessage(ENTRY_KEY_ERROR_DESCRIPTION, null),
                          Messages.formatMessage(ERROR_CANNOT_TRANSCODE_SVG,
                                                 new String[]{svgURL.toString(),
                                                              e.getClass().getName(),
                                                              e.getMessage(),
                                                              trace.toString()
                                                 })) });
            report.setPassed(false);
            tmpFile.deleteOnExit();
            return report;
        }catch(Exception e){
            StringWriter trace = new StringWriter();
            e.printStackTrace(new PrintWriter(trace));

            report.setErrorCode(ERROR_CANNOT_TRANSCODE_SVG);
            report.setDescription(new TestReport.Entry[]{
                new TestReport.Entry(Messages.formatMessage(ENTRY_KEY_ERROR_DESCRIPTION, null),
                          Messages.formatMessage(ERROR_CANNOT_TRANSCODE_SVG,
                                                 new String[]{svgURL.toString(),
                                                              e.getClass().getName(),
                                                              e.getMessage(),
                                                              trace.toString()
                                                 })) });
            report.setPassed(false);
            tmpFile.deleteOnExit();
            return report;
        }

        //
        // Do a binary comparison of the encoded images.
        //
        InputStream refStream = null;
        InputStream newStream = null;
        try {
            refStream =
                new BufferedInputStream(refImgURL.openStream());
        }catch(IOException e){
            report.setErrorCode(ERROR_CANNOT_OPEN_REFERENCE_IMAGE);
            report.setDescription( new TestReport.Entry[]{
                new TestReport.Entry(Messages.formatMessage(ENTRY_KEY_ERROR_DESCRIPTION, null),
                          Messages.formatMessage(ERROR_CANNOT_OPEN_REFERENCE_IMAGE,
                                                 new Object[]{refImgURL.toString(),
                                                              e.getMessage()})) });
            report.setPassed(false);
            // Try and save tmp file as a candidate variation
            if (candidateReference == null){
                tmpFile.delete();
            }
            return report;
        }

        try{
            newStream =
                new BufferedInputStream(new FileInputStream(tmpFile));
        }catch(IOException e){
            report.setErrorCode(ERROR_CANNOT_OPEN_GENERATED_IMAGE);
            report.setDescription(new TestReport.Entry[]{
                new TestReport.Entry(Messages.formatMessage(ENTRY_KEY_ERROR_DESCRIPTION, null),
                          Messages.formatMessage(ERROR_CANNOT_OPEN_GENERATED_IMAGE,
                                                 new Object[]{tmpFile.getAbsolutePath(),
                                                              e.getMessage()}))});
            report.setPassed(false);
            tmpFile.delete();
            return report;
        }


        boolean accurate = false;
        try{
            accurate = compare(refStream, newStream);
        } catch(IOException e) {
            report.setErrorCode(ERROR_ERROR_WHILE_COMPARING_FILES);
            report.setDescription(new TestReport.Entry[]{
                new TestReport.Entry(Messages.formatMessage(ENTRY_KEY_ERROR_DESCRIPTION, null),
                          Messages.formatMessage(ERROR_ERROR_WHILE_COMPARING_FILES,
                                                 new Object[]{refImgURL.toString(),
                                                              tmpFile.getAbsolutePath(),
                                                              e.getMessage()}))});
            report.setPassed(false);
            if (candidateReference == null){
                tmpFile.delete();
            }
            return report;
        }


        //
        // If the files differ here, it means that even the variation does
        // not account for the difference return an error
        //
        if(!accurate){
            try{
                BufferedImage ref = getImage(refImgURL);
                BufferedImage gen = getImage(tmpFile);
                BufferedImage diff = buildDiffImage(ref, gen);

                //
                // If there is an accepted variation, check if it equals the
                // computed difference.
                //
                if(variationURL != null){
                    File tmpDiff = imageToFile(diff, IMAGE_TYPE_DIFF);

                    InputStream variationURLStream = null;
                    try{
                        variationURLStream = variationURL.openStream();
                    }catch(IOException e){
                        // Could not open variationURL stream. Just trace that
                        System.err.println(Messages.formatMessage(COULD_NOT_OPEN_VARIATION_URL,
                                                                  new Object[]{variationURL.toString()}));
                    }

                    if(variationURLStream != null){
                        InputStream refDiffStream =
                            new BufferedInputStream(variationURLStream);
                       
                        InputStream tmpDiffStream =
                            new BufferedInputStream(new FileInputStream(tmpDiff));
                       
                        if(compare(refDiffStream, tmpDiffStream)){
                            // We accept the generated result.
                            accurate = true;
                        }
                    }
                }

                if(!accurate){
                    System.err.println(">>>>>>>>>>>>>>>>>>>>>> Rendering is not accurate");
                    if(saveVariation != null){
                        // There is a computed variation different from the
                        // referenced variation and there is a place where the new
                        // variation should be saved.
                        saveImage(diff, saveVariation);
                    }
                   
                    // Build two images:
                    // a. One with the reference image and the newly generated image
                    // b. One with the difference between the two images and the set of
                    //    different pixels.
                    BufferedImage cmp = makeCompareImage(ref, gen);
                    File cmpFile = imageToFile(cmp, IMAGE_TYPE_COMPARISON);
                    File diffFile = imageToFile(diff, IMAGE_TYPE_DIFF);
                   
                    report.setErrorCode(ERROR_SVG_RENDERING_NOT_ACCURATE);
                   
                    report.setDescription(new TestReport.Entry[]{
                        new TestReport.Entry(Messages.formatMessage(ENTRY_KEY_ERROR_DESCRIPTION, null),
                                             Messages.formatMessage(ERROR_SVG_RENDERING_NOT_ACCURATE, null)),
                        new TestReport.Entry(Messages.formatMessage(ENTRY_KEY_REFERENCE_GENERATED_IMAGE_URI, null),
                                             cmpFile),
                        new TestReport.Entry(Messages.formatMessage(ENTRY_KEY_DIFFERENCE_IMAGE, null),
                                             diffFile) });

                    if (candidateReference == null){
                        tmpFile.delete();
                    }
                   
                    report.setPassed(false);
                    return report;
                }
            }catch(Exception e){
                report.setErrorCode(ERROR_SVG_RENDERING_NOT_ACCURATE);
                StringWriter trace = new StringWriter();
                e.printStackTrace(new PrintWriter(trace));
               
                report.setDescription(new TestReport.Entry[]{
                    new TestReport.Entry(Messages.formatMessage(ENTRY_KEY_ERROR_DESCRIPTION, null),
                                         Messages.formatMessage(ERROR_SVG_RENDERING_NOT_ACCURATE, null)),
                    new TestReport.Entry(Messages.formatMessage(ENTRY_KEY_INTERNAL_ERROR, null),
                                         Messages.formatMessage(COULD_NOT_GENERATE_COMPARISON_IMAGES,
                                                                new Object[]{e.getClass().getName(),
                                                                             e.getMessage(),
                                                                             trace.toString()})) });

                if (candidateReference == null){
                    tmpFile.delete();
                }
               
                report.setPassed(false);
                return report;
            }
        }


        //
        // Yahooooooo! everything worked out well.
        //
        report.setPassed(true);
        tmpFile.delete();
        return report;
    }
View Full Code Here

    /**
     * This method will only throw exceptions if some aspect
     * of the test's internal operation fails.
     */
    public TestReport runImpl() throws Exception {
        DefaultTestReport report
            = new DefaultTestReport(this);

        ParsedURL url;
        try {
            url = new ParsedURL(base);
            if (sub != null) {
                url  = new ParsedURL(url, sub);
            }
        } catch(Exception e) {
            StringWriter trace = new StringWriter();
            e.printStackTrace(new PrintWriter(trace));
            report.setErrorCode(ERROR_CANNOT_PARSE_URL);
            report.setDescription(new TestReport.Entry[] {
                new TestReport.Entry
                    (Messages.formatMessage(ENTRY_KEY_ERROR_DESCRIPTION, null),
                     Messages.formatMessage
                     (ERROR_CANNOT_PARSE_URL,
                      new String[]{base,
                                   (sub == null) ? "null" : sub,
                                   trace.toString()}))
                    });
            report.setPassed(false);
            return report;
        }

        if (ref.equals(url.toString())) {
            report.setPassed(true);
            return report;
        }

        report.setErrorCode(ERROR_WRONG_RESULT);
        report.setDescription(new TestReport.Entry[] {
          new TestReport.Entry
            (Messages.formatMessage(ENTRY_KEY_ERROR_DESCRIPTION, null),
             Messages.formatMessage
             (ERROR_WRONG_RESULT, new String[]{url.toString(), ref }))
            });
        report.setPassed(false);
        return report;
    }
View Full Code Here

    /**
     * This method will only throw exceptions if some aspect
     * of the test's internal operation fails.
     */
    public TestReport runImpl() throws Exception {
        DefaultTestReport report
            = new DefaultTestReport(this);

        ParsedURL purl;
        try {
            purl  = new ParsedURL(base);
        } catch(Exception e) {
            StringWriter trace = new StringWriter();
            e.printStackTrace(new PrintWriter(trace));
            report.setErrorCode(ERROR_CANNOT_PARSE_URL);
            report.setDescription(new TestReport.Entry[] {
                new TestReport.Entry
                    (Messages.formatMessage(ENTRY_KEY_ERROR_DESCRIPTION, null),
                     Messages.formatMessage
                     (ERROR_CANNOT_PARSE_URL,
                      new String[]{"null",
                                   base,
                                   trace.toString()}))
                    });
            report.setPassed(false);
            return report;
        }

        byte[] data = new byte[5];
        int num = 0;
        try {
            InputStream is = purl.openStream();
            num = is.read(data);
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
        StringBuffer sb = new StringBuffer();
        for (int i=0; i<num; i++) {
            int val = ((int)data[i])&0xFF;
            if (val < 16) {
                sb.append("0");
            }
            sb.append(Integer.toHexString(val) + " ");
        }
       
        String info = ( "CT: " + purl.getContentType() +
                       " CE: " + purl.getContentEncoding() +
                       " DATA: " + sb +
                       "URL: " + purl);

        if (ref.equals(info)) {
            report.setPassed(true);
            return report;
        }

        report.setErrorCode(ERROR_WRONG_RESULT);
        report.setDescription(new TestReport.Entry[] {
          new TestReport.Entry
            (Messages.formatMessage(ENTRY_KEY_ERROR_DESCRIPTION, null),
             Messages.formatMessage
             (ERROR_WRONG_RESULT, new String[]{info, ref }))
            });
        report.setPassed(false);
        return report;
    }
View Full Code Here

TOP

Related Classes of org.apache.batik.test.DefaultTestReport

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.