d1aa37a4f5a7b788fd2822ce6a4f8739d4f7747d
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / event / CTFCallsiteTest.java
1 /*******************************************************************************
2 * Copyright (c) 2013 Ericsson
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Matthew Khouzam - Initial API and implementation
10 *******************************************************************************/
11
12 package org.eclipse.linuxtools.ctf.core.tests.event;
13
14 import static org.junit.Assert.assertEquals;
15 import static org.junit.Assert.assertNotNull;
16
17 import java.util.Arrays;
18
19 import org.eclipse.linuxtools.ctf.core.event.CTFCallsite;
20 import org.junit.After;
21 import org.junit.Before;
22 import org.junit.Test;
23
24 /**
25 * The class <code>CTFCallsiteTest</code> contains tests for the class
26 * <code>{@link CTFCallsite}</code>.
27 *
28 * @author Matthew Khouzam
29 * @version $Revision: 1.0 $
30 */
31
32 public class CTFCallsiteTest {
33 /**
34 * Perform pre-test initialization.
35 */
36 @Before
37 public void setUp() {
38 // add additional set up code here
39 }
40
41 /**
42 * Perform post-test clean-up.
43 */
44 @After
45 public void tearDown() {
46 // Add additional tear down code here
47 }
48
49 private static CTFCallsite GenerateCS(long ip){
50 return new CTFCallsite("event name", "func name", ip, "file.java", 1);
51 }
52
53 /**
54 * Test the constructor
55 */
56 @Test
57 public void constructorTest(){
58 CTFCallsite cs = GenerateCS(0x01);
59 assertNotNull(cs);
60 }
61
62 /**
63 * Test the comparator (it should sort using the IP)
64 */
65 @Test
66 public void comparatorTest(){
67 CTFCallsite cs[] = new CTFCallsite[5];
68 long vals[] = {1L, 0L, -2L, 2L, -1L};
69 for(int i = 0 ; i < 5 ; i++ ){
70 cs[i] = GenerateCS(vals[i]);
71 }
72
73 assertEquals(1, cs[0].compareTo(cs[1]));
74 assertEquals(-1, cs[1].compareTo(cs[0]));
75 assertEquals(0, cs[0].compareTo(cs[0]));
76 assertEquals(-1, cs[0].compareTo(cs[2]));
77 assertEquals(1, cs[2].compareTo(cs[0]));
78
79 Arrays.sort(cs);
80
81 assertEquals( 0L, cs[0].getIp());
82 assertEquals( 1L, cs[1].getIp());
83 assertEquals( 2L, cs[2].getIp());
84 assertEquals( -2L , cs[3].getIp());
85 assertEquals( -1L, cs[4].getIp());
86 }
87
88 /**
89 * Tests the output of a callsite toString function
90 */
91 @Test
92 public void toStringTest(){
93 CTFCallsite cs = GenerateCS(0x01);
94 assertEquals("file.java/func name:1", cs.toString());
95 }
96
97 /**
98 * Launch the test.
99 *
100 * @param args
101 * the command line arguments
102 */
103 public static void main(String[] args) {
104 new org.junit.runner.JUnitCore().run(CTFCallsiteTest.class);
105 }
106 }
This page took 0.033244 seconds and 5 git commands to generate.