File: smp_events_test.go

package info (click to toggle)
golang-github-twstrike-otr3 0.0~git20161015.0.744856d-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,008 kB
  • ctags: 1,863
  • sloc: ansic: 127; makefile: 76
file content (41 lines) | stat: -rw-r--r-- 1,614 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
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
package otr3

import "testing"

func Test_SMPEvent_hasValidStringImplementation(t *testing.T) {
	assertEquals(t, SMPEventError.String(), "SMPEventError")
	assertEquals(t, SMPEventAbort.String(), "SMPEventAbort")
	assertEquals(t, SMPEventCheated.String(), "SMPEventCheated")
	assertEquals(t, SMPEventAskForAnswer.String(), "SMPEventAskForAnswer")
	assertEquals(t, SMPEventAskForSecret.String(), "SMPEventAskForSecret")
	assertEquals(t, SMPEventInProgress.String(), "SMPEventInProgress")
	assertEquals(t, SMPEventSuccess.String(), "SMPEventSuccess")
	assertEquals(t, SMPEventFailure.String(), "SMPEventFailure")
	assertEquals(t, SMPEvent(20000).String(), "SMP EVENT: (THIS SHOULD NEVER HAPPEN)")
}

func Test_combinedSMPEventHandler_callsAllErrorMessageHandlersGiven(t *testing.T) {
	var called1, called2, called3 bool
	f1 := dynamicSMPEventHandler{func(event SMPEvent, progressPercent int, question string) {
		called1 = true
	}}
	f2 := dynamicSMPEventHandler{func(event SMPEvent, progressPercent int, question string) {
		called2 = true
	}}
	f3 := dynamicSMPEventHandler{func(event SMPEvent, progressPercent int, question string) {
		called3 = true
	}}
	d := CombineSMPEventHandlers(f1, nil, f2, f3)
	d.HandleSMPEvent(SMPEventError, 61, "")

	assertEquals(t, called1, true)
	assertEquals(t, called2, true)
	assertEquals(t, called3, true)
}

func Test_debugSMPEventHandler_writesTheEventToStderr(t *testing.T) {
	ss := captureStderr(func() {
		DebugSMPEventHandler{}.HandleSMPEvent(SMPEventInProgress, 43, "Maybe now?")
	})
	assertEquals(t, ss, "[DEBUG] HandleSMPEvent(SMPEventInProgress, 43, \"Maybe now?\")\n")
}