Skip to content

Commit f5c78b9

Browse files
author
Gyorgy Orban
authored
Merge pull request #159 from Vodorok/codechecker_stub
Add CodeChecker stub to the test resources
2 parents 6875c89 + 599896d commit f5c78b9

File tree

26 files changed

+769
-205
lines changed

26 files changed

+769
-205
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*.swo
66

77
# Eclipse
8+
bin/
89
.idea
910
*.iml
1011
target/

checkstyle.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<module name="TreeWalker">
1010
<module name="AvoidStarImport"/>
1111
<module name="AvoidStaticImport">
12-
<property name="excludes" value="org.hamcrest.MatcherAssert.*,org.hamcrest.Matchers.*,org.mockito.Mockito.*"/>
12+
<property name="excludes" value="org.hamcrest.MatcherAssert.*,org.hamcrest.Matchers.*,org.hamcrest.CoreMatchers.*,org.mockito.Mockito.*"/>
1313
</module>
1414
<module name="ConstantName"/>
1515
<module name="DeclarationOrder"/>

releng/org.codechecker.eclipse.target/org.codechecker.eclipse.target.target

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<unit id="org.eclipse.swtbot.forms.feature.group" version="2.7.0.201806111355"/>
99
<unit id="org.eclipse.swtbot.generator.feature.feature.group" version="2.7.0.201806111355"/>
1010
<unit id="org.eclipse.swtbot.ide.feature.group" version="2.7.0.201806111355"/>
11-
<repository location="http://download.eclipse.org/technology/swtbot/releases/latest"/>
11+
<repository location="http://download.eclipse.org/technology/swtbot/releases/2.7.0"/>
1212
</location>
1313
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
1414
<unit id="org.eclipse.tm.terminal.control.feature.feature.group" version="4.0.0.201506040610"/>

tests/org.codechecker.eclipse.rcp.it.tests/META-INF/MANIFEST.MF

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ Require-Bundle: org.junit;bundle-version="4.12.0",
1717
org.eclipse.cdt.make.ui;bundle-version="7.3.0",
1818
org.eclipse.cdt.build.gcc.core;bundle-version="1.0.0",
1919
org.eclipse.cdt.gdb.ui;bundle-version="7.0.0",
20-
org.eclipse.swtbot.eclipse.finder;bundle-version="2.7.0"
20+
org.eclipse.swtbot.eclipse.finder;bundle-version="2.7.0",
21+
org.codechecker.eclipse.rcp.shared;bundle-version="1.0.0"

tests/org.codechecker.eclipse.rcp.it.tests/build.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ source.. = src/
22
output.. = bin/
33
bin.includes = META-INF/,\
44
.,\
5-
fragment.xml
5+
fragment.xml,\
6+
resources/

