This repository has been archived by the owner on Dec 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 101
/
Context_test.go
71 lines (54 loc) · 1.93 KB
/
Context_test.go
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package imgui // nolint: testpackage
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestCurrentContextReturnsErrorIfNoContextIsCurrent(t *testing.T) {
context, err := CurrentContext()
assert.Nil(t, context, "No context expected")
assert.Equal(t, ErrNoContext, err, "Error expected")
}
func TestCreateContextReturnsNewInstance(t *testing.T) {
context := CreateContext(nil)
require.NotNil(t, context, "Context expected")
context.Destroy()
}
func TestCurrentContextCanBeRetrieved(t *testing.T) {
context := CreateContext(nil)
require.NotNil(t, context, "Context expected")
defer context.Destroy()
current, _ := CurrentContext()
assert.NotNil(t, current, "Current context expected")
}
func TestCurrentContextCanBeChanged(t *testing.T) {
context1 := CreateContext(nil)
require.NotNil(t, context1, "Context expected")
defer context1.Destroy()
first, _ := CurrentContext()
assert.True(t, context1.handle == first.handle, "First context expected")
context2 := CreateContext(nil)
require.NotNil(t, context2, "Context expected")
defer context2.Destroy()
_ = context2.SetCurrent()
second, _ := CurrentContext()
assert.True(t, context2.handle == second.handle, fmt.Sprintf("Context should have changed to second 1=%v, 2=%v", context1, context2))
_ = context1.SetCurrent()
third, _ := CurrentContext()
assert.True(t, context1.handle == third.handle, fmt.Sprintf("Context should have changed to first 1=%v, 2=%v", context1, context2))
}
func TestDestroyDoesNothingWhenCalledMultipleTimes(t *testing.T) {
context := CreateContext(nil)
require.NotNil(t, context, "Context expected")
context.Destroy()
context.Destroy()
context.Destroy()
}
func TestSetCurrentReturnsErrorWhenContextDestroyed(t *testing.T) {
context := CreateContext(nil)
require.NotNil(t, context, "Context expected")
context.Destroy()
err := context.SetCurrent()
assert.Equal(t, ErrContextDestroyed, err)
}