Esempio n. 1
0
  boolean dodata(ServletTest testcase) throws Exception {
    boolean pass = true;
    String baseline;
    // Create request and response objects
    Mocker mocker = new Mocker("dap4", testcase.makeurl(RequestMode.DAP), this);
    byte[] byteresult = null; // output

    // See if the servlet can process this
    try {
      byteresult = mocker.execute();
    } catch (Throwable t) {
      System.out.println(testcase.xfail ? "XFail" : "Fail");
      t.printStackTrace();
      return testcase.xfail;
    }

    if (prop_debug || DEBUG) {
      DapDump.dumpbytestream(byteresult, ByteOrder.nativeOrder(), "TestServlet.dodata");
    }

    if (!testcase.xfail && prop_generate) {
      // Dump the serialization into a file; this also includes the dmr
      String target = testcase.generatepath + ".raw";
      writefile(target, byteresult);
    }

    if (DEBUG) {
      System.out.println("///////////////////");
      ByteBuffer datab = ByteBuffer.wrap(byteresult).order(ByteOrder.nativeOrder());
      DapDump.dumpbytes(datab, true);
      System.out.println("///////////////////");
      System.out.flush();
    }

    // Setup a ChunkInputStream
    ByteArrayInputStream bytestream = new ByteArrayInputStream(byteresult);

    ChunkInputStream reader =
        new ChunkInputStream(bytestream, RequestMode.DAP, ByteOrder.nativeOrder());

    String sdmr = reader.readDMR(); // Read the DMR
    if (prop_visual) visual(testcase.title + ".dmr.dap", sdmr);

    Dump printer = new Dump();
    String sdata =
        printer.dumpdata(reader, testcase.checksumming, reader.getByteOrder(), testcase.template);

    if (prop_visual) visual(testcase.title + ".dap", sdata);

    if (!testcase.xfail && prop_baseline) writefile(testcase.baselinepath + ".dap", sdata);

    if (prop_diff) {
      // compare with baseline
      // Read the baseline file
      System.out.println("Note Comparison:");
      String baselinecontent = readfile(testcase.baselinepath + ".dap");
      pass = compare(baselinecontent, sdata);
      System.out.println(pass ? "Pass" : "Fail");
    }

    return pass;
  }