Esempio n. 1
0
  /**
   * Test setting/retrieval of user defined error parsers.
   *
   * @throws Exception...
   */
  public void testUserDefinedErrorParsers() throws Exception {
    final String TESTING_ID = "org.eclipse.cdt.core.test.errorparser";
    final String TESTING_NAME = "An error parser";
    // reset parsers
    {
      ErrorParserManager.setUserDefinedErrorParsers(null);
      String[] userDefinedIds = ErrorParserManager.getUserDefinedErrorParserIds();
      assertNull(userDefinedIds);

      String all =
          ErrorParserManager.toDelimitedString(ErrorParserManager.getErrorParserAvailableIds());
      String extensions =
          ErrorParserManager.toDelimitedString(ErrorParserManager.getErrorParserExtensionIds());
      assertEquals(all, extensions);
    }
    {
      ErrorParserManager.setUserDefinedErrorParsers(
          new IErrorParserNamed[] {
            new ErrorParserNamedWrapper(TESTING_ID, TESTING_NAME, new DummyErrorParser()),
          });
      String userDefinedIds =
          ErrorParserManager.toDelimitedString(ErrorParserManager.getUserDefinedErrorParserIds());
      assertEquals(TESTING_ID, userDefinedIds);

      String all =
          ErrorParserManager.toDelimitedString(ErrorParserManager.getErrorParserAvailableIds());
      String extensions =
          ErrorParserManager.toDelimitedString(ErrorParserManager.getErrorParserExtensionIds());
      assertFalse(all.equals(extensions));
    }
  }
Esempio n. 2
0
  /**
   * Make sure special characters are serialized properly.
   *
   * @throws Exception...
   */
  public void testSerializeRegexErrorParserSpecialCharacters() throws Exception {

    final String TESTING_ID = "org.eclipse.cdt.core.test.regexerrorparser";
    final String TESTING_NAME = "<>\"'\\& Error Parser";
    final String TESTING_REGEX = "Pattern-<>\"'\\&";
    final String ALL_IDS =
        ErrorParserManager.toDelimitedString(ErrorParserManager.getErrorParserAvailableIds());
    {
      // Create error parser with the same id as in eclipse registry
      RegexErrorParser regexErrorParser = new RegexErrorParser(TESTING_ID, TESTING_NAME);
      regexErrorParser.addPattern(
          new RegexErrorPattern(
              TESTING_REGEX,
              "line-<>\"'\\&",
              "file-<>\"'\\&",
              "description-<>\"'\\&",
              null,
              IMarkerGenerator.SEVERITY_WARNING,
              false));

      // Add to available parsers
      ErrorParserExtensionManager.setUserDefinedErrorParsersInternal(
          new IErrorParserNamed[] {regexErrorParser});
      assertNotNull(ErrorParserManager.getErrorParserCopy(TESTING_ID));
      // And serialize in persistent storage
      ErrorParserExtensionManager.serializeUserDefinedErrorParsers();
    }

    {
      // Re-load from persistent storage and check it out
      ErrorParserExtensionManager.loadUserDefinedErrorParsers();
      String all =
          ErrorParserManager.toDelimitedString(ErrorParserManager.getErrorParserAvailableIds());
      assertTrue(all.contains(TESTING_ID));

      IErrorParser errorParser = ErrorParserManager.getErrorParserCopy(TESTING_ID);
      assertNotNull(errorParser);
      assertTrue(errorParser instanceof RegexErrorParser);
      RegexErrorParser regexErrorParser = (RegexErrorParser) errorParser;
      assertEquals(TESTING_ID, regexErrorParser.getId());
      assertEquals(TESTING_NAME, regexErrorParser.getName());

      RegexErrorPattern[] errorPatterns = regexErrorParser.getPatterns();
      assertEquals(1, errorPatterns.length);
      assertEquals(TESTING_REGEX, errorPatterns[0].getPattern());
    }
  }
Esempio n. 3
0
  /**
   * Test setting/retrieval of default error parser IDs preferences.
   *
   * @throws Exception...
   */
  public void testDefaultErrorParserIds() throws Exception {
    final String[] availableParserIds = ErrorParserManager.getErrorParserAvailableIds();
    assertNotNull(availableParserIds);
    final String[] initialDefaultErrorParserIds = ErrorParserManager.getDefaultErrorParserIds();

    // preconditions
    {
      String[] defaultErrorParserIds = ErrorParserManager.getDefaultErrorParserIds();
      assertNotNull(defaultErrorParserIds);
      assertEquals(
          ErrorParserManager.toDelimitedString(availableParserIds),
          ErrorParserManager.toDelimitedString(defaultErrorParserIds));
    }
    // setDefaultErrorParserIds
    {
      String[] newDefaultErrorParserIds = {
        "org.eclipse.cdt.core.test.errorparser0",
        "org.eclipse.cdt.core.test.errorparser1",
        "org.eclipse.cdt.core.test.errorparser2",
      };
      ErrorParserManager.setDefaultErrorParserIds(newDefaultErrorParserIds);
      String[] defaultErrorParserIds = ErrorParserManager.getDefaultErrorParserIds();
      assertNotNull(defaultErrorParserIds);
      assertEquals(
          ErrorParserManager.toDelimitedString(newDefaultErrorParserIds),
          ErrorParserManager.toDelimitedString(defaultErrorParserIds));
    }

    // reset
    {
      ErrorParserManager.setDefaultErrorParserIds(null);
      String[] defaultErrorParserIds = ErrorParserManager.getDefaultErrorParserIds();
      assertNotNull(defaultErrorParserIds);
      assertEquals(
          ErrorParserManager.toDelimitedString(availableParserIds),
          ErrorParserManager.toDelimitedString(defaultErrorParserIds));
    }
  }
