blob: a4eb64a0fdf5546d59c7af890f5af53d5c62e987 [file] [log] [blame]
/*******************************************************************************
* 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
*******************************************************************************/
package org.eclipse.cdt.debug.edc.tests;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import java.util.Iterator;
import org.eclipse.cdt.debug.edc.internal.symbols.dwarf.RangeList;
import org.eclipse.cdt.debug.edc.symbols.IRangeList;
import org.eclipse.cdt.debug.edc.symbols.IRangeList.Entry;
import org.junit.BeforeClass;
import org.junit.Test;
public class TestRangeList {
private static RangeList first;
private static int low;
private static int high;
private static RangeList second;
private static RangeList expectedMerged;
@BeforeClass
public static void init(){
low = 0;
high = 120;
first = new RangeList();
first.addRange(low,10);
first.addRange(25,32);
first.addRange(60,68);
first.addRange(107,high);
second = new RangeList();
second.addRange(7,18);
second.addRange(32,35);
second.addRange(52,60);
second.addRange(75,80);
second.addRange(93,high);
expectedMerged = new RangeList();
expectedMerged.addRange(low,18);
expectedMerged.addRange(25,35);
expectedMerged.addRange(52,68);
expectedMerged.addRange(75,80);
expectedMerged.addRange(93,high);
}
@Test
public void lowHigh(){
assertEquals(low,first.getLowAddress());
assertEquals(high,first.getHighAddress());
assertEquals(low,expectedMerged.getLowAddress());
assertEquals(high,expectedMerged.getHighAddress());
}
@Test
public void merge(){
IRangeList merged = RangeList.mergeRangeLists(first, second);
Iterator<Entry> mergedIter = merged.iterator();
Iterator<Entry> expectedIter = expectedMerged.iterator();
while (mergedIter.hasNext() && expectedIter.hasNext()){
assertEquals("Entries should be equal",expectedIter.next(),mergedIter.next());
}
assertFalse("Should be finished",mergedIter.hasNext());
assertFalse("Should be finished",expectedIter.hasNext());
}
@Test
public void isInRange(){
checkInRange(7,true,true,true);
checkInRange(8,true,true,true);
checkInRange(10,false,true,true);
checkInRange(20,false,false,false);
checkInRange(60,true,false,true);
}
private void checkInRange(int point, boolean inFirst, boolean inSecond, boolean inExpectedMerged) {
assertEquals(inFirst,first.isInRange(point));
assertEquals(inSecond,second.isInRange(point));
assertEquals(inExpectedMerged,expectedMerged.isInRange(point));
}
}