/**
   * This function performs an individual formatting test after the input and output streams have
   * been created.
   *
   * @param commands the input that decides which tests to perform
   * @return a String holding the error messages for any failed tests or null if no tests are
   *     failed.
   */
  private static /*@Nullable*/ String performTest(LineNumberReader commands) {
    StringBuffer output = new StringBuffer();
    //  List invariantTestCases = new Vector();
    boolean noTestFailed = true;

    while (true) {
      // Create a new test case
      //  FormatTestCase currentCase = FormatTestCase.instantiate(commands, generateGoals);

      // if (currentCase == null)
      //  break;
      //  else {
      //  invariantTestCases.add(currentCase);
      String results = AddAndCheckTestCase.runTest(commands);
      if (results == null) break;
      if (!(results.length() == 0)) {
        //  output.print(currentCase.getDiffString());
        output.append(results);
        noTestFailed = false;
      }
    }
    if (noTestFailed) {
      return null;
    } else {
      return output.toString();
    }
  }
  private static String generateCommands(LineNumberReader input) {
    StringBuffer output = new StringBuffer();

    while (true) {
      String commands = AddAndCheckTestCase.generateTest(input);
      if (commands == null) break;
      output.append(commands);
    }
    return output.toString();
  }
 public void addFailure(Test test, AssertionFailedError t) {
   StringBuffer sb = new StringBuffer();
   sb.append(test.toString());
   sb.append("\n");
   StringWriter sw = new StringWriter();
   t.printStackTrace(new PrintWriter(sw, true));
   sb.append(sw.toString());
   Log.getLogWriter().severe("zzzzzFAILURE IN " + test, t);
   // reportFailure(test, sb.toString());
   lastFailClass = getClassName(test);
   lastFailMethod = getMethodName(test);
   lastThrowable = t;
 }
