Example #1
2
 /**
  * This function is used to re-run the analyser, and re-create the rows corresponding the its
  * results.
  */
 private void refreshReviewTable() {
   reviewPanel.removeAll();
   rows.clear();
   GridBagLayout gbl = new GridBagLayout();
   reviewPanel.setLayout(gbl);
   GridBagConstraints gbc = new GridBagConstraints();
   gbc.fill = GridBagConstraints.HORIZONTAL;
   gbc.gridy = 0;
   try {
     Map<String, Long> sums =
         analyser.processLogFile(config.getLogFilename(), fromDate.getDate(), toDate.getDate());
     for (Entry<String, Long> entry : sums.entrySet()) {
       String project = entry.getKey();
       double hours = 1.0 * entry.getValue() / (1000 * 3600);
       addRow(gbl, gbc, project, hours);
     }
     for (String project : main.getProjectsTree().getTopLevelProjects())
       if (!rows.containsKey(project)) addRow(gbl, gbc, project, 0);
     gbc.insets = new Insets(10, 0, 0, 0);
     addLeftLabel(gbl, gbc, "TOTAL");
     gbc.gridx = 1;
     gbc.weightx = 1;
     totalLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 3));
     gbl.setConstraints(totalLabel, gbc);
     reviewPanel.add(totalLabel);
     gbc.weightx = 0;
     addRightLabel(gbl, gbc);
   } catch (IOException e) {
     e.printStackTrace();
   }
   recomputeTotal();
   pack();
 }
 @Test
 public void shouldRegisterAndInvokeCompilerOfBlockWhenVisitBeginOfBlock() {
   Block block = mock(Block.class);
   when(parent.className()).thenReturn("SomeClass");
   when(parent.packageName()).thenReturn("st.redline");
   ProgramAnalyser spy = spy(analyser);
   SmalltalkEnvironment smalltalkEnvironment = mock(SmalltalkEnvironment.class);
   doReturn(smalltalkEnvironment).when(spy).smalltalkEnvironment();
   spy.visitBegin(block, 1);
   verify(smalltalkEnvironment).registerBlockToBeCompiled(block, "st.redline.SomeClass$M1");
   verify(writer).invokeObjectCompileBlock("st.redline.SomeClass$M1", 1);
 }