tests/org.codechecker.eclipse.rcp.it.tests/pom.xml

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,9 @@
2424
<useUIThread>false</useUIThread>
2525
<product>org.codechecker.eclipse.feature</product>
2626
<application>org.eclipse.ui.ide.workbench</application>
27+
<testClass>org.codechecker.eclipse.plugin.AllTests</testClass>
2728
</configuration>
2829
</plugin>
29-
<plugin>
30-
<groupId>org.apache.maven.plugins</groupId>
31-
<artifactId>maven-checkstyle-plugin</artifactId>
32-
<version>3.0.0</version>
33-
<executions>
34-
<execution>
35-
<id>validate</id>
36-
<configuration>
37-
<failOnViolation>true</failOnViolation>
38-
</configuration>
39-
</execution>
40-
</executions>
41-
</plugin>
4230
</plugins>
4331
</build>
4432

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package org.codechecker.eclipse.plugin;
2+
3+
import org.codechecker.eclipse.plugin.utils.GuiUtils;
4+
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
5+
import org.junit.BeforeClass;
6+
import org.junit.runner.RunWith;
7+
import org.junit.runners.Suite;
8+
import org.junit.runners.Suite.SuiteClasses;
9+
10+
/**
11+
* Test Suite for running the gui tests. Add your class to the Suite class list.
12+
*/
13+
@RunWith(Suite.class)
14+
@SuiteClasses({ PluginTest.class, IndicatorTest.class })
15+
public class AllTests {
16+
17+
/**
18+
* Never called.
19+
*/
20+
private AllTests() {}
21+
22+
/**
23+
* Import cpp project into workspace, and setup SWTBot.
24+
*
25+
*/
26+
@BeforeClass
27+
public static void setup() {
28+
//clearWs();
29+
SWTWorkbenchBot bot = new SWTWorkbenchBot();
30+
GuiUtils.closeWelcomeIfPresent(bot);
31+
GuiUtils.changePerspectiveTo(GuiUtils.C_CPP_PESPECTIVE, bot);
32+
}
33+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package org.codechecker.eclipse.plugin;
2+
3+
import java.nio.file.Path;
4+
5+
import org.codechecker.eclipse.plugin.utils.GuiUtils;
6+
import org.codechecker.eclipse.rcp.shared.utils.Utils;
7+
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
8+
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
9+
import org.eclipse.swtbot.swt.finder.widgets.SWTBotCLabel;
10+
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
11+
import org.eclipse.swtbot.swt.finder.widgets.SWTBotText;
12+
import org.hamcrest.core.IsNull;
13+
import org.junit.Before;
14+
import org.junit.BeforeClass;
15+
import org.junit.Rule;
16+
import org.junit.Test;
17+
import org.junit.rules.ExpectedException;
18+
19+
import static org.hamcrest.CoreMatchers.is;
20+
import static org.hamcrest.MatcherAssert.assertThat;
21+
22+
/**
23+
* CodeChecker plugin preferences indicator tests.
24+
*/
25+
public class IndicatorTest {
26+
27+
private static final int SHORT_WAIT_TIME = 500; // in milliseconds
28+
29+
private static final String CODECHECKER = "CodeChecker";
30+
31+
private static SWTWorkbenchBot bot;
32+
33+
@Rule
34+
public ExpectedException thrown = ExpectedException.none();
35+
36+
private SWTBotShell preferencesShell;
37+
38+
/**
39+
* Import cpp project into workspace, and setup SWTBot.
40+
*
41+
*/
42+
@BeforeClass
43+
public static void setup() {
44+
bot = new SWTWorkbenchBot();
45+
}
46+
47+
/**
48+
* Open preferences, CodeChecker page before every test.
49+
*/
50+
@Before
51+
public void openPreferences() {
52+
preferencesShell = GuiUtils.getPreferencesTab(CODECHECKER, bot);
53+
}
54+
55+
/**
56+
* Test that with unconfigured CodeChecker, a warning message is displayed.
57+
*/
58+
@Test
59+
public void testNoCodeCheckerFound() {
60+
SWTBotCLabel label = null;
61+
try {
62+
label = bot.clabel("CodeChecker package directory is invalid");
63+
} catch (WidgetNotFoundException e) {
64+
System.out.println(e.getMessage());
65+
}
66+
assertThat("There was no invalid CodeChecker message displayed", label, is(IsNull.notNullValue()));
67+
68+
preferencesShell.close();
69+
}
70+
71+
/**
72+
* Test that with CodeChecker configured, a confirmation message is displayed.
73+
*/
74+
@Test
75+
public void testCodeCheckerFound() {
76+
Path ccDir = Utils.prepareCodeChecker();
77+
78+
SWTBotText text = bot.textWithLabel("CodeChecker package root directory");
79+
text.setText(ccDir.toString());
80+
text.setFocus();
81+
bot.textWithLabel("Python virtualenv root directory (optional)").setFocus();
82+
83+
bot.sleep(SHORT_WAIT_TIME);
84+
85+
SWTBotCLabel label = null;
86+
try {
87+
label = bot.clabel("CodeChecker package directory is valid");
88+
} catch (WidgetNotFoundException e) {
89+
System.out.println(e.getMessage());
90+
}
91+
assertThat("There was no valid CodeChecker message displayed", label, is(IsNull.notNullValue()));
92+
93+
preferencesShell.close();
94+
}
95+
}

tests/org.codechecker.eclipse.rcp.it.tests/src/org/codechecker/eclipse/plugin/PluginTest.java

Lines changed: 14 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,21 @@
33
import java.io.File;
44
import java.io.IOException;
55
import java.net.URISyntaxException;
6-
import java.net.URL;
6+
import java.nio.file.Path;
77
import java.nio.file.Paths;
88

9-
import org.codechecker.eclipse.plugin.utils.Utils;
10-
import org.eclipse.core.resources.IProject;
11-
import org.eclipse.core.resources.IProjectDescription;
9+
import org.codechecker.eclipse.plugin.utils.ProjectImporter;
10+
import org.codechecker.eclipse.rcp.shared.utils.Utils;
1211
import org.eclipse.core.resources.ResourcesPlugin;
1312
import org.eclipse.core.runtime.CoreException;
14-
import org.eclipse.core.runtime.FileLocator;
15-
import org.eclipse.core.runtime.Path;
16-
import org.eclipse.core.runtime.Platform;
1713
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
1814
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
19-
import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
20-
import org.eclipse.swtbot.swt.finder.results.VoidResult;
2115
import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu;
22-
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
2316
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
24-
import org.eclipse.ui.PlatformUI;
2517
import org.junit.BeforeClass;
2618
import org.junit.Rule;
2719
import org.junit.Test;
2820
import org.junit.rules.ExpectedException;
29-
import org.osgi.framework.Bundle;
3021

3122
import static org.hamcrest.MatcherAssert.assertThat;
3223
import static org.hamcrest.Matchers.containsString;
@@ -38,10 +29,6 @@
3829
public class PluginTest {
3930

4031
private static final String CPP_PROJ = "cppTest";
41-
private static final String WINDOW_MENU = "Window";
42-
private static final String PERSP_MENU = "Perspective";
43-
private static final String OPEN_PERSP = "Open Perspective";
44-
private static final String OTHER_MENU = "Other...";
4532
private static final String ADD_NATURE_MENU = "Add CodeChecker Nature";
4633

4734
private static SWTWorkbenchBot bot;
@@ -51,56 +38,30 @@ public class PluginTest {
5138

5239
/**
5340
* Import cpp project into workspace, and setup SWTBot.
54-
*
5541
*/
5642
@BeforeClass
5743
public static void setup() {
5844

59-
// http://blog.vogella.com/2010/07/06/reading-resources-from-plugin/
60-
Bundle bundle = Platform.getBundle("org.codechecker.eclipse.rcp.it.tests");
61-
URL fileURL = bundle.getEntry("resources/cppTest");
62-
File file = null;
45+
bot = new SWTWorkbenchBot();
46+
47+
Path file = null;
6348
try {
64-
file = new File(FileLocator.resolve(fileURL).toURI());
65-
} catch (URISyntaxException e1) {
66-
e1.printStackTrace();
67-
} catch (IOException e1) {
68-
e1.printStackTrace();
49+
file = Utils.loadFileFromBundle("org.codechecker.eclipse.rcp.it.tests",
50+
Utils.RES + CPP_PROJ);
51+
} catch (URISyntaxException | IOException e) {
52+
e.printStackTrace();
6953
}
70-
assertThat("File not exists.", file.exists());
71-
Utils.copyFolder(file.toPath(),
54+
55+
Utils.copyFolder(file,
7256
Paths.get(ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString() + File.separator));
7357

7458
File project = new File(ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString() + File.separator
7559
+ CPP_PROJ + File.separator + ".project");
7660
try {
77-
importProject(project, CPP_PROJ);
61+
ProjectImporter.importProject(project.toPath(), CPP_PROJ);
7862
} catch (CoreException e1) {
7963
e1.printStackTrace();
8064
}
81-
82-
bot = new SWTWorkbenchBot();
83-
UIThreadRunnable.syncExec(new VoidResult() {
84-
public void run() {
85-
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().forceActive();
86-
}
87-
});
88-
89-
try {
90-
bot.viewByTitle("Welcome").close();
91-
} catch (WidgetNotFoundException e) {
92-
System.out.println("Welcome Screen wasn't present.");
93-
}
94-
95-
// Change the perspective via the Open Perspective dialog
96-
bot.menu(WINDOW_MENU).menu(PERSP_MENU).menu(OPEN_PERSP).menu(OTHER_MENU).click();
97-
SWTBotShell openPerspectiveShell = bot.shell(OPEN_PERSP);
98-
openPerspectiveShell.activate();
99-
100-
// select the dialog
101-
bot.table().select("C/C++");
102-
bot.button("Open").click();
103-
10465
}
10566

10667
/**
@@ -121,37 +82,4 @@ public void testAddNatureDisappears() {
12182
thrown.expectMessage(containsString("Could not find"));
12283
project.contextMenu(ADD_NATURE_MENU);
12384
}
124-
125-
126-
/**
127-
* Imports a project into workspace.
128-
* https://www.eclipse.org/forums/index.php/t/560903/
129-
*
130-
* @param projectFile
131-
* The project file to be imported.
132-
* @param projectName
133-
* The project name that will be used to create the project
134-
* @throws CoreException
135-
* Project cannot be created: if this method fails. Reasons include:
136-
* - This project already exists in the workspace. - The name of
137-
* this resource is not valid (according to
138-
* IWorkspace.validateName). - The project location is not valid
139-
* (according to IWorkspace.validateProjectLocation). - The project
140-
* description file could not be created in the project content
141-
* area. - Resource changes are disallowed during certain types of
142-
* resource change event notification. See IResourceChangeEvent for
143-
* more details. .project file has troubles. Reasons include: - The
144-
* project description file does not exist. - The file cannot be
145-
* opened or read. - The file cannot be parsed as a legal project
146-
* description. or during opening - Resource changes are disallowed
147-
* during certain types of resource change event notification. See
148-
* IResourceChangeEvent for more details.
149-
*/
150-
private static void importProject(final File projectFile, final String projectName) throws CoreException {
151-
IProjectDescription description = ResourcesPlugin.getWorkspace()
152-
.loadProjectDescription(new Path(projectFile.getAbsolutePath()));
153-
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(description.getName());
154-
project.create(description, null);
155-
project.open(null);
156-
}
157-
}
85+
}

0 commit comments

Comments
 (0)