mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-30 00:12:50 -05:00
core: mock wayland context for tests & add i18n guidance to CONTRIBUTING
This commit is contained in:
@@ -2,10 +2,14 @@ package clipboard
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/mock"
|
||||
|
||||
mocks_wlcontext "github.com/AvengeMedia/DankMaterialShell/core/internal/mocks/wlcontext"
|
||||
)
|
||||
|
||||
func TestEncodeDecodeEntry_Roundtrip(t *testing.T) {
|
||||
@@ -454,3 +458,74 @@ func TestDefaultConfig(t *testing.T) {
|
||||
assert.False(t, cfg.DisableHistory)
|
||||
assert.False(t, cfg.DisablePersist)
|
||||
}
|
||||
|
||||
func TestManager_PostDelegatesToWlContext(t *testing.T) {
|
||||
mockCtx := mocks_wlcontext.NewMockWaylandContext(t)
|
||||
|
||||
var called atomic.Bool
|
||||
mockCtx.EXPECT().Post(mock.AnythingOfType("func()")).Run(func(fn func()) {
|
||||
called.Store(true)
|
||||
fn()
|
||||
}).Once()
|
||||
|
||||
m := &Manager{
|
||||
wlCtx: mockCtx,
|
||||
}
|
||||
|
||||
executed := false
|
||||
m.post(func() {
|
||||
executed = true
|
||||
})
|
||||
|
||||
assert.True(t, called.Load())
|
||||
assert.True(t, executed)
|
||||
}
|
||||
|
||||
func TestManager_PostExecutesFunctionViaContext(t *testing.T) {
|
||||
mockCtx := mocks_wlcontext.NewMockWaylandContext(t)
|
||||
|
||||
var capturedFn func()
|
||||
mockCtx.EXPECT().Post(mock.AnythingOfType("func()")).Run(func(fn func()) {
|
||||
capturedFn = fn
|
||||
}).Times(3)
|
||||
|
||||
m := &Manager{
|
||||
wlCtx: mockCtx,
|
||||
}
|
||||
|
||||
counter := 0
|
||||
m.post(func() { counter++ })
|
||||
m.post(func() { counter += 10 })
|
||||
m.post(func() { counter += 100 })
|
||||
|
||||
assert.NotNil(t, capturedFn)
|
||||
capturedFn()
|
||||
assert.Equal(t, 100, counter)
|
||||
}
|
||||
|
||||
func TestManager_ConcurrentPostWithMock(t *testing.T) {
|
||||
mockCtx := mocks_wlcontext.NewMockWaylandContext(t)
|
||||
|
||||
var postCount atomic.Int32
|
||||
mockCtx.EXPECT().Post(mock.AnythingOfType("func()")).Run(func(fn func()) {
|
||||
postCount.Add(1)
|
||||
}).Times(100)
|
||||
|
||||
m := &Manager{
|
||||
wlCtx: mockCtx,
|
||||
}
|
||||
|
||||
var wg sync.WaitGroup
|
||||
for i := 0; i < 10; i++ {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
for j := 0; j < 10; j++ {
|
||||
m.post(func() {})
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
assert.Equal(t, int32(100), postCount.Load())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user