예제 #4
0
    public boolean process(final SimpleRequest request, final SimpleResponse response)
        throws IOException {
      HttpVersion httpversion = request.getRequestLine().getHttpVersion();
      response.setStatusLine(httpversion, HttpStatus.SC_OK);
      response.addHeader(new Header("Content-Type", "text/plain"));

      URI uri = new URI(request.getRequestLine().getUri(), true);

      StringBuffer buffer = new StringBuffer();
      buffer.append("QueryString=\"");
      buffer.append(uri.getQuery());
      buffer.append("\"\r\n");
      response.setBodyString(buffer.toString());
      return true;
    }
    /** Given a line from an input file, generates appropriate check or add command. */
    private static void generateCheckOrAddCommand(String command, int lineNumber) {
      // remove the command
      String args = command.substring(command.indexOf(":") + 1);

      StringTokenizer tokens = new StringTokenizer(args, argDivider);
      if (tokens.countTokens() != types.length) {
        throw new RuntimeException(
            "Number of arguments to generate an add command on line: "
                + lineNumber
                + " is: "
                + tokens.countTokens()
                + " but should be: "
                + types.length);
      }
      Object[] params = getParams(tokens);
      assert !tokens.hasMoreTokens();
      InvariantStatus goalStatus = null;
      if (isCheckCommand(command)) {
        goalStatus = getCheckStatus(params);
      } else {
        goalStatus = getAddStatus(params);
      }
      String invariantFormat = getInvariantFormat();
      results.append(
          command
              + argDivider
              + " "
              + goalStatus.toString()
              + argDivider
              + " "
              + invariantFormat
              + lineSep);
    }
    /**
     * Initializes the fields of this class based on the first two lines of a case which include the
     * class name and parameter types.
     *
     * @return true is end of file is reached.
     */
    private static boolean initFields(LineNumberReader commands, boolean generatingCommands) {

      results = new StringBuffer();

      String className = getNextRealLine(commands);

      // End of file reached
      if (className == null) return true;

      // Load the class from file
      Class<? extends Invariant> classToTest = asInvClass(getClass(className));

      try {
        classToTest.getField("dkconfig_enabled"); // Enable if needs to be done
        InvariantAddAndCheckTester.config.apply(className + ".enabled", "true");
      } catch (NoSuchFieldException e) { // Otherwise do nothing
      }

      if (generatingCommands) {
        results.append(className + lineSep);
      }

      // Instantiate variables to be used as the names in the
      // invariants, variables are labeled a,b,c and so on as they
      // appear
      String typeString = getNextRealLine(commands);

      types = getTypes(typeString);

      VarInfo[] vars = getVarInfos(classToTest, types);
      PptSlice sl = createSlice(vars, daikon.test.Common.makePptTopLevel("Test:::OBJECT", vars));

      // Create an actual instance of the class
      invariantToTest = instantiateClass(classToTest, sl);

      addModified = getAddModified(invariantToTest.getClass());
      checkModified = getCheckModified(invariantToTest.getClass());
      outputProducer = getOutputProducer(invariantToTest.getClass());

      assert getArity(invariantToTest.getClass()) == types.length;

      if (generatingCommands) {
        results.append(typeString + lineSep);
      }
      return false;
    }
 /**
  * @return a String containing the proper add and check commands for this input lines of this
  *     test case.
  */
 public static String generateTest(LineNumberReader commands) {
   boolean endOfFile = initFields(commands, true);
   if (endOfFile) return null;
   while (true) {
     String commandLine = getNextLine(commands).trim();
     int lineNumber = commands.getLineNumber();
     if (InvariantAddAndCheckTester.isComment(commandLine)) {
       results.append(commandLine + lineSep);
     } else if (isTestTerminator(commandLine)) {
       results.append(commandLine + lineSep + lineSep);
       break;
     } else if (isAddCommand(commandLine) || isCheckCommand(commandLine)) {
       generateCheckOrAddCommand(commandLine, lineNumber);
     } else if (isCompareCommand(commandLine)) {
       // generateCompareCommand(commandLine);
     } else {
       throw new RuntimeException("unrecognized command");
     }
   }
   return results.toString();
 }
  protected void setUp() throws Exception {
    testSB = new StringBuffer();

    for (int i = 0; i < 12; i++) {
      testSB.append("\t1\t3\t4\t5\n");
      testSB.append("\t1\t2\t3\t4\t5\n");
      testSB.append("\t1\t2\t3\t4\t5\n");
      testSB.append("\t1\t2\t3\t5\n");
      testSB.append("\t1\t2\t3\t4\t5\n");
      testSB.append("\t4\t5\n");
    }

    try {
      File tmpF = File.createTempFile("ImportTaskTest", "testRun");
      assertTrue(tmpF.canRead());
      assertTrue(tmpF.canWrite());

      FileWriter fw = new FileWriter(tmpF);
      fw.write(testSB.toString());
      fw.close();

      fis = new FileInputStream(tmpF);

    } catch (IOException exc) {
      assertTrue(false);
    }
  }
