blob: 7c6fe979c400bd0406f0040be6f80203fbcc7b54 [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
* Nokia
*******************************************************************************/
package org.eclipse.cdt.debug.edc.tests;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.cdt.core.IAddress;
import org.eclipse.cdt.core.IAddressFactory;
import org.eclipse.cdt.debug.edc.internal.symbols.ISection;
import org.eclipse.cdt.debug.edc.internal.symbols.LexicalBlockScope;
import org.eclipse.cdt.debug.edc.internal.symbols.Section;
import org.eclipse.cdt.debug.edc.internal.symbols.Symbol;
import org.eclipse.cdt.debug.edc.internal.symbols.files.ExecutableSection;
import org.eclipse.cdt.debug.edc.internal.symbols.files.SectionInfo;
import org.eclipse.cdt.debug.edc.symbols.IHasSize;
import org.eclipse.cdt.debug.edc.symbols.IAddressInterval;
import org.eclipse.cdt.debug.edc.symbols.IExecutableSection;
import org.eclipse.cdt.utils.Addr64Factory;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
public class TestIAddressInterval {
private static IAddressInterval emptyExecutableSection;
private static IExecutableSection fullExecutableSection;
private static IAddressInterval emptyScope;
private static IAddressInterval fullScope;
private static IAddressInterval emptySection;
private static ISection fullSection;
private static IAddressInterval fullSymbol;
private static IAddressInterval emptySymbol;
private static IAddress twenty;
private static IAddress fourty;
private static IAddress twoFourty;
private static IAddress oneFourty;
@BeforeClass
public static void setup() {
IAddressFactory addrF = new Addr64Factory();
// IAddress zero = addrF.createAddress("0x0");
twenty = addrF.createAddress("0x20");
fourty = addrF.createAddress("0x40");
oneFourty = addrF.createAddress("0x140");
twoFourty = addrF.createAddress("0x240");
Map<String, Object> emptyMap = new HashMap<String, Object>();
emptySection = new Section(0, 0, fourty, emptyMap);
fullSection = new Section(1, 0x200, fourty, emptyMap);
emptyExecutableSection
= new ExecutableSection(null, "emptyExecutableSection",
new SectionInfo(fourty, 0, 0));
fullExecutableSection
= new ExecutableSection(null, "fullExecutableSection",
new SectionInfo(fourty, 0, 0x100));
emptyScope = new LexicalBlockScope("emptyScope", null, twenty, twenty);
fullScope = new LexicalBlockScope("fullScope", null, twenty, fourty);
emptySymbol = new Symbol("emptySymbol", fourty, 0);
fullSymbol = new Symbol("fullSymbol", twenty, 0x20);
}
@Test
public void getName() {
testName(emptySection, "0");
testName(fullSection, "1");
testName(emptyExecutableSection, "emptyExecutableSection");
testName(fullExecutableSection, "fullExecutableSection");
testName(emptyScope, "emptyScope");
testName(fullScope, "fullScope");
testName(emptySymbol, "emptySymbol");
testName(fullSymbol, "fullSymbol");
}
private void testName(IAddressInterval interval, String name) {
Assert.assertNotNull(interval.getName());
Assert.assertEquals(name, interval.getName());
}
@Test
public void hasEmptyRange() {
testEmpty(emptySection, true);
testEmpty(fullSection, false);
testEmpty(emptyExecutableSection, true);
testEmpty(fullExecutableSection, false);
testEmpty(emptyScope, true);
testEmpty(fullScope, false);
testEmpty(emptySymbol, true);
testEmpty(fullSymbol, false);
}
private void testEmpty(IAddressInterval interval, boolean empty) {
Assert.assertEquals(empty, interval.hasEmptyRange());
}
@Test
public void getLowAddress() {
testLowAddress(emptySection, fourty);
testLowAddress(fullSection, fourty);
testLowAddress(emptyExecutableSection, fourty);
testLowAddress(fullExecutableSection, fourty);
testLowAddress(emptyScope, twenty);
testLowAddress(fullScope, twenty);
testLowAddress(emptySymbol, fourty);
testLowAddress(fullSymbol, twenty);
}
private void testLowAddress(IAddressInterval interval, IAddress address) {
Assert.assertEquals(address, interval.getLowAddress());
}
@Test
public void getHighAddress() {
testHighAddress(emptySection, fourty);
testHighAddress(fullSection, twoFourty);
testHighAddress(emptyExecutableSection, fourty);
testHighAddress(fullExecutableSection, oneFourty);
testHighAddress(emptyScope, twenty);
testHighAddress(fullScope, fourty);
testHighAddress(emptySymbol, fourty);
testHighAddress(fullSymbol, fourty);
}
private void testHighAddress(IAddressInterval interval, IAddress address) {
Assert.assertEquals(address, interval.getHighAddress());
}
@Test
public void getSize() {
testGetSize(emptySection, 0);
testGetSize(fullSection, 0x200);
testGetSize(emptyExecutableSection, 0);
testGetSize(fullExecutableSection, 0x100);
testGetSize(emptySymbol, 0);
testGetSize(fullSymbol, 0x20);
}
private void testGetSize(IAddressInterval interval, int size) {
Assert.assertTrue(interval instanceof IHasSize);
Assert.assertEquals(size, ((IHasSize) interval).getSize());
}
}