From 3474f828de682a0b36e8f4ea17a27e4e6178619b Mon Sep 17 00:00:00 2001 From: Jonah Graham Date: Wed, 26 Oct 2022 16:23:13 -0400 Subject: [PATCH] Convert pdom tests to JUnit5 format This will allow, if needed, to mark tests as flaky Part of #117 --- .../pdom/tests/CCompositeTypeTests.java | 42 ++++-- .../internal/pdom/tests/CFunctionTests.java | 28 ++-- .../pdom/tests/CPPClassTemplateTests.java | 129 +++++++++--------- .../pdom/tests/CPPCompositeTypeTests.java | 41 ++++-- .../internal/pdom/tests/CPPFieldTests.java | 36 +++-- .../pdom/tests/CPPFunctionTemplateTests.java | 15 +- .../internal/pdom/tests/CPPFunctionTests.java | 54 ++++++-- .../internal/pdom/tests/CPPVariableTests.java | 25 ++-- .../internal/pdom/tests/CVariableTests.java | 24 ++-- .../pdom/tests/ChangeConfigurationTests.java | 14 +- .../tests/ClassMemberVisibilityTests.java | 25 ++-- .../cdt/internal/pdom/tests/ClassTests.java | 39 ++++-- .../pdom/tests/DBPropertiesTests.java | 30 ++-- .../cdt/internal/pdom/tests/DatabaseTest.java | 33 +++-- .../cdt/internal/pdom/tests/DefDeclTests.java | 40 ++++-- .../internal/pdom/tests/EnumerationTests.java | 23 ++-- .../pdom/tests/FilesOnReindexTests.java | 21 +-- .../tests/GeneratePDOMApplicationTest.java | 38 ++++-- .../internal/pdom/tests/IncludesTests.java | 28 ++-- .../cdt/internal/pdom/tests/MethodTests.java | 71 ++++++++-- .../internal/pdom/tests/NamespaceTests.java | 28 ++-- .../OverloadsWithinCommonHeaderTests.java | 31 +++-- .../tests/OverloadsWithinSingleTUTests.java | 28 ++-- .../internal/pdom/tests/PDOMCBugsTest.java | 29 ++-- .../internal/pdom/tests/PDOMCPPBugsTest.java | 44 +++--- .../pdom/tests/PDOMInlineCodeTestBase.java | 12 +- .../pdom/tests/PDOMLocationTests.java | 27 ++-- .../internal/pdom/tests/PDOMNameTests.java | 31 +++-- .../pdom/tests/PDOMProviderTests.java | 12 +- .../internal/pdom/tests/PDOMSearchTest.java | 27 ++-- .../pdom/tests/PDOMStringSetTests.java | 29 ++-- .../pdom/tests/PDOMTagIndexTests.java | 32 +++-- .../cdt/internal/pdom/tests/PDOMTestBase.java | 21 ++- .../pdom/tests/RaceCondition157992Test.java | 14 +- .../cdt/internal/pdom/tests/TypesTests.java | 22 +-- .../core/testplugin/util/BaseTestCase5.java | 4 +- .../testplugin/util/TestSourceReader.java | 6 +- 37 files changed, 692 insertions(+), 461 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CCompositeTypeTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CCompositeTypeTests.java index 20877d38d78..a740ddc33c6 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CCompositeTypeTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CCompositeTypeTests.java @@ -14,6 +14,8 @@ package org.eclipse.cdt.internal.pdom.tests; +import static org.junit.jupiter.api.Assertions.assertEquals; + import java.util.regex.Pattern; import org.eclipse.cdt.core.dom.ast.ICompositeType; @@ -24,9 +26,9 @@ import org.eclipse.cdt.internal.core.CCoreInternals; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.NullProgressMonitor; - -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Tests for verifying whether the PDOM correctly stores information about @@ -37,12 +39,8 @@ public class CCompositeTypeTests extends PDOMTestBase { private ICProject project; private PDOM pdom; - public static Test suite() { - return new TestSuite(CCompositeTypeTests.class); - } - - @Override - protected void setUp() throws Exception { + @BeforeEach + protected void beforeEach() throws Exception { CCompositeTypeTests foo = null; project = createProject("compositeTypeTests"); @@ -50,8 +48,8 @@ public class CCompositeTypeTests extends PDOMTestBase { pdom.acquireReadLock(); } - @Override - protected void tearDown() throws Exception { + @AfterEach + protected void afterEach() throws Exception { pdom.releaseReadLock(); if (project != null) { project.getProject().delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, @@ -69,24 +67,28 @@ public class CCompositeTypeTests extends PDOMTestBase { } // test struct definitions and struct member declarations in C + @Test public void testSimpleCStructureDeclarations() throws Exception { assertDeclarationCount(pdom, "SimpleCStructure", 1); assertDeclarationCount(pdom, "SimpleCStructure::scsa", 1); } // test struct definitions and struct member definitions in C + @Test public void testSimpleCStructureDefinitions() throws Exception { assertDefinitionCount(pdom, "SimpleCStructure", 1); assertDefinitionCount(pdom, "SimpleCStructure::scsa", 1); } // test struct definitions and struct member references in C + @Test public void testSimpleCStructureReferences() throws Exception { assertReferenceCount(pdom, "SimpleCStructure", 2); assertReferenceCount(pdom, "SimpleCStructure::scsa", 2); } // test nesting of structs in C, they should not nest + @Test public void testDeepCStructure() throws Exception { assertType(pdom, "CStructure1", ICompositeType.class); assertType(pdom, "CStructure2", ICompositeType.class); @@ -94,6 +96,7 @@ public class CCompositeTypeTests extends PDOMTestBase { } // test "nested" struct declarations in C, they should not nest + @Test public void testDeepCStructureDeclarations() throws Exception { assertDeclarationCount(pdom, "CStructure1", 1); assertDeclarationCount(pdom, "CStructure1::CStructure2", 0); @@ -103,6 +106,7 @@ public class CCompositeTypeTests extends PDOMTestBase { } // test "nested" struct member declarations in C, they should not nest + @Test public void testDeepCStructureMemberDeclarations() throws Exception { assertDeclarationCount(pdom, "CStructure1::cs1a", 1); assertDeclarationCount(pdom, "CStructure1::cs1b", 1); @@ -114,6 +118,7 @@ public class CCompositeTypeTests extends PDOMTestBase { } // test "nested" struct definitions in C, they should not nest + @Test public void testDeepCStructureDefinitions() throws Exception { assertDefinitionCount(pdom, "CStructure1", 1); assertDefinitionCount(pdom, "CStructure1::CStructure2", 0); @@ -123,6 +128,7 @@ public class CCompositeTypeTests extends PDOMTestBase { } // test "nested" struct member definitions in C, they should not nest + @Test public void testDeepCStructureMemberDefinitions() throws Exception { assertDefinitionCount(pdom, "CStructure1::cs1a", 1); assertDefinitionCount(pdom, "CStructure1::cs1b", 1); @@ -134,6 +140,7 @@ public class CCompositeTypeTests extends PDOMTestBase { } // test "nested" struct references in C, they should not nest + @Test public void testDeepCStructureReferences() throws Exception { assertReferenceCount(pdom, "CStructure1", 2); assertReferenceCount(pdom, "CStructure1::CStructure2", 0); @@ -143,6 +150,7 @@ public class CCompositeTypeTests extends PDOMTestBase { } // test "nested" struct member references in C, they should not nest + @Test public void testDeepCStructureMemberReferences() throws Exception { assertReferenceCount(pdom, "CStructure1::cs1a", 2); assertReferenceCount(pdom, "CStructure1::cs1b", 3); @@ -162,6 +170,7 @@ public class CCompositeTypeTests extends PDOMTestBase { } //test union and "nested" union declarations in C, but there is no nesting in C + @Test public void testCUnionDeclarations() throws Exception { assertDeclarationCount(pdom, "CUnion1", 1); assertDeclarationCount(pdom, "CUnion1::CUnion2", 0); @@ -169,6 +178,7 @@ public class CCompositeTypeTests extends PDOMTestBase { } //test union and "nested" union definitons in C, but there is no nesting in C + @Test public void testCUnionDefinitions() throws Exception { assertDefinitionCount(pdom, "CUnion1", 1); assertDefinitionCount(pdom, "CUnion1::CUnion2", 0); @@ -176,6 +186,7 @@ public class CCompositeTypeTests extends PDOMTestBase { } //test union and "nested" union references in C, but there is no nesting in C + @Test public void testCUnionReferences() throws Exception { assertReferenceCount(pdom, "CUnion1", 2); assertReferenceCount(pdom, "CUnion1::CUnion2", 0); @@ -183,24 +194,28 @@ public class CCompositeTypeTests extends PDOMTestBase { } //test union member declarations in C + @Test public void testCUnionMemberDeclarations() throws Exception { assertDeclarationCount(pdom, "CUnion1::cu1a", 1); assertDeclarationCount(pdom, "CUnion1::cu1d", 1); } //test union member defintions in C + @Test public void testCUnionMemberDefinitions() throws Exception { assertDefinitionCount(pdom, "CUnion1::cu1a", 1); assertDefinitionCount(pdom, "CUnion1::cu1d", 1); } //test union member references in C + @Test public void testCUnionMemberReferences() throws Exception { assertReferenceCount(pdom, "CUnion1::cu1a", 2); assertReferenceCount(pdom, "CUnion1::cu1d", 1); } // test "nested" unions and structs declarations in C, they should not nest + @Test public void testCMixedDeclarations() throws Exception { assertDeclarationCount(pdom, "CMixedS1::CMixedU1", 0); assertDeclarationCount(pdom, "CMixedS1::CMixedU1::CMixedS2", 0); @@ -214,6 +229,7 @@ public class CCompositeTypeTests extends PDOMTestBase { } // test "nested" unions and structs definitions in C, they should not nest + @Test public void testCMixedDefinitions() throws Exception { assertDefinitionCount(pdom, "CMixedS1::CMixedU1", 0); assertDefinitionCount(pdom, "CMixedS1::CMixedU1::CMixedS2", 0); @@ -227,6 +243,7 @@ public class CCompositeTypeTests extends PDOMTestBase { } // test "nested" unions and structs references in C, they should not nest + @Test public void testCMixedReferences() throws Exception { assertReferenceCount(pdom, "CMixedS1::CMixedU1", 0); assertReferenceCount(pdom, "CMixedS1::CMixedU1::CMixedS2", 0); @@ -240,6 +257,7 @@ public class CCompositeTypeTests extends PDOMTestBase { } // test "nested" union members and struct members declarations in C, they should not nest + @Test public void testCMixedMemberDeclarations() throws Exception { assertDeclarationCount(pdom, "CMixedS1::CMixedU1::cmu1a", 0); assertDeclarationCount(pdom, "CMixedS1::CMixedU1::CMixedS2::cms2a", 0); @@ -253,6 +271,7 @@ public class CCompositeTypeTests extends PDOMTestBase { } // test "nested" union members and struct members definitions in C, they should not nest + @Test public void testCMixedMemberDefinitions() throws Exception { assertDefinitionCount(pdom, "CMixedS1::CMixedU1::cmu1a", 0); assertDefinitionCount(pdom, "CMixedS1::CMixedU1::CMixedS2::cms2a", 0); @@ -266,6 +285,7 @@ public class CCompositeTypeTests extends PDOMTestBase { } // test "nested" union members and struct members references in C, they should not nest + @Test public void testCMixedMemberReferences() throws Exception { assertReferenceCount(pdom, "CMixedS1::CMixedU1::cmu1a", 0); assertReferenceCount(pdom, "CMixedS1::CMixedU1::CMixedS2::cms2a", 0); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CFunctionTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CFunctionTests.java index 5e829fc4680..3212d32c817 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CFunctionTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CFunctionTests.java @@ -14,6 +14,10 @@ *******************************************************************************/ package org.eclipse.cdt.internal.pdom.tests; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IFunction; import org.eclipse.cdt.core.dom.ast.IParameter; @@ -23,8 +27,9 @@ import org.eclipse.cdt.internal.core.CCoreInternals; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.NullProgressMonitor; - -import junit.framework.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Tests for verifying whether the PDOM correctly stores information about @@ -34,19 +39,15 @@ public class CFunctionTests extends PDOMTestBase { protected ICProject project; protected PDOM pdom; - public static Test suite() { - return suite(CFunctionTests.class); - } - - @Override - protected void setUp() throws Exception { + @BeforeEach + protected void beforeEach() throws Exception { project = createProject("functionTests"); pdom = (PDOM) CCoreInternals.getPDOMManager().getPDOM(project); pdom.acquireReadLock(); } - @Override - protected void tearDown() throws Exception { + @AfterEach + protected void afterEach() throws Exception { pdom.releaseReadLock(); if (project != null) { project.getProject().delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, @@ -54,12 +55,14 @@ public class CFunctionTests extends PDOMTestBase { } } + @Test public void testExternCFunction() throws Exception { IBinding[] bindings = findQualifiedName(pdom, "externCFunction"); assertEquals(1, bindings.length); assertTrue(((IFunction) bindings[0]).isExtern()); } + @Test public void testStaticCFunction() throws Exception { // static elements cannot be found on global scope, see bug 161216 IBinding[] bindings = findUnqualifiedName(pdom, "staticCFunction"); @@ -67,24 +70,28 @@ public class CFunctionTests extends PDOMTestBase { assertTrue(((IFunction) bindings[0]).isStatic()); } + @Test public void testInlineCFunction() throws Exception { IBinding[] bindings = findQualifiedName(pdom, "inlineCFunction"); assertEquals(1, bindings.length); assertTrue(((IFunction) bindings[0]).isInline()); } + @Test public void testVarArgsCFunction() throws Exception { IBinding[] bindings = findQualifiedName(pdom, "varArgsCFunction"); assertEquals(1, bindings.length); assertTrue(((IFunction) bindings[0]).takesVarArgs()); } + @Test public void testNoReturnCFunction() throws Exception { IBinding[] bindings = findQualifiedName(pdom, "noReturnCFunction"); assertEquals(1, bindings.length); assertTrue(((IFunction) bindings[0]).isNoReturn()); } + @Test public void testKnRStyleFunctionWithProblemParameters() throws Exception { IBinding[] bindings = findQualifiedName(pdom, "KnRfunctionWithProblemParameters"); assertEquals(1, bindings.length); @@ -96,6 +103,7 @@ public class CFunctionTests extends PDOMTestBase { assertTrue(params[2].getType() instanceof ICBasicType); } + @Test public void testFunctionWithRegisterParam() throws Exception { IBinding[] bindings = findQualifiedName(pdom, "storageClassCFunction"); assertEquals(1, bindings.length); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPClassTemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPClassTemplateTests.java index 27d5886f515..d76eaacc881 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPClassTemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPClassTemplateTests.java @@ -14,7 +14,12 @@ *******************************************************************************/ package org.eclipse.cdt.internal.pdom.tests; -import java.util.Arrays; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.eclipse.cdt.core.dom.ast.IBasicType; import org.eclipse.cdt.core.dom.ast.IBinding; @@ -41,21 +46,16 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType; import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance; import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding; - -import junit.framework.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Tests PDOM class template related bindings */ public class CPPClassTemplateTests extends PDOMInlineCodeTestBase { - public static Test suite() { - return suite(CPPClassTemplateTests.class); - } - - @Override - public void setUp() throws Exception { - super.setUp(); + @BeforeEach + protected void beforeEach2() throws Exception { setUpSections(1); } @@ -71,20 +71,21 @@ public class CPPClassTemplateTests extends PDOMInlineCodeTestBase { // // Foo a; // Foo b; + @Test public void testSpecializations() throws Exception { IBinding[] as = pdom.findBindings(new char[][] { { 'a' } }, IndexFilter.ALL, npm()); IBinding[] bs = pdom.findBindings(new char[][] { { 'b' } }, IndexFilter.ALL, npm()); assertEquals(1, as.length); assertEquals(1, bs.length); - assertInstance(as[0], ICPPVariable.class); - assertInstance(bs[0], ICPPVariable.class); + assertInstanceOf(ICPPVariable.class, as[0]); + assertInstanceOf(ICPPVariable.class, bs[0]); ICPPVariable a = (ICPPVariable) as[0]; ICPPVariable b = (ICPPVariable) bs[0]; - assertInstance(a.getType(), ICPPSpecialization.class); - assertInstance(b.getType(), ICPPSpecialization.class); + assertInstanceOf(ICPPSpecialization.class, a.getType()); + assertInstanceOf(ICPPSpecialization.class, b.getType()); ICPPSpecialization asp = (ICPPSpecialization) a.getType(); ICPPSpecialization bsp = (ICPPSpecialization) b.getType(); @@ -94,8 +95,8 @@ public class CPPClassTemplateTests extends PDOMInlineCodeTestBase { assertEquals(1, aArgs.getAllParameterPositions().length); assertEquals(1, bArgs.getAllParameterPositions().length); - assertInstance(aArgs.getArgument(0).getTypeValue(), ICPPClassType.class); - assertInstance(bArgs.getArgument(0).getTypeValue(), ICPPClassType.class); + assertInstanceOf(ICPPClassType.class, aArgs.getArgument(0).getTypeValue()); + assertInstanceOf(ICPPClassType.class, bArgs.getArgument(0).getTypeValue()); assertEquals("A", ((ICPPClassType) aArgs.getArgument(0).getTypeValue()).getName()); assertEquals("B", ((ICPPClassType) bArgs.getArgument(0).getTypeValue()).getName()); @@ -109,6 +110,7 @@ public class CPPClassTemplateTests extends PDOMInlineCodeTestBase { // public: // int foo(C c) {return 1}; // }; + @Test public void testSimpleDefinition() throws Exception { assertDeclarationCount(pdom, "D", 1); IIndexFragmentBinding[] b = pdom.findBindings(new char[][] { { 'D' } }, IndexFilter.ALL_DECLARED, npm()); @@ -128,6 +130,7 @@ public class CPPClassTemplateTests extends PDOMInlineCodeTestBase { // public: // int foo(C c) {return 1}; // }; + @Test public void testDefinition() throws Exception { assertDeclarationCount(pdom, "D", 1); IIndexFragmentBinding[] b = pdom.findBindings(new char[][] { { 'D' } }, IndexFilter.ALL_DECLARED, npm()); @@ -138,8 +141,8 @@ public class CPPClassTemplateTests extends PDOMInlineCodeTestBase { assertEquals(1, tp.length); assertTrue(tp[0] instanceof ICPPTemplateTypeParameter); assertEquals("C", tp[0].getName()); - assertEquals(new String[] { "D", "C" }, tp[0].getQualifiedName()); - assertEquals(new char[][] { { 'D' }, { 'C' } }, tp[0].getQualifiedNameCharArray()); + assertArrayEquals(new String[] { "D", "C" }, tp[0].getQualifiedName()); + assertArrayOfArrayEquals(new char[][] { { 'D' }, { 'C' } }, tp[0].getQualifiedNameCharArray()); ICPPTemplateTypeParameter ctp = (ICPPTemplateTypeParameter) tp[0]; IType def = ctp.getDefault(); assertTrue(def instanceof IBasicType); @@ -154,6 +157,7 @@ public class CPPClassTemplateTests extends PDOMInlineCodeTestBase { // public: // int foo(C c, B b, A a) {return 1}; // }; + @Test public void testDefinition2() throws Exception { assertDeclarationCount(pdom, "E", 1); IIndexFragmentBinding[] b = pdom.findBindings(new char[][] { { 'E' } }, IndexFilter.ALL_DECLARED, npm()); @@ -165,31 +169,31 @@ public class CPPClassTemplateTests extends PDOMInlineCodeTestBase { assertTrue(tp[0] instanceof ICPPTemplateTypeParameter); assertEquals("A", tp[0].getName()); - assertEquals(new String[] { "E", "A" }, tp[0].getQualifiedName()); - assertEquals(new char[][] { { 'E' }, { 'A' } }, tp[0].getQualifiedNameCharArray()); + assertArrayEquals(new String[] { "E", "A" }, tp[0].getQualifiedName()); + assertArrayOfArrayEquals(new char[][] { { 'E' }, { 'A' } }, tp[0].getQualifiedNameCharArray()); ICPPTemplateTypeParameter ctpa = (ICPPTemplateTypeParameter) tp[0]; IType defa = ctpa.getDefault(); assertTrue(defa instanceof ICPPClassType); ICPPClassType ctdefa = (ICPPClassType) defa; - assertEquals(new char[][] { { 'T', 'A' } }, ctdefa.getQualifiedNameCharArray()); + assertArrayOfArrayEquals(new char[][] { { 'T', 'A' } }, ctdefa.getQualifiedNameCharArray()); assertTrue(tp[1] instanceof ICPPTemplateTypeParameter); assertEquals("B", tp[1].getName()); - assertEquals(new String[] { "E", "B" }, tp[1].getQualifiedName()); - assertEquals(new char[][] { { 'E' }, { 'B' } }, tp[1].getQualifiedNameCharArray()); + assertArrayEquals(new String[] { "E", "B" }, tp[1].getQualifiedName()); + assertArrayOfArrayEquals(new char[][] { { 'E' }, { 'B' } }, tp[1].getQualifiedNameCharArray()); ICPPTemplateTypeParameter ctpb = (ICPPTemplateTypeParameter) tp[1]; IType defb = ctpb.getDefault(); assertNull(defb); assertTrue(tp[2] instanceof ICPPTemplateTypeParameter); assertEquals("C", tp[2].getName()); - assertEquals(new String[] { "E", "C" }, tp[2].getQualifiedName()); - assertEquals(new char[][] { { 'E' }, { 'C' } }, tp[2].getQualifiedNameCharArray()); + assertArrayEquals(new String[] { "E", "C" }, tp[2].getQualifiedName()); + assertArrayOfArrayEquals(new char[][] { { 'E' }, { 'C' } }, tp[2].getQualifiedNameCharArray()); ICPPTemplateTypeParameter ctpc = (ICPPTemplateTypeParameter) tp[2]; IType defc = ctpc.getDefault(); assertTrue(defc instanceof ICPPClassType); ICPPClassType ctdefc = (ICPPClassType) defc; - assertEquals(new char[][] { { 'T', 'C' } }, ctdefc.getQualifiedNameCharArray()); + assertArrayOfArrayEquals(new char[][] { { 'T', 'C' } }, ctdefc.getQualifiedNameCharArray()); assertEquals(0, ct.getPartialSpecializations().length); } @@ -205,22 +209,23 @@ public class CPPClassTemplateTests extends PDOMInlineCodeTestBase { // void bar() { // foo->f(*new A()); // } + @Test public void testFunctionPointer() throws Exception { IIndexFragmentBinding[] bs = pdom.findBindings(new char[][] { "foo".toCharArray() }, IndexFilter.ALL, npm()); assertEquals(1, bs.length); - assertInstance(bs[0], ICPPVariable.class); + assertInstanceOf(ICPPVariable.class, bs[0]); ICPPVariable var = (ICPPVariable) bs[0]; - assertInstance(var.getType(), ICPPClassType.class); + assertInstanceOf(ICPPClassType.class, var.getType()); ICPPClassType ct = (ICPPClassType) var.getType(); IField[] fields = ClassTypeHelper.getFields(ct); assertEquals(1, fields.length); - assertInstance(fields[0].getType(), IPointerType.class); + assertInstanceOf(IPointerType.class, fields[0].getType()); IPointerType pt = (IPointerType) fields[0].getType(); - assertInstance(pt.getType(), IFunctionType.class); + assertInstanceOf(IFunctionType.class, pt.getType()); IFunctionType ft = (IFunctionType) pt.getType(); - assertInstance(ft.getReturnType(), ICPPClassType.class); + assertInstanceOf(ICPPClassType.class, ft.getReturnType()); assertEquals(1, ft.getParameterTypes().length); - assertInstance(ft.getParameterTypes()[0], ICPPClassType.class); + assertInstanceOf(ICPPClassType.class, ft.getParameterTypes()[0]); } // template @@ -239,6 +244,7 @@ public class CPPClassTemplateTests extends PDOMInlineCodeTestBase { // // D dn; // D dint; + @Test public void testExplicitInstantiation() throws Exception { { // template @@ -247,11 +253,11 @@ public class CPPClassTemplateTests extends PDOMInlineCodeTestBase { assertTrue(!(b[0] instanceof ICPPClassTemplate) || !(b[1] instanceof ICPPClassTemplate)); int i = b[0] instanceof ICPPClassTemplate ? 0 : 1; - assertInstance(b[i], ICPPClassTemplate.class); + assertInstanceOf(ICPPClassTemplate.class, b[i]); ICPPClassTemplate ct = (ICPPClassTemplate) b[i]; ICPPTemplateParameter[] tp = ct.getTemplateParameters(); assertEquals(1, tp.length); - assertInstance(tp[i], ICPPTemplateTypeParameter.class); + assertInstanceOf(ICPPTemplateTypeParameter.class, tp[i]); ICPPTemplateTypeParameter ctp = (ICPPTemplateTypeParameter) tp[i]; assertNull(ctp.getDefault()); } @@ -260,16 +266,16 @@ public class CPPClassTemplateTests extends PDOMInlineCodeTestBase { assertDeclarationCount(pdom, "dn", 1); IIndexFragmentBinding[] b = pdom.findBindings(new char[][] { "dn".toCharArray() }, IndexFilter.ALL, npm()); assertEquals(1, b.length); - assertInstance(b[0], ICPPVariable.class); + assertInstanceOf(ICPPVariable.class, b[0]); ICPPVariable var = (ICPPVariable) b[0]; - assertInstance(var.getType(), ICPPClassType.class); - assertInstance(var.getType(), ICPPSpecialization.class); + assertInstanceOf(ICPPClassType.class, var.getType()); + assertInstanceOf(ICPPSpecialization.class, var.getType()); ICPPSpecialization cp = (ICPPSpecialization) var.getType(); ICPPTemplateParameterMap m = cp.getTemplateParameterMap(); assertEquals(1, m.getAllParameterPositions().length); ICPPTemplateArgument arg = m.getArgument(0); - assertInstance(arg.getTypeValue(), ICPPClassType.class); - assertEquals(new String[] { "N" }, ((ICPPClassType) arg.getTypeValue()).getQualifiedName()); + assertInstanceOf(ICPPClassType.class, arg.getTypeValue()); + assertArrayEquals(new String[] { "N" }, ((ICPPClassType) arg.getTypeValue()).getQualifiedName()); } { @@ -279,13 +285,13 @@ public class CPPClassTemplateTests extends PDOMInlineCodeTestBase { assertEquals(1, b.length); assertTrue(b[0] instanceof ICPPVariable); ICPPVariable var = (ICPPVariable) b[0]; - assertInstance(var.getType(), ICPPClassType.class); - assertInstance(var.getType(), ICPPSpecialization.class); + assertInstanceOf(ICPPClassType.class, var.getType()); + assertInstanceOf(ICPPSpecialization.class, var.getType()); ICPPSpecialization cp = (ICPPSpecialization) var.getType(); ICPPTemplateParameterMap m = cp.getTemplateParameterMap(); assertEquals(1, m.getAllParameterPositions().length); ICPPTemplateArgument arg = m.getArgument(0); - assertInstance(arg.getTypeValue(), IBasicType.class); + assertInstanceOf(IBasicType.class, arg.getTypeValue()); assertEquals(IBasicType.Kind.eInt, ((IBasicType) arg.getTypeValue()).getKind()); } } @@ -296,6 +302,7 @@ public class CPPClassTemplateTests extends PDOMInlineCodeTestBase { // }; // template // using A = S; + @Test public void testSimpleAliasDefinition() throws Exception { assertDeclarationCount(pdom, "A", 1); IIndexFragmentBinding[] bindingA = pdom.findBindings(new char[][] { { 'A' } }, IndexFilter.ALL_DECLARED, npm()); @@ -328,6 +335,7 @@ public class CPPClassTemplateTests extends PDOMInlineCodeTestBase { // }; // template // using A = S; + @Test public void testSimpleAliasDefinitionDefaultTemplateArgument() throws Exception { assertDeclarationCount(pdom, "A", 1); IIndexFragmentBinding[] bindingA = pdom.findBindings(new char[][] { { 'A' } }, IndexFilter.ALL_DECLARED, npm()); @@ -370,6 +378,7 @@ public class CPPClassTemplateTests extends PDOMInlineCodeTestBase { // }; // template // using A = S; + @Test public void testSimpleAliasDefinitionValueTemplateArguments() throws Exception { assertDeclarationCount(pdom, "A", 1); IIndexFragmentBinding[] bindingA = pdom.findBindings(new char[][] { { 'A' } }, IndexFilter.ALL_DECLARED, npm()); @@ -391,7 +400,7 @@ public class CPPClassTemplateTests extends PDOMInlineCodeTestBase { ICPPTemplateArgument aT2DefaultArgument = templateParameterAT2.getDefaultValue(); assertNotNull(aT2DefaultArgument); assertTrue(new CPPBasicType(IBasicType.Kind.eInt, 0).isSameType(aT2DefaultArgument.getTypeOfNonTypeValue())); - assertEquals(5, aT2DefaultArgument.getNonTypeValue().numberValue().longValue()); + assertEquals(5L, aT2DefaultArgument.getNonTypeValue().numberValue().longValue()); assertEquals(0, templateParameterAT2.getTemplateNestingLevel()); assertDeclarationCount(pdom, "S", 1); @@ -409,6 +418,7 @@ public class CPPClassTemplateTests extends PDOMInlineCodeTestBase { // }; // template class TT> // using A = S; + @Test public void testSimpleAliasTemplateParameter() throws Exception { assertDeclarationCount(pdom, "A", 1); IIndexFragmentBinding[] bindingA = pdom.findBindings(new char[][] { { 'A' } }, IndexFilter.ALL_DECLARED, npm()); @@ -434,11 +444,12 @@ public class CPPClassTemplateTests extends PDOMInlineCodeTestBase { // using A = S; // A aB; // S sB; + @Test public void testSimpleAliasReference() throws Exception { assertDeclarationCount(pdom, "A", 1); IIndexFragmentBinding[] bindingA = pdom.findBindings(new char[][] { { 'A' } }, IndexFilter.ALL_DECLARED, npm()); assertEquals(1, bindingA.length); - assertInstance(bindingA[0], ICPPAliasTemplate.class); + assertInstanceOf(ICPPAliasTemplate.class, bindingA[0]); ICPPAliasTemplate aliasA = (ICPPAliasTemplate) bindingA[0]; ICPPTemplateParameter[] aliasParameters = aliasA.getTemplateParameters(); assertEquals(1, aliasParameters.length); @@ -450,15 +461,15 @@ public class CPPClassTemplateTests extends PDOMInlineCodeTestBase { IIndexFragmentBinding[] bindingB = pdom.findBindings(new char[][] { { 'B' } }, IndexFilter.ALL_DECLARED, npm()); assertEquals(1, bindingB.length); - assertInstance(bindingB[0], ICPPClassType.class); + assertInstanceOf(ICPPClassType.class, bindingB[0]); IIndexFragmentBinding[] bindingVarSB = pdom.findBindings(new char[][] { "sB".toCharArray() }, IndexFilter.ALL, npm()); assertEquals(1, bindingVarSB.length); - assertInstance(bindingVarSB[0], ICPPVariable.class); + assertInstanceOf(ICPPVariable.class, bindingVarSB[0]); ICPPVariable variableSB = (ICPPVariable) bindingVarSB[0]; IType varSBType = variableSB.getType(); - assertInstance(varSBType, ICPPClassSpecialization.class); + assertInstanceOf(ICPPClassSpecialization.class, varSBType); ICPPClassSpecialization templateInstanceSB = (ICPPClassSpecialization) varSBType; IIndexFragmentBinding[] bindingVarAB = pdom.findBindings(new char[][] { "aB".toCharArray() }, IndexFilter.ALL, @@ -467,13 +478,13 @@ public class CPPClassTemplateTests extends PDOMInlineCodeTestBase { assertTrue(bindingVarAB[0] instanceof ICPPVariable); ICPPVariable variableAB = (ICPPVariable) bindingVarAB[0]; IType varABType = variableAB.getType(); - assertInstance(varABType, ICPPAliasTemplateInstance.class); + assertInstanceOf(ICPPAliasTemplateInstance.class, varABType); ICPPAliasTemplateInstance aliasInstanceAB = (ICPPAliasTemplateInstance) varABType; assertTrue(varABType.isSameType(templateInstanceSB)); assertTrue(aliasInstanceAB.getTemplateDefinition().isSameType(aliasA)); assertEquals("A", aliasInstanceAB.getName()); IType aliasedType = aliasInstanceAB.getType(); - assertInstance(aliasedType, ICPPTemplateInstance.class); + assertInstanceOf(ICPPTemplateInstance.class, aliasedType); ICPPTemplateArgument[] args = ((ICPPTemplateInstance) aliasedType).getTemplateArguments(); assertEquals(1, args.length); assertTrue(((ICPPClassType) bindingB[0]).isSameType(args[0].getTypeValue())); @@ -483,6 +494,7 @@ public class CPPClassTemplateTests extends PDOMInlineCodeTestBase { // template using A= T; // nesting level 1 // A x; // }; + @Test public void testPDOMNestedAliasDeclarationNestingLevel() throws Exception { IIndexFragmentBinding[] bindingCT = pdom.findBindings(new char[][] { "CT".toCharArray() }, IndexFilter.ALL_DECLARED, npm()); @@ -509,6 +521,7 @@ public class CPPClassTemplateTests extends PDOMInlineCodeTestBase { // template class CT { // nesting level 0 // typedef Alias TYPE; // }; + @Test public void testPDOMAliasDeclarationNestingLevel() throws Exception { assertDeclarationCount(pdom, "A", 1); IIndexFragmentBinding[] bindingA = pdom.findBindings(new char[][] { { 'A' } }, IndexFilter.ALL_DECLARED, npm()); @@ -540,21 +553,7 @@ public class CPPClassTemplateTests extends PDOMInlineCodeTestBase { assertEquals(0, templateParameterTofCT.getTemplateNestingLevel()); } - @Override - protected void assertInstance(Object o, Class c) { - assertNotNull(o); - assertTrue("Expected " + c.getName() + " but got " + o.getClass().getName(), c.isInstance(o)); - } - - protected void assertEquals(char[] c1, char[] c2) { - assertTrue(Arrays.equals(c1, c2)); - } - - protected void assertEquals(String[] s1, String[] s2) { - assertTrue(Arrays.equals(s1, s2)); - } - - protected void assertEquals(char[][] c1, char[][] c2) { + protected void assertArrayOfArrayEquals(char[][] c1, char[][] c2) { if (c1 == null || c2 == null) { assertTrue(c1 == c2); return; @@ -562,7 +561,7 @@ public class CPPClassTemplateTests extends PDOMInlineCodeTestBase { assertEquals(c1.length, c2.length); for (int i = 0; i < c1.length; i++) { - assertEquals(c1[i], c2[i]); + assertArrayEquals(c1[i], c2[i]); } } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPCompositeTypeTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPCompositeTypeTests.java index aa0400d35dc..b3f69ad16b8 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPCompositeTypeTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPCompositeTypeTests.java @@ -18,9 +18,9 @@ import org.eclipse.cdt.core.dom.ast.ICompositeType; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.internal.core.CCoreInternals; import org.eclipse.cdt.internal.core.pdom.PDOM; - -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Tests for verifying whether the PDOM correctly stores information about @@ -31,12 +31,8 @@ public class CPPCompositeTypeTests extends PDOMTestBase { private ICProject project; private PDOM pdom; - public static Test suite() { - return new TestSuite(CPPCompositeTypeTests.class); - } - - @Override - protected void setUp() throws Exception { + @BeforeEach + protected void beforeEach() throws Exception { CPPCompositeTypeTests foo = null; project = createProject("compositeTypeTests"); @@ -44,42 +40,49 @@ public class CPPCompositeTypeTests extends PDOMTestBase { pdom.acquireReadLock(); } - @Override - protected void tearDown() throws Exception { + @AfterEach + protected void afterEach() throws Exception { pdom.releaseReadLock(); } + @Test public void testSimpleStructure() throws Exception { assertType(pdom, "SimpleStructure", ICompositeType.class); } + @Test public void testSimpleStructureDeclarations() throws Exception { assertDeclarationCount(pdom, "SimpleStructure", 1); assertDeclarationCount(pdom, "SimpleStructure::ssa", 1); } + @Test public void testSimpleStructureDefinitions() throws Exception { assertDefinitionCount(pdom, "SimpleStructure", 1); assertDefinitionCount(pdom, "SimpleStructure::ssa", 1); } + @Test public void testSimpleStructureReferences() throws Exception { assertReferenceCount(pdom, "SimpleStructure", 2); assertReferenceCount(pdom, "SimpleStructure::ssa", 2); } + @Test public void testDeepStructure() throws Exception { assertType(pdom, "Structure1", ICompositeType.class); assertType(pdom, "Structure1::Structure2", ICompositeType.class); assertType(pdom, "Structure1::Structure2::Structure3", ICompositeType.class); } + @Test public void testDeepStructureDeclarations() throws Exception { assertDeclarationCount(pdom, "Structure1", 1); assertDeclarationCount(pdom, "Structure1::Structure2", 1); assertDeclarationCount(pdom, "Structure1::Structure2::Structure3", 1); } + @Test public void testDeepStructureMemberDeclarations() throws Exception { assertDeclarationCount(pdom, "Structure1::s1a", 1); assertDeclarationCount(pdom, "Structure1::s1b", 1); @@ -88,12 +91,14 @@ public class CPPCompositeTypeTests extends PDOMTestBase { assertDeclarationCount(pdom, "Structure1::Structure2::Structure3::s3a", 1); } + @Test public void testDeepStructureDefinitions() throws Exception { assertDefinitionCount(pdom, "Structure1", 1); assertDefinitionCount(pdom, "Structure1::Structure2", 1); assertDefinitionCount(pdom, "Structure1::Structure2::Structure3", 1); } + @Test public void testDeepStructureMemberDefinitions() throws Exception { assertDefinitionCount(pdom, "Structure1::s1a", 1); assertDefinitionCount(pdom, "Structure1::s1b", 1); @@ -102,12 +107,14 @@ public class CPPCompositeTypeTests extends PDOMTestBase { assertDefinitionCount(pdom, "Structure1::Structure2::Structure3::s3a", 1); } + @Test public void testDeepStructureReferences() throws Exception { assertReferenceCount(pdom, "Structure1", 6); assertReferenceCount(pdom, "Structure1::Structure2", 4); assertReferenceCount(pdom, "Structure1::Structure2::Structure3", 2); } + @Test public void testDeepStructureMemberReferences() throws Exception { assertReferenceCount(pdom, "Structure1::s1a", 2); assertReferenceCount(pdom, "Structure1::s1b", 3); @@ -116,36 +123,43 @@ public class CPPCompositeTypeTests extends PDOMTestBase { assertReferenceCount(pdom, "Structure1::Structure2::Structure3::s3a", 8); } + @Test public void testUnionDeclarations() throws Exception { assertDeclarationCount(pdom, "Union1", 1); assertDeclarationCount(pdom, "Union1::Union2", 1); } + @Test public void testUnionDefinitions() throws Exception { assertDefinitionCount(pdom, "Union1", 1); assertDefinitionCount(pdom, "Union1::Union2", 1); } + @Test public void testUnionReferences() throws Exception { assertReferenceCount(pdom, "Union1", 4); assertReferenceCount(pdom, "Union1::Union2", 2); } + @Test public void testUnionMemberDeclarations() throws Exception { assertDeclarationCount(pdom, "Union1::u1a", 1); assertDeclarationCount(pdom, "Union1::u1d", 1); } + @Test public void testUnionMemberDefinitions() throws Exception { assertDefinitionCount(pdom, "Union1::u1a", 1); assertDefinitionCount(pdom, "Union1::u1d", 1); } + @Test public void testUnionMemberReferences() throws Exception { assertReferenceCount(pdom, "Union1::u1a", 2); assertReferenceCount(pdom, "Union1::u1d", 1); } + @Test public void testMixedDeclarations() throws Exception { assertDeclarationCount(pdom, "MixedS1::MixedU1", 1); assertDeclarationCount(pdom, "MixedS1::MixedU1::MixedS2", 1); @@ -153,6 +167,7 @@ public class CPPCompositeTypeTests extends PDOMTestBase { assertDeclarationCount(pdom, "MixedS1::MixedS3", 1); } + @Test public void testMixedDefinitions() throws Exception { assertDefinitionCount(pdom, "MixedS1::MixedU1", 1); assertDefinitionCount(pdom, "MixedS1::MixedU1::MixedS2", 1); @@ -160,6 +175,7 @@ public class CPPCompositeTypeTests extends PDOMTestBase { assertDefinitionCount(pdom, "MixedS1::MixedS3", 1); } + @Test public void testMixedReferences() throws Exception { assertReferenceCount(pdom, "MixedS1::MixedU1", 6); assertReferenceCount(pdom, "MixedS1::MixedU1::MixedS2", 2); @@ -167,6 +183,7 @@ public class CPPCompositeTypeTests extends PDOMTestBase { assertReferenceCount(pdom, "MixedS1::MixedS3", 2); } + @Test public void testMixedMemberDeclarations() throws Exception { assertDeclarationCount(pdom, "MixedS1::MixedU1::mu1a", 1); assertDeclarationCount(pdom, "MixedS1::MixedU1::MixedS2::ms2a", 1); @@ -174,6 +191,7 @@ public class CPPCompositeTypeTests extends PDOMTestBase { assertDeclarationCount(pdom, "MixedS1::MixedS3::ms3a", 1); } + @Test public void testMixedMemberDefinitions() throws Exception { assertDefinitionCount(pdom, "MixedS1::MixedU1::mu1a", 1); assertDefinitionCount(pdom, "MixedS1::MixedU1::MixedS2::ms2a", 1); @@ -181,6 +199,7 @@ public class CPPCompositeTypeTests extends PDOMTestBase { assertDefinitionCount(pdom, "MixedS1::MixedS3::ms3a", 1); } + @Test public void testMixedMemberReferences() throws Exception { assertReferenceCount(pdom, "MixedS1::MixedU1::mu1a", 2); assertReferenceCount(pdom, "MixedS1::MixedU1::MixedS2::ms2a", 2); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPFieldTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPFieldTests.java index d57e25f881c..4763b4c8374 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPFieldTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPFieldTests.java @@ -14,6 +14,9 @@ package org.eclipse.cdt.internal.pdom.tests; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IBasicType; import org.eclipse.cdt.core.dom.ast.IBinding; @@ -26,8 +29,9 @@ import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.NullProgressMonitor; - -import junit.framework.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Tests for verifying whether the PDOM correctly stores information about @@ -38,19 +42,15 @@ public class CPPFieldTests extends PDOMTestBase { protected PDOM pdom; protected ICProject project; - public static Test suite() { - return suite(CPPFieldTests.class); - } - - @Override - protected void setUp() throws Exception { + @BeforeEach + protected void beforeEach() throws Exception { project = createProject("fieldTests"); pdom = (PDOM) CCoreInternals.getPDOMManager().getPDOM(project); pdom.acquireReadLock(); } - @Override - protected void tearDown() throws Exception { + @AfterEach + protected void afterEach() throws Exception { pdom.releaseReadLock(); if (project != null) { project.getProject().delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, @@ -58,46 +58,57 @@ public class CPPFieldTests extends PDOMTestBase { } } + @Test public void testFieldDeclarations() throws Exception { assertDeclarationCount(pdom, "Class1::c1a", 1); } + @Test public void testFieldDefinitions() throws Exception { assertDefinitionCount(pdom, "Class1::c1a", 1); } + @Test public void testFieldReferences() throws Exception { assertReferenceCount(pdom, "Class1::c1a", 4); } + @Test public void testInheritedFieldDeclarations() throws Exception { assertDeclarationCount(pdom, "Class2::c1a", 0); } + @Test public void testInheritedFieldDefinitions() throws Exception { assertDefinitionCount(pdom, "Class2::c1a", 0); } + @Test public void testInheritedFieldReferences() throws Exception { assertReferenceCount(pdom, "Class2::c1a", 0); } + @Test public void testDefaultPrivateField() throws Exception { assertCPPMemberVisibility(pdom, "Class1::defaultField", ICPPMember.v_private); } + @Test public void testPrivateField() throws Exception { assertCPPMemberVisibility(pdom, "Class1::privateField", ICPPMember.v_private); } + @Test public void testProtectedField() throws Exception { assertCPPMemberVisibility(pdom, "Class1::protectedField", ICPPMember.v_protected); } + @Test public void testPublicField() throws Exception { assertCPPMemberVisibility(pdom, "Class1::publicField", ICPPMember.v_public); } + @Test public void testMutableField() throws Exception { IBinding[] bindings = findQualifiedName(pdom, "Class1::mutableField"); assertEquals(1, bindings.length); @@ -105,6 +116,7 @@ public class CPPFieldTests extends PDOMTestBase { assertTrue(field.isMutable()); } + @Test public void testStaticField() throws Exception { IBinding[] bindings = findQualifiedName(pdom, "Class1::staticField"); assertEquals(1, bindings.length); @@ -112,18 +124,22 @@ public class CPPFieldTests extends PDOMTestBase { assertTrue(field.isStatic()); } + @Test public void testIntField() throws Exception { assertFieldType(pdom, "Class1::c1a", IBasicType.t_int); } + @Test public void testDoubleField() throws Exception { assertFieldType(pdom, "Class1::c1b", IBasicType.t_double); } + @Test public void testCharField() throws Exception { assertFieldType(pdom, "Class2::c2a", IBasicType.t_char); } + @Test public void testFloatField() throws Exception { assertFieldType(pdom, "Class2::c2b", IBasicType.t_float); } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPFunctionTemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPFunctionTemplateTests.java index ae82028abed..a392f4ae17c 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPFunctionTemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPFunctionTemplateTests.java @@ -14,6 +14,9 @@ *******************************************************************************/ package org.eclipse.cdt.internal.pdom.tests; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; + import java.util.Arrays; import java.util.List; @@ -23,15 +26,10 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance; import org.eclipse.cdt.core.index.IndexFilter; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInstanceCache; import org.eclipse.cdt.internal.core.index.IIndexFragment; - -import junit.framework.Test; +import org.junit.jupiter.api.Test; public class CPPFunctionTemplateTests extends PDOMInlineCodeTestBase { - public static Test suite() { - return suite(CPPFunctionTemplateTests.class); - } - /*************************************************************************/ // template @@ -53,12 +51,13 @@ public class CPPFunctionTemplateTests extends PDOMInlineCodeTestBase { // foo(*new C3(), *new C2()); // foo(*new C1(), *new C3()); // } + @Test public void testSimpleInstantiation() throws Exception { setUpSections(1); IBinding[] bs = pdom.findBindings(new char[][] { "foo".toCharArray() }, IndexFilter.ALL_DECLARED, npm()); assertEquals(2, bs.length); - assertInstance(bs[0], ICPPFunctionTemplate.class); - assertInstance(bs[1], ICPPFunctionTemplate.class); + assertInstanceOf(ICPPFunctionTemplate.class, bs[0]); + assertInstanceOf(ICPPFunctionTemplate.class, bs[1]); boolean b = ((ICPPFunctionTemplate) bs[0]).getTemplateParameters().length == 1; ICPPFunctionTemplate fooX = (ICPPFunctionTemplate) bs[b ? 0 : 1]; diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPFunctionTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPFunctionTests.java index cd056891704..332d78087b4 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPFunctionTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPFunctionTests.java @@ -15,6 +15,12 @@ *******************************************************************************/ package org.eclipse.cdt.internal.pdom.tests; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IBasicType; import org.eclipse.cdt.core.dom.ast.IBinding; @@ -33,8 +39,9 @@ import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; - -import junit.framework.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Tests for verifying whether the PDOM correctly stores information about @@ -44,62 +51,64 @@ public class CPPFunctionTests extends PDOMTestBase { protected ICProject project; protected PDOM pdom; - public static Test suite() { - return suite(CPPFunctionTests.class); - } - - @Override - protected void setUp() throws Exception { + @BeforeEach + protected void beforeEach() throws Exception { project = createProject("functionTests"); pdom = (PDOM) CCoreInternals.getPDOMManager().getPDOM(project); pdom.acquireReadLock(); } - @Override - protected void tearDown() throws Exception { + @AfterEach + protected void afterEach() throws Exception { pdom.releaseReadLock(); if (project != null) { project.getProject().delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, npm()); } } + @Test public void testPointerToFunctionType() throws Exception { assertDeclarationCount(pdom, "int2intPtr", 1); IIndexFragmentBinding[] b = pdom.findBindings(new char[][] { "int2intPtr".toCharArray() }, IndexFilter.ALL, npm()); assertEquals(1, b.length); - assertInstance(b[0], ICPPVariable.class); + assertInstanceOf(ICPPVariable.class, b[0]); ICPPVariable v = (ICPPVariable) b[0]; - assertInstance(v.getType(), IPointerType.class); + assertInstanceOf(IPointerType.class, v.getType()); IPointerType pt = (IPointerType) v.getType(); - assertInstance(pt.getType(), IFunctionType.class); + assertInstanceOf(IFunctionType.class, pt.getType()); IFunctionType ft = (IFunctionType) pt.getType(); - assertInstance(ft.getReturnType(), ICPPBasicType.class); + assertInstanceOf(ICPPBasicType.class, ft.getReturnType()); assertEquals(1, ft.getParameterTypes().length); - assertInstance(ft.getParameterTypes()[0], ICPPBasicType.class); + assertInstanceOf(ICPPBasicType.class, ft.getParameterTypes()[0]); } + @Test public void testFunctionType() throws Exception { assertType(pdom, "normalDeclaration1", ICPPFunction.class); assertType(pdom, "normalDeclaration2", ICPPFunction.class); } + @Test public void testFunctionDeclarations() throws Exception { assertDeclarationCount(pdom, "normalDeclaration1", 1); assertDeclarationCount(pdom, "normalDeclaration2", 1); } + @Test public void testFunctionDefinitions() throws Exception { assertDefinitionCount(pdom, "normalDeclaration1", 1); assertDefinitionCount(pdom, "normalDeclaration2", 1); } + @Test public void testFunctionReferences() throws Exception { assertReferenceCount(pdom, "normalDeclaration1", 2); assertReferenceCount(pdom, "normalDeclaration2", 3); assertReferenceCount(pdom, "forwardDeclaration", 2); } + @Test public void testParameters() throws Exception { IBinding[] bindings = findQualifiedName(pdom, "normalCPPFunction"); assertEquals(1, bindings.length); @@ -113,6 +122,7 @@ public class CPPFunctionTests extends PDOMTestBase { assertEquals("p3", parameters[2].getName()); } + @Test public void testStorageClassSpecParameters() throws Exception { IBinding[] bindings = findQualifiedName(pdom, "storageClassCPPFunction"); assertEquals(1, bindings.length); @@ -121,12 +131,14 @@ public class CPPFunctionTests extends PDOMTestBase { assertEquals(2, parameters.length); } + @Test public void testExternCPPFunction() throws Exception { IBinding[] bindings = findQualifiedName(pdom, "externCPPFunction"); assertEquals(1, bindings.length); assertTrue(((ICPPFunction) bindings[0]).isExtern()); } + @Test public void testStaticCPPFunction() throws Exception { // Static elements cannot be found in global scope, see bug 161216 IBinding[] bindings = findUnqualifiedName(pdom, "staticCPPFunction"); @@ -134,12 +146,14 @@ public class CPPFunctionTests extends PDOMTestBase { assertTrue(((ICPPFunction) bindings[0]).isStatic()); } + @Test public void testInlineCPPFunction() throws Exception { IBinding[] bindings = findQualifiedName(pdom, "inlineCPPFunction"); assertEquals(1, bindings.length); assertTrue(((ICPPFunction) bindings[0]).isInline()); } + @Test public void testVarArgsCPPFunction() throws Exception { IBinding[] bindings = findQualifiedName(pdom, "varArgsCPPFunction"); assertEquals(1, bindings.length); @@ -158,6 +172,7 @@ public class CPPFunctionTests extends PDOMTestBase { assertTrue(((ICPPFunction) bindings[0]).isNoDiscard()); } + @Test public void testNoReturnCPPFunction() throws Exception { assertNoReturnFunction("noReturnCPPFunction"); assertNoReturnFunction("trailingNoReturnStdAttributeDecl"); @@ -166,6 +181,7 @@ public class CPPFunctionTests extends PDOMTestBase { assertNoReturnFunction("leadingNoReturnStdAttributeDef"); } + @Test public void testNoDiscardCPPFunction() throws Exception { assertNoDiscardFunction("noDiscardCPPFunction"); assertNoDiscardFunction("trailingNoDiscardStdAttributeDecl"); @@ -174,35 +190,43 @@ public class CPPFunctionTests extends PDOMTestBase { assertNoDiscardFunction("leadingNoDiscardStdAttributeDef"); } + @Test public void testForwardDeclarationType() throws Exception { assertType(pdom, "forwardDeclaration", ICPPFunction.class); } + @Test public void testForwardDeclaration() throws Exception { assertDeclarationCount(pdom, "forwardDeclaration", 2); assertDefinitionCount(pdom, "forwardDeclaration", 1); } + @Test public void testVoidFunction() throws Exception { assertReturnType(pdom, "voidCPPFunction", IBasicType.t_void); } + @Test public void testIntFunction() throws Exception { assertReturnType(pdom, "intCPPFunction", IBasicType.t_int); } + @Test public void testDoubleFunction() throws Exception { assertReturnType(pdom, "doubleCPPFunction", IBasicType.t_double); } + @Test public void testCharFunction() throws Exception { assertReturnType(pdom, "charCPPFunction", IBasicType.t_char); } + @Test public void testFloatFunction() throws Exception { assertReturnType(pdom, "floatCPPFunction", IBasicType.t_float); } + @Test public void testOverloadedFunction() throws Exception { IBinding[] bindings = findQualifiedName(pdom, "overloadedFunction"); assertEquals(2, bindings.length); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPVariableTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPVariableTests.java index 09b57ce44ea..cb21602ecff 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPVariableTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPVariableTests.java @@ -15,6 +15,10 @@ package org.eclipse.cdt.internal.pdom.tests; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable; import org.eclipse.cdt.core.model.ICProject; @@ -22,8 +26,9 @@ import org.eclipse.cdt.internal.core.CCoreInternals; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.NullProgressMonitor; - -import junit.framework.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Tests for verifying whether the PDOM correctly stores information about @@ -34,19 +39,15 @@ public class CPPVariableTests extends PDOMTestBase { protected ICProject project; protected PDOM pdom; - public static Test suite() { - return suite(CPPVariableTests.class); - } - - @Override - protected void setUp() throws Exception { + @BeforeEach + protected void beforeEach() throws Exception { project = createProject("variableTests"); pdom = (PDOM) CCoreInternals.getPDOMManager().getPDOM(project); pdom.acquireReadLock(); } - @Override - protected void tearDown() throws Exception { + @AfterEach + protected void afterEach() throws Exception { pdom.releaseReadLock(); if (project != null) { project.getProject().delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, @@ -54,6 +55,7 @@ public class CPPVariableTests extends PDOMTestBase { } } + @Test public void testCPPAutoVariable() throws Exception { IBinding[] bindings = findQualifiedName(pdom, "autoCPPVariable"); assertEquals(1, bindings.length); @@ -62,6 +64,7 @@ public class CPPVariableTests extends PDOMTestBase { assertFalse(variable.isStatic()); } + @Test public void testCPPExternVariable() throws Exception { IBinding[] bindings = findQualifiedName(pdom, "externCPPVariable"); assertEquals(1, bindings.length); @@ -69,12 +72,14 @@ public class CPPVariableTests extends PDOMTestBase { assertTrue(variable.isExtern()); } + @Test public void testCPPRegisterVariable() throws Exception { IBinding[] bindings = findQualifiedName(pdom, "registerCPPVariable"); assertEquals(1, bindings.length); ICPPVariable variable = (ICPPVariable) bindings[0]; } + @Test public void testCPPStaticVariable() throws Exception { // static elements cannot be found on global scope, see bug 161216 IBinding[] bindings = findUnqualifiedName(pdom, "staticCPPVariable"); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CVariableTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CVariableTests.java index 539c1fd4a46..ef75770a9ed 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CVariableTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CVariableTests.java @@ -15,6 +15,9 @@ package org.eclipse.cdt.internal.pdom.tests; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IVariable; import org.eclipse.cdt.core.model.ICProject; @@ -22,8 +25,9 @@ import org.eclipse.cdt.internal.core.CCoreInternals; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.NullProgressMonitor; - -import junit.framework.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Tests for verifying whether the PDOM correctly stores information about @@ -34,19 +38,15 @@ public class CVariableTests extends PDOMTestBase { protected ICProject project; protected PDOM pdom; - public static Test suite() { - return suite(CVariableTests.class); - } - - @Override - protected void setUp() throws Exception { + @BeforeEach + protected void beforeEach() throws Exception { project = createProject("variableTests"); pdom = (PDOM) CCoreInternals.getPDOMManager().getPDOM(project); pdom.acquireReadLock(); } - @Override - protected void tearDown() throws Exception { + @AfterEach + protected void afterEach() throws Exception { pdom.releaseReadLock(); if (project != null) { project.getProject().delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, @@ -54,6 +54,7 @@ public class CVariableTests extends PDOMTestBase { } } + @Test public void testCAutoVariable() throws Exception { IBinding[] bindings = findQualifiedName(pdom, "autoCVariable"); assertEquals(1, bindings.length); @@ -61,6 +62,7 @@ public class CVariableTests extends PDOMTestBase { assertTrue(variable.isAuto()); } + @Test public void testCExternVariable() throws Exception { IBinding[] bindings = findQualifiedName(pdom, "externCVariable"); assertEquals(1, bindings.length); @@ -68,6 +70,7 @@ public class CVariableTests extends PDOMTestBase { assertTrue(variable.isExtern()); } + @Test public void testCRegisterVariable() throws Exception { IBinding[] bindings = findQualifiedName(pdom, "registerCVariable"); assertEquals(1, bindings.length); @@ -75,6 +78,7 @@ public class CVariableTests extends PDOMTestBase { assertTrue(variable.isRegister()); } + @Test public void testCStaticVariable() throws Exception { // static elements cannot be found on global scope, see bug 161216 IBinding[] bindings = findUnqualifiedName(pdom, "staticCVariable"); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/ChangeConfigurationTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/ChangeConfigurationTests.java index 8f6b1dab75c..c1d194de868 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/ChangeConfigurationTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/ChangeConfigurationTests.java @@ -13,6 +13,8 @@ *******************************************************************************/ package org.eclipse.cdt.internal.pdom.tests; +import static org.junit.jupiter.api.Assertions.assertEquals; + import java.util.regex.Pattern; import org.eclipse.cdt.core.CCorePlugin; @@ -38,15 +40,10 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; - -import junit.framework.Test; +import org.junit.jupiter.api.Test; public class ChangeConfigurationTests extends PDOMTestBase { - public static Test suite() { - return suite(ChangeConfigurationTests.class); - } - private void changeConfigRelations(ICProject project, int option) throws CoreException, InterruptedException { ICProjectDescription pd = CCorePlugin.getDefault().getProjectDescription(project.getProject()); pd.setConfigurationRelations(option); @@ -77,6 +74,7 @@ public class ChangeConfigurationTests extends PDOMTestBase { //#ifdef MACRO2 //void testFunc2(); //#endif + @Test public void testRepeatedlyChangeConfig_bug375226() throws Exception { ModelJoiner mj = new ModelJoiner(); ICProject cProject = CProjectHelper.createNewStyleCProject("testChangeConfiguration", @@ -121,8 +119,8 @@ public class ChangeConfigurationTests extends PDOMTestBase { new NullProgressMonitor()); IBinding[] noBindings = index.findBindings(isFirstConfig ? testFunc2 : testFunc1, true, IndexFilter.ALL, new NullProgressMonitor()); - assertEquals(1, bindings.length); - assertEquals(0, noBindings.length); + assertEquals(1, bindings.length, "Failed at try number " + i); + assertEquals(0, noBindings.length, "Failed at try number " + i); } finally { index.releaseReadLock(); } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/ClassMemberVisibilityTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/ClassMemberVisibilityTests.java index 3e7e5f923ba..655d29e447d 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/ClassMemberVisibilityTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/ClassMemberVisibilityTests.java @@ -15,12 +15,13 @@ package org.eclipse.cdt.internal.pdom.tests; import static org.eclipse.cdt.core.parser.tests.VisibilityAsserts.assertVisibility; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.core.runtime.CoreException; - -import junit.framework.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * @author Thomas Corbat @@ -29,13 +30,8 @@ import junit.framework.Test; */ public class ClassMemberVisibilityTests extends PDOMInlineCodeTestBase { - public static Test suite() { - return suite(ClassMemberVisibilityTests.class); - } - - @Override - public void setUp() throws Exception { - super.setUp(); + @BeforeEach + protected void beforeEach2() throws Exception { setUpSections(1); } @@ -48,6 +44,7 @@ public class ClassMemberVisibilityTests extends PDOMInlineCodeTestBase { // private: // void privateMemFun(); // }; + @Test public void testVisibilityDefaultMemberFunction() throws Exception { IBinding[] defaultFunction = findQualifiedPossiblyImplicit(pdom, "A::defaultMemFun"); assertVisibility(ICPPClassType.v_private, getMemberVisibility(defaultFunction[0])); @@ -71,6 +68,7 @@ public class ClassMemberVisibilityTests extends PDOMInlineCodeTestBase { // private: // int privateVariable; // }; + @Test public void testVisibilityDefaultMemberVariable() throws Exception { IBinding[] defaultVariable = findQualifiedPossiblyImplicit(pdom, "A::defaultVariable"); assertVisibility(ICPPClassType.v_private, getMemberVisibility(defaultVariable[0])); @@ -94,6 +92,7 @@ public class ClassMemberVisibilityTests extends PDOMInlineCodeTestBase { // private: // class PrivateNested {}; // }; + @Test public void testVisibilityDefaultNestedClass() throws Exception { IBinding[] defaultNested = findQualifiedPossiblyImplicit(pdom, "A::DefaultNested"); assertVisibility(ICPPClassType.v_private, getMemberVisibility(defaultNested[0])); @@ -110,6 +109,7 @@ public class ClassMemberVisibilityTests extends PDOMInlineCodeTestBase { // class A { // }; + @Test public void testVisibilityImplicitClassMembers() throws Exception { IBinding[] memberBindings = findQualifiedPossiblyImplicit(pdom, "A::A"); @@ -123,6 +123,7 @@ public class ClassMemberVisibilityTests extends PDOMInlineCodeTestBase { // template<> // class Tpl { // }; + @Test public void testVisibilityImplicitTemplateMembers() throws Exception { IBinding[] memberBindings = findQualifiedPossiblyImplicit(pdom, "Tpl::Tpl"); @@ -140,6 +141,7 @@ public class ClassMemberVisibilityTests extends PDOMInlineCodeTestBase { // class Tpl { // int specializedDefaultVariable; // }; + @Test public void testVisibilitySpecializedDefaultVariable() throws Exception { IBinding[] memberBindings = findQualifiedPossiblyImplicit(pdom, "Tpl::specializedDefaultVariable"); assertVisibility(ICPPClassType.v_private, getMemberVisibility(memberBindings[0])); @@ -153,6 +155,7 @@ public class ClassMemberVisibilityTests extends PDOMInlineCodeTestBase { // public: // int specializedPublicVariable; // }; + @Test public void testVisibilitySpecializedPublicVariable() throws Exception { IBinding[] memberBindings = findQualifiedPossiblyImplicit(pdom, "Tpl::specializedPublicVariable"); assertVisibility(ICPPClassType.v_public, getMemberVisibility(memberBindings[0])); @@ -166,6 +169,7 @@ public class ClassMemberVisibilityTests extends PDOMInlineCodeTestBase { // protected: // int specializedProtectedVariable; // }; + @Test public void testVisibilitySpecializedProtectedVariable() throws Exception { IBinding[] memberBindings = findQualifiedPossiblyImplicit(pdom, "Tpl::specializedProtectedVariable"); assertVisibility(ICPPClassType.v_protected, getMemberVisibility(memberBindings[0])); @@ -179,6 +183,7 @@ public class ClassMemberVisibilityTests extends PDOMInlineCodeTestBase { // private: // int specializedPrivateVariable; // }; + @Test public void testVisibilitySpecializedPrivateVariable() throws Exception { IBinding[] memberBinding = findQualifiedPossiblyImplicit(pdom, "Tpl::specializedPrivateVariable"); assertVisibility(ICPPClassType.v_private, getMemberVisibility(memberBinding[0])); @@ -186,7 +191,7 @@ public class ClassMemberVisibilityTests extends PDOMInlineCodeTestBase { private int getMemberVisibility(IBinding memberBinding) throws CoreException { IBinding owner = memberBinding.getOwner(); - assertInstance(owner, ICPPClassType.class); + assertInstanceOf(ICPPClassType.class, owner); ICPPClassType classBinding = (ICPPClassType) owner; return classBinding.getVisibility(memberBinding); } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/ClassTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/ClassTests.java index 28de19d5a6f..6a63a8a03bc 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/ClassTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/ClassTests.java @@ -16,6 +16,11 @@ *******************************************************************************/ package org.eclipse.cdt.internal.pdom.tests; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.util.regex.Pattern; import org.eclipse.cdt.core.dom.IName; @@ -36,8 +41,9 @@ import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.internal.core.CCoreInternals; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.dom.PDOMName; - -import junit.framework.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * @author Doug Schaefer @@ -45,12 +51,8 @@ import junit.framework.Test; public class ClassTests extends PDOMTestBase { protected PDOM pdom; - public static Test suite() { - return suite(ClassTests.class, "_"); - } - - @Override - protected void setUp() throws Exception { + @BeforeEach + protected void beforeEach() throws Exception { if (pdom == null) { ICProject project = createProject("classTests"); pdom = (PDOM) CCoreInternals.getPDOMManager().getPDOM(project); @@ -58,11 +60,12 @@ public class ClassTests extends PDOMTestBase { pdom.acquireReadLock(); } - @Override - protected void tearDown() throws Exception { + @AfterEach + protected void afterEach() throws Exception { pdom.releaseReadLock(); } + @Test public void test1() throws Exception { IBinding[] Bs = pdom.findBindings(Pattern.compile("B"), true, IndexFilter.ALL, npm()); assertEquals(1, Bs.length); @@ -89,6 +92,7 @@ public class ClassTests extends PDOMTestBase { return null; } + @Test public void testNested() throws Exception { IBinding[] bindings = pdom.findBindings(Pattern.compile("NestedA"), false, IndexFilter.ALL_DECLARED, npm()); assertEquals(1, bindings.length); @@ -112,6 +116,7 @@ public class ClassTests extends PDOMTestBase { assertEquals(offset("nested.cpp", "x.x") + 2, loc.getNodeOffset()); } + @Test public void test147903() throws Exception { IBinding[] bindings = pdom.findBindings(Pattern.compile("pr147903"), false, IndexFilter.ALL, npm()); assertEquals(1, bindings.length); @@ -125,6 +130,7 @@ public class ClassTests extends PDOMTestBase { } /* Test friend relationships between classes */ + @Test public void testFriend() throws Exception { IBinding[] bindings = pdom.findBindings(Pattern.compile("ClassA"), true, IndexFilter.ALL_DECLARED, npm()); assertEquals(1, bindings.length); @@ -175,6 +181,7 @@ public class ClassTests extends PDOMTestBase { assertEquals(bindings[0], ((PDOMName) refs[0]).getBinding()); } + @Test public void testAbsenceOfDefaultConstructorWhenExplicitNonDefaultPresentA() throws Exception { IndexFilter JUST_CONSTRUCTORS = new IndexFilter() { @Override @@ -187,6 +194,7 @@ public class ClassTests extends PDOMTestBase { assertEquals(2, bindings.length); } + @Test public void testAbsenceOfDefaultConstructorWhenExplicitNonDefaultPresentB() throws Exception { IndexFilter JUST_CONSTRUCTORS = new IndexFilter() { @Override @@ -199,6 +207,7 @@ public class ClassTests extends PDOMTestBase { assertEquals(1, bindings.length); } + @Test public void testClassScope_bug185408() throws Exception { char[][] name = { "B".toCharArray(), "bf".toCharArray() }; IBinding[] bindings = pdom.findBindings(name, IndexFilter.ALL, npm()); @@ -225,31 +234,33 @@ public class ClassTests extends PDOMTestBase { private ICPPMethod extractSingleMethod(IBinding[] bindings) { assertEquals(1, bindings.length); - assertInstance(bindings[0], ICPPMethod.class); + assertInstanceOf(ICPPMethod.class, bindings[0]); return (ICPPMethod) bindings[0]; } private ICPPClassType extractSingleClass(IBinding[] bindings) { assertEquals(1, bindings.length); - assertInstance(bindings[0], ICPPClassType.class); + assertInstanceOf(ICPPClassType.class, bindings[0]); return (ICPPClassType) bindings[0]; } + @Test public void testFinalClass() throws Exception { char[][] name = { "E".toCharArray() }; IBinding[] bindings = pdom.findBindings(name, IndexFilter.ALL, npm()); assertEquals(1, bindings.length); - assertInstance(bindings[0], ICPPClassType.class); + assertInstanceOf(ICPPClassType.class, bindings[0]); ICPPClassType classBinding = (ICPPClassType) bindings[0]; assertTrue(classBinding.isFinal()); } + @Test public void testNoDiscardClass() throws Exception { char[][] name = { "F".toCharArray() }; IBinding[] bindings = pdom.findBindings(name, IndexFilter.ALL, npm()); assertEquals(1, bindings.length); - assertInstance(bindings[0], ICPPClassType.class); + assertInstanceOf(ICPPClassType.class, bindings[0]); ICPPClassType classBinding = (ICPPClassType) bindings[0]; assertTrue(classBinding.isNoDiscard()); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/DBPropertiesTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/DBPropertiesTests.java index 32ccd243b3f..3d58b53dab9 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/DBPropertiesTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/DBPropertiesTests.java @@ -14,42 +14,45 @@ *******************************************************************************/ package org.eclipse.cdt.internal.pdom.tests; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.fail; + import java.io.File; import java.util.Iterator; import java.util.Properties; -import org.eclipse.cdt.core.testplugin.util.BaseTestCase; +import org.eclipse.cdt.core.testplugin.util.BaseTestCase5; import org.eclipse.cdt.internal.core.pdom.db.ChunkCache; import org.eclipse.cdt.internal.core.pdom.db.DBProperties; import org.eclipse.cdt.internal.core.pdom.db.Database; import org.eclipse.core.runtime.CoreException; - -import junit.framework.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Tests for the {@link DBProperties} class. */ -public class DBPropertiesTests extends BaseTestCase { +public class DBPropertiesTests extends BaseTestCase5 { File dbLoc; Database db; - public static Test suite() { - return suite(DBPropertiesTests.class); - } - - @Override - protected void setUp() throws Exception { + @BeforeEach + protected void beforeEach() throws Exception { dbLoc = File.createTempFile("test", "db"); dbLoc.deleteOnExit(); db = new Database(dbLoc, new ChunkCache(), 0, false); db.setExclusiveLock(); } - @Override - protected void tearDown() throws Exception { + @AfterEach + protected void afterEach() throws Exception { db.close(); } + @Test public void testBasic() throws CoreException { DBProperties properties = new DBProperties(db); Properties expected = System.getProperties(); @@ -74,6 +77,7 @@ public class DBPropertiesTests extends BaseTestCase { properties.delete(); } + @Test public void testLong() throws Exception { DBProperties ps = new DBProperties(db); @@ -90,6 +94,7 @@ public class DBPropertiesTests extends BaseTestCase { ps.delete(); } + @Test public void testNulls() throws Exception { DBProperties ps = new DBProperties(db); try { @@ -121,6 +126,7 @@ public class DBPropertiesTests extends BaseTestCase { assertEquals(s, ps.getProperty(null, s)); } + @Test public void testSeq() throws Exception { DBProperties ps = new DBProperties(db); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/DatabaseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/DatabaseTest.java index d297945ef76..266a1d11f12 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/DatabaseTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/DatabaseTest.java @@ -15,11 +15,15 @@ *******************************************************************************/ package org.eclipse.cdt.internal.pdom.tests; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + import java.io.File; import java.util.Random; import org.eclipse.cdt.core.testplugin.CTestPlugin; -import org.eclipse.cdt.core.testplugin.util.BaseTestCase; +import org.eclipse.cdt.core.testplugin.util.BaseTestCase5; import org.eclipse.cdt.internal.core.pdom.db.BTree; import org.eclipse.cdt.internal.core.pdom.db.ChunkCache; import org.eclipse.cdt.internal.core.pdom.db.Database; @@ -29,21 +33,21 @@ import org.eclipse.cdt.internal.core.pdom.db.IString; import org.eclipse.cdt.internal.core.pdom.db.ShortString; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; - -import junit.framework.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Tests for the {@link Database} class. */ -public class DatabaseTest extends BaseTestCase { +public class DatabaseTest extends BaseTestCase5 { // This constant can be used to run the test with very large databases. // Try, for example, setting it to Integer.MAX_VALUE * 7L; private static final long TEST_OFFSET = 0; protected Database db; - @Override - protected void setUp() throws Exception { - super.setUp(); + @BeforeEach + protected void beforeEach() throws Exception { db = new Database(getTestDir().append(getName() + System.currentTimeMillis() + ".dat").toFile(), new ChunkCache(), 0, false); db.setExclusiveLock(); @@ -60,10 +64,6 @@ public class DatabaseTest extends BaseTestCase { db.flush(); } - public static Test suite() { - return suite(DatabaseTest.class); - } - protected IPath getTestDir() { IPath path = CTestPlugin.getDefault().getStateLocation().append("tests/"); File file = path.toFile(); @@ -72,8 +72,8 @@ public class DatabaseTest extends BaseTestCase { return path; } - @Override - protected void tearDown() throws Exception { + @AfterEach + protected void afterEach() throws Exception { db.close(); if (!db.getLocation().delete()) { db.getLocation().deleteOnExit(); @@ -81,6 +81,7 @@ public class DatabaseTest extends BaseTestCase { db = null; } + @Test public void testBlockSizeAndFirstBlock() throws Exception { assertEquals(0, db.getVersion()); @@ -98,6 +99,7 @@ public class DatabaseTest extends BaseTestCase { assertEquals(mem + blocksize, db.getRecPtr((freeDeltas - Database.MIN_BLOCK_DELTAS + 1) * Database.INT_SIZE)); } + @Test public void testBug192437() throws Exception { File tmp = File.createTempFile("readOnlyEmpty", ".db"); try { @@ -122,6 +124,7 @@ public class DatabaseTest extends BaseTestCase { } } + @Test public void testFreeBlockLinking() throws Exception { final int realsize = 42; final int deltas = (realsize + Database.BLOCK_HEADER_SIZE + Database.BLOCK_SIZE_DELTA - 1) @@ -140,6 +143,7 @@ public class DatabaseTest extends BaseTestCase { assertEquals(0, db.getRecPtr(mem1 + Database.INT_SIZE)); } + @Test public void testSimpleAllocationLifecycle() throws Exception { long mem1 = db.malloc(42); db.free(mem1); @@ -173,6 +177,7 @@ public class DatabaseTest extends BaseTestCase { } } + @Test public void testStringsInBTree() throws Exception { String[] names = { "ARLENE", "BRET", "CINDY", "DENNIS", "EMILY", "FRANKLIN", "GERT", "HARVEY", "IRENE", "JOSE", "KATRINA", "LEE", "MARIA", "NATE", "OPHELIA", "PHILIPPE", "RITA", "STAN", "TAMMY", "VINCE", "WILMA", @@ -211,6 +216,7 @@ public class DatabaseTest extends BaseTestCase { private final int GT = 1, LT = -1, EQ = 0; + @Test public void testShortStringComparison() throws CoreException { Random r = new Random(90210); @@ -234,6 +240,7 @@ public class DatabaseTest extends BaseTestCase { assertCMP("a", EQ, "A", false); } + @Test public void testLongStringComparison() throws CoreException { Random r = new Random(314159265); doTrials(100, ShortString.MAX_BYTE_LENGTH + 1, ShortString.MAX_BYTE_LENGTH * 2, r, true); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/DefDeclTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/DefDeclTests.java index 7612ca47e00..6d1fc8c1af9 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/DefDeclTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/DefDeclTests.java @@ -14,6 +14,10 @@ *******************************************************************************/ package org.eclipse.cdt.internal.pdom.tests; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + import java.io.File; import java.util.regex.Pattern; @@ -40,9 +44,11 @@ import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.Path; import org.eclipse.jface.text.BadLocationException; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import junit.framework.AssertionFailedError; -import junit.framework.Test; /** * Test that PDOM correctly track declarations, definitions and references of objects. @@ -55,12 +61,8 @@ public class DefDeclTests extends PDOMTestBase { protected PDOM pdom; protected ICProject cproject; - public static Test suite() { - return suite(DefDeclTests.class); - } - - @Override - protected void setUp() throws Exception { + @BeforeEach + protected void beforeEach() throws Exception { String requiredName = "defDeclTests"; cproject = createProject(requiredName); this.projectName = cproject.getElementName(); @@ -68,8 +70,8 @@ public class DefDeclTests extends PDOMTestBase { pdom.acquireReadLock(); } - @Override - protected void tearDown() throws Exception { + @AfterEach + protected void afterEach() throws Exception { pdom.releaseReadLock(); if (cproject != null) { cproject.getProject().delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, null); @@ -181,34 +183,42 @@ public class DefDeclTests extends PDOMTestBase { } /* ------------------ Tests Started Here ------------------------ */ + @Test public void testInit() { // will fail if setUp fails, maybe timelimit is too small for warm-up } + @Test public void testSimpleDeclUsage_f01() throws Exception { assertDefDeclRef("foo", "01", 0, 1, 1); } + @Test public void testKRDeclUsage_f02() throws Exception { assertDefDeclRef("foo", "02", 0, 1, 1); } + @Test public void testImplicitDeclPostDecl_f03() throws Exception { assertDefDeclRef("foo", "03", 0, 1, 1); } + @Test public void testImplicitDeclPostDef_f04() throws Exception { assertDefDeclRef("foo", "04", 1, 0, 1); } + @Test public void testImplicitDeclNone_f05() throws Exception { assertDefDeclRef("foo", "05", 0, 0, 1); } + @Test public void testNonLocalDefintion_f06() throws Exception { assertDefDeclRef("foo", "06", 1, 1, 1); } + @Test public void testWrongMatchedStaticDefinition() throws Exception { String elName = "foo" + "07"; IIndexBinding[] binds = pdom.findBindings(Pattern.compile(elName), true, IndexFilter.ALL, null); @@ -232,6 +242,7 @@ public class DefDeclTests extends PDOMTestBase { checkReference(binds[1], "ref" + "07", 0); } + @Test public void testStaticBindings_f08() throws Exception { String elName = "foo" + "08"; @@ -260,43 +271,53 @@ public class DefDeclTests extends PDOMTestBase { checkReference(element, "refS" + "08", 1); } + @Test public void testSimpleGlobalWrite_v09() throws Exception { assertDefDeclRef("var", "_v09", 1, 0, 1); } + @Test public void testGlobalInitRead_v10() throws Exception { assertDefDeclRef("var", "_v10", 1, 0, 1); } + @Test public void testGlobalInitRead2_v11() throws Exception { assertDefDeclRef("var", "_v11", 1, 0, 1); } + @Test public void testDeclUseDef_v12() throws Exception { assertDefDeclRef("var", "_v12", 1, 1, 1); } + @Test public void testDeclDefUse_v13() throws Exception { assertDefDeclRef("var", "_v13", 1, 1, 1); } + @Test public void testDefDeclUse_v14() throws Exception { // Hmm. This test seems to work, but Find Declaration in the UI does not work. assertDefDeclRef("var", "_v14", 1, 1, 1); } + @Test public void testNamedStruct_t01() throws Exception { assertDefDeclRef("type", "_t01", 1, 0, 1); } + @Test public void testStructPreDefintion_t02() throws Exception { assertDefDeclRef("type", "_t02", 0, 1, 1); } + @Test public void testStructRecursive_t03() throws Exception { assertDefDeclRef("type", "_t03", 1, 1, 1); } + @Test public void testStructAndTypedef_t04() throws Exception { String num = "_t04"; String elName = "type" + num; @@ -314,6 +335,7 @@ public class DefDeclTests extends PDOMTestBase { checkDefinition(struct, "defS" + num, 1); } + @Test public void testTypedefAndAnonymousStruct_t05() throws Exception { assertDefDeclRef("type", "_t05", 1, 0, 1); } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/EnumerationTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/EnumerationTests.java index abac00004b3..d07cd79bc58 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/EnumerationTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/EnumerationTests.java @@ -14,6 +14,10 @@ *******************************************************************************/ package org.eclipse.cdt.internal.pdom.tests; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.util.Arrays; import java.util.Comparator; import java.util.regex.Pattern; @@ -30,8 +34,9 @@ import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.internal.core.CCoreInternals; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.core.runtime.NullProgressMonitor; - -import junit.framework.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * @author Doug Schaefer @@ -40,12 +45,8 @@ public class EnumerationTests extends PDOMTestBase { protected PDOM pdom; - public static Test suite() { - return suite(EnumerationTests.class); - } - - @Override - protected void setUp() throws Exception { + @BeforeEach + protected void beforeEach() throws Exception { if (pdom == null) { ICProject project = createProject("enumerationTests"); pdom = (PDOM) CCoreInternals.getPDOMManager().getPDOM(project); @@ -53,11 +54,12 @@ public class EnumerationTests extends PDOMTestBase { pdom.acquireReadLock(); } - @Override - protected void tearDown() throws Exception { + @AfterEach + protected void afterEach() throws Exception { pdom.releaseReadLock(); } + @Test public void testC() throws Exception { // Check bindings Pattern pattern = Pattern.compile("TestCEnum"); @@ -97,6 +99,7 @@ public class EnumerationTests extends PDOMTestBase { assertEquals(offset("enumTest.c", "ca;"), loc.getNodeOffset()); } + @Test public void testCPP() throws Exception { // Check bindings Pattern pattern = Pattern.compile("TestCPPEnum"); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/FilesOnReindexTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/FilesOnReindexTests.java index 7564f347290..86bc329d9ff 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/FilesOnReindexTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/FilesOnReindexTests.java @@ -13,6 +13,9 @@ *******************************************************************************/ package org.eclipse.cdt.internal.pdom.tests; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.util.regex.Pattern; import org.eclipse.cdt.core.CCorePlugin; @@ -29,8 +32,9 @@ 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 junit.framework.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * See bugzilla @@ -39,12 +43,8 @@ public class FilesOnReindexTests extends PDOMTestBase { protected ICProject project; protected IIndex pdom; - public static Test suite() { - return suite(FilesOnReindexTests.class); - } - - @Override - protected void setUp() throws Exception { + @BeforeEach + protected void beforeEach() throws Exception { if (pdom == null) { project = createProject("filesOnReindex"); pdom = CCorePlugin.getIndexManager().getIndex(project); @@ -52,8 +52,8 @@ public class FilesOnReindexTests extends PDOMTestBase { pdom.acquireReadLock(); } - @Override - protected void tearDown() throws Exception { + @AfterEach + protected void afterEach() throws Exception { pdom.releaseReadLock(); if (project != null) { project.getProject().delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, @@ -61,6 +61,7 @@ public class FilesOnReindexTests extends PDOMTestBase { } } + @Test public void testFilesOnReindex() throws CoreException, InterruptedException { IFile file = project.getProject().getFile("simple.cpp"); performAssertions(file); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/GeneratePDOMApplicationTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/GeneratePDOMApplicationTest.java index 674e344e6d5..229b06f75f4 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/GeneratePDOMApplicationTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/GeneratePDOMApplicationTest.java @@ -14,6 +14,11 @@ *******************************************************************************/ package org.eclipse.cdt.internal.pdom.tests; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.io.File; import java.net.URI; import java.net.URL; @@ -49,10 +54,11 @@ import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; import org.eclipse.equinox.app.IApplication; import org.eclipse.equinox.app.IApplicationContext; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.osgi.framework.Bundle; -import junit.framework.Test; - /** * Tests the GeneratePDOMApplication */ @@ -68,39 +74,36 @@ public class GeneratePDOMApplicationTest extends PDOMTestBase { private static Deque projectsToDeleteOnTearDown = new ArrayDeque<>(); - public static Test suite() { - return suite(GeneratePDOMApplicationTest.class); - } - protected File target; // the location of the generated PDOM - @Override - protected void setUp() throws Exception { - super.setUp(); + @BeforeEach + protected void beforeEach() throws Exception { projectsToDeleteOnTearDown.clear(); target = nonExistentTempFile("temp", ".pdom"); } - @Override - protected void tearDown() throws Exception { + @AfterEach + protected void afterEach() throws Exception { for (ICProject cproject; (cproject = projectsToDeleteOnTearDown.pollLast()) != null;) { cproject.getProject().delete(true, new NullProgressMonitor()); } - super.tearDown(); } + @Test public void testBrokenExportProjectProvider1() throws Exception { setExpectedNumberOfLoggedNonOKStatusObjects(1); // IExportProjectProvider implementation returns null for createProject doGenerate(new String[] { GeneratePDOMApplication.OPT_TARGET, target.getAbsolutePath(), GeneratePDOMApplication.OPT_PROJECTPROVIDER, TestProjectProvider1.class.getName() }); } + @Test public void testBrokenExportProjectProvider2() throws Exception { setExpectedNumberOfLoggedNonOKStatusObjects(1); // IExportProjectProvider implementation returns null for getLocationConverter doGenerate(new String[] { GeneratePDOMApplication.OPT_TARGET, target.getAbsolutePath(), GeneratePDOMApplication.OPT_PROJECTPROVIDER, TestProjectProvider2.class.getName() }); } + @Test public void testSimpleExportProjectProvider1() throws Exception { doGenerate(new String[] { GeneratePDOMApplication.OPT_TARGET, target.getAbsolutePath(), GeneratePDOMApplication.OPT_PROJECTPROVIDER, TestProjectProvider3.class.getName() }); @@ -120,6 +123,7 @@ public class GeneratePDOMApplicationTest extends PDOMTestBase { assertTrue(fid.startsWith("export")); // check for default export id } + @Test public void testSimpleExportProjectProvider2() throws Exception { doGenerate(new String[] { GeneratePDOMApplication.OPT_TARGET, target.getAbsolutePath(), GeneratePDOMApplication.OPT_PROJECTPROVIDER, TestProjectProvider4.class.getName() }); @@ -141,6 +145,7 @@ public class GeneratePDOMApplicationTest extends PDOMTestBase { } } + @Test public void testExternalExportProjectProvider_BadCmdLine1() throws Exception { setExpectedNumberOfLoggedNonOKStatusObjects(1); // Expected failure: -source must be specified @@ -149,6 +154,7 @@ public class GeneratePDOMApplicationTest extends PDOMTestBase { assertFalse(target.exists()); } + @Test public void testExternalExportProjectProvider_BadCmdLine2() throws Exception { TestProjectProvider4 tpp4 = new TestProjectProvider4(); ICProject cproject = tpp4.createProject(); @@ -162,6 +168,7 @@ public class GeneratePDOMApplicationTest extends PDOMTestBase { assertFalse(target.exists()); } + @Test public void testExternalExportProjectProvider_BadCmdLine3() throws Exception { TestProjectProvider4 tpp4 = new TestProjectProvider4(); ICProject cproject = tpp4.createProject(); @@ -173,6 +180,7 @@ public class GeneratePDOMApplicationTest extends PDOMTestBase { assertFalse(target.exists()); } + @Test public void testExternalExportProjectProvider() throws Exception { final int[] stateCount = new int[1]; WritablePDOM wpdom = generatePDOM(LOC_TSTPRJ1, ExternalExportProjectProvider.class, stateCount); @@ -187,24 +195,28 @@ public class GeneratePDOMApplicationTest extends PDOMTestBase { wpdom.releaseReadLock(); } // depending on the timing the index of the temporary project is changed once or twice. - assertTrue("state is " + stateCount[0], stateCount[0] == 2 || stateCount[0] == 4); + assertTrue(stateCount[0] == 2 || stateCount[0] == 4, "state is " + stateCount[0]); } + @Test public void testExternalExportProjectProvider_SysIncludes() throws Exception { WritablePDOM wpdom = generatePDOM(LOC_TSTPRJ2, ExternalExportProjectProvider.class, null); verifyProject2Content(wpdom); } + @Test public void testGenerateOnCyclicIncludes1() throws Exception { // testing for zero NON-OK status objects (see BaseTestCase.setExpectedNumberOfLoggedNonOKStatusObjects) WritablePDOM wpdom = generatePDOM(LOC_CYCINC1, ExternalExportProjectProvider.class, null); } + @Test public void testGenerateOnCyclicIncludes2() throws Exception { // testing for zero NON-OK status objects (see BaseTestCase.setExpectedNumberOfLoggedNonOKStatusObjects) WritablePDOM wpdom = generatePDOM(LOC_CYCINC2, ExternalExportProjectProvider.class, null); } + @Test public void testExternalExportProjectProvider_CLinkage() throws Exception { WritablePDOM wpdom = generatePDOM(LOC_TSTPRJ3, TestProjectProvider5.class, null); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/IncludesTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/IncludesTests.java index 28f74fc7e34..f9350d15f37 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/IncludesTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/IncludesTests.java @@ -14,6 +14,10 @@ *******************************************************************************/ package org.eclipse.cdt.internal.pdom.tests; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ILinkage; import org.eclipse.cdt.core.index.IIndex; @@ -25,8 +29,9 @@ import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.Path; - -import junit.framework.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * @author Doug Schaefer @@ -35,12 +40,8 @@ public class IncludesTests extends PDOMTestBase { protected ICProject project; protected IIndex index; - public static Test suite() { - return suite(IncludesTests.class); - } - - @Override - protected void setUp() throws Exception { + @BeforeEach + protected void beforeEach() throws Exception { if (index == null) { project = createProject("includesTests"); index = CCorePlugin.getIndexManager().getIndex(project); @@ -48,18 +49,19 @@ public class IncludesTests extends PDOMTestBase { index.acquireReadLock(); } - @Override - protected void tearDown() throws Exception { + @AfterEach + protected void afterEach() throws Exception { index.releaseReadLock(); } private IIndexFile getIndexFile(IFile file) throws CoreException { IIndexFile[] files = index.getFiles(ILinkage.CPP_LINKAGE_ID, IndexLocationFactory.getWorkspaceIFL(file)); - assertTrue("Can't find " + file.getLocation(), files.length > 0); - assertEquals("Found " + files.length + " files for " + file.getLocation() + " instead of one", 1, files.length); + assertTrue(files.length > 0, "Can't find " + file.getLocation()); + assertEquals(1, files.length, "Found " + files.length + " files for " + file.getLocation() + " instead of one"); return files[0]; } + @Test public void testIncludedBy() throws Exception { IResource loc = project.getProject().findMember("I2.h"); IIndexFile file = getIndexFile((IFile) loc); @@ -67,6 +69,7 @@ public class IncludesTests extends PDOMTestBase { assertEquals(9, allIncludedBy.length); // i.e. all of them } + @Test public void testIncludes() throws Exception { IResource loc = project.getProject().findMember("I1.cpp"); IIndexFile file = getIndexFile((IFile) loc); @@ -74,6 +77,7 @@ public class IncludesTests extends PDOMTestBase { assertEquals(2, allIncludesTo.length); // i.e. I1.h, I2.h } + @Test public void testIncludeName() throws Exception { IResource loc = project.getProject().findMember("a/b/I6.h"); IIndexFile file = getIndexFile((IFile) loc); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/MethodTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/MethodTests.java index 682a823b228..10d30be9e08 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/MethodTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/MethodTests.java @@ -14,6 +14,12 @@ *******************************************************************************/ package org.eclipse.cdt.internal.pdom.tests; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + import org.eclipse.cdt.core.dom.ast.IBasicType; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IParameter; @@ -27,8 +33,9 @@ import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.testplugin.CProjectHelper; import org.eclipse.cdt.internal.core.CCoreInternals; import org.eclipse.cdt.internal.core.pdom.PDOM; - -import junit.framework.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Tests for verifying whether the PDOM correctly stores information about @@ -38,19 +45,15 @@ public class MethodTests extends PDOMTestBase { protected ICProject project; protected PDOM pdom; - public static Test suite() { - return suite(MethodTests.class); - } - - @Override - protected void setUp() throws Exception { + @BeforeEach + protected void beforeEach() throws Exception { project = createProject("methodTests"); pdom = (PDOM) CCoreInternals.getPDOMManager().getPDOM(project); pdom.acquireReadLock(); } - @Override - protected void tearDown() throws Exception { + @AfterEach + protected void afterEach() throws Exception { pdom.releaseReadLock(); if (project != null) { CProjectHelper.delete(project); @@ -58,6 +61,7 @@ public class MethodTests extends PDOMTestBase { } } + @Test public void testMethodParameters() throws Exception { IBinding[] bindings = findQualifiedName(pdom, "Class1::normalMethod"); assertEquals(1, bindings.length); @@ -71,6 +75,7 @@ public class MethodTests extends PDOMTestBase { assertEquals("p3", parameters[2].getName()); } + @Test public void testVirtualMethod() throws Exception { IBinding[] bindings = findQualifiedName(pdom, "Class1::inheritedMethod"); assertEquals(1, bindings.length); @@ -78,38 +83,47 @@ public class MethodTests extends PDOMTestBase { assertTrue(method.isVirtual()); } + @Test public void testVirtualMethodType() throws Exception { assertType(pdom, "Class1::inheritedMethod", ICPPFunction.class); } + @Test public void testVirtualMethodDeclarations() throws Exception { assertDeclarationCount(pdom, "Class1::inheritedMethod", 2); } + @Test public void testVirtualMethodDefinitions() throws Exception { assertDefinitionCount(pdom, "Class1::inheritedMethod", 1); } + @Test public void testVirtualMethodReferences() throws Exception { assertReferenceCount(pdom, "Class1::inheritedMethod", 3); } + @Test public void testInheritedMethodType() throws Exception { assertEquals(0, findQualifiedName(pdom, "Class2::inheritedMethod").length); } + @Test public void testInheritedMethodDeclarations() throws Exception { assertDeclarationCount(pdom, "Class2::inheritedMethod", 0); } + @Test public void testInheritedMethodDefinitions() throws Exception { assertDefinitionCount(pdom, "Class2::inheritedMethod", 0); } + @Test public void testInheritedMethodReferences() throws Exception { assertReferenceCount(pdom, "Class2::inheritedMethod", 0); } + @Test public void testPureVirtualMethod() throws Exception { IBinding[] bindings = findQualifiedName(pdom, "Class1::pureVirtualMethod"); assertEquals(1, bindings.length); @@ -118,46 +132,55 @@ public class MethodTests extends PDOMTestBase { assertTrue(method.isPureVirtual()); } + @Test public void testPureVirtualMethodType() throws Exception { assertType(pdom, "Class1::pureVirtualMethod", ICPPFunction.class); assertType(pdom, "Class2::pureVirtualMethod", ICPPFunction.class); } + @Test public void testPureVirtualMethodDeclarations() throws Exception { assertDeclarationCount(pdom, "Class1::pureVirtualMethod", 1); assertDeclarationCount(pdom, "Class2::pureVirtualMethod", 2); } + @Test public void testPureVirtualMethodDefinitions() throws Exception { assertDefinitionCount(pdom, "Class1::pureVirtualMethod", 0); assertDefinitionCount(pdom, "Class2::pureVirtualMethod", 1); } + @Test public void testPureVirtualMethodReferences() throws Exception { assertReferenceCount(pdom, "Class1::pureVirtualMethod", 2); assertReferenceCount(pdom, "Class2::pureVirtualMethod", 3); } + @Test public void testOverriddenMethodType() throws Exception { assertType(pdom, "Class1::overriddenMethod", ICPPFunction.class); assertType(pdom, "Class2::overriddenMethod", ICPPFunction.class); } + @Test public void testOverriddenMethodDeclarations() throws Exception { assertDeclarationCount(pdom, "Class1::overriddenMethod", 2); assertDeclarationCount(pdom, "Class2::overriddenMethod", 2); } + @Test public void testOverriddenMethodDefinitions() throws Exception { assertDefinitionCount(pdom, "Class1::overriddenMethod", 1); assertDefinitionCount(pdom, "Class2::overriddenMethod", 1); } + @Test public void testOverriddenMethodReferences() throws Exception { assertReferenceCount(pdom, "Class1::overriddenMethod", 3); assertReferenceCount(pdom, "Class2::overriddenMethod", 4); } + @Test public void testDestructor() throws Exception { IBinding[] bindings = findQualifiedName(pdom, "Class1::~Class1"); assertEquals(1, bindings.length); @@ -165,22 +188,27 @@ public class MethodTests extends PDOMTestBase { assertTrue(method.isDestructor()); } + @Test public void testDefaultPrivateMethod() throws Exception { assertCPPMemberVisibility(pdom, "Class3::defaultMethod", ICPPMember.v_private); } + @Test public void testPrivateMethod() throws Exception { assertCPPMemberVisibility(pdom, "Class3::privateMethod", ICPPMember.v_private); } + @Test public void testProtectedMethod() throws Exception { assertCPPMemberVisibility(pdom, "Class3::protectedMethod", ICPPMember.v_protected); } + @Test public void testPublicMethod() throws Exception { assertCPPMemberVisibility(pdom, "Class3::publicMethod", ICPPMember.v_public); } + @Test public void testInlineMethod() throws Exception { IBinding[] bindings = findQualifiedName(pdom, "Class1::inlineMethod"); assertEquals(1, bindings.length); @@ -188,6 +216,7 @@ public class MethodTests extends PDOMTestBase { assertTrue(method.isInline()); } + @Test public void testStaticMethod() throws Exception { IBinding[] bindings = findQualifiedName(pdom, "Class1::staticMethod"); assertEquals(1, bindings.length); @@ -195,6 +224,7 @@ public class MethodTests extends PDOMTestBase { assertTrue(method.isStatic()); } + @Test public void testVarArgsMethod() throws Exception { IBinding[] bindings = findQualifiedName(pdom, "Class1::varArgsMethod"); assertEquals(1, bindings.length); @@ -202,6 +232,7 @@ public class MethodTests extends PDOMTestBase { assertTrue(method.takesVarArgs()); } + @Test public void testConstMethod() throws Exception { IBinding[] bindings = findQualifiedName(pdom, "Class1::constMethod"); assertEquals(1, bindings.length); @@ -210,6 +241,7 @@ public class MethodTests extends PDOMTestBase { assertTrue(type.isConst()); } + @Test public void testVolatileMethod() throws Exception { IBinding[] bindings = findQualifiedName(pdom, "Class1::volatileMethod"); assertEquals(1, bindings.length); @@ -218,6 +250,7 @@ public class MethodTests extends PDOMTestBase { assertTrue(type.isVolatile()); } + @Test public void testConstVolatileMethod() throws Exception { IBinding[] bindings = findQualifiedName(pdom, "Class1::constVolatileMethod"); assertEquals(1, bindings.length); @@ -227,6 +260,7 @@ public class MethodTests extends PDOMTestBase { assertTrue(type.isVolatile()); } + @Test public void testNotConstMethod() throws Exception { IBinding[] bindings = findQualifiedName(pdom, "Class1::notConstMethod"); assertEquals(1, bindings.length); @@ -235,6 +269,7 @@ public class MethodTests extends PDOMTestBase { assertFalse(type.isConst()); } + @Test public void testNotVolatileMethod() throws Exception { IBinding[] bindings = findQualifiedName(pdom, "Class1::notVolatileMethod"); assertEquals(1, bindings.length); @@ -243,6 +278,7 @@ public class MethodTests extends PDOMTestBase { assertFalse(type.isVolatile()); } + @Test public void testNotConstVolatileMethod() throws Exception { IBinding[] bindings = findQualifiedName(pdom, "Class1::notConstVolatileMethod"); assertEquals(1, bindings.length); @@ -252,6 +288,7 @@ public class MethodTests extends PDOMTestBase { assertFalse(type.isVolatile()); } + @Test public void testNoExceptionSpecification() throws Exception { IBinding[] bindings = findQualifiedName(pdom, "Class1::noExceptionSpecMethod"); assertEquals(1, bindings.length); @@ -260,6 +297,7 @@ public class MethodTests extends PDOMTestBase { assertNull(exceptionSpec); } + @Test public void testEmptyExceptionSpecification() throws Exception { IBinding[] bindings = findQualifiedName(pdom, "Class1::emptyExceptionSpecMethod"); assertEquals(1, bindings.length); @@ -268,6 +306,7 @@ public class MethodTests extends PDOMTestBase { assertEquals(0, exceptionSpec.length); } + @Test public void testNonEmptyExceptionSpecification() throws Exception { IBinding[] bindings = findQualifiedName(pdom, "Class1::nonEmptyExceptionSpecMethod"); assertEquals(1, bindings.length); @@ -277,6 +316,7 @@ public class MethodTests extends PDOMTestBase { assertEquals(IBasicType.t_int, ((ICPPBasicType) exceptionSpec[0]).getType()); } + @Test public void testImplicitCtorExceptionSpec() throws Exception { IBinding[] bindings = findQualifiedPossiblyImplicit(pdom, "D::D"); // get both default ctor + copy ctor @@ -286,6 +326,7 @@ public class MethodTests extends PDOMTestBase { assertNull(exceptionSpec); } + @Test public void testImplicitCopyCtorExceptionSpec() throws Exception { IBinding[] bindings = findQualifiedPossiblyImplicit(pdom, "D::D"); // get both default ctor + copy ctor @@ -295,6 +336,7 @@ public class MethodTests extends PDOMTestBase { assertEquals(0, exceptionSpec.length); } + @Test public void testImplicitDtorExceptionSpec() throws Exception { IBinding[] bindings = findQualifiedPossiblyImplicit(pdom, "D::~D"); assertEquals(1, bindings.length); @@ -307,28 +349,31 @@ public class MethodTests extends PDOMTestBase { assertEquals(IBasicType.t_double, Math.max(t1, t2)); } + @Test public void testVirtualMemberFunction() throws Exception { IBinding[] bindings = findQualifiedName(pdom, "E::virtualMemberFunction"); assertEquals(1, bindings.length); - assertInstance(bindings[0], ICPPMethod.class); + assertInstanceOf(ICPPMethod.class, bindings[0]); ICPPMethod virtMemFun = (ICPPMethod) bindings[0]; assertFalse(virtMemFun.isOverride()); assertFalse(virtMemFun.isFinal()); } + @Test public void testOverrideVirtualMemberFunction() throws Exception { IBinding[] bindings = findQualifiedName(pdom, "F::virtualMemberFunction"); assertEquals(1, bindings.length); - assertInstance(bindings[0], ICPPMethod.class); + assertInstanceOf(ICPPMethod.class, bindings[0]); ICPPMethod virtMemFun = (ICPPMethod) bindings[0]; assertTrue(virtMemFun.isOverride()); assertFalse(virtMemFun.isFinal()); } + @Test public void testOverrideFinalVirtualMemberFunction() throws Exception { IBinding[] bindings = findQualifiedName(pdom, "G::virtualMemberFunction"); assertEquals(1, bindings.length); - assertInstance(bindings[0], ICPPMethod.class); + assertInstanceOf(ICPPMethod.class, bindings[0]); ICPPMethod virtMemFun = (ICPPMethod) bindings[0]; assertTrue(virtMemFun.isOverride()); assertTrue(virtMemFun.isFinal()); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/NamespaceTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/NamespaceTests.java index 5618368f9bd..e0d162498f1 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/NamespaceTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/NamespaceTests.java @@ -13,6 +13,9 @@ *******************************************************************************/ package org.eclipse.cdt.internal.pdom.tests; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.util.regex.Pattern; import org.eclipse.cdt.core.dom.IName; @@ -30,8 +33,9 @@ import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; - -import junit.framework.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Tests for verifying whether the PDOM correctly stores information about C++ namespaces. @@ -44,12 +48,8 @@ public class NamespaceTests extends PDOMTestBase { protected IProgressMonitor NULL_MONITOR = new NullProgressMonitor(); protected IndexFilter INDEX_FILTER = IndexFilter.ALL; - public static Test suite() { - return suite(NamespaceTests.class); - } - - @Override - protected void setUp() throws Exception { + @BeforeEach + protected void beforeEach() throws Exception { if (pdom == null) { project = createProject("namespaceTests", true); pdom = (PDOM) CCoreInternals.getPDOMManager().getPDOM(project); @@ -57,8 +57,8 @@ public class NamespaceTests extends PDOMTestBase { pdom.acquireReadLock(); } - @Override - protected void tearDown() throws Exception { + @AfterEach + protected void afterEach() throws Exception { pdom.releaseReadLock(); if (project != null) { project.getProject().delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, @@ -66,6 +66,7 @@ public class NamespaceTests extends PDOMTestBase { } } + @Test public void testAlias() throws Exception { // Find all the namespace IBinding[] namespaces = pdom.findBindings(Pattern.compile("namespace1"), false, INDEX_FILTER, NULL_MONITOR); @@ -89,6 +90,7 @@ public class NamespaceTests extends PDOMTestBase { assertEquals(namespace2, namespaceAlias.getBinding()); } + @Test public void testNested() throws Exception { // Find deeply nested namespace Pattern[] patterns = { Pattern.compile("namespace1"), Pattern.compile("namespace2"), @@ -98,6 +100,7 @@ public class NamespaceTests extends PDOMTestBase { assertTrue(namespaces[0] instanceof ICPPNamespace); } + @Test public void testMemberDefinition() throws Exception { // Find the definition of a member declared in a namespace Pattern[] patterns = { Pattern.compile("namespace1"), Pattern.compile("namespace2"), Pattern.compile("foo") }; @@ -116,6 +119,7 @@ public class NamespaceTests extends PDOMTestBase { assertEquals(offset("namespace.cpp", "::foo()") + 2, loc.getNodeOffset()); // character offset } + @Test public void testExtend() throws Exception { // Extending a namespace IBinding[] namespaces = pdom.findBindings(Pattern.compile("ns1"), false, INDEX_FILTER, NULL_MONITOR); @@ -127,6 +131,7 @@ public class NamespaceTests extends PDOMTestBase { assertEquals(1, members.length); // c was added by extending the namespace } + @Test public void testOverload() throws Exception { // Function overloading in namespace Pattern[] patterns = { Pattern.compile("ns3"), Pattern.compile("blah") }; @@ -151,6 +156,7 @@ public class NamespaceTests extends PDOMTestBase { assertEquals(offset("overload.cpp", "blah('a')"), loc.getNodeOffset()); // character offset } + @Test public void testUnnamed_162226() throws Exception { // Unnamed Namespace IBinding[] functions = pdom.findBindings(Pattern.compile("function1"), true, INDEX_FILTER, NULL_MONITOR); @@ -174,6 +180,7 @@ public class NamespaceTests extends PDOMTestBase { assertEquals(offset("unnamed.cpp", "function1();"), loc.getNodeOffset()); // character offset } + @Test public void testFriend_162011() throws Exception { // Friend in namespace - function2 is not in Class1 IBinding[] functions = pdom.findBindings(Pattern.compile("function2"), false, INDEX_FILTER, NULL_MONITOR); @@ -197,6 +204,7 @@ public class NamespaceTests extends PDOMTestBase { assertEquals(offset("friend.cpp", "ns4::function2(element)") + 5, loc.getNodeOffset()); // character offset } + @Test public void testUsingDirective() throws Exception { // TODO need to test for PDOM? or is it more for compiler? Pattern[] patterns = { Pattern.compile("ns4"), Pattern.compile("element") }; diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/OverloadsWithinCommonHeaderTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/OverloadsWithinCommonHeaderTests.java index c48b7cdfb20..28bc393e34e 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/OverloadsWithinCommonHeaderTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/OverloadsWithinCommonHeaderTests.java @@ -13,6 +13,8 @@ *******************************************************************************/ package org.eclipse.cdt.internal.pdom.tests; +import static org.junit.jupiter.api.Assertions.assertEquals; + import java.util.regex.Pattern; import org.eclipse.cdt.core.dom.ILinkage; @@ -26,8 +28,9 @@ import org.eclipse.cdt.internal.core.CCoreInternals; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.NullProgressMonitor; - -import junit.framework.TestSuite; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Test overloaded symbols are correctly resolved when in a common header. This @@ -37,12 +40,8 @@ import junit.framework.TestSuite; public class OverloadsWithinCommonHeaderTests extends PDOMTestBase { protected PDOM pdom; - public static TestSuite suite() { - return suite(OverloadsWithinCommonHeaderTests.class); - } - - @Override - protected void setUp() throws Exception { + @BeforeEach + protected void beforeEach() throws Exception { if (pdom == null) { ICProject project = createProject("overloadsWithinCommonHeader", true); pdom = (PDOM) CCoreInternals.getPDOMManager().getPDOM(project); @@ -50,13 +49,14 @@ public class OverloadsWithinCommonHeaderTests extends PDOMTestBase { pdom.acquireReadLock(); } - @Override - protected void tearDown() throws Exception { + @AfterEach + protected void afterEach() throws Exception { pdom.releaseReadLock(); } + @Test public void testOverloadedInCommonHeader_ClassScope() throws CoreException { - Pattern[] ManyOverloadedQuxPath = makePatternArray(new String[] { "ManyOverloaded", "qux" }); + Pattern[] ManyOverloadedQuxPath = makePatternArray("ManyOverloaded", "qux"); IBinding[] ManyOverloadedQux = pdom.findBindings(ManyOverloadedQuxPath, true, IndexFilter.ALL, new NullProgressMonitor()); assertEquals(5, ManyOverloadedQux.length); @@ -77,8 +77,9 @@ public class OverloadsWithinCommonHeaderTests extends PDOMTestBase { assertFunctionRefCount(new Class[] { ICPPClassType.class }, ManyOverloadedQux, 10); } + @Test public void testOverloadedInCommonHeader_FileScope() throws CoreException { - Pattern[] QuuxPath = makePatternArray(new String[] { "quux" }); + Pattern[] QuuxPath = makePatternArray("quux"); IBinding[] Quux = pdom.findBindings(QuuxPath, true, IndexFilter.getFilter(ILinkage.CPP_LINKAGE_ID), new NullProgressMonitor()); @@ -100,8 +101,9 @@ public class OverloadsWithinCommonHeaderTests extends PDOMTestBase { assertFunctionRefCount(new Class[] { ICPPClassType.class }, Quux, 12); } + @Test public void testOverloadedInCommonHeader_NamespaceScope() throws CoreException { - Pattern[] GraultPath = makePatternArray(new String[] { "corge", "grault" }); + Pattern[] GraultPath = makePatternArray("corge", "grault"); IBinding[] Grault = pdom.findBindings(GraultPath, true, IndexFilter.getFilter(ILinkage.CPP_LINKAGE_ID), new NullProgressMonitor()); assertEquals(5, Grault.length); @@ -122,8 +124,9 @@ public class OverloadsWithinCommonHeaderTests extends PDOMTestBase { assertFunctionRefCount(new Class[] { ICPPClassType.class }, Grault, 14); } + @Test public void testOverloadedInCommonHeader_NamespaceScope_Collides_With_Filescope() throws CoreException { - Pattern[] ns2Path = makePatternArray(new String[] { "ns2", "quux" }); + Pattern[] ns2Path = makePatternArray("ns2", "quux"); IBinding[] ns2 = pdom.findBindings(ns2Path, true, IndexFilter.getFilter(ILinkage.CPP_LINKAGE_ID), new NullProgressMonitor()); assertEquals(5, ns2.length); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/OverloadsWithinSingleTUTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/OverloadsWithinSingleTUTests.java index 8008047d34d..662fd89c005 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/OverloadsWithinSingleTUTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/OverloadsWithinSingleTUTests.java @@ -13,6 +13,8 @@ *******************************************************************************/ package org.eclipse.cdt.internal.pdom.tests; +import static org.junit.jupiter.api.Assertions.assertEquals; + import java.util.regex.Pattern; import org.eclipse.cdt.core.dom.ast.IBasicType; @@ -24,8 +26,9 @@ import org.eclipse.cdt.internal.core.CCoreInternals; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.NullProgressMonitor; - -import junit.framework.TestSuite; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Test overloaded symbols are correctly resolved when within a single translation @@ -35,12 +38,8 @@ import junit.framework.TestSuite; public class OverloadsWithinSingleTUTests extends PDOMTestBase { protected PDOM pdom; - public static TestSuite suite() { - return suite(OverloadsWithinSingleTUTests.class); - } - - @Override - protected void setUp() throws Exception { + @BeforeEach + protected void beforeEach() throws Exception { if (pdom == null) { ICProject project = createProject("overloadsWithinSingleTU"); pdom = (PDOM) CCoreInternals.getPDOMManager().getPDOM(project); @@ -48,11 +47,12 @@ public class OverloadsWithinSingleTUTests extends PDOMTestBase { pdom.acquireReadLock(); } - @Override - protected void tearDown() throws Exception { + @AfterEach + protected void afterEach() throws Exception { pdom.releaseReadLock(); } + @Test public void testDistinctBindingsPresent() throws Exception { IBinding[] fooBs = pdom.findBindings(Pattern.compile("foo"), false, IndexFilter.ALL, new NullProgressMonitor()); assertEquals(3, fooBs.length); @@ -64,15 +64,16 @@ public class OverloadsWithinSingleTUTests extends PDOMTestBase { new NullProgressMonitor()); assertEquals(4, FooBs.length); - Pattern[] XBarAbsPath = makePatternArray(new String[] { "X", "bar" }); + Pattern[] XBarAbsPath = makePatternArray("X", "bar"); IBinding[] XBarBs = pdom.findBindings(XBarAbsPath, true, IndexFilter.ALL, new NullProgressMonitor()); assertEquals(4, XBarBs.length); - Pattern[] XFooPath = makePatternArray(new String[] { "X", "Foo" }); + Pattern[] XFooPath = makePatternArray("X", "Foo"); IBinding[] XFooPathBs = pdom.findBindings(XFooPath, true, IndexFilter.ALL, new NullProgressMonitor()); assertEquals(1, XFooPathBs.length); } + @Test public void testReferencesToGlobalBindings() throws Exception { IBinding[] BarBs = pdom.findBindings(Pattern.compile("bar"), true, IndexFilter.ALL, new NullProgressMonitor()); assertEquals(4, BarBs.length); @@ -90,8 +91,9 @@ public class OverloadsWithinSingleTUTests extends PDOMTestBase { assertFunctionRefCount(new Class[] { ICPPClassType.class, IBasicType.class }, BarBs, 1); } + @Test public void testReferencesToNamespacedBindings() throws Exception { - Pattern[] XBarAbsPath = makePatternArray(new String[] { "X", "bar" }); + Pattern[] XBarAbsPath = makePatternArray("X", "bar"); IBinding[] XBarBs = pdom.findBindings(XBarAbsPath, false, IndexFilter.ALL, new NullProgressMonitor()); // X::bar() diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMCBugsTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMCBugsTest.java index c2d5848184b..25ec68d2d19 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMCBugsTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMCBugsTest.java @@ -14,6 +14,9 @@ *******************************************************************************/ package org.eclipse.cdt.internal.pdom.tests; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.util.Arrays; import java.util.HashSet; import java.util.Set; @@ -31,7 +34,7 @@ import org.eclipse.cdt.core.index.IndexFilter; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.testplugin.CProjectHelper; import org.eclipse.cdt.core.testplugin.CTestPlugin; -import org.eclipse.cdt.core.testplugin.util.BaseTestCase; +import org.eclipse.cdt.core.testplugin.util.BaseTestCase5; import org.eclipse.cdt.core.testplugin.util.TestSourceReader; import org.eclipse.cdt.internal.core.CCoreInternals; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; @@ -40,20 +43,17 @@ import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.osgi.framework.Bundle; -import junit.framework.Test; - -public class PDOMCBugsTest extends BaseTestCase { +public class PDOMCBugsTest extends BaseTestCase5 { ICProject cproject; PDOM pdom; - public static Test suite() { - return suite(PDOMCBugsTest.class); - } - - @Override - protected void setUp() throws Exception { + @BeforeEach + protected void beforeEach() throws Exception { cproject = CProjectHelper.createCProject("PDOMCBugsTest" + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER); Bundle b = CTestPlugin.getDefault().getBundle(); @@ -65,16 +65,14 @@ public class PDOMCBugsTest extends BaseTestCase { waitForIndexer(cproject); pdom = (PDOM) CCoreInternals.getPDOMManager().getPDOM(cproject); - super.setUp(); } - @Override - protected void tearDown() throws Exception { + @AfterEach + protected void afterEach() throws Exception { if (cproject != null) { cproject.getProject().delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, new NullProgressMonitor()); } - super.tearDown(); } // // check we get the right IProblemBinding objects @@ -85,6 +83,7 @@ public class PDOMCBugsTest extends BaseTestCase { // typedef H *H; // typedef I *************I; // typedef int (*J)(J); + @Test public void test192165() throws Exception { pdom.acquireReadLock(); IBinding[] bindings = pdom.findBindings(Pattern.compile(".*"), false, IndexFilter.ALL, npm()); @@ -93,7 +92,7 @@ public class PDOMCBugsTest extends BaseTestCase { for (IBinding binding : bindings) { final String name = binding.getName(); bnames.add(name); - assertTrue("expected typedef, got " + binding, binding instanceof ITypedef); + assertTrue(binding instanceof ITypedef, "expected typedef, got " + binding); IType type = SemanticUtil.getUltimateType((IType) binding, false); if (name.equals("J")) { // for plain C the second J has to be interpreted as a (useless) parameter name. diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMCPPBugsTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMCPPBugsTest.java index 45f3209de8d..224093eb8b5 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMCPPBugsTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMCPPBugsTest.java @@ -15,6 +15,11 @@ *******************************************************************************/ package org.eclipse.cdt.internal.pdom.tests; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.io.File; import java.util.regex.Pattern; @@ -30,7 +35,7 @@ import org.eclipse.cdt.core.index.ResourceContainerRelativeLocationConverter; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.LanguageManager; import org.eclipse.cdt.core.testplugin.CProjectHelper; -import org.eclipse.cdt.core.testplugin.util.BaseTestCase; +import org.eclipse.cdt.core.testplugin.util.BaseTestCase5; import org.eclipse.cdt.core.testplugin.util.TestSourceReader; import org.eclipse.cdt.internal.core.CCoreInternals; import org.eclipse.cdt.internal.core.index.IIndexFragment; @@ -46,36 +51,32 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.NullProgressMonitor; - -import junit.framework.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Tests bugs found in the PDOM. */ -public class PDOMCPPBugsTest extends BaseTestCase { +public class PDOMCPPBugsTest extends BaseTestCase5 { ICProject cproject; - public static Test suite() { - return suite(PDOMCPPBugsTest.class); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); + @BeforeEach + protected void beforeEach() throws Exception { cproject = CProjectHelper.createCCProject("PDOMBugsTest" + System.currentTimeMillis(), "bin", IPDOMManager.ID_FAST_INDEXER); waitForIndexer(cproject); } - @Override - protected void tearDown() throws Exception { + @AfterEach + protected void afterEach() throws Exception { if (cproject != null) { cproject.getProject().delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, new NullProgressMonitor()); } - super.tearDown(); } + @Test public void testPDOMProperties() throws Exception { PDOM pdom = (PDOM) CCoreInternals.getPDOMManager().getPDOM(cproject); pdom.acquireWriteLock(0, null); @@ -93,6 +94,7 @@ public class PDOMCPPBugsTest extends BaseTestCase { } } + @Test public void testProjectPDOMProperties() throws Exception { PDOM pdom = (PDOM) CCoreInternals.getPDOMManager().getPDOM(cproject); pdom.acquireReadLock(); @@ -110,6 +112,7 @@ public class PDOMCPPBugsTest extends BaseTestCase { } } + @Test public void testProjectPDOMPropertiesOnExport() throws Exception { // this test is currently failing on the cdt test build machine, but // not on my local linux or windows boxes. @@ -128,18 +131,18 @@ public class PDOMCPPBugsTest extends BaseTestCase { String id2 = getFragmentID(cproject); assertNotNull("Project pdom ID is null", id2); - assertFalse("Project pdom ID equals export PDOM id", id2.equals(id)); + assertFalse(id2.equals(id), "Project pdom ID equals export PDOM id"); pdomManager.reindex(cproject); waitForIndexer(cproject); String id3 = pdom.getProperty(IIndexFragment.PROPERTY_FRAGMENT_ID); assertNotNull("Exported pdom ID is null after project reindex", id3); - assertEquals("Exported pdom ID hasChanged during reindex", id, id3); + assertEquals(id, id3, "Exported pdom ID hasChanged during reindex"); String id4 = getFragmentID(cproject); assertNotNull("Reindexed project pdom ID is null", id4); - assertFalse("Reindexex project pdom ID equals exported pdom ID", id4.equals(id)); + assertFalse(id4.equals(id), "Reindexex project pdom ID equals exported pdom ID"); } finally { pdom.releaseReadLock(); } @@ -158,6 +161,7 @@ public class PDOMCPPBugsTest extends BaseTestCase { return id2; } + @Test public void testInterruptingAcquireReadLock() throws Exception { final PDOM pdom = (PDOM) CCoreInternals.getPDOMManager().getPDOM(cproject); final boolean[] ok = { false }; @@ -176,7 +180,7 @@ public class PDOMCPPBugsTest extends BaseTestCase { other.start(); other.interrupt(); other.join(); - assertTrue("thread was not interrupted", ok[0]); + assertTrue(ok[0], "thread was not interrupted"); } finally { pdom.releaseWriteLock(); } @@ -184,6 +188,7 @@ public class PDOMCPPBugsTest extends BaseTestCase { pdom.releaseWriteLock(); } + @Test public void testInterruptingAcquireWriteLock() throws Exception { final WritablePDOM pdom = (WritablePDOM) CCoreInternals.getPDOMManager().getPDOM(cproject); final boolean[] ok = { false }; @@ -204,7 +209,7 @@ public class PDOMCPPBugsTest extends BaseTestCase { other.start(); other.interrupt(); other.join(); - assertTrue("thread was not interrupted", ok[0]); + assertTrue(ok[0], "thread was not interrupted"); } finally { pdom.releaseReadLock(); } @@ -212,6 +217,7 @@ public class PDOMCPPBugsTest extends BaseTestCase { pdom.releaseWriteLock(); } + @Test public void test191679() throws Exception { IProject project = cproject.getProject(); IFolder cHeaders = cproject.getProject().getFolder("cHeaders"); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMInlineCodeTestBase.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMInlineCodeTestBase.java index 3ee93704c41..f5ded9523e2 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMInlineCodeTestBase.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMInlineCodeTestBase.java @@ -24,6 +24,8 @@ import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences; import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.Path; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; /** * @author Thomas Corbat @@ -31,12 +33,12 @@ import org.eclipse.core.runtime.Path; * Base class for PDOM tests relying on code placed in comments in front * of the test. */ -public class PDOMInlineCodeTestBase extends PDOMTestBase { +public abstract class PDOMInlineCodeTestBase extends PDOMTestBase { protected PDOM pdom; protected ICProject cproject; - @Override - public void setUp() throws Exception { + @BeforeEach + protected void beforeEach() throws Exception { cproject = CProjectHelper.createCCProject("classTemplateTests" + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER); } @@ -53,8 +55,8 @@ public class PDOMInlineCodeTestBase extends PDOMTestBase { pdom.acquireReadLock(); } - @Override - protected void tearDown() throws Exception { + @AfterEach + protected void afterEach() throws Exception { if (pdom != null) { pdom.releaseReadLock(); } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMLocationTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMLocationTests.java index a66acbb4760..02cb82c1f98 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMLocationTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMLocationTests.java @@ -13,6 +13,9 @@ *******************************************************************************/ package org.eclipse.cdt.internal.pdom.tests; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.util.Arrays; import java.util.HashSet; import java.util.Set; @@ -22,40 +25,36 @@ import org.eclipse.cdt.core.index.IIndexFileLocation; import org.eclipse.cdt.core.index.IndexLocationFactory; 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.BaseTestCase5; import org.eclipse.cdt.internal.core.pdom.dom.PDOMProjectIndexLocationConverter; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Platform; - -import junit.framework.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Tests behavior related to location representation in the PDOM */ -public class PDOMLocationTests extends BaseTestCase { +public class PDOMLocationTests extends BaseTestCase5 { ICProject cproject; - public static Test suite() { - return suite(PDOMLocationTests.class); - } - - @Override - protected void setUp() throws Exception { + @BeforeEach + protected void beforeEach() throws Exception { cproject = CProjectHelper.createCCProject("PDOMLocationTests" + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER); - super.setUp(); } - @Override - protected void tearDown() throws Exception { + @AfterEach + protected void afterEach() throws Exception { if (cproject != null) { cproject.getProject().delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, new NullProgressMonitor()); } - super.tearDown(); } + @Test public void testLocationConverter() { PDOMProjectIndexLocationConverter converter = new PDOMProjectIndexLocationConverter(cproject.getProject()); String[] winExternals = new String[] { "c:/a/b/c/d.foo", "c:\\a\\b\\c\\d\\e.foo", "d:/foo.bar", diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMNameTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMNameTests.java index abb00ae383c..ceacff97e6e 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMNameTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMNameTests.java @@ -13,13 +13,20 @@ *******************************************************************************/ package org.eclipse.cdt.internal.pdom.tests; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; + import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.IPDOMManager; import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IndexFilter; 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.BaseTestCase5; import org.eclipse.cdt.core.testplugin.util.TestSourceReader; import org.eclipse.cdt.internal.core.CCoreInternals; import org.eclipse.cdt.internal.core.pdom.PDOM; @@ -30,33 +37,29 @@ import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.NullProgressMonitor; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import junit.framework.Test; - -public class PDOMNameTests extends BaseTestCase { +public class PDOMNameTests extends BaseTestCase5 { private ICProject cproject; - public static Test suite() { - return suite(PDOMNameTests.class); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); + @BeforeEach + protected void beforeEach() throws Exception { cproject = CProjectHelper.createCCProject("PDOMNameTest" + System.currentTimeMillis(), "bin", IPDOMManager.ID_FAST_INDEXER); waitForIndexer(cproject); } - @Override - protected void tearDown() throws Exception { + @AfterEach + protected void afterEach() throws Exception { if (cproject != null) { cproject.getProject().delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, new NullProgressMonitor()); } - super.tearDown(); } + @Test public void testExternalReferences() throws Exception { IProject project = cproject.getProject(); // Use enum because this uses a different NodeType in C++ and C. diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMProviderTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMProviderTests.java index 38f256ac29b..46c61e72160 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMProviderTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMProviderTests.java @@ -15,6 +15,8 @@ package org.eclipse.cdt.internal.pdom.tests; import static org.eclipse.cdt.core.testplugin.CProjectHelper.createCCProject; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.File; import java.net.URI; @@ -44,8 +46,7 @@ import org.eclipse.cdt.internal.core.pdom.WritablePDOM; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; - -import junit.framework.Test; +import org.junit.jupiter.api.Test; /** * Tests addition of external pdom's into the logical index @@ -53,10 +54,7 @@ import junit.framework.Test; public class PDOMProviderTests extends PDOMTestBase { private static final int A_FRAGMENT_OPTIONS = IIndexManager.ADD_EXTENSION_FRAGMENTS_ADD_IMPORT; - public static Test suite() { - return suite(PDOMProviderTests.class); - } - + @Test public void testLifeCycle() throws Exception { final File tempPDOM = createTempFile("temp", ".pdom"); @@ -128,6 +126,7 @@ public class PDOMProviderTests extends PDOMTestBase { } } + @Test public void testCommonSDK() throws Exception { final File tempPDOM = createTempFile("temp", ".pdom"); @@ -247,6 +246,7 @@ public class PDOMProviderTests extends PDOMTestBase { } } + @Test public void testVersionMismatchOfExternalPDOM_178998() throws Exception { final File tempPDOM = createTempFile("temp", ".pdom"); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMSearchTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMSearchTest.java index 42a6f15461d..25eb8b5540a 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMSearchTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMSearchTest.java @@ -14,6 +14,9 @@ *******************************************************************************/ package org.eclipse.cdt.internal.pdom.tests; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.util.Arrays; import java.util.Comparator; import java.util.regex.Pattern; @@ -39,8 +42,9 @@ import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; - -import junit.framework.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Test the correctness of C/C++ searches. @@ -60,19 +64,15 @@ public class PDOMSearchTest extends PDOMTestBase { protected IProgressMonitor NULL_MONITOR = new NullProgressMonitor(); protected IndexFilter INDEX_FILTER = IndexFilter.ALL_DECLARED; - public static Test suite() { - return suite(PDOMSearchTest.class); - } - - @Override - protected void setUp() throws Exception { + @BeforeEach + protected void beforeEach() throws Exception { project = createProject("searchTests", true); pdom = (PDOM) CCoreInternals.getPDOMManager().getPDOM(project); pdom.acquireReadLock(); } - @Override - protected void tearDown() throws Exception { + @AfterEach + protected void afterEach() throws Exception { pdom.releaseReadLock(); if (project != null) { project.getProject().delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, @@ -83,6 +83,7 @@ public class PDOMSearchTest extends PDOMTestBase { /** * Tests the members inside namespaces */ + @Test public void testNamespaces() throws Exception { /* Members in the namespace */ IBinding[] namespaces = pdom.findBindings(Pattern.compile("namespace1"), false, INDEX_FILTER, NULL_MONITOR); @@ -126,6 +127,7 @@ public class PDOMSearchTest extends PDOMTestBase { assertEquals(offset("Class1.h", "namespace namespace1") + 10, loc.getNodeOffset()); //character offset } + @Test public void testAnonymousNamespace_460646() throws Exception { char[][] name = new char[][] { "ns1".toCharArray(), "ns2".toCharArray(), "Class3".toCharArray() }; IIndexBinding[] bindings = pdom.findBindings(name, IndexFilter.ALL, npm()); @@ -134,6 +136,7 @@ public class PDOMSearchTest extends PDOMTestBase { assertEquals("ns1::ns2::Class3", getQualifiedName(bindings[0])); } + @Test public void testClasses_160913() throws Exception { // classes and nested classes @@ -237,6 +240,7 @@ public class PDOMSearchTest extends PDOMTestBase { assertEquals(offset("Class1.h", "class Class2 { //namespace1::Class1::Class2") + 6, loc.getNodeOffset()); //character offset } + @Test public void testFunction() throws Exception { IBinding[] functions = pdom.findBindings(Pattern.compile("foo2"), false, INDEX_FILTER, NULL_MONITOR); assertEquals(1, functions.length); @@ -249,6 +253,7 @@ public class PDOMSearchTest extends PDOMTestBase { assertEquals("main", getQualifiedName(functions[0])); } + @Test public void testMethods() throws Exception { IBinding[] methods = pdom.findBindings(Pattern.compile("~Class2"), false, INDEX_FILTER, NULL_MONITOR); assertEquals(1, methods.length); @@ -256,6 +261,7 @@ public class PDOMSearchTest extends PDOMTestBase { assertEquals("Class2::~Class2", getQualifiedName(methods[0])); } + @Test public void testFields() throws Exception { IBinding[] fields = pdom.findBindings(Pattern.compile("class1x"), false, INDEX_FILTER, NULL_MONITOR); assertEquals(1, fields.length); @@ -268,6 +274,7 @@ public class PDOMSearchTest extends PDOMTestBase { assertEquals("namespace1::Class1::class1y", getQualifiedName(fields[0])); } + @Test public void testVariables() throws Exception { IBinding[] variables = pdom.findBindings(Pattern.compile("var"), false, INDEX_FILTER, NULL_MONITOR); assertEquals(1, variables.length); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMStringSetTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMStringSetTests.java index e06d410e430..43d093e6cc6 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMStringSetTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMStringSetTests.java @@ -13,30 +13,28 @@ */ package org.eclipse.cdt.internal.pdom.tests; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.io.File; -import org.eclipse.cdt.core.testplugin.util.BaseTestCase; +import org.eclipse.cdt.core.testplugin.util.BaseTestCase5; import org.eclipse.cdt.internal.core.pdom.db.ChunkCache; import org.eclipse.cdt.internal.core.pdom.db.Database; import org.eclipse.cdt.internal.core.pdom.db.PDOMStringSet; - -import junit.framework.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; // copy/pasted from BTreeTests -public class PDOMStringSetTests extends BaseTestCase { +public class PDOMStringSetTests extends BaseTestCase5 { protected File dbFile; protected Database db; protected PDOMStringSet stringSet; protected int rootRecord; - public static Test suite() { - return suite(PDOMStringSetTests.class); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - + @BeforeEach + protected void beforeEach() throws Exception { dbFile = File.createTempFile("pdomstringsettest", "db"); db = new Database(dbFile, new ChunkCache(), 0, false); db.setExclusiveLock(); @@ -44,15 +42,14 @@ public class PDOMStringSetTests extends BaseTestCase { stringSet = new PDOMStringSet(db, rootRecord); } - @Override - protected void tearDown() throws Exception { + @AfterEach + protected void afterEach() throws Exception { db.close(); dbFile.deleteOnExit(); - - super.tearDown(); } // Quick tests to exercise the basic functionality. + @Test public void testInterface() throws Exception { long val1_rec_a = stringSet.add("val1"); long val2_rec_a = stringSet.add("val2"); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTagIndexTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTagIndexTests.java index fcf6f9e3342..71b102eb30e 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTagIndexTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTagIndexTests.java @@ -13,6 +13,11 @@ *******************************************************************************/ package org.eclipse.cdt.internal.pdom.tests; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.io.File; import java.util.Arrays; @@ -20,24 +25,21 @@ import org.eclipse.cdt.core.dom.ast.tag.ITag; import org.eclipse.cdt.core.index.IIndexFileLocation; import org.eclipse.cdt.core.index.IIndexLocationConverter; import org.eclipse.cdt.core.model.LanguageManager; -import org.eclipse.cdt.core.testplugin.util.BaseTestCase; +import org.eclipse.cdt.core.testplugin.util.BaseTestCase5; import org.eclipse.cdt.internal.core.dom.ast.tag.Tag; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.WritablePDOM; import org.eclipse.cdt.internal.core.pdom.tag.PDOMTag; import org.eclipse.cdt.internal.core.pdom.tag.PDOMTagIndex; - -import junit.framework.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; // copy/pasted from BTreeTests -public class PDOMTagIndexTests extends BaseTestCase { +public class PDOMTagIndexTests extends BaseTestCase5 { private File pdomFile; private PDOM pdom; - public static Test suite() { - return suite(PDOMTagIndexTests.class); - } - private static class MockIndexLocationConverter implements IIndexLocationConverter { @Override public IIndexFileLocation fromInternalFormat(String raw) { @@ -50,10 +52,8 @@ public class PDOMTagIndexTests extends BaseTestCase { } } - @Override - protected void setUp() throws Exception { - super.setUp(); - + @BeforeEach + protected void beforeEach() throws Exception { pdomFile = File.createTempFile(getClass().getSimpleName() + '.' + Double.toString(Math.random()).substring(2), null); pdom = new WritablePDOM(pdomFile, new MockIndexLocationConverter(), @@ -61,15 +61,14 @@ public class PDOMTagIndexTests extends BaseTestCase { pdom.acquireWriteLock(null); } - @Override - protected void tearDown() throws Exception { + @AfterEach + protected void afterEach() throws Exception { try { pdom.close(); } finally { pdom.releaseWriteLock(); } pdomFile.delete(); - super.tearDown(); } // return the nearest valid record that is less than the specified base @@ -81,6 +80,7 @@ public class PDOMTagIndexTests extends BaseTestCase { } // A quick sanity test to confirm basic functionality. + @Test public void testSimple() throws Exception { String tagger = "tagger_a"; long rec = computeValidRecord(); @@ -89,6 +89,7 @@ public class PDOMTagIndexTests extends BaseTestCase { assertNotNull(PDOMTagIndex.getTag(pdom, rec, tagger)); } + @Test public void testMultipleTaggers() throws Exception { String tagger_a = "tagger_a"; String tagger_b = "tagger_b"; @@ -112,6 +113,7 @@ public class PDOMTagIndexTests extends BaseTestCase { assertEquals(2, tag_count); } + @Test public void testReplaceTags() throws Exception { String tagger_a = "tagger_a"; String tagger_b = "tagger_b"; diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTestBase.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTestBase.java index 5d4f6a97937..5f46e280587 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTestBase.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTestBase.java @@ -16,8 +16,12 @@ *******************************************************************************/ package org.eclipse.cdt.internal.pdom.tests; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.io.File; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -37,7 +41,7 @@ import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.parser.tests.VisibilityAsserts; import org.eclipse.cdt.core.testplugin.CProjectHelper; import org.eclipse.cdt.core.testplugin.CTestPlugin; -import org.eclipse.cdt.core.testplugin.util.BaseTestCase; +import org.eclipse.cdt.core.testplugin.util.BaseTestCase5; import org.eclipse.cdt.core.testplugin.util.ModelJoiner; import org.eclipse.cdt.core.testplugin.util.TestSourceReader; import org.eclipse.cdt.internal.core.index.IIndexFragment; @@ -59,7 +63,7 @@ import org.eclipse.ui.wizards.datatransfer.ImportOperation; /** * @author Doug Schaefer */ -public class PDOMTestBase extends BaseTestCase { +public class PDOMTestBase extends BaseTestCase5 { protected static final IProgressMonitor PROGRESS = new NullProgressMonitor(); static IPath rootPath = new Path("resources/pdomtests"); private String projectName; @@ -246,16 +250,7 @@ public class PDOMTestBase extends BaseTestCase { return (IBinding[]) preresult.toArray(new IBinding[preresult.size()]); } - protected void assertInstance(Object o, Class c) { - assertNotNull(o); - assertTrue("Expected " + c.getName() + " but got " + o.getClass().getName(), c.isInstance(o)); - } - - public static Pattern[] makePatternArray(String[] args) { - List preresult = new ArrayList(); - for (String arg : args) { - preresult.add(Pattern.compile(arg)); - } - return (Pattern[]) preresult.toArray(new Pattern[preresult.size()]); + public static Pattern[] makePatternArray(String... args) { + return Arrays.asList(args).stream().map(Pattern::compile).toArray(Pattern[]::new); } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/RaceCondition157992Test.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/RaceCondition157992Test.java index c83a91e2286..7757838c377 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/RaceCondition157992Test.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/RaceCondition157992Test.java @@ -16,6 +16,8 @@ *******************************************************************************/ package org.eclipse.cdt.internal.pdom.tests; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.util.regex.Pattern; import org.eclipse.cdt.core.dom.ast.IBinding; @@ -24,18 +26,14 @@ import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.internal.core.CCoreInternals; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.core.runtime.NullProgressMonitor; - -import junit.framework.Test; +import org.junit.jupiter.api.Test; /** * Test case for a race condition from Bugzilla#157992 */ public class RaceCondition157992Test extends PDOMTestBase { - public static Test suite() { - return suite(RaceCondition157992Test.class); - } - + @Test public void testRepeatedly() throws Exception { int successes = 0, noTrials = 100; @@ -53,7 +51,7 @@ public class RaceCondition157992Test extends PDOMTestBase { String msg = "Same indexer on same project produces different results." + "Failure rate of " + (noTrials - successes) + " failures in " + noTrials + " tests"; - assertTrue("Non-race-condition failure", successes != 0); - assertTrue(msg, successes == noTrials); + assertTrue(successes != 0, "Non-race-condition failure"); + assertTrue(successes == noTrials, msg); } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/TypesTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/TypesTests.java index 00cfdd60c14..9f0ee7fda99 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/TypesTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/TypesTests.java @@ -14,6 +14,8 @@ *******************************************************************************/ package org.eclipse.cdt.internal.pdom.tests; +import static org.junit.jupiter.api.Assertions.assertEquals; + import java.util.regex.Pattern; import org.eclipse.cdt.core.dom.IName; @@ -30,8 +32,9 @@ import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.internal.core.CCoreInternals; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.core.runtime.NullProgressMonitor; - -import junit.framework.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * @author Doug Schaefer @@ -41,12 +44,8 @@ public class TypesTests extends PDOMTestBase { protected PDOM pdom; - public static Test suite() { - return suite(TypesTests.class); - } - - @Override - protected void setUp() throws Exception { + @BeforeEach + protected void beforeEach() throws Exception { if (pdom == null) { ICProject project = createProject("types"); pdom = (PDOM) CCoreInternals.getPDOMManager().getPDOM(project); @@ -54,11 +53,12 @@ public class TypesTests extends PDOMTestBase { pdom.acquireReadLock(); } - @Override - protected void tearDown() throws Exception { + @AfterEach + protected void afterEach() throws Exception { pdom.releaseReadLock(); } + @Test public void testC() throws Exception { // Get the binding for A::f IBinding[] CAs = pdom.findBindings(Pattern.compile("CA"), false, IndexFilter.ALL, new NullProgressMonitor()); @@ -76,6 +76,7 @@ public class TypesTests extends PDOMTestBase { assertEquals(offset("typedef.c", "x->x") + 3, loc.getNodeOffset()); } + @Test public void testCPP() throws Exception { // Get the binding for A::f IBinding[] As = pdom.findBindings(Pattern.compile("A"), true, IndexFilter.ALL, new NullProgressMonitor()); @@ -93,6 +94,7 @@ public class TypesTests extends PDOMTestBase { assertEquals(offset("typedef.cpp", "x->f") + 3, loc.getNodeOffset()); } + @Test public void test145351() throws Exception { IBinding[] bindings = pdom.findBindings(Pattern.compile("spinlock_t"), false, IndexFilter.ALL, new NullProgressMonitor()); diff --git a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/BaseTestCase5.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/BaseTestCase5.java index e070f870214..36cad3fdf69 100644 --- a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/BaseTestCase5.java +++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/BaseTestCase5.java @@ -107,7 +107,9 @@ public abstract class BaseTestCase5 { * enough for the general use case of getName. */ public String getName() { - return testInfo.getDisplayName(); + String displayName = testInfo.getDisplayName(); + String replaceFirst = displayName.replaceFirst("\\(.*\\)", ""); + return replaceFirst; } public static NullProgressMonitor npm() { 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 3290acb2ab6..f23ee59d87b 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 @@ -124,10 +124,8 @@ public class TestSourceReader { while (clazz.getMethod(testName).getDeclaringClass() != clazz) { clazz = clazz.getSuperclass(); } - } catch (SecurityException e) { - Assert.fail(e.getMessage()); - } catch (NoSuchMethodException e) { - Assert.fail(e.getMessage()); + } catch (NoSuchMethodException | SecurityException e1) { + throw new AssertionError("Failed to find expected class", e1); } while (true) {