Commit | Line | Data |
---|---|---|
03c71d1e ASL |
1 | |
2 | package org.eclipse.linuxtools.lttng.tests.jni; | |
3 | ||
9c841e9c | 4 | |
03c71d1e ASL |
5 | import org.eclipse.linuxtools.lttng.jni.JniEvent; |
6 | import org.eclipse.linuxtools.lttng.jni.JniMarker; | |
9c841e9c WB |
7 | import org.eclipse.linuxtools.lttng.jni.common.Jni_C_Pointer; |
8 | import org.eclipse.linuxtools.lttng.jni.exception.JniException; | |
9 | import org.eclipse.linuxtools.lttng.jni.factory.JniTraceFactory; | |
86de1b08 ASL |
10 | |
11 | import junit.framework.TestCase; | |
03c71d1e ASL |
12 | |
13 | /* | |
14 | Functions tested here : | |
15 | public JniMarker(JniMarker oldMarker) | |
16 | public JniMarker(long newMarkerPtr) throws JniException | |
17 | ||
18 | public String[] requestMarkerFieldToString() | |
19 | ||
20 | public String getName() | |
21 | public String getFormatOverview() | |
22 | public ArrayList<JniMarkerField> getMarkerFieldArrayList() | |
23 | ||
24 | public String toString() | |
25 | public void printMarkerInformation() | |
26 | */ | |
27 | ||
28 | public class JniMarkerTest extends TestCase | |
29 | { | |
30 | private final static boolean printLttDebug = false; | |
31 | ||
1c859a36 | 32 | private final static String tracepath="traceset/trace-15316events_nolost_newformat"; |
03c71d1e ASL |
33 | private final static String eventName="kernel0"; |
34 | ||
35 | private final static int numberOfMarkersFieldInMarker = 3; | |
36 | ||
37 | private JniMarker prepareMarkerToTest() { | |
38 | ||
39 | JniEvent tmpEvent = null; | |
40 | JniMarker tmpMarker = null; | |
41 | ||
42 | // This trace should be valid | |
43 | // We will read the second event to have something interesting to test on | |
44 | try { | |
9c841e9c | 45 | tmpEvent = JniTraceFactory.getJniTrace(tracepath, printLttDebug).requestEventByName(eventName); |
03c71d1e ASL |
46 | tmpEvent.readNextEvent(); |
47 | ||
48 | tmpMarker = tmpEvent.requestEventMarker(); | |
49 | } | |
50 | catch( JniException e) { } | |
51 | ||
52 | return tmpMarker; | |
53 | } | |
54 | ||
55 | public void testEventConstructors() { | |
56 | ||
57 | JniEvent tmpEvent = null; | |
58 | ||
9c841e9c WB |
59 | @SuppressWarnings("unused") |
60 | JniMarker testMarker1 = null; | |
61 | @SuppressWarnings("unused") | |
62 | JniMarker testMarker2 = null; | |
03c71d1e ASL |
63 | |
64 | // This event should be valid and will be used in test | |
65 | try { | |
9c841e9c | 66 | tmpEvent = JniTraceFactory.getJniTrace(tracepath, printLttDebug).requestEventByName(eventName); |
03c71d1e ASL |
67 | } |
68 | catch( JniException e) { } | |
69 | ||
86de1b08 ASL |
70 | // Test constructor with pointer on a wrong pointer |
71 | try { | |
9c841e9c | 72 | testMarker1 = tmpEvent.getParentTracefile().allocateNewJniMarker( new Jni_C_Pointer(0) ); |
86de1b08 ASL |
73 | fail("Construction with wrong pointer should fail!"); |
74 | } | |
75 | catch( JniException e) { | |
76 | } | |
77 | ||
03c71d1e ASL |
78 | // Test constructor with pointer on a correct pointer |
79 | try { | |
9c841e9c | 80 | testMarker1 = tmpEvent.getParentTracefile().allocateNewJniMarker( tmpEvent.requestEventMarker().getMarkerPtr() ); |
03c71d1e ASL |
81 | } |
82 | catch( JniException e) { | |
83 | fail("Construction with correct pointer failed!"); | |
84 | } | |
85 | ||
9c841e9c | 86 | /* |
03c71d1e ASL |
87 | // Test copy constructor |
88 | try { | |
89 | testMarker1 = new JniMarker( tmpEvent.requestEventMarker().getMarkerPtr() ); | |
90 | testMarker2 = new JniMarker( testMarker1); | |
91 | } | |
92 | catch( JniException e) { | |
93 | fail("Copy constructor failed!"); | |
94 | } | |
95 | assertSame("JniMarker name not same after using copy constructor", testMarker1.getName() , testMarker2.getName()); | |
9c841e9c | 96 | */ |
03c71d1e ASL |
97 | |
98 | } | |
99 | ||
100 | public void testGetSet() { | |
101 | ||
102 | JniMarker testMarker = prepareMarkerToTest(); | |
103 | ||
104 | // Test that all Get/Set return data | |
105 | assertNotSame("getName is empty","",testMarker.getName() ); | |
106 | assertNotSame("getFormat is empty","",testMarker.getFormatOverview() ); | |
107 | ||
108 | assertNotSame("getMarkerFieldArrayList is null",null,testMarker.getMarkerFieldsArrayList() ); | |
109 | // Also check that the map contain a certains number of data | |
110 | assertSame("getMarkerFieldArrayList returned an unexpected number of markers",numberOfMarkersFieldInMarker,testMarker.getMarkerFieldsArrayList().size() ); | |
111 | ||
112 | assertNotSame("getMarkerPtr is 0",0,testMarker.getMarkerPtr() ); | |
113 | } | |
114 | ||
115 | public void testPrintAndToString() { | |
116 | ||
117 | JniMarker testMarker = prepareMarkerToTest(); | |
118 | ||
119 | // Test printMarkerInformation | |
120 | try { | |
121 | testMarker.printMarkerInformation(); | |
122 | } | |
123 | catch( Exception e) { | |
124 | fail("printMarkerInformation failed!"); | |
125 | } | |
126 | ||
127 | // Test ToString() | |
128 | assertNotSame("toString returned empty data","",testMarker.toString() ); | |
129 | ||
130 | } | |
131 | } |