|
15 | 15 | *******************************************************************************/ |
16 | 16 | package org.eclipse.cdt.internal.index.tests; |
17 | 17 |
|
| 18 | +import static org.junit.jupiter.api.Assertions.assertNotEquals; |
| 19 | + |
18 | 20 | import java.io.ByteArrayInputStream; |
19 | 21 | import java.io.File; |
20 | 22 | import java.io.IOException; |
@@ -1576,6 +1578,109 @@ public void testUnrelatedTypedef_Bug214146() throws Exception { |
1576 | 1578 | } |
1577 | 1579 | } |
1578 | 1580 |
|
| 1581 | + // // h1.h |
| 1582 | + // typedef struct { |
| 1583 | + // int ts1; |
| 1584 | + // } ts; |
| 1585 | + // |
| 1586 | + // using tu = struct { |
| 1587 | + // int tu1; |
| 1588 | + // }; |
| 1589 | + // |
| 1590 | + // struct A { |
| 1591 | + // int a1; |
| 1592 | + // }; |
| 1593 | + |
| 1594 | + // // h2.h |
| 1595 | + // typedef struct { |
| 1596 | + // int ts2; |
| 1597 | + // } ts; |
| 1598 | + // |
| 1599 | + // using tu = struct { |
| 1600 | + // int tu2; |
| 1601 | + // }; |
| 1602 | + // |
| 1603 | + // struct A { |
| 1604 | + // int a2; |
| 1605 | + // }; |
| 1606 | + |
| 1607 | + // // s1.cpp |
| 1608 | + // #include "h1.h" |
| 1609 | + // int test1() { |
| 1610 | + // ts t; |
| 1611 | + // t.ts1 = 1; |
| 1612 | + // tu u; |
| 1613 | + // u.tu1 = 2; |
| 1614 | + // A a; |
| 1615 | + // a.a1 = 3; |
| 1616 | + // return u.u1 + a.a1; |
| 1617 | + // } |
| 1618 | + |
| 1619 | + // // s2.cpp |
| 1620 | + // #include "h2.h" |
| 1621 | + // int test2() { |
| 1622 | + // ts t; |
| 1623 | + // t.ts2 = 4; |
| 1624 | + // tu u; |
| 1625 | + // u.tu2 = 5; |
| 1626 | + // A a; |
| 1627 | + // a.a2 = 6; |
| 1628 | + // return u.u2 + a.a2; |
| 1629 | + // } |
| 1630 | + public void testUnrelatedTypedefInHeader_Bug214146() throws Exception { |
| 1631 | + String[] contents = getContentsForTest(4); |
| 1632 | + final IIndexManager indexManager = CCorePlugin.getIndexManager(); |
| 1633 | + IFile h1h = TestSourceReader.createFile(fCProject.getProject(), "h1.h", contents[0]); |
| 1634 | + IFile h2h = TestSourceReader.createFile(fCProject.getProject(), "h2.h", contents[1]); |
| 1635 | + IFile s1cpp = TestSourceReader.createFile(fCProject.getProject(), "s1.cpp", contents[2]); |
| 1636 | + IFile s2cpp = TestSourceReader.createFile(fCProject.getProject(), "s2.cpp", contents[3]); |
| 1637 | + indexManager.reindex(fCProject); |
| 1638 | + waitForIndexer(); |
| 1639 | + fIndex.acquireReadLock(); |
| 1640 | + try { |
| 1641 | + BindingAssertionHelper h1Helper = new BindingAssertionHelper(h1h, contents[0], fIndex); |
| 1642 | + ITypedef typedef1h = h1Helper.assertNonProblem("ts;", 2, ITypedef.class); |
| 1643 | + ITypedef alias1h = h1Helper.assertNonProblem("tu =", 2, ITypedef.class); |
| 1644 | + ICPPClassType class1h = h1Helper.assertNonProblem("A", 1, ICPPClassType.class); |
| 1645 | + |
| 1646 | + BindingAssertionHelper h2Helper = new BindingAssertionHelper(h2h, contents[1], fIndex); |
| 1647 | + ITypedef typedef2h = h2Helper.assertNonProblem("ts;", 2, ITypedef.class); |
| 1648 | + ITypedef alias2h = h2Helper.assertNonProblem("tu =", 2, ITypedef.class); |
| 1649 | + ICPPClassType class2h = h2Helper.assertNonProblem("A", 1, ICPPClassType.class); |
| 1650 | + |
| 1651 | + assertNotEquals(typedef1h, typedef2h); |
| 1652 | + assertNotEquals(alias1h, alias2h); |
| 1653 | + assertNotEquals(class1h, class2h); |
| 1654 | + |
| 1655 | + BindingAssertionHelper s1Helper = new BindingAssertionHelper(s1cpp, contents[2], fIndex); |
| 1656 | + ITypedef typedef1binding = s1Helper.assertNonProblem("ts t;", 2, ITypedef.class); |
| 1657 | + s1Helper.assertNonProblem("ts1 = 1;", 3, ICPPVariable.class); |
| 1658 | + ITypedef alias1binding = s1Helper.assertNonProblem("tu u;", 2, ITypedef.class); |
| 1659 | + s1Helper.assertNonProblem("tu1 = 2;", 3, ICPPVariable.class); |
| 1660 | + ICPPClassType a1binding = s1Helper.assertNonProblem("A a;", 1, ICPPClassType.class); |
| 1661 | + s1Helper.assertNonProblem("a1 = 3;", 2, ICPPVariable.class); |
| 1662 | + |
| 1663 | + BindingAssertionHelper s2Helper = new BindingAssertionHelper(s2cpp, contents[3], fIndex); |
| 1664 | + ITypedef typedef2binding = s2Helper.assertNonProblem("ts t;", 2, ITypedef.class); |
| 1665 | + s2Helper.assertNonProblem("ts2 = 4;", 3, ICPPVariable.class); |
| 1666 | + ITypedef alias2binding = s2Helper.assertNonProblem("tu u;", 2, ITypedef.class); |
| 1667 | + s2Helper.assertNonProblem("tu2 = 5;", 3, ICPPVariable.class); |
| 1668 | + ICPPClassType a2binding = s2Helper.assertNonProblem("A a;", 1, ICPPClassType.class); |
| 1669 | + s2Helper.assertNonProblem("a2 = 6;", 2, ICPPVariable.class); |
| 1670 | + |
| 1671 | + // typedefs must be unique |
| 1672 | + assertNotEquals(typedef1binding, typedef2binding); |
| 1673 | + |
| 1674 | + // aliases must be unique |
| 1675 | + assertNotEquals(alias1binding, alias2binding); |
| 1676 | + |
| 1677 | + // class should be the same since CDT indexer adopts class redeclaration from different TU |
| 1678 | + assertEquals(a1binding, a2binding); |
| 1679 | + } finally { |
| 1680 | + fIndex.releaseReadLock(); |
| 1681 | + } |
| 1682 | + } |
| 1683 | + |
1579 | 1684 | // #undef BBB |
1580 | 1685 |
|
1581 | 1686 | // #define BBB |
|
0 commit comments