예제 #9
0
 static final String fixCRLF(String source) {
   StringBuffer buf = new StringBuffer(source.length());
   StringTokenizer chunks = new StringTokenizer(source, "\r\n");
   while (chunks.hasMoreTokens()) {
     buf.append(chunks.nextToken());
     if (buf.charAt(buf.length() - 1) != '\n') {
       buf.append('\n');
     }
   }
   return buf.toString();
 }
 /**
  * @return String containing error messages for any failed cases. In the case that there are no
  *     failed cases, the empty string is returned. In the case where commands is empty (there
  *     are no more test cases and the end of the file has been reached), null is returned.
  */
 public static String runTest(LineNumberReader commands) {
   boolean endOfFile = initFields(commands, false);
   if (endOfFile) {
     return null;
   }
   while (true) {
     String commandLine = getNextRealLine(commands);
     int lineNumber = commands.getLineNumber();
     if (InvariantAddAndCheckTester.isComment(commandLine)) {
       continue;
     } else if (isTestTerminator(commandLine)) {
       break;
     } else if (isAddCommand(commandLine) || isCheckCommand(commandLine)) {
       exicuteCheckOrAddCommand(commandLine, lineNumber);
     } else if (isCompareCommand(commandLine)) {
     } else {
       throw new RuntimeException("unrecognized command");
     }
   }
   return results.toString();
 }
    /**
     * Given a line from a command file, generates executes the appropriate check or add command and
     * checks the results against the goal. If the results and goal do not match, a message is added
     * to the results string buffer.
     */
    private static void exicuteCheckOrAddCommand(String command, int lineNumber) {

      // remove the command
      String args = command.substring(command.indexOf(":") + 1);

      StringTokenizer tokens = new StringTokenizer(args, argDivider);
      if (tokens.countTokens() != types.length + 2) {
        throw new RuntimeException(
            "Number of arguments to add command on line "
                + lineNumber
                + " is: "
                + tokens.countTokens()
                + " but should be: "
                + (types.length + 2));
      }
      Object[] params = getParams(tokens);
      InvariantStatus goalStatus = parseStatus(tokens.nextToken().trim());
      tokens.nextToken(); // executed for side effect
      assert !tokens.hasMoreTokens();
      InvariantStatus resultStatus = null;
      if (isCheckCommand(command)) {
        resultStatus = getCheckStatus(params);
      } else {
        resultStatus = getAddStatus(params);
      }
      if (resultStatus != goalStatus) {
        results.append(
            "Error on line "
                + lineNumber
                + ":"
                + lineSep
                + "Expected  InvariantStatus: "
                + goalStatus
                + lineSep
                + "Found InvariantStatus: "
                + resultStatus
                + lineSep);
      }
    }
    public String toString() {
      StringBuffer buffer = new StringBuffer();

      buffer.append(_methodName);
      buffer.append("( ");

      if (_argTypes != null) {
        int count = _argTypes.length;

        for (int i = 0; i < count; i++) {
          if (i > 0) {
            buffer.append(", ");
          }

          buffer.append(_argTypes[i].getName());
        }
      }

      buffer.append(" )");

      return buffer.toString();
    }
예제 #13
0
  /** Test of execute method, of class org.netbeans.mobility.antext.RunTask. */
  public void testExecute() throws IOException {
    System.out.println("execute");

    // Prepare test
    File dir = getWorkDir();
    clearWorkDir();
    String path = getGoldenFile("bin").getParent() + File.separator;
    File srcDir = new File(path);
    File jadfile = new File(path + "MobileApplication1.jad");
    File jarfile = new File(path + "MobileApplication1.jad");
    File f = File.createTempFile("cmdline", "", dir);
    File log = null;
    PrintStream out = new PrintStream(new FileOutputStream(f));
    File em = null;
    File exe = null;
    try {
      Project p = new Project();
      RunTask instance = new RunTask();
      instance.setProject(p);
      instance.setClassPath(new Path(p, srcDir.getAbsolutePath()));
      instance.setPlatformHome(srcDir);
      instance.setJadFile(jadfile);
      instance.setJarFile(jarfile);
      instance.setJadUrl(jadfile.toURL().toString());
      instance.setDevice("MyDevice");
      instance.setDebug(true);
      instance.setDebugAddress("MyAddress");
      instance.setDebugServer(true);
      instance.setDebugSuspend(false);

      String name = System.getProperty("os.name");
      StringBuffer commandLine =
          new StringBuffer(Bundle.getMessage("CMD_Run_" + DEFAULT_PLATFORM_TYPE));

      /* Prepare right executable */
      int index = name.indexOf("Windows");
      em = index != -1 ? getGoldenFile("bin/emulator.bin") : getGoldenFile("bin/emulator.sh");
      exe = new File(em.getParent() + "/emulator");
      exe.delete();
      em.renameTo(exe);

      HashMap args = new HashMap();
      args.put("platformhome", srcDir); // No I18N
      args.put("classpath", srcDir.getAbsolutePath()); // No I18N
      args.put("jadfile", jadfile);
      args.put("jarfile", jarfile);
      args.put("jadurl", jadfile.toURL().toString());
      args.put("device", "MyDevice");
      args.put("debug", ""); // NO I18N
      args.put("debugaddress", "MyAddress");
      args.put("debugserver", "y"); // NO I18N
      args.put("debugsuspend", "n"); // NO I18N
      args.put("debugtransport", "dt_socket"); // NO I18N
      args.put("/", File.separator); // NO I18N
      String line = EMapFormat.format(commandLine.toString(), args);

      String[] commands = Commandline.translateCommandline(line);
      if (name.indexOf("Windows") == -1) {
        Process pr = java.lang.Runtime.getRuntime().exec("chmod +x " + commands[0]);
        try {
          assertTrue(pr.waitFor() == 0);
        } catch (InterruptedException ex) {
          fail(ex.getMessage());
        }
      }
      for (int i = 0; i < commands.length; i++) {
        out.println(commands[i]);
      }
      instance.execute();
      String wdir = System.getProperty("user.dir");
      log = new File(wdir + File.separator + "cmdLine.log");
      this.assertFile(log, f);
    } finally {
      out.close();
      clearWorkDir();
      if (f != null) f.delete();
      if (log != null) log.delete();
      if (exe != null) exe.renameTo(em);
    }
  }
 private void log(String text) {
   logBuffer.append(text).append('\n');
 }
