37451940c3ddec2baadc31ba777bf02dc44fd561
[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 @SuppressWarnings("nls")
50 private static CTFCallsite GenerateCS(long ip){
51 return new CTFCallsite("event name", "func name", ip, "file.java", 1);
52 }
53
54 /**
55 * Test the constructor
56 */
57 @Test
58 public void constructorTest(){
59 CTFCallsite cs = GenerateCS(0x01);
60 assertNotNull(cs);
61 }
62
63 /**
64 * Test the comparator (it should sort using the IP)
65 */
66 @Test
67 public void comparatorTest(){
68 CTFCallsite cs[] = new CTFCallsite[5];
69 long vals[] = {1L, 0L, -2L, 2L, -1L};
70 for(int i = 0 ; i < 5 ; i++ ){
71 cs[i] = GenerateCS(vals[i]);
72 }
73
74 assertEquals(1, cs[0].compareTo(cs[1]));
75 assertEquals(-1, cs[1].compareTo(cs[0]));
76 assertEquals(0, cs[0].compareTo(cs[0]));
77 assertEquals(-1, cs[0].compareTo(cs[2]));
78 assertEquals(1, cs[2].compareTo(cs[0]));
79
80 Arrays.sort(cs);
81
82 assertEquals( 0L, cs[0].getIp());
83 assertEquals( 1L, cs[1].getIp());
84 assertEquals( 2L, cs[2].getIp());
85 assertEquals( -2L , cs[3].getIp());
86 assertEquals( -1L, cs[4].getIp());
87 }
88
89 /**
90 * Tests the output of a callsite toString function
91 */
92 @Test
93 public void toStringTest(){
94 CTFCallsite cs = GenerateCS(0x01);
95 assertEquals("file.java/func name:1", cs.toString()); //$NON-NLS-1$
96 }
97
98 /**
99 * Launch the test.
100 *
101 * @param args
102 * the command line arguments
103 */
104 public static void main(String[] args) {
105 new org.junit.runner.JUnitCore().run(CTFCallsiteTest.class);
106 }
107 }
This page took 0.048606 seconds and 5 git commands to generate.