github.com/jwijenbergh/purego@v0.0.0-20240126093400-70ff3a61df13/func_sysv_test.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // SPDX-FileCopyrightText: 2022 The Ebitengine Authors 3 4 //go:build darwin || freebsd || (linux && (amd64 || arm64)) 5 6 package purego_test 7 8 import ( 9 "testing" 10 11 "github.com/jwijenbergh/purego" 12 ) 13 14 func TestUnrefCallback(t *testing.T) { 15 imp := func() bool { 16 return true 17 } 18 19 if err := purego.UnrefCallback(0); err == nil { 20 t.Errorf("unref of unknown callback produced nil but wanted error") 21 } 22 23 ref := purego.NewCallback(imp) 24 25 if err := purego.UnrefCallback(ref); err != nil { 26 t.Errorf("callback unref produced %v but wanted nil", err) 27 } 28 if err := purego.UnrefCallback(ref); err == nil { 29 t.Errorf("callback unref of already unref'd callback produced nil but wanted error") 30 } 31 } 32 33 func TestUnrefCallbackFnPtr(t *testing.T) { 34 imp := func() bool { 35 return true 36 } 37 38 if err := purego.UnrefCallbackFnPtr(&imp); err == nil { 39 t.Errorf("unref of unknown callback produced nil but wanted error") 40 } 41 42 ref := purego.NewCallbackFnPtr(&imp) 43 44 if err := purego.UnrefCallbackFnPtr(&imp); err != nil { 45 t.Errorf("unref produced %v but wanted nil", err) 46 } 47 if err := purego.UnrefCallbackFnPtr(&imp); err == nil { 48 t.Errorf("unref of already unref'd callback produced nil but wanted error") 49 } 50 if err := purego.UnrefCallback(ref); err == nil { 51 t.Errorf("unref of already unref'd callback ptr produced nil but wanted error") 52 } 53 }