Esempio n. 4
0
  /**
   * Test setting/retrieval of error parsers and their IDs.
   *
   * @throws Exception...
   */
  public void testAvailableErrorParsers() throws Exception {
    final String TESTING_ID = "org.eclipse.cdt.core.test.errorparser";
    final String TESTING_NAME = "An error parser";

    final String[] availableParserIds = ErrorParserManager.getErrorParserAvailableIds();
    assertNotNull(availableParserIds);
    assertTrue(availableParserIds.length > 0);
    final String firstId = ErrorParserManager.getErrorParserAvailableIds()[0];
    final IErrorParserNamed firstErrorParser = ErrorParserManager.getErrorParserCopy(firstId);
    assertNotNull(firstErrorParser);
    assertEquals(firstId, firstErrorParser.getId());
    final String firstName = firstErrorParser.getName();
    // Preconditions
    {
      String all =
          ErrorParserManager.toDelimitedString(ErrorParserManager.getErrorParserAvailableIds());
      assertEquals(false, all.contains(TESTING_ID));
      assertEquals(true, all.contains(firstId));

      assertNull(ErrorParserManager.getErrorParserCopy(TESTING_ID));

      IErrorParserNamed retrieved2 = ErrorParserManager.getErrorParserCopy(firstId);
      assertNotNull(retrieved2);
      assertEquals(firstErrorParser, retrieved2);
    }

    // set available parsers
    {
      IErrorParser dummy1 = new DummyErrorParser();
      IErrorParser dummy2 = new DummyErrorParser();
      ErrorParserManager.setUserDefinedErrorParsers(
          new IErrorParserNamed[] {
            // add brand new one
            new ErrorParserNamedWrapper(TESTING_ID, TESTING_NAME, dummy1),
            // override extension with another one
            new ErrorParserNamedWrapper(firstId, firstName, dummy2),
          });
      String all =
          ErrorParserManager.toDelimitedString(ErrorParserManager.getErrorParserAvailableIds());
      assertEquals(true, all.contains(TESTING_ID));
      assertEquals(true, all.contains(firstId));

      IErrorParserNamed retrieved1 = ErrorParserManager.getErrorParserCopy(TESTING_ID);
      assertNotNull(retrieved1);
      assertEquals(TESTING_NAME, retrieved1.getName());
      assertTrue(retrieved1 instanceof ErrorParserNamedWrapper);
      assertEquals(dummy1, ((ErrorParserNamedWrapper) retrieved1).getErrorParser());

      IErrorParserNamed retrieved2 = ErrorParserManager.getErrorParserCopy(firstId);
      assertNotNull(retrieved2);
      assertEquals(firstName, retrieved2.getName());
      assertTrue(retrieved2 instanceof ErrorParserNamedWrapper);
      assertEquals(dummy2, ((ErrorParserNamedWrapper) retrieved2).getErrorParser());

      IErrorParserNamed retrieved2_ext = ErrorParserManager.getErrorParserExtensionCopy(firstId);
      assertNotNull(retrieved2_ext);
      assertEquals(firstName, retrieved2_ext.getName());
      assertEquals(firstErrorParser, retrieved2_ext);
    }
    // reset available parsers
    {
      ErrorParserManager.setUserDefinedErrorParsers(null);
      String[] userDefinedIds = ErrorParserManager.getUserDefinedErrorParserIds();
      assertNull(userDefinedIds);

      String all =
          ErrorParserManager.toDelimitedString(ErrorParserManager.getErrorParserAvailableIds());
      assertEquals(false, all.contains(TESTING_ID));
      assertEquals(true, all.contains(firstId));

      assertNull(ErrorParserManager.getErrorParserCopy(TESTING_ID));

      IErrorParserNamed retrieved2 = ErrorParserManager.getErrorParserCopy(firstId);
      assertNotNull(retrieved2);
      assertEquals(firstErrorParser, retrieved2);
    }
  }