/** * 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)); } }
/** * 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()); } }
/** * Checks if compatibility with CCorePlugin methods from CDT 6.0 was not violated. * * @throws Exception... */ public void testCompatibility() throws Exception { final CCorePlugin cCorePlugin = CCorePlugin.getDefault(); // CCorePlugin.getAllErrorParsersIDs() String all = ErrorParserManager.toDelimitedString(cCorePlugin.getAllErrorParsersIDs()); assertTrue(all.contains(NOTREGEX_ERRORPARSER_ID)); // CCorePlugin.getErrorParser(id) IErrorParser[] gccErrorParserArray = cCorePlugin.getErrorParser(NOTREGEX_ERRORPARSER_ID); assertNotNull(gccErrorParserArray); assertEquals(1, gccErrorParserArray.length); assertTrue(gccErrorParserArray[0] instanceof GASErrorParser); }
/** * Check that default parser IDs are stored properly. * * @throws Exception... */ public void testSerializeDefaultErrorParserIds() throws Exception { final String[] testingDefaultErrorParserIds = { "org.eclipse.cdt.core.test.errorparser0", "org.eclipse.cdt.core.test.errorparser1", "org.eclipse.cdt.core.test.errorparser2", }; final String TESTING_IDS = ErrorParserManager.toDelimitedString(testingDefaultErrorParserIds); final String DEFAULT_IDS = ErrorParserManager.toDelimitedString(ErrorParserManager.getDefaultErrorParserIds()); { // setDefaultErrorParserIds ErrorParserExtensionManager.setDefaultErrorParserIdsInternal(testingDefaultErrorParserIds); String[] defaultErrorParserIds = ErrorParserManager.getDefaultErrorParserIds(); assertNotNull(defaultErrorParserIds); assertEquals(TESTING_IDS, ErrorParserManager.toDelimitedString(defaultErrorParserIds)); // serialize them ErrorParserExtensionManager.serializeDefaultErrorParserIds(); } { // Remove from internal list ErrorParserExtensionManager.setDefaultErrorParserIdsInternal(null); assertEquals( DEFAULT_IDS, ErrorParserManager.toDelimitedString(ErrorParserManager.getDefaultErrorParserIds())); } { // Re-load from persistent storage and check it out ErrorParserExtensionManager.loadDefaultErrorParserIds(); String[] defaultErrorParserIds = ErrorParserManager.getDefaultErrorParserIds(); assertNotNull(defaultErrorParserIds); assertEquals(TESTING_IDS, ErrorParserManager.toDelimitedString(defaultErrorParserIds)); } { // Reset IDs and serialize ErrorParserExtensionManager.setDefaultErrorParserIdsInternal(null); ErrorParserExtensionManager.serializeDefaultErrorParserIds(); // Check that default IDs are loaded ErrorParserExtensionManager.loadDefaultErrorParserIds(); String[] defaultErrorParserIds = ErrorParserManager.getDefaultErrorParserIds(); assertNotNull(defaultErrorParserIds); assertEquals(DEFAULT_IDS, ErrorParserManager.toDelimitedString(defaultErrorParserIds)); } }
/** * 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)); } }
/** * 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); } }