1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-09-09 11:33:20 +02:00

Code streamlining.

This commit is contained in:
Sergey Prigogin 2011-11-07 14:37:14 -08:00
parent 666828f68a
commit 11ea0ed928
5 changed files with 36 additions and 63 deletions

View file

@ -28,7 +28,7 @@ public class CaseBreakQuickFixTest extends QuickFixTestCase {
// case 2: // case 2:
// } // }
// } // }
public void testMiddleCase() { public void testMiddleCase() throws Exception {
loadcode(getAboveComment()); loadcode(getAboveComment());
String result = runQuickFixOneFile(); String result = runQuickFixOneFile();
assertContainedIn("break; case 2:", result); assertContainedIn("break; case 2:", result);
@ -41,7 +41,7 @@ public class CaseBreakQuickFixTest extends QuickFixTestCase {
// hello(); // hello();
// } // }
// } // }
public void testLastCase() { public void testLastCase() throws Exception {
loadcode(getAboveComment()); loadcode(getAboveComment());
String result = runQuickFixOneFile(); String result = runQuickFixOneFile();
assertContainedIn("break; }", result); assertContainedIn("break; }", result);
@ -55,9 +55,9 @@ public class CaseBreakQuickFixTest extends QuickFixTestCase {
// } // }
// } // }
// } // }
public void testLastCaseComp() { public void testLastCaseComp() throws Exception {
loadcode(getAboveComment()); loadcode(getAboveComment());
String result = runQuickFixOneFile(); String result = runQuickFixOneFile();
assertContainedIn("hello();\n\nbreak;", result); assertContainedIn("hello();\t\tbreak;", result);
} }
} }

View file

@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Tomasz Wesolowski - initial API and implementation * Tomasz Wesolowski - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.codan.internal.checkers.ui.quickfix; package org.eclipse.cdt.codan.internal.checkers.ui.quickfix;
@ -93,5 +93,4 @@ public class CatchByReferenceQuickFixTest extends QuickFixTestCase {
String result = runQuickFixOneFile(); String result = runQuickFixOneFile();
assertContainedIn("catch (const C &)", result); //$NON-NLS-1$ assertContainedIn("catch (const C &)", result); //$NON-NLS-1$
} }
} }

View file

@ -43,7 +43,7 @@ public class CreateLocalVariableQuickFixTest extends QuickFixTestCase {
// void func() { // void func() {
// aChar = 'a'; // aChar = 'a';
// } // }
public void testChar() { public void testChar() throws Exception {
loadcode(getAboveComment()); loadcode(getAboveComment());
String result = runQuickFixOneFile(); String result = runQuickFixOneFile();
assertContainedIn("char aChar;", result); //$NON-NLS-1$ assertContainedIn("char aChar;", result); //$NON-NLS-1$
@ -52,7 +52,7 @@ public class CreateLocalVariableQuickFixTest extends QuickFixTestCase {
// void func() { // void func() {
// aDouble = 40.; // aDouble = 40.;
// } // }
public void testDouble() { public void testDouble() throws Exception {
loadcode(getAboveComment()); loadcode(getAboveComment());
String result = runQuickFixOneFile(); String result = runQuickFixOneFile();
assertContainedIn("double aDouble;", result); //$NON-NLS-1$ assertContainedIn("double aDouble;", result); //$NON-NLS-1$
@ -61,7 +61,7 @@ public class CreateLocalVariableQuickFixTest extends QuickFixTestCase {
// void func() { // void func() {
// aString = "foo"; // aString = "foo";
// } // }
public void testString() { public void testString() throws Exception {
loadcode(getAboveComment()); loadcode(getAboveComment());
String result = runQuickFixOneFile(); String result = runQuickFixOneFile();
assertContainedIn("const char* aString;", result); //$NON-NLS-1$ assertContainedIn("const char* aString;", result); //$NON-NLS-1$
@ -70,7 +70,7 @@ public class CreateLocalVariableQuickFixTest extends QuickFixTestCase {
// void func() { // void func() {
// aWString = L"foo"; // aWString = L"foo";
// } // }
public void testWString() { public void testWString() throws Exception {
loadcode(getAboveComment()); loadcode(getAboveComment());
String result = runQuickFixOneFile(); String result = runQuickFixOneFile();
assertContainedIn("const wchar_t* aWString;", result); //$NON-NLS-1$ assertContainedIn("const wchar_t* aWString;", result); //$NON-NLS-1$
@ -79,7 +79,7 @@ public class CreateLocalVariableQuickFixTest extends QuickFixTestCase {
// void func() { // void func() {
// aFuncPtr = func; // aFuncPtr = func;
// } // }
public void testFuncPtr() { public void testFuncPtr() throws Exception {
loadcode(getAboveComment()); loadcode(getAboveComment());
String result = runQuickFixOneFile(); String result = runQuickFixOneFile();
assertContainedIn("void (*aFuncPtr)();", result); //$NON-NLS-1$ assertContainedIn("void (*aFuncPtr)();", result); //$NON-NLS-1$

View file

@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* QNX Software Systems (Alena Laskavaia) - initial API and implementation * QNX Software Systems (Alena Laskavaia) - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.codan.internal.checkers.ui.quickfix; package org.eclipse.cdt.codan.internal.checkers.ui.quickfix;
@ -17,7 +17,6 @@ import org.eclipse.cdt.codan.core.test.CheckerTestCase;
import org.eclipse.cdt.codan.core.test.TestUtils; import org.eclipse.cdt.codan.core.test.TestUtils;
import org.eclipse.cdt.codan.internal.ui.CodanUIActivator; import org.eclipse.cdt.codan.internal.ui.CodanUIActivator;
import org.eclipse.cdt.codan.ui.AbstractCodanCMarkerResolution; import org.eclipse.cdt.codan.ui.AbstractCodanCMarkerResolution;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.IPreferenceStore;
@ -27,12 +26,12 @@ import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI; import org.eclipse.ui.PlatformUI;
/** /**
* TODO: add description * Abstract base class for Quck Fix tests.
*/ */
@SuppressWarnings("restriction")
public abstract class QuickFixTestCase extends CheckerTestCase { public abstract class QuickFixTestCase extends CheckerTestCase {
AbstractCodanCMarkerResolution quickFix; AbstractCodanCMarkerResolution quickFix;
Display display; Display display;
@ -60,7 +59,7 @@ public abstract class QuickFixTestCase extends CheckerTestCase {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IWorkbenchPage activePage = window.getActivePage(); IWorkbenchPage activePage = window.getActivePage();
IWorkbenchPart activePart = activePage.getActivePart(); IWorkbenchPart activePart = activePage.getActivePart();
if (activePart.getTitle().equals("Welcome")) { if (activePart.getTitle().equals("Welcome")) { //$NON-NLS-1$
//activePage.close(); //activePage.close();
activePart.dispose(); activePart.dispose();
} }
@ -69,7 +68,6 @@ public abstract class QuickFixTestCase extends CheckerTestCase {
} }
} }
@SuppressWarnings("restriction")
@Override @Override
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
@ -77,7 +75,7 @@ public abstract class QuickFixTestCase extends CheckerTestCase {
display = PlatformUI.getWorkbench().getDisplay(); display = PlatformUI.getWorkbench().getDisplay();
closeWelcome(); closeWelcome();
IPreferenceStore store = CodanUIActivator.getDefault().getPreferenceStore(cproject.getProject()); IPreferenceStore store = CodanUIActivator.getDefault().getPreferenceStore(cproject.getProject());
// turn off editor reconsiler // turn off editor reconciler
store.setValue(PreferenceConstants.P_RUN_IN_EDITOR, false); store.setValue(PreferenceConstants.P_RUN_IN_EDITOR, false);
} }
@ -105,31 +103,15 @@ public abstract class QuickFixTestCase extends CheckerTestCase {
return new TextSelection(code.indexOf(string), string.length()); return new TextSelection(code.indexOf(string), string.length());
} }
/** public String runQuickFixOneFile() throws IOException, CoreException {
* @return
* @throws CModelException
* @throws PartInitException
* @throws IOException
* @throws CoreException
*/
public String runQuickFixOneFile() {
// need to load before running codan because otherwise marker is lost when doing quick fix 8[] // need to load before running codan because otherwise marker is lost when doing quick fix 8[]
try { runCodan();
runCodan(); doRunQuickFix();
doRunQuickFix(); dispatch(500);
dispatch(500); String result = TestUtils.loadFile(currentIFile.getContents());
String result = TestUtils.loadFile(currentIFile.getContents()); return result;
return result;
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
return null;
}
} }
/**
*
*/
public void doRunQuickFix() { public void doRunQuickFix() {
for (int i = 0; i < markers.length; i++) { for (int i = 0; i < markers.length; i++) {
IMarker marker = markers[i]; IMarker marker = markers[i];

View file

@ -6,25 +6,22 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* QNX Software Systems (Alena Laskavaia) - initial API and implementation * QNX Software Systems (Alena Laskavaia) - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.codan.internal.checkers.ui.quickfix; package org.eclipse.cdt.codan.internal.checkers.ui.quickfix;
import java.io.File;
import java.io.FileInputStream;
import org.eclipse.cdt.codan.core.test.TestUtils; import org.eclipse.cdt.codan.core.test.TestUtils;
import org.eclipse.cdt.codan.ui.AbstractCodanCMarkerResolution; import org.eclipse.cdt.codan.ui.AbstractCodanCMarkerResolution;
import org.eclipse.cdt.internal.ui.util.EditorUtility; import org.eclipse.cdt.internal.ui.util.EditorUtility;
import org.eclipse.core.runtime.CoreException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
/** /**
* Test for quick fix for suggested parenthesis * Test for quick fix for suggested parenthesis
*/ */
@SuppressWarnings("restriction")
public class SuggestedParenthesisQuickFixTest extends QuickFixTestCase { public class SuggestedParenthesisQuickFixTest extends QuickFixTestCase {
@SuppressWarnings("restriction")
@Override @Override
public AbstractCodanCMarkerResolution createQuickFix() { public AbstractCodanCMarkerResolution createQuickFix() {
return new SuggestedParenthesisQuickFix(); return new SuggestedParenthesisQuickFix();
@ -34,7 +31,7 @@ public class SuggestedParenthesisQuickFixTest extends QuickFixTestCase {
// int a=1,b=3; // int a=1,b=3;
// if (b+a && a>b || b-a) b--; // error here // if (b+a && a>b || b-a) b--; // error here
// } // }
public void testSimple() throws IOException, CoreException { public void testSimple() throws Exception {
loadcode(getAboveComment()); loadcode(getAboveComment());
String result = runQuickFixOneFile(); String result = runQuickFixOneFile();
assertContainedIn("(b+a && a>b)", result); //$NON-NLS-1$ assertContainedIn("(b+a && a>b)", result); //$NON-NLS-1$
@ -52,23 +49,18 @@ public class SuggestedParenthesisQuickFixTest extends QuickFixTestCase {
* this test is using two files, there was not actually bugs here so * this test is using two files, there was not actually bugs here so
* quick fix is not called * quick fix is not called
*/ */
public void test2FilesExample() throws FileNotFoundException, IOException { public void test2FilesExample() throws Exception {
CharSequence[] code = getContents(2); CharSequence[] code = getContents(2);
File f1 = loadcode(code[0].toString()); File f1 = loadcode(code[0].toString());
File f2 = loadcode(code[1].toString()); File f2 = loadcode(code[1].toString());
// lets pretend marker is found in main.c but fixes go in both files, // lets pretend marker is found in main.c but fixes go in both files,
// to check do something like this // to check do something like this
try { EditorUtility.openInEditor(f2);
EditorUtility.openInEditor(f2); runCodan();
runCodan(); doRunQuickFix();
doRunQuickFix(); String result_main = TestUtils.loadFile(new FileInputStream(f2));
String result_main = TestUtils.loadFile(new FileInputStream(f2)); String result_header = TestUtils.loadFile(new FileInputStream(f1));
String result_header = TestUtils.loadFile(new FileInputStream(f1)); assertContainedIn("foo", result_main); //$NON-NLS-1$
assertContainedIn("foo", result_main); //$NON-NLS-1$ assertContainedIn("foo", result_header); //$NON-NLS-1$
assertContainedIn("foo", result_header); //$NON-NLS-1$
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
} }
} }