github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/pkg/sync/atomicptr/atomicptr_test.go (about)

     1  // Copyright 2019 The gVisor Authors.
     2  //
     3  // Use of this source code is governed by a BSD-style
     4  // license that can be found in the LICENSE file.
     5  
     6  package atomicptr
     7  
     8  import (
     9  	"testing"
    10  )
    11  
    12  func newInt(val int) *int {
    13  	return &val
    14  }
    15  
    16  func TestAtomicPtr(t *testing.T) {
    17  	var p AtomicPtrInt
    18  	if got := p.Load(); got != nil {
    19  		t.Errorf("initial value is %p (%v), wanted nil", got, got)
    20  	}
    21  	want := newInt(42)
    22  	p.Store(want)
    23  	if got := p.Load(); got != want {
    24  		t.Errorf("wrong value: got %p (%v), wanted %p (%v)", got, got, want, want)
    25  	}
    26  	want = newInt(100)
    27  	p.Store(want)
    28  	if got := p.Load(); got != want {
    29  		t.Errorf("wrong value: got %p (%v), wanted %p (%v)", got, got, want, want)
    30  	}
    31  }