From 6addb930f2c8746bfeae0788ee70f4f2ef485975 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Sat, 5 Feb 2011 02:50:43 +0000 Subject: [PATCH] Bug 336123 - Test case by Marc-Andre Laperle --- .../refactoring/DefinitionFinder.rts | 20 +++++++ .../utils/DefinitionFinderTest.java | 52 +++++++++++++++++++ .../refactoring/utils/UtilTestSuite.java | 6 +-- 3 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 core/org.eclipse.cdt.ui.tests/resources/refactoring/DefinitionFinder.rts create mode 100644 core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/DefinitionFinderTest.java diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/DefinitionFinder.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/DefinitionFinder.rts new file mode 100644 index 00000000000..0fbde7fc777 --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/resources/refactoring/DefinitionFinder.rts @@ -0,0 +1,20 @@ +//!Find function definition +//#org.eclipse.cdt.ui.tests.refactoring.utils.DefinitionFinderTest +//@.config +filename=A.h +//@A.h +#ifndef A_H_ +#define A_H_ + +void foo(); + +#endif /*A_H_*/ + +//@A.cpp +#include "A.h" + +void foo() +{ + +} + diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/DefinitionFinderTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/DefinitionFinderTest.java new file mode 100644 index 00000000000..c3ce292d94e --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/DefinitionFinderTest.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 Marc-Andre Laperle 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: + * Marc-Andre Laperle - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.ui.tests.refactoring.utils; + +import java.util.Collection; +import java.util.Properties; + +import org.eclipse.core.resources.IFile; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.dom.ast.IASTDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.ITranslationUnit; +import org.eclipse.cdt.ui.tests.refactoring.RefactoringTest; +import org.eclipse.cdt.ui.tests.refactoring.TestSourceFile; + +import org.eclipse.cdt.internal.ui.refactoring.utils.DefinitionFinder2; + +public class DefinitionFinderTest extends RefactoringTest { + + public DefinitionFinderTest(String name, Collection files) { + super(name, files); + } + + @Override + protected void configureRefactoring(Properties refactoringProperties) { + } + + @Override + protected void runTest() throws Throwable { + IFile file = project.getFile(fileName); + ICElement element = CCorePlugin.getDefault().getCoreModel().create(file); + if (element instanceof ITranslationUnit) { + IASTTranslationUnit unit = astCache.getAST((ITranslationUnit) element, null); + for (IASTDeclaration declaration : unit.getDeclarations()) { + if (declaration instanceof IASTSimpleDeclaration) { + assertNotNull(DefinitionFinder2.getDefinition((IASTSimpleDeclaration) declaration, astCache)); + } + } + } + } +} diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/UtilTestSuite.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/UtilTestSuite.java index bdeca35b3f5..c5eaae6de90 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/UtilTestSuite.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/UtilTestSuite.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik + * Copyright (c) 2008, 2011 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 @@ -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.utils; @@ -18,7 +18,6 @@ import org.eclipse.cdt.ui.tests.refactoring.RefactoringTester; /** * @author Thomas Corbat - * */ public class UtilTestSuite extends TestSuite { @@ -26,6 +25,7 @@ public class UtilTestSuite extends TestSuite { UtilTestSuite suite = new UtilTestSuite(); suite.addTest(IdentifierHelperTest.suite()); suite.addTest(RefactoringTester.suite("TranslationUnitHelperTest", "resources/refactoring/TranslationunitHelper.rts")); //$NON-NLS-1$ //$NON-NLS-2$ + suite.addTest(RefactoringTester.suite("DefinitionFinderTest", "resources/refactoring/DefinitionFinder.rts")); //$NON-NLS-1$ //$NON-NLS-2$ suite.addTestSuite(PseudoNameGeneratorTest.class); return suite; }