forked from go-sql-driver/mysql
-
Notifications
You must be signed in to change notification settings - Fork 1
/
atomic_bool_test.go
71 lines (63 loc) · 1.43 KB
/
atomic_bool_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
// Go MySQL Driver - A MySQL-Driver for Go's database/sql package.
//
// Copyright 2022 The Go-MySQL-Driver Authors. All rights reserved.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at http://mozilla.org/MPL/2.0/.
//go:build !go1.19
// +build !go1.19
package mysql
import (
"testing"
)
func TestAtomicBool(t *testing.T) {
var ab atomicBool
if ab.Load() {
t.Fatal("Expected value to be false")
}
ab.Store(true)
if ab.value != 1 {
t.Fatal("Set(true) did not set value to 1")
}
if !ab.Load() {
t.Fatal("Expected value to be true")
}
ab.Store(true)
if !ab.Load() {
t.Fatal("Expected value to be true")
}
ab.Store(false)
if ab.value != 0 {
t.Fatal("Set(false) did not set value to 0")
}
if ab.Load() {
t.Fatal("Expected value to be false")
}
ab.Store(false)
if ab.Load() {
t.Fatal("Expected value to be false")
}
if ab.Swap(false) {
t.Fatal("Expected the old value to be false")
}
if ab.Swap(true) {
t.Fatal("Expected the old value to be false")
}
if !ab.Load() {
t.Fatal("Expected value to be true")
}
ab.Store(true)
if !ab.Load() {
t.Fatal("Expected value to be true")
}
if !ab.Swap(true) {
t.Fatal("Expected the old value to be true")
}
if !ab.Swap(false) {
t.Fatal("Expected the old value to be true")
}
if ab.Load() {
t.Fatal("Expected value to be false")
}
}