Skip to content

Commit

Permalink
Add tests for the new async types
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacalz committed Jan 12, 2024
1 parent 21f10d0 commit d04d5e5
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions internal/async/vector_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package async_test

import (
"testing"

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/internal/async"
"github.com/stretchr/testify/assert"
)

var globalSize fyne.Size

func BenchmarkAtomicLoadAndStore(b *testing.B) {
local := fyne.Size{}
size := async.Size{}

// Each loop iteration replicates how .Resize() in BaseWidget checks size changes.
for i := 0; i < b.N; i++ {
new := fyne.Size{Width: float32(i), Height: float32(i)}
if new == size.Load() {
continue
}

size.Store(new)
}

globalSize = local
}

func TestSize(t *testing.T) {
size := async.Size{}
assert.Equal(t, fyne.Size{}, size.Load())

square := fyne.NewSquareSize(100)
size.Store(square)
assert.Equal(t, square, size.Load())

uneven := fyne.NewSize(125, 600)
size.Store(uneven)
assert.Equal(t, uneven, size.Load())
}

func TestPosition(t *testing.T) {
pos := async.Position{}
assert.Equal(t, fyne.Position{}, pos.Load())

even := fyne.NewSquareOffsetPos(100)
pos.Store(even)
assert.Equal(t, even, pos.Load())

uneven := fyne.NewPos(125, 600)
pos.Store(uneven)
assert.Equal(t, uneven, pos.Load())
}

0 comments on commit d04d5e5

Please sign in to comment.