/******************************************************************************* | |
* Copyright (c) 2011 Broadcom and others. | |
* All rights reserved. This program and the accompanying materials | |
* are made available under the terms of the Eclipse Public License v1.0 | |
* which accompanies this distribution, and is available at | |
* http://www.eclipse.org/legal/epl-v10.html | |
* | |
* Contributors: | |
* Broadcom - Initial API and implementation | |
* Nokia - renamed and moved to package org.eclipse.cdt.debug.edc.tests | |
*******************************************************************************/ | |
package org.eclipse.cdt.debug.edc.tests; | |
import java.util.Collection; | |
import java.util.Iterator; | |
import org.eclipse.cdt.debug.edc.internal.services.dsf.Symbols; | |
import org.eclipse.cdt.debug.edc.symbols.ICompileUnitScope; | |
import org.eclipse.cdt.debug.edc.symbols.IEDCSymbolReader; | |
import org.eclipse.cdt.debug.edc.symbols.IScope; | |
import org.junit.Test; | |
public class TestDwarfCompileUnitChildren extends AbstractDwarfReaderTest { | |
@Test | |
public void checkChildrenParsed() { | |
for (TestInfo info : testInfos.values()) { | |
IEDCSymbolReader symbolReader = Symbols.getSymbolReader(info.symFile); | |
if (symbolReader != null) { | |
doCheckChildrenParsed(symbolReader.getModuleScope()); | |
} | |
} | |
} | |
private void doCheckChildrenParsed(IScope scope) { | |
Collection<IScope> originalChildren = scope.getChildren(); | |
if (scope instanceof ICompileUnitScope) { | |
((ICompileUnitScope) scope).getFunctions(); | |
} | |
Collection<IScope> newChildren = scope.getChildren(); | |
assertFalse("Should be different unmodifiable collections", newChildren == originalChildren); | |
assertEquals("Size should be identical", newChildren.size(), originalChildren.size()); | |
assertEquals("Same degree of emptiness", newChildren.isEmpty(), originalChildren.isEmpty()); | |
checkChildrenEqual(newChildren,originalChildren); | |
// Recurse into children | |
for (IScope child : newChildren) { | |
doCheckChildrenParsed(child); | |
} | |
} | |
private void checkChildrenEqual(Collection<IScope> newChildren, Collection<IScope> originalChildren) { | |
Iterator<IScope> newChildrenIter = newChildren.iterator(); | |
Iterator<IScope> origChildrenIter = originalChildren.iterator(); | |
while (newChildrenIter.hasNext() && origChildrenIter.hasNext()){ | |
IScope newChild = newChildrenIter.next(); | |
IScope origChild = origChildrenIter.next(); | |
assertEquals(newChild,origChild); | |
} | |
assertFalse(newChildrenIter.hasNext()); | |
assertFalse(origChildrenIter.hasNext()); | |
} | |
} |