Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Eidsness2014-04-24 13:01:17 +0000
committerAndrew Eidsness2014-05-22 02:13:30 +0000
commit54a174626a47932e46a3da3d445ad0a6d570c2e7 (patch)
tree9908eac74a80d592877bdc344165d79c684d3091 /extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp
parent591bd57b8694a950b1afb6862c250291c97a3e11 (diff)
downloadorg.eclipse.papyrus-54a174626a47932e46a3da3d445ad0a6d570c2e7.tar.gz
org.eclipse.papyrus-54a174626a47932e46a3da3d445ad0a6d570c2e7.tar.xz
org.eclipse.papyrus-54a174626a47932e46a3da3d445ad0a6d570c2e7.zip
Bug 433550: Automated Test Suite for C++ codegen
This is a test suite to confirm basic functionality of the C++ code generator. The project includes a model as well as the copies of the files that are expected to be generated. The junit test case programmatically runs the generator on each element and then checks for differences from what is expected. This needs a minor change in the basic generation code so that it can be run in a headless fashion. The change causes the generator to avoid opening a confirmation dialog on error if a certain System property is set. The comparison utility makes allowances for different formatting so that the expected code is not tied to the formatter that happens to be selected in the user's workspace. If a difference is detected, then the individual junit test case is aborted. Phase 1 of the test suite (this commit) includes: 11 tests o 9 Classes (headers, bodies) o 2 namespace headers 9 class tests covering generation of: o Classes § Inheritance § Abstract § Reusability as type in other classes and operations § Default constructor o Operations § Empty and defined method bodies § ANSIC return types § Pointer and Reference parameters (in, out, inout) and return types § Different classifiers (const, volatile, extern) § Different visibilities § Virtual § Pure virtual § Operator overloading § Polymorphism § Constructor, destructor o Attributes § Default values § Static values § Const § Different storage classifiers (volatile, register, extern) § Strings § Char, double, int, void, float § ANSIC types o Includes § Include statements § Global definitions Namespace header tests covering: o Packages § Namespace headers § Folder generation Change-Id: If22a8d3e8e3788f600288c183ac225468db4926a Signed-off-by: Andrew Eidsness <eclipse@jfront.com>
Diffstat (limited to 'extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp')
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/LocateCppProject.java58
1 files changed, 43 insertions, 15 deletions
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/LocateCppProject.java b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/LocateCppProject.java
index 570ba6a0727..fa0b92c3409 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/LocateCppProject.java
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/LocateCppProject.java
@@ -30,6 +30,8 @@ import org.eclipse.uml2.uml.PackageableElement;
public class LocateCppProject {
public static final String LANGUAGE_NAME = "C++"; //$NON-NLS-1$
+ private static final boolean Headless = Boolean.getBoolean("papyrus.run-headless");
+
/**
* Locate and return the target project for the given packageable element. Return null if
* no target project can be found.
@@ -38,10 +40,10 @@ public class LocateCppProject {
* not create a new project, but may modify existing ones.
*
* @param pe a packageable element within a model
- * @param interactive if true, ask the user to apply the C++ nature if required.
+ * @param createIfMissing if true, ask the user to apply the C++ nature if required.
* @return the associated project, if the C++ nature is applied.
*/
- public static IProject getTargetProject(PackageableElement pe, boolean interactive) {
+ public static IProject getTargetProject(PackageableElement pe, boolean createIfMissing) {
// URI uri = pe.eResource().getURI();
Package rootPkg = PackageUtil.getRootPackage(pe);
@@ -57,30 +59,56 @@ public class LocateCppProject {
String projectName = prefix + rootPkg.getName();
IProject modelProject = root.getProject(projectName);
if(!modelProject.exists()) {
- boolean create = interactive && MessageDialog.openQuestion(new Shell(),
- Messages.LocateCppProject_CreateTargetProjectTitle,
- String.format(Messages.LocateCppProject_CreateTargetProjectDesc, projectName));
- if (create) {
- ILangSupport langSupport = LanguageSupport.getLangSupport(LANGUAGE_NAME);
- if (langSupport != null) {
- langSupport.resetConfigurationData();
- modelProject = langSupport.createProject(projectName, null);
+ if (Headless)
+ {
+ try
+ {
+ modelProject.create(null);
+ }
+ catch( CoreException e )
+ {
+ return null;
+ }
+ }
+ else
+ {
+ boolean create = createIfMissing && MessageDialog.openQuestion(new Shell(),
+ Messages.LocateCppProject_CreateTargetProjectTitle,
+ String.format(Messages.LocateCppProject_CreateTargetProjectDesc, projectName));
+ if (create) {
+ ILangSupport langSupport = LanguageSupport.getLangSupport(LANGUAGE_NAME);
+ if (langSupport != null) {
+ langSupport.resetConfigurationData();
+ modelProject = langSupport.createProject(projectName, null);
+ }
+ else {
+ return null;
+ }
}
else {
return null;
}
}
- else {
+ }
+
+ // Make sure the target project is open. If it was just created then it is likely open,
+ // however if it is an old project then it could have been closed.
+ if( ! modelProject.isOpen() )
+ try
+ {
+ modelProject.open( null );
+ }
+ catch( CoreException e )
+ {
return null;
}
- }
-
+
// Make sure the target project has the C and C++ build natures.
try {
if(!modelProject.hasNature(CCProjectNature.CC_NATURE_ID)) {
- boolean apply = interactive && MessageDialog.openQuestion(new Shell(),
+ boolean apply = createIfMissing && (Headless || MessageDialog.openQuestion(new Shell(),
Messages.LocateCppProject_ApplyCNatureTitle,
- Messages.LocateCppProject_ApplyCNatureDesc);
+ Messages.LocateCppProject_ApplyCNatureDesc));
if (!apply) {
return null;
}

Back to the top