예제 #15
0
  /**
   * Test whether output routines work as expected. This is done by comparing generating output on a
   * file "useOutput.txt" and comparing it to a file "expectedOutput.txt". On a first run this test
   * might break because the file "expectedOutput.txt" does not exist. Then just run the test,
   * verify manually whether "useOutput.txt" conforms to the expected output and if it does rename
   * "useOutput.txt" in "expectedOutput.txt". From then on the tests should work as expected.
   */
  public void testOutput() {
    Network network = Network.DefaultExample();
    String generateOutputFName = "useOutput.txt", expectedOutputFName = "expectedOutput.txt";
    FileWriter generateOutput;
    StringBuffer buf = new StringBuffer(500);
    StringWriter report = new StringWriter(500);

    try {
      generateOutput = new FileWriter(generateOutputFName);
    } catch (IOException f2exc) {
      assertTrue("Could not create '" + generateOutputFName + "'", false);
      return;
    }
    ;

    try {
      buf.append(
          "---------------------------------ASCII------------------------------------------\n");
      network.printOn(buf);
      buf.append(
          "\n\n---------------------------------HTML------------------------------------------\n");
      network.printHTMLOn(buf);
      buf.append(
          "\n\n---------------------------------XML------------------------------------------\n");
      network.printXMLOn(buf);
      generateOutput.write(buf.toString());
      report.write(
          "\n\n---------------------------------SCENARIO: Print Success --------------------------\n");
      network.requestWorkstationPrintsDocument("Filip", "Hello World", "Andy", report);
      report.write(
          "\n\n---------------------------------SCENARIO: PrintFailure (UnkownPrinter) ------------\n");
      network.requestWorkstationPrintsDocument("Filip", "Hello World", "UnknownPrinter", report);
      report.write(
          "\n\n---------------------------------SCENARIO: PrintFailure (print on Workstation) -----\n");
      network.requestWorkstationPrintsDocument("Filip", "Hello World", "Hans", report);
      report.write(
          "\n\n---------------------------------SCENARIO: PrintFailure (print on Node) -----\n");
      network.requestWorkstationPrintsDocument("Filip", "Hello World", "n1", report);
      report.write(
          "\n\n---------------------------------SCENARIO: Print Success Postscript-----------------\n");
      network.requestWorkstationPrintsDocument(
          "Filip", "!PS Hello World in postscript", "Andy", report);
      report.write(
          "\n\n---------------------------------SCENARIO: Print Failure Postscript-----------------\n");
      network.requestWorkstationPrintsDocument(
          "Filip", "!PS Hello World in postscript", "Hans", report);
      report.write(
          "\n\n---------------------------------SCENARIO: Broadcast Success -----------------\n");
      network.requestBroadcast(report);
      generateOutput.write(report.toString());
    } catch (IOException exc) {
    } finally {
      try {
        generateOutput.close();
      } catch (IOException exc) {
      }
      ;
    }
    ;
    assertTrue(
        "Generated output is not as expected ",
        compareFiles(generateOutputFName, expectedOutputFName));
  }