Update Grammar and Add support for callsites
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / event / CTFCallsiteTest.java
CommitLineData
4c9d2941
MK
1package org.eclipse.linuxtools.ctf.core.tests.event;
2
3import static org.junit.Assert.assertEquals;
4import static org.junit.Assert.assertNotNull;
5
6import java.util.Arrays;
7
8import org.eclipse.linuxtools.ctf.core.event.CTFCallsite;
9import org.junit.After;
10import org.junit.Before;
11import org.junit.Test;
12
13/**
14 * The class <code>CTFCallsiteTest</code> contains tests for the class
15 * <code>{@link CTFCallsite}</code>.
16 *
17 * @author Matthew Khouzam
18 * @version $Revision: 1.0 $
19 */
20
21public class CTFCallsiteTest {
22 /**
23 * Perform pre-test initialization.
24 */
25 @Before
26 public void setUp() {
27 // add additional set up code here
28 }
29
30 /**
31 * Perform post-test clean-up.
32 */
33 @After
34 public void tearDown() {
35 // Add additional tear down code here
36 }
37
38 @SuppressWarnings("nls")
39 private static CTFCallsite GenerateCS(long ip){
40 return new CTFCallsite("event name", "func name", ip, "file.java", 1);
41 }
42
43 /**
44 * Test the constructor
45 */
46 @Test
47 public void constructorTest(){
48 CTFCallsite cs = GenerateCS(0x01);
49 assertNotNull(cs);
50 }
51
52 /**
53 * Test the comparator (it should sort using the IP)
54 */
55 @Test
56 public void comparatorTest(){
57 CTFCallsite cs[] = new CTFCallsite[5];
58 long vals[] = {1L, 0L, -2L, 2L, -1L};
59 for(int i = 0 ; i < 5 ; i++ ){
60 cs[i] = GenerateCS(vals[i]);
61 }
62
63 assertEquals(1, cs[0].compareTo(cs[1]));
64 assertEquals(-1, cs[1].compareTo(cs[0]));
65 assertEquals(0, cs[0].compareTo(cs[0]));
66 assertEquals(-1, cs[0].compareTo(cs[2]));
67 assertEquals(1, cs[2].compareTo(cs[0]));
68
69 Arrays.sort(cs);
70
71 assertEquals( 0L, cs[0].getIp());
72 assertEquals( 1L, cs[1].getIp());
73 assertEquals( 2L, cs[2].getIp());
74 assertEquals( -2L , cs[3].getIp());
75 assertEquals( -1L, cs[4].getIp());
76 }
77
78 /**
79 * Tests the output of a callsite toString function
80 */
81 @Test
82 public void toStringTest(){
83 CTFCallsite cs = GenerateCS(0x01);
84 assertEquals("file.java/func name:1", cs.toString()); //$NON-NLS-1$
85 }
86
87 /**
88 * Launch the test.
89 *
90 * @param args
91 * the command line arguments
92 */
93 public static void main(String[] args) {
94 new org.junit.runner.JUnitCore().run(CTFCallsiteTest.class);
95 }
96}
This page took 0.03221 seconds and 5 git commands to generate.