forked from godror/godror
-
Notifications
You must be signed in to change notification settings - Fork 1
/
data_test.go
103 lines (90 loc) · 2.27 KB
/
data_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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Copyright 2020 The Godror Authors
//
//
// SPDX-License-Identifier: UPL-1.0 OR Apache-2.0
package godror
import (
"testing"
"time"
)
func TestDataSetGet(t *testing.T) {
var d Data
for _, want := range []time.Time{time.Now(), {}} {
d.SetTime(want)
if got := d.GetTime(); !got.Equal(want) && got.Format(time.RFC3339) != want.Format(time.RFC3339) {
t.Errorf("set %v, got %v", want, got)
}
}
for _, want := range []int8{-126, 126} {
d.Set(want)
if got := d.Get(); got.(int64) != int64(want) {
t.Errorf("set %v, got %v", want, got)
}
}
for _, want := range []int16{-30000, -15000, 0, 15000, 30000} {
d.Set(want)
if got := d.Get(); got.(int64) != int64(want) {
t.Errorf("set %v, got %v", want, got)
}
}
for _, want := range []uint8{0, 128, 253} {
d.Set(want)
if got := d.Get(); got.(uint64) != uint64(want) {
t.Errorf("set %v, got %v", want, got)
}
}
for _, want := range []uint16{0, 15000, 30000, 45000, 60000} {
d.Set(want)
if got := d.Get(); got.(uint64) != uint64(want) {
t.Errorf("set %v, got %v", want, got)
}
}
for _, want := range []bool{true, false} {
d.SetBool(want)
if got := d.GetBool(); got != want {
t.Errorf("set %v, got %v", want, got)
}
}
for _, want := range []string{"árvíztűrő tükörfúrógép", "\x00", ""} {
d.SetBytes([]byte(want))
if got := string(d.GetBytes()); got != want {
t.Errorf("set %v, got %v", want, got)
}
}
for _, want := range []float64{3.14, -42} {
d.SetFloat32(float32(want))
if got := d.GetFloat32(); got != float32(want) {
t.Errorf("set %v, got %v", want, got)
}
d.SetInt64(int64(want * 100))
if got := d.GetInt64(); got != int64(want*100) {
t.Errorf("set %v, got %v", want*100, got)
}
d.SetFloat64(want)
if got := d.GetFloat64(); got != want {
t.Errorf("set %v, got %v", want, got)
}
}
}
func BenchmarkDataGetBytes(b *testing.B) {
var d Data
d.SetBytes([]byte("árvíztűrő tükörfúrógép"))
b.Run("C", func(b *testing.B) {
b.ResetTimer()
var n uint64
for i := 0; i < b.N; i++ {
b := d.dpiDataGetBytes()
n += uint64(b.length)
}
b.Log("n:", n)
})
b.Run("unsafe", func(b *testing.B) {
b.ResetTimer()
var n uint64
for i := 0; i < b.N; i++ {
b := d.dpiDataGetBytesUnsafe()
n += uint64(b.length)
}
b.Log("n:", n)
})
}