mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-01 06:05:24 +02:00
New Eclipse-friendly framework for refactoring tests. Converted
ExtractFunctionReafactoringTest to the new framework.
This commit is contained in:
parent
3fa7f7213c
commit
ecb3820c77
18 changed files with 4555 additions and 5002 deletions
|
@ -67,8 +67,9 @@ public class IndexNamesTests extends BaseTestCase {
|
|||
}
|
||||
|
||||
public String getComment() throws IOException {
|
||||
return TestSourceReader.getContentsForTest(
|
||||
CTestPlugin.getDefault().getBundle(), "parser", getClass(), getName(), 1)[0].toString();
|
||||
CharSequence[] contents = TestSourceReader.getContentsForTest(
|
||||
CTestPlugin.getDefault().getBundle(), "parser", getClass(), getName(), 1);
|
||||
return contents[0].toString();
|
||||
}
|
||||
|
||||
protected IFile createFile(IContainer container, String fileName, String contents) throws Exception {
|
||||
|
|
|
@ -21,9 +21,7 @@ import org.eclipse.core.runtime.IPath;
|
|||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.Plugin;
|
||||
|
||||
|
||||
public class CTestPlugin extends Plugin {
|
||||
|
||||
public static final String PLUGIN_ID = "org.eclipse.cdt.core.tests";
|
||||
private static CTestPlugin fgDefault;
|
||||
|
||||
|
@ -55,7 +53,4 @@ public class CTestPlugin extends Plugin {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -34,6 +34,7 @@ import org.eclipse.cdt.core.model.CModelException;
|
|||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.core.testplugin.CTestPlugin;
|
||||
import org.eclipse.core.resources.IContainer;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IFolder;
|
||||
|
@ -45,8 +46,10 @@ import org.eclipse.core.runtime.CoreException;
|
|||
import org.eclipse.core.runtime.FileLocator;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.osgi.framework.Bundle;
|
||||
|
||||
/**
|
||||
|
@ -247,17 +250,23 @@ public class TestSourceReader {
|
|||
* @throws CoreException
|
||||
* @since 4.0
|
||||
*/
|
||||
public static IFile createFile(final IContainer container, final IPath filePath, final String contents) throws CoreException {
|
||||
public static IFile createFile(final IContainer container, final IPath filePath,
|
||||
final CharSequence contents) throws CoreException {
|
||||
final IWorkspace ws = ResourcesPlugin.getWorkspace();
|
||||
final IFile result[] = new IFile[1];
|
||||
ws.run(new IWorkspaceRunnable() {
|
||||
@Override
|
||||
public void run(IProgressMonitor monitor) throws CoreException {
|
||||
//Obtain file handle
|
||||
// Obtain file handle
|
||||
IFile file = container.getFile(filePath);
|
||||
|
||||
InputStream stream = new ByteArrayInputStream(contents.getBytes());
|
||||
//Create file input stream
|
||||
InputStream stream;
|
||||
try {
|
||||
stream = new ByteArrayInputStream(contents.toString().getBytes("UTF-8"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new CoreException(new Status(IStatus.ERROR, CTestPlugin.PLUGIN_ID, null, e));
|
||||
}
|
||||
// Create file input stream
|
||||
if (file.exists()) {
|
||||
long timestamp= file.getLocalTimeStamp();
|
||||
file.setContents(stream, false, false, new NullProgressMonitor());
|
||||
|
@ -290,11 +299,11 @@ public class TestSourceReader {
|
|||
* @param contents the content for the file
|
||||
* @return a file object.
|
||||
* @since 4.0
|
||||
*/
|
||||
*/
|
||||
public static IFile createFile(IContainer container, String filePath, String contents) throws CoreException {
|
||||
return createFile(container, new Path(filePath), contents);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Waits until the given file is indexed. Fails if this does not happen within the
|
||||
* given time.
|
||||
|
|
|
@ -1,691 +0,0 @@
|
|||
//!Extract boolean comparison from if-condition.
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
|
||||
//@.config
|
||||
filename=test.cpp
|
||||
methodname=check
|
||||
|
||||
//@test.h
|
||||
class Test {
|
||||
void test();
|
||||
};
|
||||
|
||||
|
||||
//=
|
||||
class Test {
|
||||
void test();
|
||||
bool check();
|
||||
};
|
||||
|
||||
|
||||
//@test.cpp
|
||||
#include "test.h"
|
||||
|
||||
void Test::test() {
|
||||
if (/*$*/5 == 3 + 2/*$$*/) {
|
||||
//...
|
||||
}
|
||||
}
|
||||
|
||||
//=
|
||||
#include "test.h"
|
||||
|
||||
bool Test::check() {
|
||||
return 5 == 3 + 2;
|
||||
}
|
||||
|
||||
void Test::test() {
|
||||
if (check()) {
|
||||
//...
|
||||
}
|
||||
}
|
||||
|
||||
//!Extract boolean comparison from if-condition with parameter.
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
|
||||
//@.config
|
||||
filename=test.cpp
|
||||
methodname=check
|
||||
|
||||
//@test.h
|
||||
class Test {
|
||||
void test();
|
||||
};
|
||||
|
||||
|
||||
//=
|
||||
class Test {
|
||||
void test();
|
||||
bool check(int num);
|
||||
};
|
||||
|
||||
|
||||
//@test.cpp
|
||||
#include "test.h"
|
||||
|
||||
void Test::test() {
|
||||
int num = 1;
|
||||
if (/*$*/5 != 3 + num/*$$*/) {
|
||||
//...
|
||||
}
|
||||
}
|
||||
|
||||
//=
|
||||
#include "test.h"
|
||||
|
||||
bool Test::check(int num) {
|
||||
return 5 != 3 + num;
|
||||
}
|
||||
|
||||
void Test::test() {
|
||||
int num = 1;
|
||||
if (check(num)) {
|
||||
//...
|
||||
}
|
||||
}
|
||||
|
||||
//!Extract binary expression that results in a function with the same return type (BasicType) as the LHS.
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
|
||||
//@.config
|
||||
filename=test.cpp
|
||||
methodname=add
|
||||
|
||||
//@test.h
|
||||
class Test {
|
||||
void test();
|
||||
};
|
||||
|
||||
|
||||
//=
|
||||
class Test {
|
||||
void test();
|
||||
int add(int five, int six);
|
||||
};
|
||||
|
||||
|
||||
//@test.cpp
|
||||
#include "test.h"
|
||||
|
||||
void Test::test() {
|
||||
int five = 5;
|
||||
int six = 6;
|
||||
int result = /*$*/five + six/*$$*/;
|
||||
}
|
||||
|
||||
//=
|
||||
#include "test.h"
|
||||
|
||||
int Test::add(int five, int six) {
|
||||
return five + six;
|
||||
}
|
||||
|
||||
void Test::test() {
|
||||
int five = 5;
|
||||
int six = 6;
|
||||
int result = add(five, six);
|
||||
}
|
||||
|
||||
//!Extract binary expression that results in a function with the same return type (ClassType) as the LHS
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
|
||||
//@.config
|
||||
filename=test.cpp
|
||||
methodname=cat
|
||||
|
||||
//@test.h
|
||||
struct helper {};
|
||||
|
||||
class Test {
|
||||
void test();
|
||||
};
|
||||
|
||||
|
||||
//=
|
||||
struct helper {};
|
||||
|
||||
class Test {
|
||||
void test();
|
||||
helper cat(helper s1, helper s2);
|
||||
};
|
||||
|
||||
|
||||
//@test.cpp
|
||||
#include "test.h"
|
||||
|
||||
void Test::test() {
|
||||
helper s1 = "a";
|
||||
helper s2 = "b";
|
||||
helper result = /*$*/s1 + s2/*$$*/;
|
||||
}
|
||||
|
||||
//=
|
||||
#include "test.h"
|
||||
|
||||
helper Test::cat(helper s1, helper s2) {
|
||||
return s1 + s2;
|
||||
}
|
||||
|
||||
void Test::test() {
|
||||
helper s1 = "a";
|
||||
helper s2 = "b";
|
||||
helper result = cat(s1, s2);
|
||||
}
|
||||
|
||||
//!Extract binary expression that results in a function with the same return type (Typedef) as the LHS
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
|
||||
//@.config
|
||||
filename=test.cpp
|
||||
methodname=cat
|
||||
|
||||
//@test.h
|
||||
struct helper {};
|
||||
typedef helper new_helper;
|
||||
|
||||
class Test {
|
||||
void test();
|
||||
};
|
||||
|
||||
|
||||
//=
|
||||
struct helper {};
|
||||
typedef helper new_helper;
|
||||
|
||||
class Test {
|
||||
void test();
|
||||
new_helper cat(new_helper s1, new_helper s2);
|
||||
};
|
||||
|
||||
|
||||
//@test.cpp
|
||||
#include "test.h"
|
||||
|
||||
void Test::test() {
|
||||
new_helper s1 = "a";
|
||||
new_helper s2 = "b";
|
||||
new_helper result = /*$*/s1 + s2/*$$*/;
|
||||
}
|
||||
|
||||
//=
|
||||
#include "test.h"
|
||||
|
||||
new_helper Test::cat(new_helper s1, new_helper s2) {
|
||||
return s1 + s2;
|
||||
}
|
||||
|
||||
void Test::test() {
|
||||
new_helper s1 = "a";
|
||||
new_helper s2 = "b";
|
||||
new_helper result = cat(s1, s2);
|
||||
}
|
||||
|
||||
//!Extract new-Expression
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
|
||||
//@.config
|
||||
filename=test.cpp
|
||||
methodname=new_helper
|
||||
|
||||
//@test.cpp
|
||||
|
||||
struct helper {};
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
helper* h = /*$*/new helper/*$$*/;
|
||||
return 0;
|
||||
}
|
||||
//=
|
||||
|
||||
struct helper {};
|
||||
|
||||
helper* new_helper() {
|
||||
return new helper;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
helper* h = new_helper();
|
||||
return 0;
|
||||
}
|
||||
//!Extract function call
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
|
||||
//@.config
|
||||
filename=test.cpp
|
||||
methodname=join_with_world
|
||||
|
||||
//@test.cpp
|
||||
class string {};
|
||||
|
||||
string join(string s1, char* s2) {
|
||||
return s1 + " " + s2;
|
||||
}
|
||||
|
||||
int main() {
|
||||
string hello = "Hello";
|
||||
cout << /*$*/join(hello, "World")/*$$*/ << endl;
|
||||
}
|
||||
//=
|
||||
class string {};
|
||||
|
||||
string join(string s1, char* s2) {
|
||||
return s1 + " " + s2;
|
||||
}
|
||||
|
||||
string join_with_world(string hello) {
|
||||
return join(hello, "World");
|
||||
}
|
||||
|
||||
int main() {
|
||||
string hello = "Hello";
|
||||
cout << join_with_world(hello) << endl;
|
||||
}
|
||||
//!Extract method call
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
|
||||
//@.config
|
||||
filename=test.cpp
|
||||
methodname=value_from
|
||||
|
||||
//@test.cpp
|
||||
struct other {
|
||||
bool value() {}
|
||||
};
|
||||
|
||||
class Klass {
|
||||
void set(bool b) {
|
||||
}
|
||||
|
||||
void test() {
|
||||
other o;
|
||||
this->set(/*$*/o.value()/*$$*/);
|
||||
}
|
||||
};
|
||||
|
||||
//=
|
||||
struct other {
|
||||
bool value() {}
|
||||
};
|
||||
|
||||
class Klass {
|
||||
void set(bool b) {
|
||||
}
|
||||
|
||||
bool value_from(other o) {
|
||||
return o.value();
|
||||
}
|
||||
|
||||
void test() {
|
||||
other o;
|
||||
this->set(value_from(o));
|
||||
}
|
||||
};
|
||||
|
||||
//!Extract function call [we only have the declaration] that returns a pointer
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
|
||||
//@.config
|
||||
filename=test.cpp
|
||||
methodname=has
|
||||
|
||||
//@test.cpp
|
||||
class Cursor{};
|
||||
|
||||
Cursor* contains(const Cursor& pos);
|
||||
|
||||
int main() {
|
||||
Cursor c;
|
||||
contains(/*$*/contains(c)/*$$*/);
|
||||
}
|
||||
|
||||
//=
|
||||
class Cursor{};
|
||||
|
||||
Cursor* contains(const Cursor& pos);
|
||||
|
||||
Cursor* has(Cursor c) {
|
||||
return contains(c);
|
||||
}
|
||||
|
||||
int main() {
|
||||
Cursor c;
|
||||
contains(has(c));
|
||||
}
|
||||
|
||||
//!Extract function call [we have the definition] that returns a pointer
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
|
||||
//@.config
|
||||
filename=test.cpp
|
||||
methodname=has
|
||||
|
||||
//@test.cpp
|
||||
class Cursor{};
|
||||
|
||||
Cursor* contains(const Cursor& pos) {
|
||||
;
|
||||
}
|
||||
|
||||
int main() {
|
||||
Cursor c;
|
||||
contains(/*$*/contains(c)/*$$*/);
|
||||
}
|
||||
|
||||
//=
|
||||
class Cursor{};
|
||||
|
||||
Cursor* contains(const Cursor& pos) {
|
||||
;
|
||||
}
|
||||
|
||||
Cursor* has(Cursor c) {
|
||||
return contains(c);
|
||||
}
|
||||
|
||||
int main() {
|
||||
Cursor c;
|
||||
contains(has(c));
|
||||
}
|
||||
|
||||
//!Extract string constant
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
|
||||
//@.config
|
||||
filename=test.cpp
|
||||
methodname=greeting
|
||||
|
||||
//@test.h
|
||||
class Test {
|
||||
void test();
|
||||
};
|
||||
|
||||
|
||||
//=
|
||||
class Test {
|
||||
void test();
|
||||
const char greeting();
|
||||
};
|
||||
|
||||
|
||||
//@test.cpp
|
||||
#include "test.h"
|
||||
|
||||
void Test::test() {
|
||||
char* hi = /*$*/"hello"/*$$*/;
|
||||
}
|
||||
|
||||
//=
|
||||
#include "test.h"
|
||||
|
||||
const char Test::greeting() {
|
||||
return "hello";
|
||||
}
|
||||
|
||||
void Test::test() {
|
||||
char* hi = greeting();
|
||||
}
|
||||
|
||||
//!Extract int constant
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
|
||||
//@.config
|
||||
filename=test.cpp
|
||||
methodname=size
|
||||
|
||||
//@test.h
|
||||
class Test {
|
||||
void test();
|
||||
};
|
||||
|
||||
|
||||
//=
|
||||
class Test {
|
||||
void test();
|
||||
int size();
|
||||
};
|
||||
|
||||
|
||||
//@test.cpp
|
||||
#include "test.h"
|
||||
|
||||
void Test::test() {
|
||||
int i = /*$*/42/*$$*/;
|
||||
}
|
||||
|
||||
//=
|
||||
#include "test.h"
|
||||
|
||||
int Test::size() {
|
||||
return 42;
|
||||
}
|
||||
|
||||
void Test::test() {
|
||||
int i = size();
|
||||
}
|
||||
|
||||
//!Extract float constant
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
|
||||
//@.config
|
||||
filename=test.cpp
|
||||
methodname=certainty
|
||||
|
||||
//@test.h
|
||||
class Test {
|
||||
void test();
|
||||
};
|
||||
|
||||
|
||||
//=
|
||||
class Test {
|
||||
void test();
|
||||
float certainty();
|
||||
};
|
||||
|
||||
|
||||
//@test.cpp
|
||||
#include "test.h"
|
||||
|
||||
void Test::test() {
|
||||
float f = /*$*/0.42f/*$$*/;
|
||||
}
|
||||
|
||||
//=
|
||||
#include "test.h"
|
||||
|
||||
float Test::certainty() {
|
||||
return 0.42f;
|
||||
}
|
||||
|
||||
void Test::test() {
|
||||
float f = certainty();
|
||||
}
|
||||
|
||||
//!Extract char constant
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
|
||||
//@.config
|
||||
filename=test.cpp
|
||||
methodname=newline
|
||||
|
||||
//@test.h
|
||||
class Test {
|
||||
void test();
|
||||
};
|
||||
|
||||
|
||||
//=
|
||||
class Test {
|
||||
void test();
|
||||
char newline();
|
||||
};
|
||||
|
||||
|
||||
//@test.cpp
|
||||
#include "test.h"
|
||||
|
||||
void Test::test() {
|
||||
char nl = /*$*/'\n'/*$$*/;
|
||||
}
|
||||
|
||||
//=
|
||||
#include "test.h"
|
||||
|
||||
char Test::newline() {
|
||||
return '\n';
|
||||
}
|
||||
|
||||
void Test::test() {
|
||||
char nl = newline();
|
||||
}
|
||||
|
||||
//!Extract boolean true constant
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
|
||||
//@.config
|
||||
filename=test.cpp
|
||||
methodname=valid
|
||||
|
||||
//@test.h
|
||||
class Test {
|
||||
void test();
|
||||
};
|
||||
|
||||
|
||||
//=
|
||||
class Test {
|
||||
void test();
|
||||
bool valid();
|
||||
};
|
||||
|
||||
|
||||
//@test.cpp
|
||||
#include "test.h"
|
||||
|
||||
void Test::test() {
|
||||
bool b = /*$*/true/*$$*/;
|
||||
}
|
||||
|
||||
//=
|
||||
#include "test.h"
|
||||
|
||||
bool Test::valid() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void Test::test() {
|
||||
bool b = valid();
|
||||
}
|
||||
|
||||
//!Extract boolean false constant
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
|
||||
//@.config
|
||||
filename=test.cpp
|
||||
methodname=invalid
|
||||
|
||||
//@test.h
|
||||
class Test {
|
||||
void test();
|
||||
};
|
||||
|
||||
|
||||
//=
|
||||
class Test {
|
||||
void test();
|
||||
bool invalid();
|
||||
};
|
||||
|
||||
|
||||
//@test.cpp
|
||||
#include "test.h"
|
||||
|
||||
void Test::test() {
|
||||
bool b = /*$*/false/*$$*/;
|
||||
}
|
||||
|
||||
//=
|
||||
#include "test.h"
|
||||
|
||||
bool Test::invalid() {
|
||||
return false;
|
||||
}
|
||||
|
||||
void Test::test() {
|
||||
bool b = invalid();
|
||||
}
|
||||
|
||||
//!Extract expression with typedef Bug 331985
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
//@.config
|
||||
filename=test.cpp
|
||||
methodname=bar
|
||||
|
||||
//@test.cpp
|
||||
typedef int& foo;
|
||||
|
||||
int test(foo s) {
|
||||
int a = /*$*/s + 1/*$$*/; // type of id-expression 's' is int, not 'foo' or 'int&'
|
||||
return a;
|
||||
}
|
||||
//=
|
||||
typedef int& foo;
|
||||
|
||||
int bar(foo s) {
|
||||
return s + 1;
|
||||
}
|
||||
|
||||
int test(foo s) {
|
||||
int a = bar(s); // type of id-expression 's' is int, not 'foo' or 'int&'
|
||||
return a;
|
||||
}
|
||||
//!Bug 260133 Extract function and extract local variable don't handle type promotion
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
|
||||
//@.config
|
||||
filename=test.cpp
|
||||
methodname=bar
|
||||
|
||||
//@test.cpp
|
||||
void foo() {
|
||||
int x = 3;
|
||||
double y = /*$*/x + 2.5/*$$*/;
|
||||
}
|
||||
//=
|
||||
double bar(int x) {
|
||||
return x + 2.5;
|
||||
}
|
||||
|
||||
void foo() {
|
||||
int x = 3;
|
||||
double y = bar(x);
|
||||
}
|
||||
//! Extract macro
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
//@.config
|
||||
filename=test.cpp
|
||||
methodname=bar
|
||||
//@test.cpp
|
||||
#define five 5
|
||||
#define ADD(a, b) a + b
|
||||
|
||||
int main() {
|
||||
int i = five; //comment3
|
||||
i = /*$*/ADD(i, five)/*$$*/;
|
||||
|
||||
return i;
|
||||
}
|
||||
//=
|
||||
#define five 5
|
||||
#define ADD(a, b) a + b
|
||||
|
||||
int bar(int i) {
|
||||
return ADD(i, five);
|
||||
}
|
||||
|
||||
int main() {
|
||||
int i = five; //comment3
|
||||
i = bar(i);
|
||||
|
||||
return i;
|
||||
}
|
|
@ -1,93 +0,0 @@
|
|||
//!Extract template function
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
//@A.cpp
|
||||
void test() {
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
int tempFunct() {
|
||||
T i;
|
||||
i = 0;
|
||||
/*$*/i++;
|
||||
i += 3;/*$$*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
//=
|
||||
void test() {
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void exp(T i) {
|
||||
i++;
|
||||
i += 3;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
int tempFunct() {
|
||||
T i;
|
||||
i = 0;
|
||||
exp(i);
|
||||
return 0;
|
||||
}
|
||||
//!Extract template function with template parameter Bug #12
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
//@A.cpp
|
||||
void test() {
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
int tempFunct(T p) {
|
||||
/*$*/++p;
|
||||
p + 4;/*$$*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
//=
|
||||
void test() {
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void exp(T p) {
|
||||
++p;
|
||||
p + 4;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
int tempFunct(T p) {
|
||||
exp(p);
|
||||
return 0;
|
||||
}
|
||||
|
||||
//!Extract template function with template type declaration Bug #11
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
//@A.cpp
|
||||
void test() {
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
int tempFunct() {
|
||||
/*$*/T p;
|
||||
p = 0;
|
||||
p + 4;/*$$*/
|
||||
p + 2;
|
||||
return 0;
|
||||
}
|
||||
//=
|
||||
void test() {
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T exp() {
|
||||
T p;
|
||||
p = 0;
|
||||
p + 4;
|
||||
return p;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
int tempFunct() {
|
||||
T p = exp();
|
||||
p + 2;
|
||||
return 0;
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -1,987 +0,0 @@
|
|||
//!Extract method with duplicates
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
//@.config
|
||||
replaceduplicates=true
|
||||
//@A.h
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
class A {
|
||||
public:
|
||||
A();
|
||||
virtual ~A();
|
||||
int foo();
|
||||
|
||||
private:
|
||||
int help();
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//=
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
class A {
|
||||
public:
|
||||
A();
|
||||
virtual ~A();
|
||||
int foo();
|
||||
|
||||
private:
|
||||
int help();
|
||||
void exp(int& i);
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//@A.cpp
|
||||
#include "A.h"
|
||||
|
||||
A::A() {
|
||||
}
|
||||
|
||||
A::~A() {
|
||||
int i = 2;
|
||||
++i;
|
||||
help();
|
||||
}
|
||||
|
||||
int A::foo() {
|
||||
int i = 2;
|
||||
/*$*/++i;
|
||||
help();/*$$*/
|
||||
return i;
|
||||
}
|
||||
|
||||
int A::help() {
|
||||
return 42;
|
||||
}
|
||||
|
||||
//=
|
||||
#include "A.h"
|
||||
|
||||
A::A() {
|
||||
}
|
||||
|
||||
A::~A() {
|
||||
int i = 2;
|
||||
exp(i);
|
||||
}
|
||||
|
||||
void A::exp(int& i) {
|
||||
++i;
|
||||
help();
|
||||
}
|
||||
|
||||
int A::foo() {
|
||||
int i = 2;
|
||||
exp(i);
|
||||
return i;
|
||||
}
|
||||
|
||||
int A::help() {
|
||||
return 42;
|
||||
}
|
||||
|
||||
//!Extract method duplicates with different Names
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
//@.config
|
||||
replaceduplicates=true
|
||||
//@A.h
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
class A {
|
||||
public:
|
||||
A();
|
||||
virtual ~A();
|
||||
int foo();
|
||||
|
||||
private:
|
||||
int help();
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//=
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
class A {
|
||||
public:
|
||||
A();
|
||||
virtual ~A();
|
||||
int foo();
|
||||
|
||||
private:
|
||||
int help();
|
||||
void exp(int& i);
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//@A.cpp
|
||||
#include "A.h"
|
||||
|
||||
A::A() {
|
||||
}
|
||||
|
||||
A::~A() {
|
||||
int oo = 99;
|
||||
++oo;
|
||||
help();
|
||||
}
|
||||
|
||||
int A::foo() {
|
||||
int i = 2;
|
||||
/*$*/++i;
|
||||
help();/*$$*/
|
||||
return i;
|
||||
}
|
||||
|
||||
int A::help() {
|
||||
return 42;
|
||||
}
|
||||
|
||||
//=
|
||||
#include "A.h"
|
||||
|
||||
A::A() {
|
||||
}
|
||||
|
||||
A::~A() {
|
||||
int oo = 99;
|
||||
exp(oo);
|
||||
}
|
||||
|
||||
void A::exp(int& i) {
|
||||
++i;
|
||||
help();
|
||||
}
|
||||
|
||||
int A::foo() {
|
||||
int i = 2;
|
||||
exp(i);
|
||||
return i;
|
||||
}
|
||||
|
||||
int A::help() {
|
||||
return 42;
|
||||
}
|
||||
|
||||
//!Extract method duplicate with field
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
//@.config
|
||||
replaceduplicates=true
|
||||
returnvalue=j
|
||||
//@A.h
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
class A {
|
||||
public:
|
||||
A();
|
||||
virtual ~A();
|
||||
void foo();
|
||||
int i;
|
||||
|
||||
private:
|
||||
int help();
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//=
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
class A {
|
||||
public:
|
||||
A();
|
||||
virtual ~A();
|
||||
void foo();
|
||||
int i;
|
||||
|
||||
private:
|
||||
int help();
|
||||
int exp(int j, int& a);
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//@A.cpp
|
||||
#include "A.h"
|
||||
|
||||
A::A() {
|
||||
}
|
||||
|
||||
A::~A() {
|
||||
int j = 0;
|
||||
i++;
|
||||
j++;
|
||||
help();
|
||||
}
|
||||
|
||||
void A::foo() {
|
||||
int j = 0;
|
||||
int a = 1;
|
||||
/*$*/j++;
|
||||
a++;
|
||||
help();/*$$*/
|
||||
a++;
|
||||
j++;
|
||||
}
|
||||
|
||||
int A::help() {
|
||||
return 42;
|
||||
}
|
||||
|
||||
//=
|
||||
#include "A.h"
|
||||
|
||||
A::A() {
|
||||
}
|
||||
|
||||
A::~A() {
|
||||
int j = 0;
|
||||
i = exp(i, j);
|
||||
}
|
||||
|
||||
int A::exp(int j, int& a) {
|
||||
j++;
|
||||
a++;
|
||||
help();
|
||||
return j;
|
||||
}
|
||||
|
||||
void A::foo() {
|
||||
int j = 0;
|
||||
int a = 1;
|
||||
j = exp(j, a);
|
||||
a++;
|
||||
j++;
|
||||
}
|
||||
|
||||
int A::help() {
|
||||
return 42;
|
||||
}
|
||||
|
||||
//!Extract method duplicate with field in marked scope
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
//@.config
|
||||
replaceduplicates=true
|
||||
returnvalue=j
|
||||
//@A.h
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
class A {
|
||||
public:
|
||||
A();
|
||||
virtual ~A();
|
||||
void foo();
|
||||
int i;
|
||||
int field;
|
||||
|
||||
private:
|
||||
int help();
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
//=
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
class A {
|
||||
public:
|
||||
A();
|
||||
virtual ~A();
|
||||
void foo();
|
||||
int i;
|
||||
int field;
|
||||
|
||||
private:
|
||||
int help();
|
||||
int exp(int j);
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
//@A.cpp
|
||||
#include "A.h"
|
||||
|
||||
A::A() {
|
||||
}
|
||||
|
||||
A::~A() {
|
||||
int j = 0;
|
||||
int a = 1;
|
||||
a++;
|
||||
j++;
|
||||
help();
|
||||
}
|
||||
|
||||
void A::foo() {
|
||||
int j = 0;
|
||||
|
||||
/*$*/field++;
|
||||
j++;
|
||||
help();/*$$*/
|
||||
field++;
|
||||
j++;
|
||||
}
|
||||
|
||||
int A::help() {
|
||||
return 42;
|
||||
}
|
||||
//=
|
||||
#include "A.h"
|
||||
|
||||
A::A() {
|
||||
}
|
||||
|
||||
A::~A() {
|
||||
int j = 0;
|
||||
int a = 1;
|
||||
a++;
|
||||
j++;
|
||||
help();
|
||||
}
|
||||
|
||||
int A::exp(int j) {
|
||||
field++;
|
||||
j++;
|
||||
help();
|
||||
return j;
|
||||
}
|
||||
|
||||
void A::foo() {
|
||||
int j = 0;
|
||||
|
||||
j = exp(j);
|
||||
field++;
|
||||
j++;
|
||||
}
|
||||
|
||||
int A::help() {
|
||||
return 42;
|
||||
}
|
||||
//!Extract method duplicates with different names and return type
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
//@.config
|
||||
replaceduplicates=true
|
||||
returnvalue=i
|
||||
//@A.h
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
class A {
|
||||
public:
|
||||
A();
|
||||
virtual ~A();
|
||||
int foo();
|
||||
|
||||
private:
|
||||
int help();
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//=
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
class A {
|
||||
public:
|
||||
A();
|
||||
virtual ~A();
|
||||
int foo();
|
||||
|
||||
private:
|
||||
int help();
|
||||
int exp(int i, float& j);
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//@A.cpp
|
||||
#include "A.h"
|
||||
|
||||
A::A() {
|
||||
}
|
||||
|
||||
A::~A() {
|
||||
int oo = 99;
|
||||
float blabla = 0;
|
||||
++oo;
|
||||
blabla += 1;
|
||||
help();
|
||||
blabla += 1;
|
||||
}
|
||||
|
||||
int A::foo() {
|
||||
int i = 2;
|
||||
float j = 8989;
|
||||
/*$*/++i;
|
||||
j+=1;
|
||||
help();/*$$*/
|
||||
j++;
|
||||
return i;
|
||||
}
|
||||
|
||||
int A::help() {
|
||||
return 42;
|
||||
}
|
||||
|
||||
//=
|
||||
#include "A.h"
|
||||
|
||||
A::A() {
|
||||
}
|
||||
|
||||
A::~A() {
|
||||
int oo = 99;
|
||||
float blabla = 0;
|
||||
oo = exp(oo, blabla);
|
||||
blabla += 1;
|
||||
}
|
||||
|
||||
int A::exp(int i, float& j) {
|
||||
++i;
|
||||
j += 1;
|
||||
help();
|
||||
return i;
|
||||
}
|
||||
|
||||
int A::foo() {
|
||||
int i = 2;
|
||||
float j = 8989;
|
||||
i = exp(i, j);
|
||||
j++;
|
||||
return i;
|
||||
}
|
||||
|
||||
int A::help() {
|
||||
return 42;
|
||||
}
|
||||
|
||||
//!Extract method duplicates with a lot of different Names an variable not used afterwards in the duplicate
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
//@.config
|
||||
replaceduplicates=true
|
||||
//@A.h
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
class A {
|
||||
public:
|
||||
A();
|
||||
virtual ~A();
|
||||
int foo();
|
||||
|
||||
private:
|
||||
int help();
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//=
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
class A {
|
||||
public:
|
||||
A();
|
||||
virtual ~A();
|
||||
int foo();
|
||||
|
||||
private:
|
||||
int help();
|
||||
void exp(int& i, float j);
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//@A.cpp
|
||||
#include "A.h"
|
||||
|
||||
A::A() {
|
||||
}
|
||||
|
||||
A::~A() {
|
||||
int oo = 99;
|
||||
float blabla = 0;
|
||||
++oo;
|
||||
blabla += 1;
|
||||
help();
|
||||
}
|
||||
|
||||
int A::foo() {
|
||||
int i = 2;
|
||||
float j = 8989;
|
||||
/*$*/++i;
|
||||
j+=1;
|
||||
help();/*$$*/
|
||||
return i;
|
||||
}
|
||||
|
||||
int A::help() {
|
||||
return 42;
|
||||
}
|
||||
|
||||
//=
|
||||
#include "A.h"
|
||||
|
||||
A::A() {
|
||||
}
|
||||
|
||||
A::~A() {
|
||||
int oo = 99;
|
||||
float blabla = 0;
|
||||
exp(oo, blabla);
|
||||
}
|
||||
|
||||
void A::exp(int& i, float j) {
|
||||
++i;
|
||||
j += 1;
|
||||
help();
|
||||
}
|
||||
|
||||
int A::foo() {
|
||||
int i = 2;
|
||||
float j = 8989;
|
||||
exp(i, j);
|
||||
return i;
|
||||
}
|
||||
|
||||
int A::help() {
|
||||
return 42;
|
||||
}
|
||||
|
||||
//!Extract method with duplicate name used afterwards in duplicate but not in original selection this is no duplicate
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
//@.config
|
||||
replaceduplicates=true
|
||||
//@A.h
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
class A {
|
||||
public:
|
||||
A();
|
||||
virtual ~A();
|
||||
void foo();
|
||||
|
||||
private:
|
||||
int help();
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//=
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
class A {
|
||||
public:
|
||||
A();
|
||||
virtual ~A();
|
||||
void foo();
|
||||
|
||||
private:
|
||||
int help();
|
||||
void exp(int i);
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//@A.cpp
|
||||
#include "A.h"
|
||||
|
||||
A::A() {
|
||||
}
|
||||
|
||||
A::~A() {
|
||||
int i = 2;
|
||||
++i;// No Duplicate
|
||||
help();
|
||||
++i;// this is the reason
|
||||
}
|
||||
|
||||
void A::foo() {
|
||||
int i = 2;
|
||||
/*$*/++i;
|
||||
help();/*$$*/
|
||||
}
|
||||
|
||||
int A::help() {
|
||||
return 42;
|
||||
}
|
||||
|
||||
//=
|
||||
#include "A.h"
|
||||
|
||||
A::A() {
|
||||
}
|
||||
|
||||
A::~A() {
|
||||
int i = 2;
|
||||
++i;// No Duplicate
|
||||
help();
|
||||
++i;// this is the reason
|
||||
}
|
||||
|
||||
void A::exp(int i) {
|
||||
++i;
|
||||
help();
|
||||
}
|
||||
|
||||
void A::foo() {
|
||||
int i = 2;
|
||||
exp(i);
|
||||
}
|
||||
|
||||
int A::help() {
|
||||
return 42;
|
||||
}
|
||||
|
||||
//!Extract method with return value and a lot ref parameter and a method call
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
//@.config
|
||||
replaceduplicates=true
|
||||
returnvalue=i
|
||||
//@A.h
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
#include "B.h"
|
||||
|
||||
class A {
|
||||
public:
|
||||
A();
|
||||
virtual ~A();
|
||||
int foo();
|
||||
|
||||
private:
|
||||
int help();
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
//=
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
#include "B.h"
|
||||
|
||||
class A {
|
||||
public:
|
||||
A();
|
||||
virtual ~A();
|
||||
int foo();
|
||||
|
||||
private:
|
||||
int help();
|
||||
int exp(int i, B* b, int y, float x);
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
//@A.cpp
|
||||
#include "A.h"
|
||||
|
||||
A::A() {
|
||||
}
|
||||
|
||||
A::~A() {
|
||||
int i = 2;
|
||||
float x = i;
|
||||
B* b = new B();
|
||||
int y = x + i;
|
||||
++i;
|
||||
b->hello(y);
|
||||
i = i + x;
|
||||
help();
|
||||
b->hello(y);
|
||||
++x;
|
||||
i++;
|
||||
}
|
||||
|
||||
int A::foo() {
|
||||
int i = 2;
|
||||
float x = i;
|
||||
B* b = new B();
|
||||
int y = x + i;
|
||||
/*$*/++i;
|
||||
b->hello(y);
|
||||
i = i + x;
|
||||
help();/*$$*/
|
||||
b->hello(y);
|
||||
++x;
|
||||
return i;
|
||||
}
|
||||
|
||||
int A::help() {
|
||||
return 42;
|
||||
}
|
||||
//=
|
||||
#include "A.h"
|
||||
|
||||
A::A() {
|
||||
}
|
||||
|
||||
A::~A() {
|
||||
int i = 2;
|
||||
float x = i;
|
||||
B* b = new B();
|
||||
int y = x + i;
|
||||
i = exp(i, b, y, x);
|
||||
b->hello(y);
|
||||
++x;
|
||||
i++;
|
||||
}
|
||||
|
||||
int A::exp(int i, B* b, int y, float x) {
|
||||
++i;
|
||||
b->hello(y);
|
||||
i = i + x;
|
||||
help();
|
||||
return i;
|
||||
}
|
||||
|
||||
int A::foo() {
|
||||
int i = 2;
|
||||
float x = i;
|
||||
B* b = new B();
|
||||
int y = x + i;
|
||||
i = exp(i, b, y, x);
|
||||
b->hello(y);
|
||||
++x;
|
||||
return i;
|
||||
}
|
||||
|
||||
int A::help() {
|
||||
return 42;
|
||||
}
|
||||
//@B.h
|
||||
#ifndef B_H_
|
||||
#define B_H_
|
||||
|
||||
class B {
|
||||
public:
|
||||
B();
|
||||
virtual ~B();
|
||||
void hello(float y);
|
||||
};
|
||||
|
||||
#endif /*B_H_*/
|
||||
//!Extract method with return value and a lot ref parameter and a method call, duplicate is similar
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
//@.config
|
||||
replaceduplicates=true
|
||||
returnvalue=i
|
||||
//@A.h
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
#include "B.h"
|
||||
|
||||
class A {
|
||||
public:
|
||||
A();
|
||||
virtual ~A();
|
||||
int foo();
|
||||
|
||||
private:
|
||||
int help();
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
//=
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
#include "B.h"
|
||||
|
||||
class A {
|
||||
public:
|
||||
A();
|
||||
virtual ~A();
|
||||
int foo();
|
||||
|
||||
private:
|
||||
int help();
|
||||
int exp(int i, B* b, int y, float x);
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
//@A.cpp
|
||||
#include "A.h"
|
||||
|
||||
A::A() {
|
||||
}
|
||||
|
||||
A::~A() {
|
||||
int i = 2;
|
||||
float x = i;
|
||||
B* b = new B();
|
||||
int y = x + i;
|
||||
++i;
|
||||
b->hello(y);
|
||||
i = i + x;
|
||||
help();
|
||||
b->hello(y);
|
||||
++x;
|
||||
i++;
|
||||
}
|
||||
|
||||
int A::foo() {
|
||||
int i = 2;
|
||||
float x = i;
|
||||
B* b = new B();
|
||||
int y = x + i;
|
||||
/*$*/++i;
|
||||
b->hello(y);
|
||||
i = i + x;
|
||||
help();/*$$*/
|
||||
b->hello(y);
|
||||
return i;
|
||||
}
|
||||
|
||||
int A::help() {
|
||||
return 42;
|
||||
}
|
||||
//=
|
||||
#include "A.h"
|
||||
|
||||
A::A() {
|
||||
}
|
||||
|
||||
A::~A() {
|
||||
int i = 2;
|
||||
float x = i;
|
||||
B* b = new B();
|
||||
int y = x + i;
|
||||
i = exp(i, b, y, x);
|
||||
b->hello(y);
|
||||
++x;
|
||||
i++;
|
||||
}
|
||||
|
||||
int A::exp(int i, B* b, int y, float x) {
|
||||
++i;
|
||||
b->hello(y);
|
||||
i = i + x;
|
||||
help();
|
||||
return i;
|
||||
}
|
||||
|
||||
int A::foo() {
|
||||
int i = 2;
|
||||
float x = i;
|
||||
B* b = new B();
|
||||
int y = x + i;
|
||||
i = exp(i, b, y, x);
|
||||
b->hello(y);
|
||||
return i;
|
||||
}
|
||||
|
||||
int A::help() {
|
||||
return 42;
|
||||
}
|
||||
//@B.h
|
||||
#ifndef B_H_
|
||||
#define B_H_
|
||||
|
||||
class B {
|
||||
public:
|
||||
B();
|
||||
virtual ~B();
|
||||
void hello(float y);
|
||||
};
|
||||
|
||||
#endif /*B_H_*/
|
||||
//!Extract method with duplicates and comments
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
//@.config
|
||||
replaceduplicates=true
|
||||
//@A.h
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
class A {
|
||||
public:
|
||||
A();
|
||||
virtual ~A();
|
||||
int foo();
|
||||
|
||||
private:
|
||||
int help();
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//=
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
class A {
|
||||
public:
|
||||
A();
|
||||
virtual ~A();
|
||||
int foo();
|
||||
|
||||
private:
|
||||
int help();
|
||||
void exp(int& i);
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//@A.cpp
|
||||
#include "A.h"
|
||||
|
||||
A::A() {
|
||||
}
|
||||
|
||||
A::~A() {
|
||||
int i = 2;
|
||||
++i;
|
||||
help();
|
||||
}
|
||||
|
||||
int A::foo() {
|
||||
int i = 2;
|
||||
/*$*/++i;
|
||||
help();/*$$*/
|
||||
return i;
|
||||
}
|
||||
|
||||
int A::help() {
|
||||
return 42;
|
||||
}
|
||||
|
||||
//=
|
||||
#include "A.h"
|
||||
|
||||
A::A() {
|
||||
}
|
||||
|
||||
A::~A() {
|
||||
int i = 2;
|
||||
exp(i);
|
||||
}
|
||||
|
||||
void A::exp(int& i) {
|
||||
++i;
|
||||
help();
|
||||
}
|
||||
|
||||
int A::foo() {
|
||||
int i = 2;
|
||||
exp(i);
|
||||
return i;
|
||||
}
|
||||
|
||||
int A::help() {
|
||||
return 42;
|
||||
}
|
||||
|
|
@ -1,333 +0,0 @@
|
|||
//!ExtractFunctionHistoryRefactoringTest variable defined in scope
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.RefactoringHistoryTest
|
||||
//@A.h
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
class A {
|
||||
public:
|
||||
A();
|
||||
virtual ~A();
|
||||
int foo();
|
||||
|
||||
private:
|
||||
int help();
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//=
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
class A {
|
||||
public:
|
||||
A();
|
||||
virtual ~A();
|
||||
int foo();
|
||||
|
||||
private:
|
||||
int help();
|
||||
int exp();
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//@A.cpp
|
||||
#include "A.h"
|
||||
|
||||
A::A() {
|
||||
}
|
||||
|
||||
A::~A() {
|
||||
}
|
||||
|
||||
int A::foo() {
|
||||
int i = 2;
|
||||
++i;
|
||||
help();
|
||||
return i;
|
||||
}
|
||||
|
||||
int A::help() {
|
||||
return 42;
|
||||
}
|
||||
|
||||
//=
|
||||
#include "A.h"
|
||||
|
||||
A::A() {
|
||||
}
|
||||
|
||||
A::~A() {
|
||||
}
|
||||
|
||||
int A::exp() {
|
||||
int i = 2;
|
||||
++i;
|
||||
help();
|
||||
return i;
|
||||
}
|
||||
|
||||
int A::foo() {
|
||||
int i = exp();
|
||||
return i;
|
||||
}
|
||||
|
||||
int A::help() {
|
||||
return 42;
|
||||
}
|
||||
|
||||
//@refScript.xml
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<session version="1.0">
|
||||
<refactoring comment="Create method exp" description="Extract Method Refactoring"
|
||||
fileName="file:$$projectPath$$/A.cpp"
|
||||
flags="4" id="org.eclipse.cdt.internal.ui.refactoring.extractfunction.ExtractFunctionRefactoring"
|
||||
name="exp" project="RegressionTestProject" selection="57,25" visibility="private"/>
|
||||
</session>
|
||||
|
||||
|
||||
//!ExtractFunctionHistoryRefactoringTest
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.RefactoringHistoryTest
|
||||
//@A.h
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
class A {
|
||||
public:
|
||||
A();
|
||||
virtual ~A();
|
||||
int foo();
|
||||
|
||||
private:
|
||||
int help();
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//=
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
class A {
|
||||
public:
|
||||
A();
|
||||
virtual ~A();
|
||||
int foo();
|
||||
|
||||
private:
|
||||
int help();
|
||||
void exp(int& i);
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//@A.cpp
|
||||
#include "A.h"
|
||||
|
||||
A::A() {
|
||||
}
|
||||
|
||||
A::~A() {
|
||||
}
|
||||
|
||||
int A::foo() {
|
||||
int i = 2;
|
||||
//comment
|
||||
++i;
|
||||
help();
|
||||
return i;
|
||||
}
|
||||
|
||||
int A::help() {
|
||||
return 42;
|
||||
}
|
||||
|
||||
//=
|
||||
#include "A.h"
|
||||
|
||||
A::A() {
|
||||
}
|
||||
|
||||
A::~A() {
|
||||
}
|
||||
|
||||
void A::exp(int& i) {
|
||||
//comment
|
||||
++i;
|
||||
help();
|
||||
}
|
||||
|
||||
int A::foo() {
|
||||
int i = 2;
|
||||
//comment
|
||||
exp(i);
|
||||
return i;
|
||||
}
|
||||
|
||||
int A::help() {
|
||||
return 42;
|
||||
}
|
||||
|
||||
//@refScript.xml
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<session version="1.0">
|
||||
<refactoring comment="Create method exp" description="Extract Method Refactoring"
|
||||
fileName="file:$$projectPath$$/A.cpp"
|
||||
flags="4" id="org.eclipse.cdt.internal.ui.refactoring.extractfunction.ExtractFunctionRefactoring"
|
||||
name="exp" project="RegressionTestProject" selection="69,24" visibility="private"/>
|
||||
</session>
|
||||
|
||||
//!Extract Function History first extracted statement with leading comment
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.RefactoringHistoryTest
|
||||
//@main.cpp
|
||||
int main() {
|
||||
int i;
|
||||
// Comment
|
||||
i = 7;
|
||||
return i;
|
||||
}
|
||||
|
||||
//=
|
||||
void exp(int& i) {
|
||||
// Comment
|
||||
i = 7;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int i;
|
||||
// Comment
|
||||
exp(i);
|
||||
return i;
|
||||
}
|
||||
|
||||
//@refScript.xml
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<session version="1.0">
|
||||
<refactoring comment="Create method exp" description="Extract Method Refactoring"
|
||||
fileName="file:$$projectPath$$/main.cpp"
|
||||
flags="4" id="org.eclipse.cdt.internal.ui.refactoring.extractfunction.ExtractFunctionRefactoring"
|
||||
name="exp" project="RegressionTestProject" selection="34,6" visibility="private"/>
|
||||
</session>
|
||||
|
||||
//!Extract Function History extracted statement with trailing comment
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.RefactoringHistoryTest
|
||||
//@main.cpp
|
||||
int main() {
|
||||
int i;
|
||||
i = 7; // Comment
|
||||
return i;
|
||||
}
|
||||
|
||||
//=
|
||||
void exp(int& i) {
|
||||
i = 7; // Comment
|
||||
}
|
||||
|
||||
int main() {
|
||||
int i;
|
||||
exp(i);
|
||||
return i;
|
||||
}
|
||||
|
||||
//@refScript.xml
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<session version="1.0">
|
||||
<refactoring comment="Create method exp" description="Extract Method Refactoring"
|
||||
fileName="file:$$projectPath$$/main.cpp"
|
||||
flags="4" id="org.eclipse.cdt.internal.ui.refactoring.extractfunction.ExtractFunctionRefactoring"
|
||||
name="exp" project="RegressionTestProject" selection="22,6" visibility="private"/>
|
||||
</session>
|
||||
|
||||
//!ExtractFunctionRefactoringTest duplicates with different Names History Test
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.RefactoringHistoryTest
|
||||
//@A.h
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
class A {
|
||||
public:
|
||||
A();
|
||||
virtual ~A();
|
||||
int foo();
|
||||
|
||||
private:
|
||||
int help();
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//=
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
class A {
|
||||
public:
|
||||
A();
|
||||
virtual ~A();
|
||||
int foo();
|
||||
|
||||
private:
|
||||
int help();
|
||||
void exp(int& i);
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//@A.cpp
|
||||
#include "A.h"
|
||||
|
||||
A::A() {
|
||||
}
|
||||
|
||||
A::~A() {
|
||||
int oo = 99;
|
||||
++oo;
|
||||
help();
|
||||
}
|
||||
|
||||
int A::foo() {
|
||||
int i = 2;
|
||||
++i;
|
||||
help();
|
||||
return i;
|
||||
}
|
||||
|
||||
int A::help() {
|
||||
return 42;
|
||||
}
|
||||
|
||||
//=
|
||||
#include "A.h"
|
||||
|
||||
A::A() {
|
||||
}
|
||||
|
||||
A::~A() {
|
||||
int oo = 99;
|
||||
exp(oo);
|
||||
}
|
||||
|
||||
void A::exp(int& i) {
|
||||
++i;
|
||||
help();
|
||||
}
|
||||
|
||||
int A::foo() {
|
||||
int i = 2;
|
||||
exp(i);
|
||||
return i;
|
||||
}
|
||||
|
||||
int A::help() {
|
||||
return 42;
|
||||
}
|
||||
|
||||
//@refScript.xml
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<session version="1.0">
|
||||
<refactoring comment="Create method exp" description="Extract Method Refactoring"
|
||||
fileName="file:$$projectPath$$/A.cpp" flags="4" id="org.eclipse.cdt.internal.ui.refactoring.extractfunction.ExtractFunctionRefactoring"
|
||||
name="exp" project="RegressionTestProject" replaceDuplicates="true" selection="99,13" visibility="private"/>
|
||||
</session>
|
|
@ -1,262 +0,0 @@
|
|||
//!ExtractFunctionRefactoringTest with FunctionStyleMacro2
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
//@A.h
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
class A {
|
||||
public:
|
||||
A();
|
||||
virtual ~A();
|
||||
int foo();
|
||||
|
||||
private:
|
||||
int help();
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//=
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
class A {
|
||||
public:
|
||||
A();
|
||||
virtual ~A();
|
||||
int foo();
|
||||
|
||||
private:
|
||||
int help();
|
||||
void exp(int& ii);
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//@A.cpp
|
||||
#include "A.h"
|
||||
|
||||
#define ADD(a,ab) a + ab + 2 + a
|
||||
|
||||
A::A() {
|
||||
}
|
||||
|
||||
A::~A() {
|
||||
}
|
||||
|
||||
int A::foo() {
|
||||
int ii = 2;
|
||||
/*$*/++ii;
|
||||
ii = ADD(ii, 42);
|
||||
help();/*$$*/
|
||||
return ii;
|
||||
}
|
||||
|
||||
int A::help() {
|
||||
return 42;
|
||||
}
|
||||
|
||||
//=
|
||||
#include "A.h"
|
||||
|
||||
#define ADD(a,ab) a + ab + 2 + a
|
||||
|
||||
A::A() {
|
||||
}
|
||||
|
||||
A::~A() {
|
||||
}
|
||||
|
||||
void A::exp(int& ii) {
|
||||
++ii;
|
||||
ii = ADD(ii, 42);
|
||||
help();
|
||||
}
|
||||
|
||||
int A::foo() {
|
||||
int ii = 2;
|
||||
exp(ii);
|
||||
return ii;
|
||||
}
|
||||
|
||||
int A::help() {
|
||||
return 42;
|
||||
}
|
||||
|
||||
//!Extract method return value assigned to macro call
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
//@.config
|
||||
returnvalue=b
|
||||
//@A.h
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
class A {
|
||||
public:
|
||||
A();
|
||||
virtual ~A();
|
||||
int foo();
|
||||
|
||||
private:
|
||||
int help();
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
//=
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
class A {
|
||||
public:
|
||||
A();
|
||||
virtual ~A();
|
||||
int foo();
|
||||
|
||||
private:
|
||||
int help();
|
||||
int exp(int& i, int b);
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
//@A.cpp
|
||||
#include "A.h"
|
||||
|
||||
#define ADD(b) b = b + 2
|
||||
|
||||
A::A() {
|
||||
}
|
||||
|
||||
A::~A() {
|
||||
}
|
||||
|
||||
int A::foo() {
|
||||
int i = 2;
|
||||
int b = 42;
|
||||
/*$*/++i;
|
||||
help();
|
||||
ADD(b);/*$$*/
|
||||
b += 2;
|
||||
return i;
|
||||
}
|
||||
|
||||
int A::help() {
|
||||
return 42;
|
||||
}
|
||||
//=
|
||||
#include "A.h"
|
||||
|
||||
#define ADD(b) b = b + 2
|
||||
|
||||
A::A() {
|
||||
}
|
||||
|
||||
A::~A() {
|
||||
}
|
||||
|
||||
int A::exp(int& i, int b) {
|
||||
++i;
|
||||
help();
|
||||
ADD(b);
|
||||
return b;
|
||||
}
|
||||
|
||||
int A::foo() {
|
||||
int i = 2;
|
||||
int b = 42;
|
||||
b = exp(i, b);
|
||||
b += 2;
|
||||
return i;
|
||||
}
|
||||
|
||||
int A::help() {
|
||||
return 42;
|
||||
}
|
||||
//!Extract method with multiple macros
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
//@.config
|
||||
returnvalue=bb
|
||||
replaceduplicates=true
|
||||
//@A.h
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
class A {
|
||||
public:
|
||||
A();
|
||||
virtual ~A();
|
||||
int foo();
|
||||
|
||||
private:
|
||||
int help();
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
//=
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
class A {
|
||||
public:
|
||||
A();
|
||||
virtual ~A();
|
||||
int foo();
|
||||
|
||||
private:
|
||||
int help();
|
||||
int exp(int bb);
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
//@A.cpp
|
||||
#include "A.h"
|
||||
|
||||
#define ADD(b) b = b + 2
|
||||
|
||||
A::A() {
|
||||
}
|
||||
|
||||
A::~A() {
|
||||
}
|
||||
|
||||
int A::foo() {
|
||||
int i = 2;
|
||||
int bb = 42;
|
||||
++i;
|
||||
/*$*/ADD(bb);
|
||||
ADD(bb);/*$$*/
|
||||
bb += 2;
|
||||
return i;
|
||||
}
|
||||
|
||||
int A::help() {
|
||||
return 42;
|
||||
}
|
||||
//=
|
||||
#include "A.h"
|
||||
|
||||
#define ADD(b) b = b + 2
|
||||
|
||||
A::A() {
|
||||
}
|
||||
|
||||
A::~A() {
|
||||
}
|
||||
|
||||
int A::exp(int bb) {
|
||||
ADD(bb);
|
||||
ADD(bb);
|
||||
return bb;
|
||||
}
|
||||
|
||||
int A::foo() {
|
||||
int i = 2;
|
||||
int bb = 42;
|
||||
++i;
|
||||
bb = exp(bb);
|
||||
bb += 2;
|
||||
return i;
|
||||
}
|
||||
|
||||
int A::help() {
|
||||
return 42;
|
||||
}
|
|
@ -27,6 +27,8 @@ import org.eclipse.jface.text.TextSelection;
|
|||
import org.eclipse.cdt.core.tests.BaseTestFramework;
|
||||
|
||||
/**
|
||||
* Don't create new tests based on this class. Use RefactoringTestBase instead.
|
||||
*
|
||||
* @author Guido Zgraggen IFS
|
||||
*/
|
||||
public abstract class RefactoringBaseTest extends BaseTestFramework implements ILogListener {
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software (IFS)- initial API and implementation
|
||||
* Institute for Software (IFS)- initial API and implementation
|
||||
* Sergey Prigogin (Google)
|
||||
******************************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.refactoring;
|
||||
|
||||
|
@ -18,18 +19,18 @@ import java.util.Properties;
|
|||
|
||||
import org.eclipse.core.filesystem.URIUtil;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.ltk.core.refactoring.Change;
|
||||
import org.eclipse.ltk.core.refactoring.Refactoring;
|
||||
import org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy;
|
||||
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
||||
import org.eclipse.ltk.core.refactoring.history.RefactoringHistory;
|
||||
import org.eclipse.ltk.internal.core.refactoring.history.RefactoringHistoryService;
|
||||
|
||||
import org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest;
|
||||
|
||||
/**
|
||||
* @author Emanuel Graf IFS
|
||||
*/
|
||||
public class RefactoringHistoryTest extends ExtractFunctionRefactoringTest {
|
||||
public class RefactoringHistoryTest extends RefactoringTest {
|
||||
private TestSourceFile scriptFile;
|
||||
|
||||
public RefactoringHistoryTest(String name, Collection<TestSourceFile> files) {
|
||||
|
@ -64,4 +65,12 @@ public class RefactoringHistoryTest extends ExtractFunctionRefactoringTest {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void executeRefactoring(Refactoring refactoring) throws Exception {
|
||||
RefactoringStatus finalConditions = refactoring.checkFinalConditions(NULL_PROGRESS_MONITOR);
|
||||
assertConditionsOk(finalConditions);
|
||||
Change createChange = refactoring.createChange(NULL_PROGRESS_MONITOR);
|
||||
createChange.perform(NULL_PROGRESS_MONITOR);
|
||||
compareFiles(fileMap);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ public abstract class RefactoringTest extends RefactoringBaseTest {
|
|||
|
||||
protected String fileName;
|
||||
protected RefactoringASTCache astCache;
|
||||
protected boolean fatalError;
|
||||
|
||||
public RefactoringTest(String name, Collection<TestSourceFile> files) {
|
||||
super(name, files);
|
||||
|
|
|
@ -0,0 +1,316 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 Google, Inc and others.
|
||||
* 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:
|
||||
* Sergey Prigogin (Google) - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.refactoring;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.StringReader;
|
||||
import java.net.URI;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.core.filesystem.URIUtil;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.jface.text.TextSelection;
|
||||
import org.eclipse.ltk.core.refactoring.Change;
|
||||
import org.eclipse.ltk.core.refactoring.Refactoring;
|
||||
import org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy;
|
||||
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
||||
import org.eclipse.ltk.core.refactoring.RefactoringStatusEntry;
|
||||
import org.eclipse.ltk.core.refactoring.history.RefactoringHistory;
|
||||
import org.eclipse.ltk.internal.core.refactoring.history.RefactoringHistoryService;
|
||||
import org.osgi.framework.Bundle;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.IPDOMManager;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
||||
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
|
||||
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
|
||||
import org.eclipse.cdt.ui.testplugin.CTestPlugin;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.refactoring.RefactoringASTCache;
|
||||
|
||||
/**
|
||||
* Common base for refactoring tests.
|
||||
*/
|
||||
public abstract class RefactoringTestBase extends BaseTestCase {
|
||||
private static final int INDEXER_TIMEOUT_SEC = 360;
|
||||
protected static final NullProgressMonitor NULL_PROGRESS_MONITOR = new NullProgressMonitor();
|
||||
|
||||
private boolean cpp = true;
|
||||
private RefactoringASTCache astCache;
|
||||
private ICProject cproject;
|
||||
private final Set<TestSourceFile> testFiles = new LinkedHashSet<TestSourceFile>();
|
||||
private TestSourceFile selectedFile;
|
||||
private TextSelection selection;
|
||||
private TestSourceFile historyScript;
|
||||
|
||||
protected RefactoringTestBase() {
|
||||
super();
|
||||
}
|
||||
|
||||
protected RefactoringTestBase(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
cproject = cpp ?
|
||||
CProjectHelper.createCCProject(getName() + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER) :
|
||||
CProjectHelper.createCProject(getName() + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER);
|
||||
Bundle bundle = CTestPlugin.getDefault().getBundle();
|
||||
CharSequence[] testData = TestSourceReader.getContentsForTest(bundle, "ui", getClass(), getName(), 0);
|
||||
|
||||
for (int i = 0; i < testData.length; i++) {
|
||||
CharSequence contents = testData[i];
|
||||
TestSourceFile testFile = null;
|
||||
boolean expectedResult = false;
|
||||
BufferedReader reader = new BufferedReader(new StringReader(contents.toString()));
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (testFile == null) {
|
||||
testFile = new TestSourceFile(line.trim());
|
||||
} else if (isResultDelimiter(line.trim())) {
|
||||
expectedResult = true;
|
||||
} else if (expectedResult) {
|
||||
testFile.addLineToExpectedSource(line);
|
||||
} else {
|
||||
testFile.addLineToSource(line);
|
||||
}
|
||||
}
|
||||
reader.close();
|
||||
|
||||
TestSourceReader.createFile(cproject.getProject(), new Path(testFile.getName()),
|
||||
testFile.getSource());
|
||||
testFiles.add(testFile);
|
||||
if (testFile.getName().endsWith(".xml")) {
|
||||
historyScript = testFile;
|
||||
} else if (selection == null) {
|
||||
selection = testFile.getSelection();
|
||||
if (selection != null)
|
||||
selectedFile = testFile;
|
||||
}
|
||||
}
|
||||
CCorePlugin.getIndexManager().setIndexerId(cproject, IPDOMManager.ID_FAST_INDEXER);
|
||||
assertTrue(CCorePlugin.getIndexManager().joinIndexer(INDEXER_TIMEOUT_SEC * 1000,
|
||||
NULL_PROGRESS_MONITOR));
|
||||
astCache = new RefactoringASTCache();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tearDown() throws Exception {
|
||||
astCache.dispose();
|
||||
if (cproject != null) {
|
||||
cproject.getProject().delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT,
|
||||
NULL_PROGRESS_MONITOR);
|
||||
}
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
protected void assertRefactoringSuccess() throws Exception {
|
||||
executeRefactoring(true);
|
||||
compareFiles();
|
||||
}
|
||||
|
||||
protected void assertRefactoringFailure() throws Exception {
|
||||
executeRefactoring(false);
|
||||
}
|
||||
|
||||
private void executeRefactoring(boolean expectedSuccess) throws Exception {
|
||||
if (historyScript != null) {
|
||||
executeHistoryRefactoring(expectedSuccess);
|
||||
return;
|
||||
}
|
||||
|
||||
Refactoring refactoring = createRefactoring();
|
||||
executeRefactoring(refactoring, true, expectedSuccess);
|
||||
}
|
||||
|
||||
protected void executeRefactoring(Refactoring refactoring, boolean withUserInput,
|
||||
boolean expectedSuccess) throws CoreException, Exception {
|
||||
RefactoringStatus initialStatus = refactoring.checkInitialConditions(NULL_PROGRESS_MONITOR);
|
||||
if (!expectedSuccess) {
|
||||
assertStatusFatalError(initialStatus);
|
||||
return;
|
||||
}
|
||||
|
||||
assertStatusOk(initialStatus);
|
||||
if (withUserInput)
|
||||
simulateUserInput();
|
||||
RefactoringStatus finalStatus = refactoring.checkFinalConditions(NULL_PROGRESS_MONITOR);
|
||||
assertStatusOk(finalStatus);
|
||||
Change change = refactoring.createChange(NULL_PROGRESS_MONITOR);
|
||||
change.perform(NULL_PROGRESS_MONITOR);
|
||||
}
|
||||
|
||||
private void executeHistoryRefactoring(boolean expectedSuccess) throws Exception {
|
||||
URI uri= URIUtil.toURI(cproject.getProject().getLocation());
|
||||
String scriptSource = historyScript.getSource().replaceAll("\\$\\{projectPath\\}", uri.getPath());
|
||||
RefactoringHistory history = RefactoringHistoryService.getInstance().readRefactoringHistory(
|
||||
new ByteArrayInputStream(scriptSource.getBytes()), 0);
|
||||
for (RefactoringDescriptorProxy proxy : history.getDescriptors()) {
|
||||
RefactoringStatus status = new RefactoringStatus();
|
||||
Refactoring refactoring =
|
||||
proxy.requestDescriptor(NULL_PROGRESS_MONITOR).createRefactoring(status);
|
||||
assertTrue(status.isOK());
|
||||
executeRefactoring(refactoring, false, expectedSuccess);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a refactoring object.
|
||||
*/
|
||||
protected abstract Refactoring createRefactoring();
|
||||
|
||||
/**
|
||||
* Subclasses can override to simulate user input.
|
||||
*/
|
||||
protected void simulateUserInput() {
|
||||
}
|
||||
|
||||
protected ICProject getCProject() {
|
||||
return cproject;
|
||||
}
|
||||
|
||||
protected TestSourceFile getSelectedTestFile() {
|
||||
return selectedFile;
|
||||
}
|
||||
|
||||
protected IFile getSelectedFile() {
|
||||
if (selectedFile == null)
|
||||
return null;
|
||||
return cproject.getProject().getFile(new Path(selectedFile.getName()));
|
||||
}
|
||||
|
||||
protected TestSourceFile getHistoryScriptFile() {
|
||||
return historyScript;
|
||||
}
|
||||
|
||||
protected TextSelection getSelection() {
|
||||
return selection;
|
||||
}
|
||||
|
||||
protected boolean isCpp() {
|
||||
return cpp;
|
||||
}
|
||||
|
||||
protected void setCpp(boolean cpp) {
|
||||
this.cpp = cpp;
|
||||
}
|
||||
|
||||
private boolean isResultDelimiter(String str) {
|
||||
if (str.isEmpty())
|
||||
return false;
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
if (str.charAt(i) != '=')
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void assertStatusOk(RefactoringStatus status) {
|
||||
if (!status.isOK())
|
||||
fail("Error or warning status: " + status.getEntries()[0].getMessage());
|
||||
}
|
||||
|
||||
protected void assertStatusWarning(RefactoringStatus status, int number) {
|
||||
if (number > 0) {
|
||||
assertTrue("Warning status expected", status.hasWarning());
|
||||
}
|
||||
RefactoringStatusEntry[] entries = status.getEntries();
|
||||
int count = 0;
|
||||
for (RefactoringStatusEntry entry : entries) {
|
||||
if (entry.isWarning()) {
|
||||
++count;
|
||||
}
|
||||
}
|
||||
assertEquals("Found " + count + " warnings instead of expected " + number, number, count);
|
||||
}
|
||||
|
||||
protected void assertStatusInfo(RefactoringStatus status, int number) {
|
||||
if (number > 0) {
|
||||
assertTrue("Info status expected", status.hasInfo());
|
||||
}
|
||||
RefactoringStatusEntry[] entries = status.getEntries();
|
||||
int count = 0;
|
||||
for (RefactoringStatusEntry entry : entries) {
|
||||
if (entry.isInfo()) {
|
||||
++count;
|
||||
}
|
||||
}
|
||||
assertEquals("Found " + count + " informational messages instead of expected " + number, number, count);
|
||||
}
|
||||
|
||||
protected void assertStatusError(RefactoringStatus status, int number) {
|
||||
if (number > 0) {
|
||||
assertTrue("Error status expected", status.hasError());
|
||||
}
|
||||
RefactoringStatusEntry[] entries = status.getEntries();
|
||||
int count = 0;
|
||||
for (RefactoringStatusEntry entry : entries) {
|
||||
if (entry.isError()) {
|
||||
++count;
|
||||
}
|
||||
}
|
||||
assertEquals("Found " + count + " errors instead of expected " + number, number, count);
|
||||
}
|
||||
|
||||
protected void assertStatusFatalError(RefactoringStatus status, int number) {
|
||||
if (number > 0) {
|
||||
assertTrue("Fatal error status expected", status.hasFatalError());
|
||||
}
|
||||
RefactoringStatusEntry[] entries = status.getEntries();
|
||||
int count = 0;
|
||||
for (RefactoringStatusEntry entry : entries) {
|
||||
if (entry.isFatalError()) {
|
||||
++count;
|
||||
}
|
||||
}
|
||||
assertEquals("Found " + count + " fatal errors instead of expected " + number, number, count);
|
||||
}
|
||||
|
||||
protected void assertStatusFatalError(RefactoringStatus status) {
|
||||
assertTrue("Fatal error status expected", status.hasFatalError());
|
||||
}
|
||||
|
||||
protected void assertEquals(TestSourceFile testFile, IFile file) throws Exception {
|
||||
String actualSource = getFileContents(file);
|
||||
assertEquals(testFile.getExpectedSource(), actualSource);
|
||||
}
|
||||
|
||||
protected void compareFiles() throws Exception {
|
||||
for (TestSourceFile testFile : testFiles) {
|
||||
String expectedSource = testFile.getExpectedSource();
|
||||
IFile file = cproject.getProject().getFile(new Path(testFile.getName()));
|
||||
String actualSource = getFileContents(file);
|
||||
assertEquals(expectedSource, actualSource);
|
||||
}
|
||||
}
|
||||
|
||||
protected String getFileContents(IFile file) throws Exception {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(file.getContents()));
|
||||
StringBuilder code = new StringBuilder();
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
code.append(line);
|
||||
code.append('\n');
|
||||
}
|
||||
reader.close();
|
||||
return code.toString();
|
||||
}
|
||||
}
|
|
@ -9,6 +9,7 @@
|
|||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
* Tom Ball (Google)
|
||||
* Sergey Prigogin (Google)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.refactoring;
|
||||
|
||||
|
@ -16,7 +17,7 @@ import junit.framework.Test;
|
|||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.ui.tests.refactoring.extractconstant.ExtractConstantTestSuite;
|
||||
import org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionTestSuite;
|
||||
import org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest;
|
||||
import org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableTestSuite;
|
||||
import org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTestSuite;
|
||||
import org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodTestSuite;
|
||||
|
@ -34,7 +35,7 @@ public class RefactoringTestSuite extends TestSuite {
|
|||
TestSuite suite = new RefactoringTestSuite();
|
||||
suite.addTest(UtilTestSuite.suite());
|
||||
suite.addTest(RenameRegressionTests.suite());
|
||||
suite.addTest(ExtractFunctionTestSuite.suite());
|
||||
suite.addTest(ExtractFunctionRefactoringTest.suite());
|
||||
suite.addTest(ExtractConstantTestSuite.suite());
|
||||
suite.addTest(HideMethodTestSuite.suite());
|
||||
suite.addTest(GenerateGettersAndSettersTestSuite.suite());
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.refactoring;
|
||||
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
* Institute for Software - initial API and implementation
|
||||
* Sergey Prigogin (Google)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.refactoring;
|
||||
|
||||
|
@ -18,71 +19,77 @@ import org.eclipse.jface.text.TextSelection;
|
|||
|
||||
/**
|
||||
* @author Emanuel Graf
|
||||
*
|
||||
*/
|
||||
public class TestSourceFile {
|
||||
private static final String EMPTY_STRING = ""; //$NON-NLS-1$
|
||||
private static final String LINE_SEPARATOR = "\n"; //$NON-NLS-1$
|
||||
private static final Pattern SELECTION_START = Pattern.compile("/\\*\\$\\*/"); //$NON-NLS-1$
|
||||
private static final Pattern SELECTION_END = Pattern.compile("/\\*\\$\\$\\*/"); //$NON-NLS-1$
|
||||
|
||||
private static final String REPLACEMENT = ""; //$NON-NLS-1$
|
||||
private String name;
|
||||
private StringBuffer source = new StringBuffer();
|
||||
private StringBuffer expectedSource = new StringBuffer();
|
||||
private String separator = "\n"; //$NON-NLS-1$
|
||||
private final String name;
|
||||
private final StringBuilder source = new StringBuilder();
|
||||
private final StringBuilder expectedSource = new StringBuilder();
|
||||
private int selectionStart = -1;
|
||||
private int selectionEnd = -1;
|
||||
|
||||
protected static final String selectionStartRegex = "/\\*\\$\\*/"; //$NON-NLS-1$
|
||||
protected static final String selectionEndRegex = "/\\*\\$\\$\\*/"; //$NON-NLS-1$
|
||||
protected static final String selectionStartLineRegex = "(.*)(" + selectionStartRegex + ")(.*)"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
protected static final String selectionEndLineRegex = "(.*)("+ selectionEndRegex + ")(.*)"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
public TestSourceFile(String name) {
|
||||
super();
|
||||
this.name = name;
|
||||
}
|
||||
public String getExpectedSource() {
|
||||
String exp = expectedSource.toString();
|
||||
if(exp.length() == 0) {
|
||||
return getSource();
|
||||
}else {
|
||||
return exp;
|
||||
}
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getSource() {
|
||||
return source.toString();
|
||||
}
|
||||
|
||||
public void addLineToSource(String code) {
|
||||
Matcher start = createMatcherFromString(selectionStartLineRegex, code);
|
||||
if(start.matches()) {
|
||||
selectionStart = start.start(2) + source.length();
|
||||
code = code.replaceAll(selectionStartRegex, REPLACEMENT);
|
||||
public String getExpectedSource() {
|
||||
if (expectedSource.length() == 0) {
|
||||
return getSource();
|
||||
}
|
||||
Matcher end = createMatcherFromString(selectionEndLineRegex, code);
|
||||
if(end.matches()) {
|
||||
selectionEnd = end.start(2) + source.length();
|
||||
code = code.replaceAll(selectionEndRegex, REPLACEMENT);
|
||||
return expectedSource.toString();
|
||||
}
|
||||
|
||||
public void addLineToSource(String code) {
|
||||
Matcher start = SELECTION_START.matcher(code);
|
||||
if (start.find()) {
|
||||
selectionStart = start.start() + source.length();
|
||||
code = start.replaceAll(EMPTY_STRING);
|
||||
}
|
||||
Matcher end = SELECTION_END.matcher(code);
|
||||
if (end.find()) {
|
||||
selectionEnd = end.start() + source.length();
|
||||
code = end.replaceAll(EMPTY_STRING);
|
||||
}
|
||||
source.append(code);
|
||||
source.append(separator);
|
||||
source.append(LINE_SEPARATOR);
|
||||
}
|
||||
|
||||
public void addLineToExpectedSource(String code) {
|
||||
expectedSource.append(code);
|
||||
expectedSource.append(separator);
|
||||
expectedSource.append(LINE_SEPARATOR);
|
||||
}
|
||||
|
||||
public TextSelection getSelection() {
|
||||
if(selectionStart < 0 || selectionEnd <0 ) {
|
||||
if (selectionStart < 0 || selectionEnd < selectionStart)
|
||||
return null;
|
||||
}else {
|
||||
return new TextSelection(selectionStart, selectionEnd -selectionStart);
|
||||
}
|
||||
return new TextSelection(selectionStart, selectionEnd - selectionStart);
|
||||
}
|
||||
|
||||
protected static Matcher createMatcherFromString(String pattern, String line) {
|
||||
return Pattern.compile(pattern).matcher(line);
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return name.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null || getClass() != obj.getClass())
|
||||
return false;
|
||||
TestSourceFile other = (TestSourceFile) obj;
|
||||
return name.equals(other.name);
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,35 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008, 2009 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* 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:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.refactoring.extractfunction;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.ui.tests.refactoring.RefactoringTester;
|
||||
|
||||
/**
|
||||
* @author Emanuel Graf
|
||||
*/
|
||||
public class ExtractFunctionTestSuite extends TestSuite {
|
||||
|
||||
@SuppressWarnings("nls")
|
||||
public static Test suite() throws Exception {
|
||||
TestSuite suite = new ExtractFunctionTestSuite();
|
||||
suite.addTest(RefactoringTester.suite("ExtractMethod.rts", "resources/refactoring/ExtractMethod.rts"));
|
||||
suite.addTest(RefactoringTester.suite("ExtractExpression.rts", "resources/refactoring/ExtractExpression.rts"));
|
||||
suite.addTest(RefactoringTester.suite("ExtractMethodPreprocessor.rts", "resources/refactoring/ExtractMethodPreprocessor.rts"));
|
||||
suite.addTest(RefactoringTester.suite("ExtractFunctionTemplates.rts", "resources/refactoring/ExtractFunctionTemplates.rts"));
|
||||
suite.addTest(RefactoringTester.suite("ExtractMethodHistory.rts", "resources/refactoring/ExtractMethodHistory.rts"));
|
||||
suite.addTest(RefactoringTester.suite("ExtractFunctionDuplicates.rts", "resources/refactoring/ExtractMethodDuplicates.rts"));
|
||||
return suite;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue