1 package net.sf.madmap;
2
3 import java.util.*;
4 import java.util.concurrent.*;
5
6 import junit.framework.Test;
7 import junit.framework.TestCase;
8 import junit.framework.TestSuite;
9
10
11
12
13 public class BinTest
14 extends TestCase
15 {
16 Madmap _owner;
17
18
19
20
21
22
23 public BinTest( String testName )
24 {
25 super( testName );
26 }
27
28
29
30
31 public static Test suite()
32 {
33 return new TestSuite( BinTest.class );
34 }
35
36
37
38
39 public void xtestApp1()
40 {
41 _owner = new Madmap( "src/test/resources/madmap-ducks.bin");
42 MadmapMain._nogui = true;
43 MadmapMain._verbose = true;
44
45 _owner.init();
46 assertNotNull( _owner );
47 }
48
49
50
51
52 public void testApp2()
53 {
54 _owner = new Madmap( "src/test/resources/heap-ducks-mac2.bin");
55 MadmapMain._nogui = true;
56 MadmapMain._verbose = true;
57
58 _owner.init();
59 assertNotNull( _owner );
60 }
61
62
63
64
65 public void testBinClass()
66 {
67 long addr = 0x12345678;
68 long superAddr = 0x87654321;
69 long loader = 0xffffffff;
70 String name = "BinaryTestClass";
71 int instanceSize = 16;
72 ArrayList names = new ArrayList();
73 ArrayList refs = new ArrayList();
74
75 names.add("field0");
76 names.add("field1");
77 refs.add(new Long(0x55555555));
78 refs.add(new Long(0x66666666));
79
80 HprofBinClassElement testClass = new HprofBinClassElement(addr, name);
81 testClass.updateLoadClass(99, instanceSize, superAddr, loader, names, refs);
82 assertEquals(testClass.instanceSize(), instanceSize);
83 assertNotNull(testClass.toString());
84 }
85
86
87
88
89 public void testBinClassSuperTypeInfoCollection()
90 {
91 long addr = 0x12345678;
92 long superAddr = 0x87654321;
93 long loader = 0xffffffff;
94 String name = "BinaryTestClass";
95 String superName = "BinaryTestSuperClass";
96 int instanceSize = 8;
97 int superSize = 4;
98 ArrayList<Byte> t1 = new ArrayList<Byte>();
99 ArrayList<Byte> t2 = new ArrayList<Byte>();
100
101 t1.add(BasicTypeInfo.INT.getCode());
102 t2.add(BasicTypeInfo.FLOAT.getCode());
103
104 HashMap<HprofClassElement,HprofClassElement> class_list = new HashMap<HprofClassElement,HprofClassElement>();
105
106 HprofBinClassElement testClass = new HprofBinClassElement(addr, name);
107 HprofBinClassElement testSuperClass = new HprofBinClassElement(superAddr, superName);
108
109 testClass.setNonStaticTypeInfo(t1);
110 testSuperClass.setNonStaticTypeInfo(t2);
111
112 class_list.put(testClass, testClass);
113 class_list.put(testSuperClass, testSuperClass);
114
115 testClass.updateLoadClass(99, instanceSize, superAddr, loader, null, null);
116 testSuperClass.updateLoadClass(99, superSize, 0, loader, null, null);
117
118 ArrayList<Byte> fullTypeInfo = testClass.buildSuperTypeInfo(class_list);
119
120 assertNotNull(fullTypeInfo);
121 assert testClass.getSizeForTypeInfo() == instanceSize : "getSizeForTypeInfo is wrong";
122 assert fullTypeInfo.size() == 2 : "should be 2 entries in type info";
123 assert fullTypeInfo.get(0) == BasicTypeInfo.INT.getCode() : "should be an int in type info";
124 assert fullTypeInfo.get(1) == BasicTypeInfo.FLOAT.getCode() : "should be an int in type info";
125 }
126 }