diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexNamesTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexNamesTests.java index 2b690924beb..ca8e197a13c 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexNamesTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexNamesTests.java @@ -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 { diff --git a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/CTestPlugin.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/CTestPlugin.java index 4a89ca2e2f7..b4824233953 100644 --- a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/CTestPlugin.java +++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/CTestPlugin.java @@ -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; } } - - - } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/TestSourceReader.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/TestSourceReader.java index 2869a337ba4..c43165b2a58 100644 --- a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/TestSourceReader.java +++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/TestSourceReader.java @@ -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. diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractExpression.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractExpression.rts deleted file mode 100644 index 1f6f14fa15e..00000000000 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractExpression.rts +++ /dev/null @@ -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; -} diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractFunctionTemplates.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractFunctionTemplates.rts deleted file mode 100644 index b84828e254d..00000000000 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractFunctionTemplates.rts +++ /dev/null @@ -1,93 +0,0 @@ -//!Extract template function -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@A.cpp -void test() { -} - -template -int tempFunct() { - T i; - i = 0; - /*$*/i++; - i += 3;/*$$*/ - - return 0; -} -//= -void test() { -} - -template -void exp(T i) { - i++; - i += 3; -} - -template -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 -int tempFunct(T p) { - /*$*/++p; - p + 4;/*$$*/ - return 0; -} - -//= -void test() { -} - -template -void exp(T p) { - ++p; - p + 4; -} - -template -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 -int tempFunct() { - /*$*/T p; - p = 0; - p + 4;/*$$*/ - p + 2; - return 0; -} -//= -void test() { -} - -template -T exp() { - T p; - p = 0; - p + 4; - return p; -} - -template -int tempFunct() { - T p = exp(); - p + 2; - return 0; -} diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethod.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethod.rts deleted file mode 100644 index 7e1a136079d..00000000000 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethod.rts +++ /dev/null @@ -1,2487 +0,0 @@ -//!Extract function with variable defined in scope -//#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(); - 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; -} -//!Extract function with comment -//#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& 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; -} -//@.config -filename=A.cpp -methodname=exp -replaceduplicates=false - -//!Extract function first extracted statement with leading comment -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@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; -} - -//@.config -filename=main.cpp -methodname=exp -replaceduplicates=false - -//!Extract function last extracted statement with trailling comment -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@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; -} - -//@.config -filename=main.cpp -methodname=exp -replaceduplicates=false - -//!Extract function with two variable defined in scope -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -fatalerror=true -//@A.h -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(); - -private: - int help(); -}; - -#endif /*A_H_*/ - -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { -} - -int A::foo() { - /*$*/int o = 1; - int i = 2; - ++i; - o++; - help();/*$$*/ - o++; - return i; -} - -int A::help() { - return 42; -} - -//!Extract function with named typed field -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@A.h -#ifndef A_H_ -#define A_H_ - -#include "B.h" - -class A { -public: - A(); - virtual ~A(); - void foo(); - B b; - -private: - int help(); -}; - -#endif /*A_H_*/ - -//= -#ifndef A_H_ -#define A_H_ - -#include "B.h" - -class A { -public: - A(); - virtual ~A(); - void foo(); - B b; - -private: - int help(); - void exp(); -}; - -#endif /*A_H_*/ - -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { -} - -void A::foo() { - /*$*/b = new B(); - help();/*$$*/ -} - -int A::help() { - return 42; -} - -//= -#include "A.h" - -A::A() { -} - -A::~A() { -} - -void A::exp() { - b = new B(); - help(); -} - -void A::foo() { - exp(); -} - -int A::help() { - return 42; -} - -//@B.h -#ifndef B_H_ -#define B_H_ - -class B { -public: - B(); - virtual ~B(); -}; - -#endif /*B_H_*/ - -//!Extract function with named typed variable defined in scope -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@A.h -#ifndef A_H_ -#define A_H_ - -#include "B.h" - -class A { -public: - A(); - virtual ~A(); - void foo(); - B b; - -private: - int help(); -}; - -#endif /*A_H_*/ - -//= -#ifndef A_H_ -#define A_H_ - -#include "B.h" - -class A { -public: - A(); - virtual ~A(); - void foo(); - B b; - -private: - int help(); - void exp(); -}; - -#endif /*A_H_*/ - -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { -} - -void A::foo() { - /*$*/b = new B(); - help();/*$$*/ -} - -int A::help() { - return 42; -} - -//= -#include "A.h" - -A::A() { -} - -A::~A() { -} - -void A::exp() { - b = new B(); - help(); -} - -void A::foo() { - exp(); -} - -int A::help() { - return 42; -} - -//@B.h -#ifndef B_H_ -#define B_H_ - -class B { -public: - B(); - virtual ~B(); -}; - -#endif /*B_H_*/ - -//!Extract function with ObjectStyleMacro -//#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& i); -}; - -#endif /*A_H_*/ - -//@A.cpp -#include "A.h" - -#define ZWO 2 - -A::A() { -} - -A::~A() { -} - -int A::foo() { - int i = 2; - /*$*/++i; - i += ZWO; - help();/*$$*/ - return i; -} - -int A::help() { - return 42; -} - -//= -#include "A.h" - -#define ZWO 2 - -A::A() { -} - -A::~A() { -} - -void A::exp(int& i) { - ++i; - i += ZWO; - help(); -} - -int A::foo() { - int i = 2; - exp(i); - return i; -} - -int A::help() { - return 42; -} - -//!Extract function with FunctionStyleMacro -//#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& i); -}; - -#endif /*A_H_*/ - -//@A.cpp -#include "A.h" - -#define ADD(a,b) a + b + 2 - -A::A() { -} - -A::~A() { -} - -int A::foo() { - int i = 2; - /*$*/++i; - i = ADD(i, 42); - help();/*$$*/ - return i; -} - -int A::help() { - return 42; -} - -//= -#include "A.h" - -#define ADD(a,b) a + b + 2 - -A::A() { -} - -A::~A() { -} - -void A::exp(int& i) { - ++i; - i = ADD(i, 42); - help(); -} - -int A::foo() { - int i = 2; - exp(i); - return i; -} - -int A::help() { - return 42; -} - -//!Extract method with pointer -//#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* i); -}; - -#endif /*A_H_*/ - -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { -} - -int A::foo() { - int* i = new int(2); - /*$*/++*i; - help();/*$$*/ - return *i; -} - -int A::help() { - return 42; -} - -//= -#include "A.h" - -A::A() { -} - -A::~A() { -} - -void A::exp(int* i) { - ++*i; - help(); -} - -int A::foo() { - int* i = new int(2); - exp(i); - return *i; -} - -int A::help() { - return 42; -} - -//!Extract method with pointer and comment at the end -//#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* i); -}; - -#endif /*A_H_*/ -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { -} - -int A::foo() { - int* i = new int(2); - /*$*/++*i; - help(); - //A end-comment/*$$*/ - return *i; -} - -int A::help() { - return 42; -} -//= -#include "A.h" - -A::A() { -} - -A::~A() { -} - -void A::exp(int* i) { - ++*i; - help(); -} - -int A::foo() { - int* i = new int(2); - exp(i); - //A end-comment - return *i; -} - -int A::help() { - return 42; -} -//!Extract method with pointer and comment -//#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* i); -}; - -#endif /*A_H_*/ -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { -} - -int A::foo() { - //A beautiful comment - int* i = new int(2); - /*$*/++*i; - help();/*$$*/ - return *i; -} - -int A::help() { - return 42; -} -//= -#include "A.h" - -A::A() { -} - -A::~A() { -} - -void A::exp(int* i) { - ++*i; - help(); -} - -int A::foo() { - //A beautiful comment - int* i = new int(2); - exp(i); - return *i; -} - -int A::help() { - return 42; -} -//!Extract function with return value -//#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); -}; - -#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) { - ++i; - help(); - return i; -} - -int A::foo() { - int i = 2; - i = exp(i); - return i; -} - -int A::help() { - return 42; -} -//!Extract function with return value and ref parameter -//#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, int b); -}; - -#endif /*A_H_*/ -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { -} - -int A::foo() { - int i = 2; - int b = i; - /*$*/++i; - i = i + b; - help();/*$$*/ - ++b; - return i; -} - -int A::help() { - return 42; -} -//= -#include "A.h" - -A::A() { -} - -A::~A() { -} - -int A::exp(int i, int b) { - ++i; - i = i + b; - help(); - return i; -} - -int A::foo() { - int i = 2; - int b = i; - i = exp(i, b); - ++b; - return i; -} - -int A::help() { - return 42; -} -//!Extract function with return value and ref parameter and some more not used afterwards -//#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, B* b, int y, float x); -}; - -#endif /*A_H_*/ -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { -} - -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();/*$$*/ - ++x; - return i; -} - -int A::help() { - return 42; -} -//= -#include "A.h" - -A::A() { -} - -A::~A() { -} - -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); - ++x; - return i; -} - -int A::help() { - return 42; -} -//!Extract function with return value take the second and ref parameter and some more not used aferwards -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -returnparameterindex=1 -returnvalue=x -//@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(); - float exp(int& i, B* b, int y, float x); -}; - -#endif /*A_H_*/ -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { -} - -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();/*$$*/ - ++x; - return i; -} - -int A::help() { - return 42; -} -//= -#include "A.h" - -A::A() { -} - -A::~A() { -} - -float A::exp(int& i, B* b, int y, float x) { - ++i; - b->hello(y); - i = i + x; - help(); - return x; -} - -int A::foo() { - int i = 2; - float x = i; - B* b = new B(); - int y = x + i; - x = exp(i, b, y, x); - ++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 function with return value and a lot ref parameter -//#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 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 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 function with return value take the second and ref parameter -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -returnparameterindex=1 -returnvalue=b -//@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(); - B* exp(int& i, B* b, int y, float x); -}; - -#endif /*A_H_*/ -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { -} - -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() { -} - -B* A::exp(int& i, B* b, int y, float x) { - ++i; - b->hello(y); - i = i + x; - help(); - return b; -} - -int A::foo() { - int i = 2; - float x = i; - B* b = new B(); - int y = x + i; - b = 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 function with protected visibility -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -filename=A.cpp -methodname=exp -replaceduplicates=false -visibility=protected -//@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(); - -protected: - void exp(int& i); - -private: - int help(); -}; - -#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() { -} - -void A::exp(int& i) { - ++i; - help(); -} - -int A::foo() { - int i = 2; - exp(i); - return i; -} - -int A::help() { - return 42; -} -//!Extract function with public visibility -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -filename=A.cpp -methodname=exp -replaceduplicates=false -visibility=public -//@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(); - void exp(int& i); - -private: - int help(); -}; - -#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() { -} - -void A::exp(int& i) { - ++i; - help(); -} - -int A::foo() { - int i = 2; - exp(i); - return i; -} - -int A::help() { - return 42; -} -//!Extract function with const Method Bug # 46 -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -filename=A.cpp -methodname=exp -replaceduplicates=false -//@A.h -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo() const; - -private: - int help(); -}; - -#endif /*A_H_*/ -//= -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo() const; - -private: - int help(); - void exp(int& i) const; -}; - -#endif /*A_H_*/ -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { -} - -int A::foo() const { - int i = 2; - /*$*/++i; - help();/*$$*/ - return i; -} - -int A::help() { - return 42; -} -//= -#include "A.h" - -A::A() { -} - -A::~A() { -} - -void A::exp(int& i) const { - ++i; - help(); -} - -int A::foo() const { - int i = 2; - exp(i); - return i; -} - -int A::help() { - return 42; -} -//!Don't return variables that aren't used -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -filename=main.h -methodname=loop -//@main.h -void method() { - /*$*/for (int var = 0; var < 100; ++var) { - if (var < 50) - continue; - }/*$$*/ -} -//= -void loop() { - for (int var = 0; var < 100; ++var) { - if (var < 50) - continue; - } -} - -void method() { - loop(); -} -//!Don't extract code that contains 'return' -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -filename=main.h -fatalerror=true -//@main.h -void method() { - /*$*/if (true) - return;/*$$*/ - //unreachable -} -//!Test if we don't allow to extract 'continue' Bug #53 -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -fatalerror=true -filename=A.h -//@A.h -void function() { - for (int var = 0; var < 100; ++var) { - /*$*/if (var < 50) - continue;/*$$*/ - } -} -//! Bug #124 Extract function with a Macro call in selected code "forgets" the macro -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -filename=Test.cpp -methodname=runTest -//@Test.cpp -#define ASSERTM(msg,cond) if (!(cond)) throw cute::test_failure((msg),__FILE__,__LINE__) -#define ASSERT(cond) ASSERTM(#cond, cond) - -void testFuerRainer() { - int i = int(); - /*$*/++i; - //Leading Comment - ASSERT(i); - //Trailling Comment - --i;/*$$*/ -} - -//= -#define ASSERTM(msg,cond) if (!(cond)) throw cute::test_failure((msg),__FILE__,__LINE__) -#define ASSERT(cond) ASSERTM(#cond, cond) - -void runTest(int i) { - ++i; - //Leading Comment - ASSERT(i); - //Trailling Comment - --i; -} - -void testFuerRainer() { - int i = int(); - runTest(i); -} - -//! Bug #124 with comments Extract function with a Macro call in selected code "forgets" the macro -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -filename=Test.cpp -methodname=runTest -//@Test.cpp -#define ASSERTM(msg,cond) if (!(cond)) throw cute::test_failure((msg),__FILE__,__LINE__) -#define ASSERT(cond) ASSERTM(#cond, cond) - -void testFuerRainer() { - int i = int(); - /*$*/++i; - ASSERT(i); - --i;/*$$*/ -} - -//= -#define ASSERTM(msg,cond) if (!(cond)) throw cute::test_failure((msg),__FILE__,__LINE__) -#define ASSERT(cond) ASSERTM(#cond, cond) - -void runTest(int i) { - ++i; - ASSERT(i); - --i; -} - -void testFuerRainer() { - int i = int(); - runTest(i); -} - -//! Bug #137 String Array problem in Extract function -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -filename=Test.cpp -methodname=runTest -//@Test.cpp -#include - -using namespace std; - -int const INITIAL_CAPACITY = 10; - -int main() { - int m_capacity; - /*$*/m_capacity += INITIAL_CAPACITY; - string* newElements = new string[m_capacity];/*$$*/ - newElements[0] = "s"; -} - -//= -#include - -using namespace std; - -int const INITIAL_CAPACITY = 10; - -string* runTest(int m_capacity) { - m_capacity += INITIAL_CAPACITY; - string* newElements = new string[m_capacity]; - return newElements; -} - -int main() { - int m_capacity; - string* newElements = runTest(m_capacity); - newElements[0] = "s"; -} - -//!Bug 239059: Double & in signature of extracted functions -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@A.h -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(int& a); -}; - -#endif /*A_H_*/ - -//= -#ifndef A_H_ -#define A_H_ - -class A { -public: - A(); - virtual ~A(); - int foo(int& a); - -private: - void exp(int& a, int b, int c); -}; - -#endif /*A_H_*/ - -//@A.cpp -#include "A.h" - -A::A() { -} - -A::~A() { -} - -int A::foo(int& a) { - int b = 7; - int c = 8; - /*$*/a = b + c;/*$$*/ - return a; -} -//= -#include "A.h" - -A::A() { -} - -A::~A() { -} - -void A::exp(int& a, int b, int c) { - a = b + c; -} - -int A::foo(int& a) { - int b = 7; - int c = 8; - exp(a, b, c); - return a; -} -//!Bug 241717: Typedef causes void as return type -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -filename=Test.cpp -//@Test.h -#ifndef TEST_H_ -#define TEST_H_ - -class RetValueType { -}; - -typedef RetValueType RetType; - -class Test { -public: - Test(); - virtual ~Test(); -private: - void test(); -}; - -#endif /* TEST_H_ */ -//= -#ifndef TEST_H_ -#define TEST_H_ - -class RetValueType { -}; - -typedef RetValueType RetType; - -class Test { -public: - Test(); - virtual ~Test(); -private: - void test(); - RetType exp(); -}; - -#endif /* TEST_H_ */ -//@Test.cpp -#include "Test.h" - -Test::Test() { -} - -Test::~Test() { -} - -void Test::test() { - RetType v = /*$*/RetType()/*$$*/; -} - -//= -#include "Test.h" - -Test::Test() { -} - -Test::~Test() { -} - -RetType Test::exp() { - return RetType(); -} - -void Test::test() { - RetType v = exp(); -} - -//!Bug 248238: Extract Method Produces Wrong Return Type Or Just Fails Classtype -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -filename=Test.cpp -methodname=startTag -//@testString.h -namespace test { - -class string { -public: - friend string operator+(const string& lhs, const string& rhs) { - return rhs; - } - - string operator+(const string& rhs) { return rhs; } - string(char* cp) {} - string() {}; -}; - -} -//@Test.cpp -#include "testString.h" - -test::string toXML() { - test::string name; - name = "hello"; - return /*$*/"<" + name + ">"/*$$*/ + ""; -} - -int main() { - return 0; -} -//= -#include "testString.h" - -test::string startTag(test::string name) { - return "<" + name + ">"; -} - -test::string toXML() { - test::string name; - name = "hello"; - return startTag(name) + ""; -} - -int main() { - return 0; -} -//!Bug 248238: Extract Method Produces Wrong Return Type Or Just Fails Typedef -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -filename=Test.cpp -methodname=startTag -//@testString.h - -namespace test { - -class string2 { -public: - friend string2 operator+(const string2& lhs, const string2& rhs) { - return rhs; - } - - string2 operator+(const string2& rhs) { return rhs; } - string2(char* cp) {} - string2() {}; -}; - -typedef string2 string; - -} -//@Test.cpp -#include "testString.h" - -test::string toXML() { - test::string name; - name = "hello"; - return /*$*/"<" + name + ">"/*$$*/ + ""; -} - -int main() { - return 0; -} -//= -#include "testString.h" - -test::string startTag(test::string name) { - return "<" + name + ">"; -} - -test::string toXML() { - test::string name; - name = "hello"; - return startTag(name) + ""; -} - -int main() { - return 0; -} -//!Bug 248622: Extract function fails to extract several expressions; Selection at the end -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -filename=Test.cpp -methodname=endTag -//@testString.h - -namespace test { - -class string { -public: - friend string operator+(const string& lhs, const string& rhs) { - return rhs; - } - - string operator+(const string& rhs) { return rhs; } - string(char* cp) {} - string() {}; -}; - -} - -//@Test.cpp -#include "testString.h" - -test::string toXML() { - test::string name; - name = "hello"; - return "<" + name + ">" + /*$*/""/*$$*/; -} - -int main() { - return 0; -} - -//= -#include "testString.h" - -const char endTag(test::string name) { - return ""; -} - -test::string toXML() { - test::string name; - name = "hello"; - return "<" + name + ">" + endTag(name); -} - -int main() { - return 0; -} - -//!Bug 248622: Extract function fails to extract several expressions; Selection in the middle -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -filename=Test.cpp -methodname=exp -//@testString.h - -namespace test { - -class string { -public: - friend string operator+(const string& lhs, const string& rhs) { - return rhs; - } - - string operator+(const string& rhs) { return rhs; } - string(char* cp) {} - string() {}; -}; - -} - -//@Test.cpp -#include "testString.h" - -test::string toXML() { - test::string name; - name = "hello"; - return "<" + name + /*$*/">" + ""; -} - -int main() { - return 0; -} -//= -#include "testString.h" - -const char exp() { - return ">" + ""; -} - -int main() { - return 0; -} -//!Bug#262000 Extract function misinterprets artificial blocks -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -filename=main.cpp -methodname=exp -//@main.cpp -int main(int argc, char** argv) { - /*$*/int a = 0; - { - a++; - }/*$$*/ -} -//= -void exp() { - int a = 0; - { - a++; - } -} - -int main(int argc, char** argv) { - exp(); -} -//!Bug#264712 Refactor extract function deletes comments in header -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -filename=test.cpp -methodname=exp -//@classhelper.h -// Comment -// -// Comment -// Comment -#ifndef utils_classhelper_h_seen -#define utils_classhelper_h_seen -#define IMPORTANT_VALUE 1 -#endif - -//@test.h -/* - * Copyright 2009 - */ -#ifndef test_h_seen -#define test_h_seen - -#include "classhelper.h" - -class Test { - public: - /** - * Small class with some comments - */ - Test(); - - /** Calculate important things. - * @returns the result of the calculation - */ - int calculateStuff(); - - private: - /** - * Retain a value for something. - */ - int m_value; -}; - -#endif -//= -/* - * Copyright 2009 - */ -#ifndef test_h_seen -#define test_h_seen - -#include "classhelper.h" - -class Test { - public: - /** - * Small class with some comments - */ - Test(); - - /** Calculate important things. - * @returns the result of the calculation - */ - int calculateStuff(); - - private: - /** - * Retain a value for something. - */ - int m_value; - - int exp(); -}; - -#endif -//@test.cpp -#include "test.h" - -Test::Test() {} - -int Test::calculateStuff() { - // refactor these lines to a new method: - /*$*/int result = m_value; - result += 10; - result *= 10;/*$$*/ - return result; -} - -//= -#include "test.h" - -Test::Test() {} - -int Test::exp() { - // refactor these lines to a new method: - int result = m_value; - result += 10; - result *= 10; - return result; -} - -int Test::calculateStuff() { - // refactor these lines to a new method: - int result = exp(); - return result; -} - -//!Bug#281564 Extract function fails when catching an unnamed exception -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -filename=main.cpp -methodname=exp -//@main.cpp - -int myFunc() { - return 5; -} - -int main() { - int a = 0; -/*$*/try { - a = myFunc(); - } catch (const int&) { - a = 3; - }/*$$*/ - return a; -} - -//= - -int myFunc() { - return 5; -} - -void exp(int& a) { - try { - a = myFunc(); - } catch (const int&) { - a = 3; - } -} - -int main() { - int a = 0; - exp(a); - return a; -} - -//!Bug#282004 Extract function in C Project (not C++) won't extract parameters -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -filename=main.c -methodname=exp -//@main.c -int main() { - int a,b; - /*$*/b=a*2;/*$$*/ - return a; -} -//= -void exp(int b, int a) { - b = a * 2; -} - -int main() { - int a,b; - exp(b, a); - return a; -} -//!Extract function with virtual -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -filename=A.cpp -methodname=exp -replaceduplicates=false -virtual=true -visibility=public -//@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(); - virtual void exp(int& i); - -private: - int help(); -}; - -#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; -} -//!Bug 288268: c-refactoring creates c++-parameters -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -filename=main.c -methodname=test -replaceduplicates=false -//@main.c -int main() { - int a, b; - /*$*/a = b * 2;/*$$*/ - return a; -} -//= -void test(int* a, int b) { - a = b * 2; -} - -int main() { - int a, b; - test(a, b); - return a; -} -//!Handling of blank lines -//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest -//@.config -filename=main.c -methodname=fib -replaceduplicates=false -//@main.c -int main() { - int f; - /*$*/int a = 0; - int b = 1; - - for (int i = 0; i < 10; ++i) { - int c = a + b; - a = b; - b = c; - }/*$$*/ - - f = b; -} -//= -int fib() { - int a = 0; - int b = 1; - for (int i = 0; i < 10; ++i) { - int c = a + b; - a = b; - b = c; - } - return b; -} - -int main() { - int f; - int b = fib(); - f = b; -} diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethodDuplicates.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethodDuplicates.rts deleted file mode 100644 index 078efe5bced..00000000000 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethodDuplicates.rts +++ /dev/null @@ -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; -} - diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethodHistory.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethodHistory.rts deleted file mode 100644 index d10e5350ec6..00000000000 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethodHistory.rts +++ /dev/null @@ -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 - - - - - - -//!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 - - - - - -//!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 - - - - - -//!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 - - - - - -//!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 - - - - diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethodPreprocessor.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethodPreprocessor.rts deleted file mode 100644 index 34f789a380e..00000000000 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethodPreprocessor.rts +++ /dev/null @@ -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; -} diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringBaseTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringBaseTest.java index cbbe0aef074..17b353fdd53 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringBaseTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringBaseTest.java @@ -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 { diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringHistoryTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringHistoryTest.java index 1456f22c0e1..a2ab8fefe9c 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringHistoryTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringHistoryTest.java @@ -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 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); + } } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTest.java index bef2a1e6ab6..45adc3efb53 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTest.java @@ -35,6 +35,7 @@ public abstract class RefactoringTest extends RefactoringBaseTest { protected String fileName; protected RefactoringASTCache astCache; + protected boolean fatalError; public RefactoringTest(String name, Collection files) { super(name, files); diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTestBase.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTestBase.java new file mode 100644 index 00000000000..0b6f28743a5 --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTestBase.java @@ -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 testFiles = new LinkedHashSet(); + 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(); + } +} diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTestSuite.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTestSuite.java index a7e2db024dd..404b4ddde2b 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTestSuite.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTestSuite.java @@ -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()); diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/TestHelper.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/TestHelper.java index a2ec884cede..b5908e976c2 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/TestHelper.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/TestHelper.java @@ -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; diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/TestSourceFile.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/TestSourceFile.java index 3c6d5413b34..a5bad1bfaaf 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/TestSourceFile.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/TestSourceFile.java @@ -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); } } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractfunction/ExtractFunctionRefactoringTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractfunction/ExtractFunctionRefactoringTest.java index 020a2bcc54d..d1aeb10eaa7 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractfunction/ExtractFunctionRefactoringTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractfunction/ExtractFunctionRefactoringTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2011 Institute for Software, HSR Hochschule fuer Technik + * Copyright (c) 2008, 2012 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 @@ -12,90 +12,4190 @@ *******************************************************************************/ package org.eclipse.cdt.ui.tests.refactoring.extractfunction; -import java.util.Collection; -import java.util.Properties; +import junit.framework.Test; -import org.eclipse.core.resources.IFile; -import org.eclipse.ltk.core.refactoring.Change; import org.eclipse.ltk.core.refactoring.Refactoring; -import org.eclipse.ltk.core.refactoring.RefactoringStatus; -import org.eclipse.cdt.ui.tests.refactoring.RefactoringTest; -import org.eclipse.cdt.ui.tests.refactoring.TestSourceFile; +import org.eclipse.cdt.ui.tests.refactoring.RefactoringTestBase; -import org.eclipse.cdt.internal.ui.refactoring.CRefactoring; import org.eclipse.cdt.internal.ui.refactoring.NodeContainer.NameInformation; import org.eclipse.cdt.internal.ui.refactoring.extractfunction.ExtractFunctionInformation; import org.eclipse.cdt.internal.ui.refactoring.extractfunction.ExtractFunctionRefactoring; import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum; /** - * @author Emanuel Graf + * Tests for Extract Function refactoring. */ -public class ExtractFunctionRefactoringTest extends RefactoringTest { - protected String methodName; - protected boolean replaceDuplicates; - protected String returnValue; - protected int returnParameterIndex; - protected boolean fatalError; - private VisibilityEnum visibility; +public class ExtractFunctionRefactoringTest extends RefactoringTestBase { + private ExtractFunctionInformation refactoringInfo; + private String extractedFunctionName = "extracted"; + private String returnValue; + private VisibilityEnum visibility = VisibilityEnum.v_private; private boolean virtual; - private static int nr = 1; + private boolean replaceDuplicates = true; - public ExtractFunctionRefactoringTest(String name, Collection files) { - super(name, files); + public ExtractFunctionRefactoringTest() { + super(); + } + + public ExtractFunctionRefactoringTest(String name) { + super(name); + } + + public static Test suite() { + return suite(ExtractFunctionRefactoringTest.class); } @Override - protected void runTest() throws Throwable { - IFile refFile = project.getFile(fileName); - ExtractFunctionInformation info = new ExtractFunctionInformation(); - CRefactoring refactoring = new ExtractFunctionRefactoring(refFile, selection, info, cproject); - RefactoringStatus checkInitialConditions = refactoring.checkInitialConditions(NULL_PROGRESS_MONITOR); - - if (fatalError) { - assertConditionsFatalError(checkInitialConditions); - return; - } else { - assertConditionsOk(checkInitialConditions); - setValues(info); - executeRefactoring(refactoring); - } + protected Refactoring createRefactoring() { + refactoringInfo = new ExtractFunctionInformation(); + return new ExtractFunctionRefactoring(getSelectedFile(), getSelection(), refactoringInfo, + getCProject()); } - 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); - } - - private void setValues(ExtractFunctionInformation info) { - info.setMethodName(methodName); - info.setReplaceDuplicates(replaceDuplicates); - if (info.getMandatoryReturnVariable() == null) { + @Override + protected void simulateUserInput() { + refactoringInfo.setMethodName(extractedFunctionName); + refactoringInfo.setReplaceDuplicates(replaceDuplicates); + if (refactoringInfo.getMandatoryReturnVariable() == null) { if (returnValue != null) { - for (NameInformation nameInfo : info.getParameterCandidates()) { + for (NameInformation nameInfo : refactoringInfo.getParameterCandidates()) { if (returnValue.equals(String.valueOf(nameInfo.getName().getSimpleID()))) { - info.setReturnVariable(nameInfo); + refactoringInfo.setReturnVariable(nameInfo); nameInfo.setUserSetIsReference(false); break; } } } } - info.setVisibility(visibility); - info.setVirtual(virtual); + refactoringInfo.setVisibility(visibility); + refactoringInfo.setVirtual(virtual); } - @Override - protected void configureRefactoring(Properties refactoringProperties) { - methodName = refactoringProperties.getProperty("methodname", "exp"); //$NON-NLS-1$ //$NON-NLS-2$ - replaceDuplicates = Boolean.valueOf(refactoringProperties.getProperty("replaceduplicates", "false")).booleanValue(); //$NON-NLS-1$ //$NON-NLS-2$ - returnValue = refactoringProperties.getProperty("returnvalue", null); //$NON-NLS-1$ - fatalError = Boolean.valueOf(refactoringProperties.getProperty("fatalerror", "false")).booleanValue(); //$NON-NLS-1$ //$NON-NLS-2$ - visibility = VisibilityEnum.getEnumForStringRepresentation(refactoringProperties.getProperty("visibility", VisibilityEnum.v_private.toString())); //$NON-NLS-1$ - virtual = Boolean.valueOf(refactoringProperties.getProperty("virtual", "false")).booleanValue(); //$NON-NLS-1$ //$NON-NLS-2$ + //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 extracted(); + //}; + // + //#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::extracted() { + // int i = 2; + // ++i; + // help(); + // return i; + //} + // + //int A::foo() { + // int i = extracted(); + // return i; + //} + // + //int A::help() { + // return 42; + //} + public void testVariableDefinedInside() throws Exception { + assertRefactoringSuccess(); + } + + //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 extracted(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::extracted(int& i) { + // //comment + // ++i; + // help(); + //} + // + //int A::foo() { + // int i = 2; + // //comment + // extracted(i); + // return i; + //} + // + //int A::help() { + // return 42; + //} + public void testWithComment() throws Exception { + assertRefactoringSuccess(); + } + + //main.cpp + //int main() { + // int i; + // // Comment + // /*$*/i= 7;/*$$*/ + // return i; + //} + //==================== + //void extracted(int& i) { + // // Comment + // i = 7; + //} + // + //int main() { + // int i; + // // Comment + // extracted(i); + // return i; + //} + public void testFirstExtractedStatementWithLeadingComment() throws Exception { + assertRefactoringSuccess(); + } + + //main.cpp + //int main() { + // int i; + // /*$*/i= 7;/*$$*/ // Comment + // return i; + //} + //==================== + //void extracted(int& i) { + // i = 7; // Comment + //} + // + //int main() { + // int i; + // extracted(i); + // return i; + //} + public void testLastExtractedStatementWithTraillingComment() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(); + // + //private: + // int help(); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo() { + // /*$*/int o = 1; + // int i = 2; + // ++i; + // o++; + // help();/*$$*/ + // o++; + // return i; + //} + // + //int A::help() { + // return 42; + //} + public void testWithTwoVariableDefinedInScope() throws Exception { + assertRefactoringFailure(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //#include "B.h" + // + //class A { + //public: + // A(); + // virtual ~A(); + // void foo(); + // B b; + // + //private: + // int help(); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //#include "B.h" + // + //class A { + //public: + // A(); + // virtual ~A(); + // void foo(); + // B b; + // + //private: + // int help(); + // void extracted(); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //void A::foo() { + // /*$*/b = new B(); + // help();/*$$*/ + //} + // + //int A::help() { + // return 42; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //void A::extracted() { + // b = new B(); + // help(); + //} + // + //void A::foo() { + // extracted(); + //} + // + //int A::help() { + // return 42; + //} + + //B.h + //#ifndef B_H_ + //#define B_H_ + // + //class B { + //public: + // B(); + // virtual ~B(); + //}; + // + //#endif /*B_H_*/ + public void testWithNamedTypedField() throws Exception { + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //#include "B.h" + // + //class A { + //public: + // A(); + // virtual ~A(); + // void foo(); + // B b; + // + //private: + // int help(); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //#include "B.h" + // + //class A { + //public: + // A(); + // virtual ~A(); + // void foo(); + // B b; + // + //private: + // int help(); + // void extracted(); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //void A::foo() { + // /*$*/b = new B(); + // help();/*$$*/ + //} + // + //int A::help() { + // return 42; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //void A::extracted() { + // b = new B(); + // help(); + //} + // + //void A::foo() { + // extracted(); + //} + // + //int A::help() { + // return 42; + //} + + //B.h + //#ifndef B_H_ + //#define B_H_ + // + //class B { + //public: + // B(); + // virtual ~B(); + //}; + // + //#endif /*B_H_*/ + public void testWithNamedTypedVariableDefinedInScope() throws Exception { + assertRefactoringSuccess(); + } + + //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 extracted(int& i); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //#define ZWO 2 + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo() { + // int i = 2; + // /*$*/++i; + // i += ZWO; + // help();/*$$*/ + // return i; + //} + // + //int A::help() { + // return 42; + //} + //==================== + //#include "A.h" + // + //#define ZWO 2 + // + //A::A() { + //} + // + //A::~A() { + //} + // + //void A::extracted(int& i) { + // ++i; + // i += ZWO; + // help(); + //} + // + //int A::foo() { + // int i = 2; + // extracted(i); + // return i; + //} + // + //int A::help() { + // return 42; + //} + public void testWithObjectStyleMacro() throws Exception { + assertRefactoringSuccess(); + } + + //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 extracted(int& i); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //#define ADD(a,b) a + b + 2 + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo() { + // int i = 2; + // /*$*/++i; + // i = ADD(i, 42); + // help();/*$$*/ + // return i; + //} + // + //int A::help() { + // return 42; + //} + //==================== + //#include "A.h" + // + //#define ADD(a,b) a + b + 2 + // + //A::A() { + //} + // + //A::~A() { + //} + // + //void A::extracted(int& i) { + // ++i; + // i = ADD(i, 42); + // help(); + //} + // + //int A::foo() { + // int i = 2; + // extracted(i); + // return i; + //} + // + //int A::help() { + // return 42; + //} + public void testWithFunctionStyleMacro() throws Exception { + assertRefactoringSuccess(); + } + + //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 extracted(int* i); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo() { + // int* i = new int(2); + // /*$*/++*i; + // help();/*$$*/ + // return *i; + //} + // + //int A::help() { + // return 42; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //void A::extracted(int* i) { + // ++*i; + // help(); + //} + // + //int A::foo() { + // int* i = new int(2); + // extracted(i); + // return *i; + //} + // + //int A::help() { + // return 42; + //} + public void testWithPointer() throws Exception { + assertRefactoringSuccess(); + } + + //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 extracted(int* i); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo() { + // int* i = new int(2); + // /*$*/++*i; + // help(); + // //A end-comment/*$$*/ + // return *i; + //} + // + //int A::help() { + // return 42; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //void A::extracted(int* i) { + // ++*i; + // help(); + //} + // + //int A::foo() { + // int* i = new int(2); + // extracted(i); + // //A end-comment + // return *i; + //} + // + //int A::help() { + // return 42; + //} + public void testWithPointerAndCommentAtTheEnd() throws Exception { + assertRefactoringSuccess(); + } + + //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 extracted(int* i); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo() { + // //A beautiful comment + // int* i = new int(2); + // /*$*/++*i; + // help();/*$$*/ + // return *i; + //} + // + //int A::help() { + // return 42; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //void A::extracted(int* i) { + // ++*i; + // help(); + //} + // + //int A::foo() { + // //A beautiful comment + // int* i = new int(2); + // extracted(i); + // return *i; + //} + // + //int A::help() { + // return 42; + //} + public void testWithPointerAndComment() throws Exception { + assertRefactoringSuccess(); + } + + //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 extracted(int i); + //}; + // + //#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::extracted(int i) { + // ++i; + // help(); + // return i; + //} + // + //int A::foo() { + // int i = 2; + // i = extracted(i); + // return i; + //} + // + //int A::help() { + // return 42; + //} + public void testWithReturnValue() throws Exception { + returnValue = "i"; + assertRefactoringSuccess(); + } + + //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 extracted(int i, int b); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo() { + // int i = 2; + // int b = i; + // /*$*/++i; + // i = i + b; + // help();/*$$*/ + // ++b; + // return i; + //} + // + //int A::help() { + // return 42; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::extracted(int i, int b) { + // ++i; + // i = i + b; + // help(); + // return i; + //} + // + //int A::foo() { + // int i = 2; + // int b = i; + // i = extracted(i, b); + // ++b; + // return i; + //} + // + //int A::help() { + // return 42; + //} + public void testWithReturnValueAndRefParameter() throws Exception { + returnValue = "i"; + assertRefactoringSuccess(); + } + + //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 extracted(int i, B* b, int y, float x); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //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();/*$$*/ + // ++x; + // return i; + //} + // + //int A::help() { + // return 42; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::extracted(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 = extracted(i, b, y, x); + // ++x; + // return i; + //} + // + //int A::help() { + // return 42; + //} + public void testWithReturnValueAndRefParameterAndSomeMoreNotUsedAfterwards() throws Exception { + returnValue = "i"; + assertRefactoringSuccess(); + } + + //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(); + // float extracted(int& i, B* b, int y, float x); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //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();/*$$*/ + // ++x; + // return i; + //} + // + //int A::help() { + // return 42; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //float A::extracted(int& i, B* b, int y, float x) { + // ++i; + // b->hello(y); + // i = i + x; + // help(); + // return x; + //} + // + //int A::foo() { + // int i = 2; + // float x = i; + // B* b = new B(); + // int y = x + i; + // x = extracted(i, b, y, x); + // ++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_*/ + public void testWithReturnValueTakeTheSecondAndRefParameterAndSomeMoreNotUsedAferwards() throws Exception { + returnValue = "x"; + assertRefactoringSuccess(); + } + + //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 extracted(int i, B* b, int y, float x); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //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 A::extracted(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 = extracted(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_*/ + public void testWithReturnValueAndALotRefParameter() throws Exception { + returnValue = "i"; + assertRefactoringSuccess(); + } + + //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(); + // B* extracted(int& i, B* b, int y, float x); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //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() { + //} + // + //B* A::extracted(int& i, B* b, int y, float x) { + // ++i; + // b->hello(y); + // i = i + x; + // help(); + // return b; + //} + // + //int A::foo() { + // int i = 2; + // float x = i; + // B* b = new B(); + // int y = x + i; + // b = extracted(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_*/ + public void testWithReturnValueTakeTheSecondAndRefParameter() throws Exception { + returnValue = "b"; + assertRefactoringSuccess(); + } + + //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(); + // + //protected: + // void extracted(int& i); + // + //private: + // int help(); + //}; + // + //#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() { + //} + // + //void A::extracted(int& i) { + // ++i; + // help(); + //} + // + //int A::foo() { + // int i = 2; + // extracted(i); + // return i; + //} + // + //int A::help() { + // return 42; + //} + public void testWithProtectedVisibility() throws Exception { + visibility = VisibilityEnum.v_protected; + assertRefactoringSuccess(); + } + + //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(); + // void extracted(int& i); + // + //private: + // int help(); + //}; + // + //#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() { + //} + // + //void A::extracted(int& i) { + // ++i; + // help(); + //} + // + //int A::foo() { + // int i = 2; + // extracted(i); + // return i; + //} + // + //int A::help() { + // return 42; + //} + public void testWithPublicVisibility() throws Exception { + visibility = VisibilityEnum.v_public; + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo() const; + // + //private: + // int help(); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo() const; + // + //private: + // int help(); + // void extracted(int& i) const; + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo() const { + // int i = 2; + // /*$*/++i; + // help();/*$$*/ + // return i; + //} + // + //int A::help() { + // return 42; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //void A::extracted(int& i) const { + // ++i; + // help(); + //} + // + //int A::foo() const { + // int i = 2; + // extracted(i); + // return i; + //} + // + //int A::help() { + // return 42; + //} + public void testWithConstMethod() throws Exception { + assertRefactoringSuccess(); + } + + //main.h + //void method() { + // /*$*/for (int var = 0; var < 100; ++var) { + // if (var < 50) + // continue; + // }/*$$*/ + //} + //==================== + //void loop() { + // for (int var = 0; var < 100; ++var) { + // if (var < 50) + // continue; + // } + //} + // + //void method() { + // loop(); + //} + public void testDontReturnVariablesThatArentUsed() throws Exception { + extractedFunctionName = "loop"; + assertRefactoringSuccess(); + } + + //main.h + //void method() { + // /*$*/if (true) + // return;/*$$*/ + // //unreachable + //} + public void testDontExtractCodeThatContainsReturn() throws Exception { + assertRefactoringFailure(); + } + + //A.h + //void function() { + // for (int var = 0; var < 100; ++var) { + // /*$*/if (var < 50) + // continue;/*$$*/ + // } + //} + public void testTestIfWeDontAllowToExtractContinue() throws Exception { + assertRefactoringFailure(); + } + + //Test.cpp + //#define ASSERTM(msg,cond) if (!(cond)) throw cute::test_failure((msg),__FILE__,__LINE__) + //#define ASSERT(cond) ASSERTM(#cond, cond) + // + //void testFuerRainer() { + // int i = int(); + // /*$*/++i; + // //Leading Comment + // ASSERT(i); + // //Trailling Comment + // --i;/*$$*/ + //} + //==================== + //#define ASSERTM(msg,cond) if (!(cond)) throw cute::test_failure((msg),__FILE__,__LINE__) + //#define ASSERT(cond) ASSERTM(#cond, cond) + // + //void runTest(int i) { + // ++i; + // //Leading Comment + // ASSERT(i); + // //Trailling Comment + // --i; + //} + // + //void testFuerRainer() { + // int i = int(); + // runTest(i); + //} + public void testExtractFunctionWithAMacroCallInSelectedCodeForgetsTheMacro() throws Exception { + extractedFunctionName = "runTest"; + assertRefactoringSuccess(); + } + + //Test.cpp + //#define ASSERTM(msg,cond) if (!(cond)) throw cute::test_failure((msg),__FILE__,__LINE__) + //#define ASSERT(cond) ASSERTM(#cond, cond) + // + //void testFuerRainer() { + // int i = int(); + // /*$*/++i; + // ASSERT(i); + // --i;/*$$*/ + //} + //==================== + //#define ASSERTM(msg,cond) if (!(cond)) throw cute::test_failure((msg),__FILE__,__LINE__) + //#define ASSERT(cond) ASSERTM(#cond, cond) + // + //void runTest(int i) { + // ++i; + // ASSERT(i); + // --i; + //} + // + //void testFuerRainer() { + // int i = int(); + // runTest(i); + //} + public void testWithCommentsExtractFunctionWithAMacroCallInSelectedCodeForgetsTheMacro() throws Exception { + extractedFunctionName = "runTest"; + assertRefactoringSuccess(); + } + + //Test.cpp + //#include + // + //using namespace std; + // + //int const INITIAL_CAPACITY = 10; + // + //int main() { + // int m_capacity; + // /*$*/m_capacity += INITIAL_CAPACITY; + // string* newElements = new string[m_capacity];/*$$*/ + // newElements[0] = "s"; + //} + //==================== + //#include + // + //using namespace std; + // + //int const INITIAL_CAPACITY = 10; + // + //string* runTest(int m_capacity) { + // m_capacity += INITIAL_CAPACITY; + // string* newElements = new string[m_capacity]; + // return newElements; + //} + // + //int main() { + // int m_capacity; + // string* newElements = runTest(m_capacity); + // newElements[0] = "s"; + //} + public void testStringArrayProblemInExtractFunction() throws Exception { + extractedFunctionName = "runTest"; + assertRefactoringSuccess(); + } + + //A.h + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(int& a); + //}; + // + //#endif /*A_H_*/ + //==================== + //#ifndef A_H_ + //#define A_H_ + // + //class A { + //public: + // A(); + // virtual ~A(); + // int foo(int& a); + // + //private: + // void extracted(int& a, int b, int c); + //}; + // + //#endif /*A_H_*/ + + //A.cpp + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //int A::foo(int& a) { + // int b = 7; + // int c = 8; + // /*$*/a = b + c;/*$$*/ + // return a; + //} + //==================== + //#include "A.h" + // + //A::A() { + //} + // + //A::~A() { + //} + // + //void A::extracted(int& a, int b, int c) { + // a = b + c; + //} + // + //int A::foo(int& a) { + // int b = 7; + // int c = 8; + // extracted(a, b, c); + // return a; + //} + public void testBug239059DoubleAmpersandInSignatureOfExtractedFunctions() throws Exception { + assertRefactoringSuccess(); + } + + //Test.h + //#ifndef TEST_H_ + //#define TEST_H_ + // + //class RetValueType { + //}; + // + //typedef RetValueType RetType; + // + //class Test { + //public: + // Test(); + // virtual ~Test(); + //private: + // void test(); + //}; + // + //#endif /* TEST_H_ */ + //==================== + //#ifndef TEST_H_ + //#define TEST_H_ + // + //class RetValueType { + //}; + // + //typedef RetValueType RetType; + // + //class Test { + //public: + // Test(); + // virtual ~Test(); + //private: + // void test(); + // RetType extracted(); + //}; + // + //#endif /* TEST_H_ */ + + //Test.cpp + //#include "Test.h" + // + //Test::Test() { + //} + // + //Test::~Test() { + //} + // + //void Test::test() { + // RetType v = /*$*/RetType()/*$$*/; + //} + //==================== + //#include "Test.h" + // + //Test::Test() { + //} + // + //Test::~Test() { + //} + // + //RetType Test::extracted() { + // return RetType(); + //} + // + //void Test::test() { + // RetType v = extracted(); + //} + public void testBug241717TypedefCausesVoidAsReturnType() throws Exception { + assertRefactoringSuccess(); + } + + //testString.h + //namespace test { + // + //class string { + //public: + // friend string operator+(const string& lhs, const string& rhs) { + // return rhs; + // } + // + // string operator+(const string& rhs) { return rhs; } + // string(char* cp) {} + // string() {}; + //}; + // + //} + + //Test.cpp + //#include "testString.h" + // + //test::string toXML() { + // test::string name; + // name = "hello"; + // return /*$*/"<" + name + ">"/*$$*/ + ""; + //} + // + //int main() { + // return 0; + //} + //==================== + //#include "testString.h" + // + //test::string startTag(test::string name) { + // return "<" + name + ">"; + //} + // + //test::string toXML() { + // test::string name; + // name = "hello"; + // return startTag(name) + ""; + //} + // + //int main() { + // return 0; + //} + public void testBug248238ExtractMethodProducesWrongReturnTypeOrJustFailsClasstype() throws Exception { + extractedFunctionName = "startTag"; + assertRefactoringSuccess(); + } + + //testString.h + // + //namespace test { + // + //class string2 { + //public: + // friend string2 operator+(const string2& lhs, const string2& rhs) { + // return rhs; + // } + // + // string2 operator+(const string2& rhs) { return rhs; } + // string2(char* cp) {} + // string2() {}; + //}; + // + //typedef string2 string; + // + //} + + //Test.cpp + //#include "testString.h" + // + //test::string toXML() { + // test::string name; + // name = "hello"; + // return /*$*/"<" + name + ">"/*$$*/ + ""; + //} + // + //int main() { + // return 0; + //} + //==================== + //#include "testString.h" + // + //test::string startTag(test::string name) { + // return "<" + name + ">"; + //} + // + //test::string toXML() { + // test::string name; + // name = "hello"; + // return startTag(name) + ""; + //} + // + //int main() { + // return 0; + //} + public void testBug248238ExtractMethodProducesWrongReturnTypeOrJustFailsTypedef() throws Exception { + extractedFunctionName = "startTag"; + assertRefactoringSuccess(); + } + + //testString.h + // + //namespace test { + // + //class string { + //public: + // friend string operator+(const string& lhs, const string& rhs) { + // return rhs; + // } + // + // string operator+(const string& rhs) { return rhs; } + // string(char* cp) {} + // string() {}; + //}; + // + //} + + //Test.cpp + //#include "testString.h" + // + //test::string toXML() { + // test::string name; + // name = "hello"; + // return "<" + name + ">" + /*$*/""/*$$*/; + //} + // + //int main() { + // return 0; + //} + //==================== + //#include "testString.h" + // + //const char endTag(test::string name) { + // return ""; + //} + // + //test::string toXML() { + // test::string name; + // name = "hello"; + // return "<" + name + ">" + endTag(name); + //} + // + //int main() { + // return 0; + //} + public void testBug248622ExtractFunctionFailsToExtractSeveralExpressionsSelectionAtTheEnd() throws Exception { + extractedFunctionName = "endTag"; + assertRefactoringSuccess(); + } + + //testString.h + // + //namespace test { + // + //class string { + //public: + // friend string operator+(const string& lhs, const string& rhs) { + // return rhs; + // } + // + // string operator+(const string& rhs) { return rhs; } + // string(char* cp) {} + // string() {}; + //}; + // + //} + + //Test.cpp + //#include "testString.h" + // + //test::string toXML() { + // test::string name; + // name = "hello"; + // return "<" + name + /*$*/">" + ""; + //} + // + //int main() { + // return 0; + //} + //==================== + //#include "testString.h" + // + //const char extracted() { + // return ">" + ""; + //} + // + //int main() { + // return 0; + //} + public void testBug248622ExtractFunctionFailsToExtractSeveralExpressionsSelectionInTheMiddle() throws Exception { + assertRefactoringSuccess(); + } + + //main.cpp + //int main(int argc, char** argv) { + // /*$*/int a = 0; + // { + // a++; + // }/*$$*/ + //} + //==================== + //void extracted() { + // int a = 0; + // { + // a++; + // } + //} + // + //int main(int argc, char** argv) { + // extracted(); + //} + public void testBug262000ExtractFunctionMisinterpretsArtificialBlocks() throws Exception { + assertRefactoringSuccess(); + } + + //classhelper.h + //// Comment + //// + //// Comment + //// Comment + //#ifndef utils_classhelper_h_seen + //#define utils_classhelper_h_seen + //#define IMPORTANT_VALUE 1 + //#endif + + //test.h + ///* + // * Copyright 2009 + // */ + //#ifndef test_h_seen + //#define test_h_seen + // + //#include "classhelper.h" + // + //class Test { + // public: + // /** + // * Small class with some comments + // */ + // Test(); + // + // /** Calculate important things. + // * @returns the result of the calculation + // */ + // int calculateStuff(); + // + // private: + // /** + // * Retain a value for something. + // */ + // int m_value; + //}; + // + //#endif + //==================== + ///* + // * Copyright 2009 + // */ + //#ifndef test_h_seen + //#define test_h_seen + // + //#include "classhelper.h" + // + //class Test { + // public: + // /** + // * Small class with some comments + // */ + // Test(); + // + // /** Calculate important things. + // * @returns the result of the calculation + // */ + // int calculateStuff(); + // + // private: + // /** + // * Retain a value for something. + // */ + // int m_value; + // + // int extracted(); + //}; + // + //#endif + + //test.cpp + //#include "test.h" + // + //Test::Test() {} + // + //int Test::calculateStuff() { + // // refactor these lines to a new method: + // /*$*/int result = m_value; + // result += 10; + // result *= 10;/*$$*/ + // return result; + //} + //==================== + //#include "test.h" + // + //Test::Test() {} + // + //int Test::extracted() { + // // refactor these lines to a new method: + // int result = m_value; + // result += 10; + // result *= 10; + // return result; + //} + // + //int Test::calculateStuff() { + // // refactor these lines to a new method: + // int result = extracted(); + // return result; + //} + public void testBug264712ExtractFunctionDeletesCommentsInHeader() throws Exception { + assertRefactoringSuccess(); + } + + //main.cpp + // + //int myFunc() { + // return 5; + //} + // + //int main() { + // int a = 0; + ///*$*/try { + // a = myFunc(); + // } catch (const int&) { + // a = 3; + // }/*$$*/ + // return a; + //} + //==================== + // + //int myFunc() { + // return 5; + //} + // + //void extracted(int& a) { + // try { + // a = myFunc(); + // } catch (const int&) { + // a = 3; + // } + //} + // + //int main() { + // int a = 0; + // extracted(a); + // return a; + //} + public void testBug281564ExtractFunctionFailsWhenCatchingAnUnnamedException() throws Exception { + assertRefactoringSuccess(); + } + + //main.c + //int main() { + // int a,b; + // /*$*/b=a*2;/*$$*/ + // return a; + //} + //==================== + //void extracted(int b, int a) { + // b = a * 2; + //} + // + //int main() { + // int a,b; + // extracted(b, a); + // return a; + //} + public void testBug282004ExtractFunctionInCProjectNotCPPWontExtractParameters() throws Exception { + assertRefactoringSuccess(); + } + + //main.c + //int main() { + // int a, b; + // /*$*/a = b * 2;/*$$*/ + // return a; + //} + //==================== + //void extracted(int* a, int b) { + // a = b * 2; + //} + // + //int main() { + // int a, b; + // extracted(a, b); + // return a; + //} + public void testBug288268CRefactoringCreatesCPPParameters() throws Exception { + assertRefactoringSuccess(); + } + + //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(); + // virtual void extracted(int& i); + // + //private: + // int help(); + //}; + // + //#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::extracted(int& i) { + // //comment + // ++i; + // help(); + //} + // + //int A::foo() { + // int i = 2; + // //comment + // extracted(i); + // return i; + //} + // + //int A::help() { + // return 42; + //} + public void testWithVirtual() throws Exception { + visibility = VisibilityEnum.v_public; + virtual = true; + assertRefactoringSuccess(); + } + + //main.c + //int main() { + // int f; + // /*$*/int a = 0; + // int b = 1; + // + // for (int i = 0; i < 10; ++i) { + // int c = a + b; + // a = b; + // b = c; + // }/*$$*/ + // + // f = b; + //} + //==================== + //int fib() { + // int a = 0; + // int b = 1; + // for (int i = 0; i < 10; ++i) { + // int c = a + b; + // a = b; + // b = c; + // } + // return b; + //} + // + //int main() { + // int f; + // int b = fib(); + // f = b; + //} + public void testHandlingOfBlankLines() throws Exception { + extractedFunctionName = "fib"; + assertRefactoringSuccess(); + } + + //A.cpp + //void test() { + //} + // + //template + //int tempFunct() { + // T i; + // i = 0; + // /*$*/i++; + // i += 3;/*$$*/ + // + // return 0; + //} + //==================== + //void test() { + //} + // + //template + //void extracted(T i) { + // i++; + // i += 3; + //} + // + //template + //int tempFunct() { + // T i; + // i = 0; + // extracted(i); + // return 0; + //} + public void testTemplateFunction() throws Exception { + assertRefactoringSuccess(); + } + + //A.cpp + //void test() { + //} + // + //template + //int tempFunct(T p) { + // /*$*/++p; + // p + 4;/*$$*/ + // return 0; + //} + //==================== + //void test() { + //} + // + //template + //void extracted(T p) { + // ++p; + // p + 4; + //} + // + //template + //int tempFunct(T p) { + // extracted(p); + // return 0; + //} + public void testTemplateFunctionWithTemplateParameter() throws Exception { + assertRefactoringSuccess(); + } + + //A.cpp + //void test() { + //} + // + //template + //int tempFunct() { + // /*$*/T p; + // p = 0; + // p + 4;/*$$*/ + // p + 2; + // return 0; + //} + //==================== + //void test() { + //} + // + //template + //T extracted() { + // T p; + // p = 0; + // p + 4; + // return p; + //} + // + //template + //int tempFunct() { + // T p = extracted(); + // p + 2; + // return 0; + //} + public void testTemplateFunctionWithTemplateTypeDeclaration() throws Exception { + assertRefactoringSuccess(); + } + + //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 extracted(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; + // extracted(i); + //} + // + //void A::extracted(int& i) { + // ++i; + // help(); + //} + // + //int A::foo() { + // int i = 2; + // extracted(i); + // return i; + //} + // + //int A::help() { + // return 42; + //} + public void testWithDuplicates() throws Exception { + assertRefactoringSuccess(); + } + + //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 extracted(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; + // extracted(oo); + //} + // + //void A::extracted(int& i) { + // ++i; + // help(); + //} + // + //int A::foo() { + // int i = 2; + // extracted(i); + // return i; + //} + // + //int A::help() { + // return 42; + //} + public void testDuplicatesWithDifferentNames() throws Exception { + assertRefactoringSuccess(); + } + + //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 extracted(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 = extracted(i, j); + //} + // + //int A::extracted(int j, int& a) { + // j++; + // a++; + // help(); + // return j; + //} + // + //void A::foo() { + // int j = 0; + // int a = 1; + // j = extracted(j, a); + // a++; + // j++; + //} + // + //int A::help() { + // return 42; + //} + public void testDuplicateWithField() throws Exception { + returnValue = "j"; + assertRefactoringSuccess(); + } + + //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 extracted(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::extracted(int j) { + // field++; + // j++; + // help(); + // return j; + //} + // + //void A::foo() { + // int j = 0; + // + // j = extracted(j); + // field++; + // j++; + //} + // + //int A::help() { + // return 42; + //} + public void testDuplicateWithFieldInMarkedScope() throws Exception { + returnValue = "j"; + assertRefactoringSuccess(); + } + + //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 extracted(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 = extracted(oo, blabla); + // blabla += 1; + //} + // + //int A::extracted(int i, float& j) { + // ++i; + // j += 1; + // help(); + // return i; + //} + // + //int A::foo() { + // int i = 2; + // float j = 8989; + // i = extracted(i, j); + // j++; + // return i; + //} + // + //int A::help() { + // return 42; + //} + public void testDuplicatesWithDifferentNamesAndReturnType() throws Exception { + returnValue = "i"; + assertRefactoringSuccess(); + } + + //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 extracted(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; + // extracted(oo, blabla); + //} + // + //void A::extracted(int& i, float j) { + // ++i; + // j += 1; + // help(); + //} + // + //int A::foo() { + // int i = 2; + // float j = 8989; + // extracted(i, j); + // return i; + //} + // + //int A::help() { + // return 42; + //} + public void testDuplicatesWithALotOfDifferentNamesAnVariableNotUsedAfterwardsInTheDuplicate() throws Exception { + assertRefactoringSuccess(); + } + + //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 extracted(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::extracted(int i) { + // ++i; + // help(); + //} + // + //void A::foo() { + // int i = 2; + // extracted(i); + //} + // + //int A::help() { + // return 42; + //} + public void testWithDuplicateNameUsedAfterwardsInDuplicateButNotInOriginalSelectionThisIsNoDuplicate() throws Exception { + assertRefactoringSuccess(); + } + + //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 extracted(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 = extracted(i, b, y, x); + // b->hello(y); + // ++x; + // i++; + //} + // + //int A::extracted(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 = extracted(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_*/ + public void testWithReturnValueAndALotRefParameterAndAMethodCall() throws Exception { + returnValue = "i"; + assertRefactoringSuccess(); + } + + //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 extracted(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 = extracted(i, b, y, x); + // b->hello(y); + // ++x; + // i++; + //} + // + //int A::extracted(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 = extracted(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_*/ + public void testWithReturnValueAndALotRefParameterAndAMethodCallDuplicateIsSimilar() throws Exception { + returnValue = "i"; + assertRefactoringSuccess(); + } + + //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 extracted(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; + // extracted(i); + //} + // + //void A::extracted(int& i) { + // ++i; + // help(); + //} + // + //int A::foo() { + // int i = 2; + // extracted(i); + // return i; + //} + // + //int A::help() { + // return 42; + //} + public void testWithDuplicatesAndComments() throws Exception { + assertRefactoringSuccess(); + } + + //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 extracted(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::extracted(int& ii) { + // ++ii; + // ii = ADD(ii, 42); + // help(); + //} + // + //int A::foo() { + // int ii = 2; + // extracted(ii); + // return ii; + //} + // + //int A::help() { + // return 42; + //} + public void testExtractFunctionRefactoringTestWithFunctionStyleMacro2() throws Exception { + assertRefactoringSuccess(); + } + + //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 extracted(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::extracted(int& i, int b) { + // ++i; + // help(); + // ADD(b); + // return b; + //} + // + //int A::foo() { + // int i = 2; + // int b = 42; + // b = extracted(i, b); + // b += 2; + // return i; + //} + // + //int A::help() { + // return 42; + //} + public void testReturnValueAssignedToMacroCall() throws Exception { + returnValue = "b"; + assertRefactoringSuccess(); + } + + //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 extracted(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::extracted(int bb) { + // ADD(bb); + // ADD(bb); + // return bb; + //} + // + //int A::foo() { + // int i = 2; + // int bb = 42; + // ++i; + // bb = extracted(bb); + // bb += 2; + // return i; + //} + // + //int A::help() { + // return 42; + //} + public void testWithMultipleMacros() throws Exception { + returnValue = "bb"; + assertRefactoringSuccess(); + } + + //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 extracted(); + //}; + // + //#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::extracted() { + // int i = 2; + // ++i; + // help(); + // return i; + //} + // + //int A::foo() { + // int i = extracted(); + // return i; + //} + // + //int A::help() { + // return 42; + //} + + //refactoringScript.xml + // + // + // + // + // + public void testExtractFunctionHistoryRefactoringTestVariableDefinedInScope() throws Exception { + assertRefactoringSuccess(); + } + + //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 extracted(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::extracted(int& i) { + // //comment + // ++i; + // help(); + //} + // + //int A::foo() { + // int i = 2; + // //comment + // extracted(i); + // return i; + //} + // + //int A::help() { + // return 42; + //} + + //refactoringScript.xml + // + // + // + // + public void testExtractFunctionHistoryRefactoringTest() throws Exception { + assertRefactoringSuccess(); + } + + //main.cpp + //int main() { + // int i; + // // Comment + // i = 7; + // return i; + //} + //==================== + //void extracted(int& i) { + // // Comment + // i = 7; + //} + // + //int main() { + // int i; + // // Comment + // extracted(i); + // return i; + //} + + //refactoringScript.xml + // + // + // + // + public void testHistoryFirstExtractedStatementWithLeadingComment() throws Exception { + assertRefactoringSuccess(); + } + + //main.cpp + //int main() { + // int i; + // i = 7; // Comment + // return i; + //} + //==================== + //void extracted(int& i) { + // i = 7; // Comment + //} + // + //int main() { + // int i; + // extracted(i); + // return i; + //} + + //refactoringScript.xml + // + // + // + // + public void testHistoryExtractedStatementWithTrailingComment() throws Exception { + assertRefactoringSuccess(); + } + + //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 extracted(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; + // extracted(oo); + //} + // + //void A::extracted(int& i) { + // ++i; + // help(); + //} + // + //int A::foo() { + // int i = 2; + // extracted(i); + // return i; + //} + // + //int A::help() { + // return 42; + //} + + //refactoringScript.xml + // + // + // + // + public void testExtractFunctionRefactoringTestDuplicatesWithDifferentNamesHistoryTest() throws Exception { + assertRefactoringSuccess(); } } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractfunction/ExtractFunctionTestSuite.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractfunction/ExtractFunctionTestSuite.java deleted file mode 100644 index 42d36bc0513..00000000000 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractfunction/ExtractFunctionTestSuite.java +++ /dev/null @@ -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; - } -}