-
Notifications
You must be signed in to change notification settings - Fork 867
/
matprofile_test.go
72 lines (64 loc) · 2.01 KB
/
matprofile_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
72
//go:build matprofile
// +build matprofile
package gocv
import (
"bytes"
"fmt"
"os"
"testing"
)
func TestMain(m *testing.M) {
ret := m.Run()
if MatProfile.Count() != 0 {
var b bytes.Buffer
MatProfile.WriteTo(&b, 1)
fmt.Printf("Not all Mat's in tests were closed: %v", b.String())
os.Exit(1)
}
os.Exit(ret)
}
func TestMatProfile(t *testing.T) {
if MatProfile.Count() != 0 {
var b bytes.Buffer
MatProfile.WriteTo(&b, 1)
t.Errorf("Mat profile should start with 0 entries. A test failure here likely means that some other test is not closing all Mats. Here are the current profile entries:\n%v", b.String())
}
mat := NewMat()
if MatProfile.Count() != 1 {
t.Errorf("Mat profile should == 1 after NewMat but instead was %v", MatProfile.Count())
}
mat2 := NewMat()
if MatProfile.Count() != 2 {
t.Errorf("Mat profile should == 2 after NewMat but instead was %v", MatProfile.Count())
}
mat.Close()
mat2.Close()
if MatProfile.Count() != 0 {
t.Errorf("Mat profile should == 0 after Close but instead was %v", MatProfile.Count())
}
}
func TestAddMatToProfile(t *testing.T) {
if MatProfile.Count() != 0 {
var b bytes.Buffer
MatProfile.WriteTo(&b, 1)
t.Errorf("Mat profile should start with 0 entries. A test failure here likely means that some other test is not closing all Mats. Here are the current profile entries:\n%v", b.String())
}
mat := NewMatWithSize(5, 5, MatTypeCV8UC3)
if MatProfile.Count() != 1 {
t.Errorf("Mat profile should == 1 after creating 3 channel mat but instead was %v", MatProfile.Count())
}
channels := Split(mat)
if MatProfile.Count() != 4 {
t.Errorf("Mat profile should == 4 after split channel but instead was %v", MatProfile.Count())
}
for _, channel := range channels {
channel.Close()
}
if MatProfile.Count() != 1 {
t.Errorf("Mat profile should == 1 after closing channels but instead was %v", MatProfile.Count())
}
mat.Close()
if MatProfile.Count() != 0 {
t.Errorf("Mat profile should == 0 after closing all mats but instead was %v", MatProfile.Count())
}
}