Skip to content

Commit

Permalink
Convert pdom tests to JUnit5 format
Browse files Browse the repository at this point in the history
This will allow, if needed, to mark tests as flaky
  • Loading branch information
jonahgraham committed Oct 26, 2022
1 parent 64925b8 commit b5bdf61
Show file tree
Hide file tree
Showing 39 changed files with 708 additions and 552 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,9 +26,9 @@
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
Expand All @@ -37,21 +39,17 @@ 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");
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,
Expand All @@ -69,31 +67,36 @@ public void _testSimpleCStructureDistinction() throws Exception {
}

// 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);
assertType(pdom, "CStructure3", ICompositeType.class);
}

// 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);
Expand All @@ -103,6 +106,7 @@ public void testDeepCStructureDeclarations() throws Exception {
}

// 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);
Expand All @@ -114,6 +118,7 @@ public void testDeepCStructureMemberDeclarations() throws Exception {
}

// 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);
Expand All @@ -123,6 +128,7 @@ public void testDeepCStructureDefinitions() throws Exception {
}

// 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);
Expand All @@ -134,6 +140,7 @@ public void testDeepCStructureMemberDefinitions() throws Exception {
}

// 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);
Expand All @@ -143,6 +150,7 @@ public void testDeepCStructureReferences() throws Exception {
}

// 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);
Expand All @@ -162,45 +170,52 @@ public void _testCUnionDistinction() throws Exception {
}

//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);
assertDeclarationCount(pdom, "CUnion2", 1);
}

//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);
assertDefinitionCount(pdom, "CUnion2", 1);
}

//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);
assertReferenceCount(pdom, "CUnion2", 2);
}

//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);
Expand All @@ -214,6 +229,7 @@ public void testCMixedDeclarations() throws Exception {
}

// 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);
Expand All @@ -227,6 +243,7 @@ public void testCMixedDefinitions() throws Exception {
}

// 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);
Expand All @@ -240,6 +257,7 @@ public void testCMixedReferences() throws Exception {
}

// 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);
Expand All @@ -253,6 +271,7 @@ public void testCMixedMemberDeclarations() throws Exception {
}

// 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);
Expand All @@ -266,6 +285,7 @@ public void testCMixedMemberDefinitions() throws Exception {
}

// 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,8 +27,9 @@
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
Expand All @@ -34,57 +39,59 @@ 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,
new NullProgressMonitor());
}
}

@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");
assertEquals(1, bindings.length);
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);
Expand All @@ -96,6 +103,7 @@ public void testKnRStyleFunctionWithProblemParameters() throws Exception {
assertTrue(params[2].getType() instanceof ICBasicType);
}

@Test
public void testFunctionWithRegisterParam() throws Exception {
IBinding[] bindings = findQualifiedName(pdom, "storageClassCFunction");
assertEquals(1, bindings.length);
Expand Down
Loading

0 comments on commit b5bdf61

Please sign in to comment.