Ejemplo n.º 1
0
 /**
  * main - entry point when used standalone. NOTE: no routines return error codes or throw any
  * local exceptions. Instead, any routine may complain to stderr and then exit with error to the
  * system.
  */
 public static void main(String argstrings[]) throws Exception {
   if (argstrings.length != 2) {
     System.err.println("Usage: diff oldfile newfile");
     System.exit(1);
   }
   Diff d = new Diff("Diff");
   d.doDiff(argstrings[0], argstrings[1]);
   return;
 }
Ejemplo n.º 2
0
 public boolean compare(String baselinecontent, String testresult) throws Exception {
   StringReader baserdr = new StringReader(baselinecontent);
   StringReader resultrdr = new StringReader(testresult);
   // Diff the two files
   Diff diff = new Diff("Testing " + getTitle());
   boolean pass = !diff.doDiff(baserdr, resultrdr);
   baserdr.close();
   resultrdr.close();
   return pass;
 }
Ejemplo n.º 3
0
  @Test
  public void testDuplicates() throws Exception {
    // Check if we are running against motherlode or localhost, or what.
    String testserver = System.getProperty("testserver");
    if (testserver == null) testserver = DFALTTESTSERVER;

    List<Result> results = new ArrayList<Result>();
    if (true) {
      results.add(
          new Result(
              "Top and field vars have same names",
              "http://" + testserver + "/dts/structdupname",
              "netcdf dods://"
                  + testserver
                  + "/dts/structdupname {\n"
                  + " variables:\n"
                  + "   int time;\n"
                  + "Structure {\n"
                  + "   float time;\n"
                  + "} record;\n"
                  + "}"));
    }
    if (true) {
      results.add(
          new Result(
              "TestFailure",
              "http://" + testserver + "/dts/simplestruct",
              "netcdf dods://"
                  + testserver
                  + "/dts/simplestruct {\n"
                  + " variables:\n"
                  + "Structure {\n"
                  + "   int i32;\n"
                  + "} types;\n"
                  + "}"));
    }
    boolean pass = true;
    for (Result result : results) {
      System.out.println("TestDuplicates: " + result.url);
      boolean localpass = true;
      try {
        DODSNetcdfFile ncfile = new DODSNetcdfFile(result.url);
        if (ncfile == null) throw new Exception("Cannot read: " + result.url);
        StringWriter ow = new StringWriter();
        PrintWriter pw = new PrintWriter(ow);
        ncfile.writeCDL(pw, false);
        try {
          pw.close();
          ow.close();
        } catch (IOException ioe) {
        }
        ;
        StringReader baserdr = new StringReader(result.cdl);
        String captured = ow.toString();
        StringReader resultrdr = new StringReader(captured);
        // Diff the two files
        Diff diff = new Diff("Testing " + result.title);
        localpass = !diff.doDiff(baserdr, resultrdr);
        baserdr.close();
        resultrdr.close();
        // Dump the output for visual comparison
        if (System.getProperty("visual") != null) {
          System.out.println("Testing " + result.title + " visual:");
          System.out.println("---------------");
          System.out.print(captured);
          System.out.println("---------------");
        }
      } catch (IllegalArgumentException e) {
        localpass = false;
      }
      if (!localpass) pass = false;
    }
    System.out.flush();
    System.err.flush();
    junit.framework.Assert.assertTrue("Testing " + getTitle(), pass);
  }