blob: e06baa2f08e3d73c2d328a7d3ddb04717d7b96d3 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
/*******************************************************************************
* Copyright (c) 2009,2010 QNX Software Systems
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* QNX Software Systems (Alena Laskavaia) - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.codan.internal.checkers.ui.quickfix;
import org.eclipse.cdt.codan.core.test.TestUtils;
import org.eclipse.cdt.codan.ui.AbstractCodanCMarkerResolution;
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
*/
public class SuggestedParenthesisQuickFixTest extends QuickFixTestCase {
@SuppressWarnings("restriction")
@Override
public AbstractCodanCMarkerResolution createQuickFix() {
return new SuggestedParenthesisQuickFix();
}
// main() {
// int a=1,b=3;
// if (b+a && a>b || b-a) b--; // error here
// }
public void testSimple() throws IOException, CoreException {
loadcode(getAboveComment());
String result = runQuickFixOneFile();
assertContainedIn("(b+a && a>b)", result); //$NON-NLS-1$
}
// @file:header.h
// int foo();
/* ---- */
// @file:main.c
// #include "header.h"
// main() {
// foo();
// }
/*
* this test is using two files, there was not actually bugs here so
* quick fix is not called
*/
public void test2FilesExample() throws FileNotFoundException, IOException {
CharSequence[] code = getContents(2);
File f1 = loadcode(code[0].toString());
File f2 = loadcode(code[1].toString());
// lets pretend marker is found in main.c but fixes go in both files,
// to check do something like this
try {
EditorUtility.openInEditor(f2);
runCodan();
doRunQuickFix();
String result_main = TestUtils.loadFile(new FileInputStream(f2));
String result_header = TestUtils.loadFile(new FileInputStream(f1));
assertContainedIn("foo", result_main); //$NON-NLS-1$
assertContainedIn("foo", result_header); //$NON-NLS-1$
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
}
|