TracerTest.kt 1.3 KB
Newer Older
Noric Couderc's avatar
Noric Couderc committed
1
2
3
4
5
6
7
8
9
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import papi.Papi
import se.lth.cs.smartmodules.tracer.Tracer
import se.lth.util.ArrayListTracer
import java.io.ByteArrayOutputStream
import java.io.PrintStream

// Test the Tracer class because I don't understand what it does.
Noric Couderc's avatar
Noric Couderc committed
10
class TracerTest {
Noric Couderc's avatar
Noric Couderc committed
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

    @Test
    fun testTraceOnce() {
        Papi.init()
        Tracer.reset()

        val coll = ArrayListTracer<Int>("NO LOCATION")

        coll.add(1)
        coll.add(2)

        val stream = ByteArrayOutputStream()
        Tracer.printRecords(0, PrintStream(stream))

        // We don't want just the header, we want data!
        Assertions.assertNotEquals(1, stream.toString().lines().size)
    }

    @Test
    fun testTraceTwice() {
        Papi.init()
        Tracer.reset()

        val coll = ArrayListTracer<Int>("NO LOCATION")

        coll.add(1)
        coll.add(2)

        val stream = ByteArrayOutputStream()
        Tracer.printRecords(0, PrintStream(stream))

        // It's necessary to call reset on the tracer before tracing again.
        Tracer.reset()
        val coll2 = ArrayListTracer<Int>("NO LOCATION 2")
        coll2.add(1)
        coll2.add(1)
        coll2.add(32)
        coll2.add(32)

        Tracer.printRecords(0, PrintStream(stream))

        println(stream)
    }
Noric Couderc's avatar
Noric Couderc committed
54
}