Commit | Line | Data |
---|---|---|
cc7fe910 FC |
1 | |
2 | package org.eclipse.linuxtools.lttng.jni; | |
3 | ||
28b94d61 | 4 | import junit.framework.TestCase; |
cc7fe910 FC |
5 | |
6 | /* | |
7 | Functions tested here : | |
8 | public JniMarkerField(JniMarkerField oldMarkerField) | |
9 | public JniMarkerField(long newMarkerPtr) throws JniException | |
10 | ||
11 | public String getField() | |
12 | public String getFormat() | |
13 | ||
14 | public String toString() | |
15 | public void printMarkerFieldInformation() | |
16 | */ | |
17 | ||
28b94d61 | 18 | public class JniMarkerFieldTest extends TestCase |
cc7fe910 | 19 | { |
28b94d61 FC |
20 | private final static boolean printLttDebug = false; |
21 | ||
eddd9002 | 22 | private final static String tracepath="traceset/trace-618339events-1293lost-1cpu"; |
cc7fe910 FC |
23 | private final static String eventName="kernel0"; |
24 | ||
25 | private JniMarkerField prepareMarkerFieldToTest() { | |
26 | ||
27 | JniEvent tmpEvent = null; | |
28 | JniMarkerField tmpMarkerField = null; | |
29 | ||
30 | // This trace should be valid | |
31 | // We will read the first 2 event to have something interesting to test on | |
32 | try { | |
28b94d61 | 33 | tmpEvent = new JniTrace(tracepath, printLttDebug).requestEventByName(eventName); |
cc7fe910 FC |
34 | tmpEvent.readNextEvent(); |
35 | tmpEvent.readNextEvent(); | |
36 | ||
37 | // Use the first field | |
38 | tmpMarkerField = tmpEvent.requestEventMarker().getMarkerFieldsArrayList().get(0); | |
39 | } | |
40 | catch( JniException e) { } | |
41 | ||
42 | return tmpMarkerField; | |
43 | } | |
44 | ||
cc7fe910 FC |
45 | public void testEventConstructors() { |
46 | ||
47 | JniMarker tmpMarker = null; | |
48 | ||
49 | JniMarkerField tmpMarkerField1 = null; | |
50 | JniMarkerField tmpMarkerField2 = null; | |
51 | ||
52 | // This event should be valid and will be used in test | |
53 | try { | |
28b94d61 | 54 | tmpMarker = new JniTrace(tracepath, printLttDebug).requestEventByName(eventName).requestEventMarker(); |
cc7fe910 FC |
55 | } |
56 | catch( JniException e) { } | |
57 | ||
58 | // Test constructor with pointer on a wrong pointer | |
59 | try { | |
07d9e2ee | 60 | tmpMarkerField1 = new JniMarkerField( new Jni_C_Pointer(0) ); |
cc7fe910 FC |
61 | fail("Construction with wrong pointer should fail!"); |
62 | } | |
63 | catch( JniException e) { | |
64 | } | |
65 | ||
66 | // Test constructor with pointer on a correct pointer | |
67 | try { | |
68 | tmpMarkerField1 = new JniMarkerField( tmpMarker.getMarkerFieldsArrayList().get(0).getMarkerFieldPtr() ); | |
69 | } | |
70 | catch( JniException e) { | |
71 | fail("Construction with correct pointer failed!"); | |
72 | } | |
73 | ||
74 | ||
75 | // Test copy constructor | |
76 | try { | |
77 | tmpMarkerField1 = new JniMarkerField( tmpMarker.getMarkerFieldsArrayList().get(0) ); | |
78 | tmpMarkerField2 = new JniMarkerField( tmpMarkerField1); | |
79 | } | |
80 | catch( Exception e) { | |
81 | fail("Copy constructor failed!"); | |
82 | } | |
83 | ||
84 | assertSame("JniMarker name not same after using copy constructor", tmpMarkerField1.getField() , tmpMarkerField2.getField()); | |
85 | ||
86 | } | |
87 | ||
cc7fe910 FC |
88 | public void testGetSet() { |
89 | ||
90 | JniMarkerField testMarkerField = prepareMarkerFieldToTest(); | |
91 | ||
92 | // Test that all Get/Set return data | |
93 | assertNotSame("getName is empty","",testMarkerField.getField() ); | |
94 | assertNotSame("getFormat is empty","",testMarkerField.getFormat() ); | |
95 | assertNotSame("getMarkerFieldPtr is 0",0,testMarkerField.getMarkerFieldPtr() ); | |
96 | } | |
97 | ||
cc7fe910 FC |
98 | public void testPrintAndToString() { |
99 | ||
100 | JniMarkerField testMarkerField = prepareMarkerFieldToTest(); | |
101 | ||
102 | // Test printMarkerInformation | |
103 | try { | |
104 | testMarkerField.printMarkerFieldInformation(); | |
105 | } | |
106 | catch( Exception e) { | |
107 | fail("printMarkerFieldInformation failed!"); | |
108 | } | |
109 | ||
110 | // Test ToString() | |
111 | assertNotSame("toString returned empty data","",testMarkerField.toString() ); | |
112 | } | |
113 | } |