/******************************************************************************* | |
* 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 - move to package org.eclipse.cdt.debug.edc.tests | |
*******************************************************************************/ | |
package org.eclipse.cdt.debug.edc.tests; | |
import org.eclipse.cdt.debug.edc.internal.symbols.ArrayBoundType; | |
import org.eclipse.cdt.debug.edc.internal.symbols.ArrayType; | |
import org.eclipse.cdt.debug.edc.internal.symbols.CPPBasicType; | |
import org.eclipse.cdt.debug.edc.internal.symbols.IArrayType; | |
import org.eclipse.cdt.debug.edc.internal.symbols.IBasicType; | |
import org.eclipse.cdt.debug.edc.internal.symbols.ICPPBasicType; | |
import org.junit.Assert; | |
import org.junit.BeforeClass; | |
import org.junit.Test; | |
public class TestArrayType { | |
private static ArrayType int4; | |
private static ArrayType long689; | |
@BeforeClass | |
public static void setup(){ | |
int4 = new ArrayType("int", null, 4, null); | |
int4.setType(new CPPBasicType("int", IBasicType.t_int, 0, 4)); | |
int4.addBound(new ArrayBoundType(null, 4)); | |
long689 = new ArrayType("long", null, 8, null); | |
long689.setType(new CPPBasicType("long", IBasicType.t_int, ICPPBasicType.IS_LONG, 8)); | |
long689.addBound(new ArrayBoundType(null, 6)); | |
long689.addBound(new ArrayBoundType(null, 8)); | |
long689.addBound(new ArrayBoundType(null, 9)); | |
} | |
@Test | |
public void testNameGeneration(){ | |
Assert.assertEquals("int[4]",int4.getName()); | |
Assert.assertFalse("int[]".equals(int4.getName())); | |
Assert.assertFalse("int".equals(int4.getName())); | |
Assert.assertEquals("long[6][8][9]",long689.getName()); | |
IArrayType foo = new ArrayType("foo",null,1,null); | |
foo.addBound(new ArrayBoundType(null, 1)); | |
Assert.assertEquals("foo[1]",foo.getName()); | |
foo.addBound(new ArrayBoundType(null, 5)); | |
Assert.assertEquals("foo[1][5]",foo.getName()); | |
} | |
@Test | |
public void getByteSize() { | |
Assert.assertEquals(16, int4.getByteSize()); | |
Assert.assertEquals(3456, long689.getByteSize()); | |
IArrayType foo = new ArrayType("foo", null, 1, null); | |
foo.setType(new CPPBasicType("foo", IBasicType.t_char, 0, 1)); | |
foo.addBound(new ArrayBoundType(null, 1)); | |
Assert.assertEquals(1, foo.getByteSize()); | |
foo.addBound(new ArrayBoundType(null, 5)); | |
Assert.assertEquals(5, foo.getByteSize()); | |
} | |
} |