Example #3
0
  /**
   * Naming convention for test directories: all testes are placed under one directory called
   * "testSuite/tests". Usage: java sereneTestSchematron.Driver {a} test-directory [-d
   * destination-directory-name] [-r result-file-name] [-x xml-file name].
   */
  public static void main(String args[]) {
    long startTime = System.currentTimeMillis();
    if (args == null || args.length == 0) {
      System.out.println(
          "Usage: java sereneTestSchematron.Driver [a] test-directory [-d destination-directory-name] [-r result-file-name] [-x xml-file name]."
              + "\n"
              + "\nBy convention all the test files are placed in the testSuite/tests directory. There is one schema file per leaf directory named schema.rng and zero or more corresponding xml files named document1.xml, document2.xml ... The test-directory argument must specify either the entire testSuite or a subdirectory thereof."
              + "\n"
              + "\nBy default all the files in the specified test-directory are processed recursively and the results of every testing session are written in a directory named debug placed on the same level as sereneTestSchematron.jar in a directory with the name testSuite_date-hour-min-sec, preserving the original tree structure, the results of each specific test are placed in text files named testResults.txt in the corresponding subdirectories."
              + "\n"
              + "\nPlease use:"
              + "\n-a if you want the test results to be automatically tested for regression against the corresponding expected results from testSuite/acceptedResults; the results of the test will be written in the results directory in  a text file named regressionAnalysis.txt"
              + "\n-d if you want to specify another destination directory"
              + "\n-r if you want to specify another result file name; when this option is used it is impossible to execute automatical regression analysis"
              + "\n-x if you want to only test one specific xml file from the test directory.");
      return;
    }

    boolean analyse = false;
    String s = args[0];
    String sourceDirName;
    int optionsStart = 1;
    if (s.equals("-a")) {
      if (args.length == 1) {
        System.out.println(
            "Usage: java sereneTestSchematron.Driver [a] test-directory [-d destination-directory-name] [-r result-file-name] [-x xml-file name]."
                + "\n"
                + "\nBy convention all the test files are placed in the testSuite/tests directory. There is one schema file per leaf directory named schema.rng and zero or more corresponding xml files named document1.xml, document2.xml ... The test-directory argument must specify either the entire testSuite or a subdirectory thereof."
                + "\n"
                + "\nBy default all the files in the specified test-directory are processed recursively and the results of every testing session are written in a directory named debug placed on the same level as sereneTestSchematron.jar in a directory with the name testSuite_date-hour-min-sec, preserving the original tree structure, the results of each specific test are placed in text files named testResults.txt in the corresponding subdirectories."
                + "\n"
                + "\nPlease use:"
                + "\n-a if you want the test results to be automatically tested for regression against the corresponding expected results from testSuite/acceptedResults; the results of the test will be written in the results directory in  a text file named regressionAnalysis.txt"
                + "\n-d if you want to specify another destination directory"
                + "\n-r if you want to specify another result file name; when this option is used it is impossible to execute automatical regression analysis"
                + "\n-x if you want to only test one specific xml file from the test directory.");
        return;
      }
      sourceDirName = args[1];
      analyse = true;
      optionsStart = 2;
    } else {
      sourceDirName = s;
    }

    if (sourceDirName == null || sourceDirName.equals("")) return;

    // TODO see about index out of bounds

    String destinationDirName = "debug";
    String resultsDestinationFileName = "testResults.txt";
    String xmlFileName = null;
    for (int i = optionsStart; i < args.length; i = i + 2) {
      if (args[i].equals("-d")) {
        if (args.length > i) {
          destinationDirName = args[i + 1];
        } else {
          System.out.println(
              "Usage: java sereneTestSchematron.Driver {a} test-directory [-d destination-directory-name] [-r result-file-name] [-x xml-file name]."
                  + "\n"
                  + "\nBy convention all the test files are placed in the testSuite/tests directory. There is one schema file per leaf directory named schema.rng and zero or more corresponding xml files named document1.xml, document2.xml ... The test-directory argument must specify either the entire testSuite or a subdirectory thereof."
                  + "\n"
                  + "\nBy default all the files in the specified test-directory are processed recursively and the results of every testing session are written in a directory named debug placed on the same level as sereneTestSchematron.jar in a directory with the name testSuite_date-hour-min-sec, preserving the original tree structure, the results of each specific test are placed in text files named testResults.txt in the corresponding subdirectories."
                  + "\n"
                  + "\nPlease use:"
                  + "\n-a if you want the test results to be automatically tested for regression against the corresponding expected results from testSuite/acceptedResults; the results of the test will be written in the results directory in  a text file named regressionAnalysis.txt"
                  + "\n-d if you want to specify another destination directory"
                  + "\n-r if you want to specify another result file name; when this option is used it is impossible to execute automatical regression analysis"
                  + "\n-x if you want to only test one specific xml file from the test directory.");
          return;
        }
      } else if (args[i].equals("-r")) {
        if (args.length > i) {
          resultsDestinationFileName = args[i + 1];
        } else {
          System.out.println(
              "Usage: java sereneTestSchematron.Driver {a} test-directory [-d destination-directory-name] [-r result-file-name] [-x xml-file name]."
                  + "\n"
                  + "\nBy convention all the test files are placed in the testSuite/tests directory. There is one schema file per leaf directory named schema.rng and zero or more corresponding xml files named document1.xml, document2.xml ... The test-directory argument must specify either the entire testSuite or a subdirectory thereof."
                  + "\n"
                  + "\nBy default all the files in the specified test-directory are processed recursively and the results of every testing session are written in a directory named debug placed on the same level as sereneTestSchematron.jar in a directory with the name testSuite_date-hour-min-sec, preserving the original tree structure, the results of each specific test are placed in text files named testResults.txt in the corresponding subdirectories."
                  + "\n"
                  + "\nPlease use:"
                  + "\n-a if you want the test results to be automatically tested for regression against the corresponding expected results from testSuite/acceptedResults; the results of the test will be written in the results directory in  a text file named regressionAnalysis.txt"
                  + "\n-d if you want to specify another destination directory"
                  + "\n-r if you want to specify another result file name; when this option is used it is impossible to execute automatical regression analysis"
                  + "\n-x if you want to only test one specific xml file from the test directory.");
          return;
        }
      } else if (args[i].equals("-x")) {
        if (args.length > i) {
          xmlFileName = args[i + 1];
        } else {
          System.out.println(
              "Usage: java sereneTestSchematron.Driver {a} test-directory [-d destination-directory-name] [-r result-file-name] [-x xml-file name]."
                  + "\n"
                  + "\nBy convention all the test files are placed in the testSuite/tests directory. There is one schema file per leaf directory named schema.rng and zero or more corresponding xml files named document1.xml, document2.xml ... The test-directory argument must specify either the entire testSuite or a subdirectory thereof."
                  + "\n"
                  + "\nBy default all the files in the specified test-directory are processed recursively and the results of every testing session are written in a directory named debug placed on the same level as sereneTestSchematron.jar in a directory with the name testSuite_date-hour-min-sec, preserving the original tree structure, the results of each specific test are placed in text files named testResults.txt in the corresponding subdirectories."
                  + "\n"
                  + "\nPlease use:"
                  + "\n-a if you want the test results to be automatically tested for regression against the corresponding expected results from testSuite/acceptedResults; the results of the test will be written in the results directory in  a text file named regressionAnalysis.txt"
                  + "\n-d if you want to specify another destination directory"
                  + "\n-r if you want to specify another result file name; when this option is used it is impossible to execute automatical regression analysis"
                  + "\n-x if you want to only test one specific xml file from the test directory.");
          return;
        }
      } else {
        System.out.println(
            "Usage: java sereneTestSchematron.Driver {a} test-directory [-d destination-directory-name] [-r result-file-name] [-x xml-file name]."
                + "\n"
                + "\nBy convention all the test files are placed in the testSuite/tests directory. There is one schema file per leaf directory named schema.rng and zero or more corresponding xml files named document1.xml, document2.xml ... The test-directory argument must specify either the entire testSuite or a subdirectory thereof."
                + "\n"
                + "\nBy default all the files in the specified test-directory are processed recursively and the results of every testing session are written in a directory named debug placed on the same level as sereneTestSchematron.jar in a directory with the name testSuite_date-hour-min-sec, preserving the original tree structure, the results of each specific test are placed in text files named testResults.txt in the corresponding subdirectories."
                + "\n"
                + "\nPlease use:"
                + "\n-a if you want the test results to be automatically tested for regression against the corresponding expected results from testSuite/acceptedResults; the results of the test will be written in the results directory in  a text file named regressionAnalysis.txt"
                + "\n-d if you want to specify another destination directory"
                + "\n-r if you want to specify another result file name; when this option is used it is impossible to execute automatical regression analysis"
                + "\n-x if you want to only test one specific xml file from the test directory.");
        return;
      }
    }

    File sourceDir = new File(sourceDirName);
    String sourcePath = sourceDir.getAbsolutePath();
    int sereneIndex = sourcePath.indexOf("testSuite");
    if (sereneIndex < 0) {
      System.out.println(
          "Usage: java sereneTestSchematron.Driver {a} test-directory [-d destination-directory-name] [-r result-file-name] [-x xml-file name]."
              + "\n"
              + "\nBy convention all the test files are placed in the testSuite/tests directory. There is one schema file per leaf directory named schema.rng and zero or more corresponding xml files named document1.xml, document2.xml ... The test-directory argument must specify either the entire testSuite or a subdirectory thereof."
              + "\n"
              + "\nBy default all the files in the specified test-directory are processed recursively and the results of every testing session are written in a directory named debug placed on the same level as sereneTestSchematron.jar in a directory with the name testSuite_date-hour-min-sec, preserving the original tree structure, the results of each specific test are placed in text files named testResults.txt in the corresponding subdirectories."
              + "\n"
              + "\nPlease use:"
              + "\n-a if you want the test results to be automatically tested for regression against the corresponding expected results from testSuite/acceptedResults; the results of the test will be written in the results directory in  a text file named regressionAnalysis.txt"
              + "\n-d if you want to specify another destination directory"
              + "\n-r if you want to specify another result file name; when this option is used it is impossible to execute automatical regression analysis"
              + "\n-x if you want to only test one specific xml file from the test directory.");
      return;
    }

    String tail = sourcePath.substring(sereneIndex + 22);

    Date date = new Date();
    Locale locale = new Locale("Romanian", "Romania");
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MMMdd");
    SimpleDateFormat simpleTimeFormat = new SimpleDateFormat("kk-mm-ss");
    String runId = simpleDateFormat.format(date) + "H" + simpleTimeFormat.format(date);

    if (destinationDirName.endsWith(File.separator)) {
      destinationDirName = destinationDirName + "testSuiteRNGSchematron_" + runId + tail;
    } else {
      destinationDirName =
          destinationDirName + File.separator + "testSuiteRNGSchematron_" + runId + tail;
    }

    Tester tester = new Tester();

    if (xmlFileName != null)
      tester.test(sourcePath, xmlFileName, destinationDirName, resultsDestinationFileName);
    else tester.test(sourcePath, destinationDirName, resultsDestinationFileName);

    System.out.println("Tests: " + tester.getTestCount());
    System.out.println("Elapsed time: " + (System.currentTimeMillis() - startTime));

    if (analyse) {
      if (!resultsDestinationFileName.equals("testResults.txt")) {
        System.out.println(
            "\nRegression analysis not performed, see usage:"
                + "\n"
                + "\n"
                + "\nUsage: java sereneTestSchematron.Driver {a} test-directory [-d destination-directory-name] [-r result-file-name] [-x xml-file name]."
                + "\n"
                + "\nBy convention all the test files are placed in the testSuite/tests directory. There is one schema file per leaf directory named schema.rng and zero or more corresponding xml files named document1.xml, document2.xml ... The test-directory argument must specify either the entire testSuite or a subdirectory thereof."
                + "\n"
                + "\nBy default all the files in the specified test-directory are processed recursively and the results of every testing session are written in a directory named debug placed on the same level as sereneTestSchematron.jar in a directory with the name testSuite_date-hour-min-sec, preserving the original tree structure, the results of each specific test are placed in text files named testResults.txt in the corresponding subdirectories."
                + "\n"
                + "\nPlease use:"
                + "\n-a if you want the test results to be automatically tested for regression against the corresponding expected results from testSuite/acceptedResults; the results of the test will be written in the results directory in  a text file named regressionAnalysis.txt"
                + "\n-d if you want to specify another destination directory"
                + "\n-r if you want to specify another result file name; when this option is used it is impossible to execute automatical regression analysis"
                + "\n-x if you want to only test one specific xml file from the test directory.");
        return;
      }
      destinationDirName =
          destinationDirName.substring(0, destinationDirName.indexOf("testSuite") + 37);
      File testDir = new File(destinationDirName);
      String testPath = testDir.getAbsolutePath();

      String standardDirName = "testSuiteRNGSchematron/acceptedResults";
      destinationDirName = destinationDirName;
      resultsDestinationFileName = "regressionAnalysis.txt";

      Analyser analyser = new Analyser();
      analyser.analyse(testPath, standardDirName, destinationDirName, resultsDestinationFileName);
    }
  }
 public AnalyserDelegate createJVMAnalyser(Analyser analyser, ClassBytecodeWriter bytecodeWriter) {
   JVMAnalyser jvmAnalyser = new JVMAnalyser(analyser, bytecodeWriter);
   return verboseAnalysis ? analyser.tracingDelegate(jvmAnalyser) : jvmAnalyser;
 }
  public void actionPerformed(ActionEvent event) {
    if (event.getSource().equals(instance.menuItem_Add)) {
      if (instance.textArea.isEditable()) {
        currText = JOptionPane.showInputDialog(null, "Enter text:");
        instance.textArea.append(currText + "\n");
      } else {
        JOptionPane.showMessageDialog(
            null,
            "You may not add a line to read results! Click Text - Clear Text to start adding text again.");
      }

    } else if (event.getSource().equals(instance.menuItem_Clear)) {
      instance.textArea.setText("");
      instance.textArea.setEditable(true);
    } else if (event.getSource().equals(instance.menuItem_Groups)) {
      if (!instance.textArea.isEditable()) {
        JOptionPane.showMessageDialog(
            null,
            "You may not read the results of a read action! Click Text - Clear Text to start adding text again.");
        return;
      }
      if (instance.textArea.getText().trim().equalsIgnoreCase("")) {
        instance.textArea.setText("Please enter data!");
        return;
      }
      GroupAnalyser analyser = new GroupAnalyser(instance.textArea.getText());
      instance.analyser = analyser;
      analyser.setup();
      analyser.startAnalysing();
      instance.textArea.setText("");
      for (int i = 0; i < Analyser.filteredData.size(); i++) {
        DataGroup dataGroup = Analyser.getDataGroupFromLineNum(i);
        instance.textArea.append("Name: " + dataGroup.getName() + "\n");
        instance.textArea.append("Prefix: " + dataGroup.getPrefix() + "\n");
        instance.textArea.append("Commands: " + dataGroup.getCommands() + "\n");
        instance.textArea.append("Inherited: " + dataGroup.getInherited() + "\n");
        instance.textArea.append("Admin: " + dataGroup.getAdmin() + "\n");
        instance.textArea.append("IP: " + dataGroup.getIP() + "\n");
        instance.textArea.append("Group: " + dataGroup.getGroup() + "\n");
        instance.textArea.append("\n");
        instance.textArea.append("Validity: " + dataGroup.getValidity() + "\n");
        instance.textArea.append("--\n");
        instance.textArea.append("\n");
      } // end for
      instance.textArea.setEditable(false);
    } else if (event.getSource().equals(instance.menuItem_Users)) {
      if (!instance.textArea.isEditable()) {
        JOptionPane.showMessageDialog(
            null,
            "You may not read the results of a read action! Click Text - Clear Text to start adding text again.");
        return;
      }
      if (instance.textArea.getText().trim().equalsIgnoreCase("")) {
        instance.textArea.setText("Please enter data!\n");
        return;
      }
      UserAnalyser analyser = new UserAnalyser(instance.textArea.getText());
      instance.analyser = analyser;
      analyser.setup();
      analyser.startAnalysing();
      instance.textArea.setText("");
      for (int i = 0; i < Analyser.filteredData.size(); i++) {
        DataGroup dataGroup = Analyser.getDataGroupFromLineNum(i);
        instance.textArea.append("Name: " + dataGroup.getName() + "\n");
        instance.textArea.append("Group: " + dataGroup.getGroup() + "\n");
        instance.textArea.append("Admin: " + dataGroup.getAdmin() + "\n");
        instance.textArea.append("Prefix: " + dataGroup.getPrefix() + "\n");
        instance.textArea.append("Commands: " + dataGroup.getCommands() + "\n");
        instance.textArea.append("Inherited: " + dataGroup.getInherited() + "\n");
        instance.textArea.append("IP: " + dataGroup.getIP() + "\n");
        instance.textArea.append("\n");
        instance.textArea.append("Validity: " + dataGroup.getValidity() + "\n");
        instance.textArea.append("\n\n");
        instance.textArea.append("--\n");
        instance.textArea.append("\n\n");
      } // end for
      instance.textArea.setEditable(false);
    } else if (event.getSource().equals(instance.menuItem_Help)) {
      JOptionPane.showMessageDialog(
          null,
          "Enter text directly in the text area. \nAfter a read you must click Text - Clear Text to be able to edit the text box again.");
    } else if (event.getSource().equals(instance.menuItem_About)) {
      JOptionPane.showMessageDialog(
          null,
          "CanarySyntaxChecker v:1.3 \n\nAuthor: WWOL (Brian McCarthy) \n\nThanks: \nThanks to Scoin0 for ver:1.3 fixes.");
    } else if (event.getSource().equals(instance.menuItem_Change)) {
      JOptionPane.showMessageDialog(
          null,
          "Changelog:\n1.3 - \nFixed closing and centered frame. Thanks Scoin0.\n\n1.2 - \nFixing bugs, \nReading already read results, \nAdding a line to results,\n\n1.1 - \nText area editing, \nReading with no text check, \nHelp, About and Change Log menu items, \nFixed spelling, \n\n1.0 - \nInitial release,");
    }
  } // end actionPerformed