aboutsummaryrefslogtreecommitdiff
path: root/specs/TestUtils.hs
blob: d6f3cd2537cb7003b3471c42ddce40113b2885e8 (plain) (blame)
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
module TestUtils where

import Chelleport.AppShell (MonadAppShell (..))
import Chelleport.Control (MonadControl (..))
import Chelleport.Draw (MonadDraw (..))
import Chelleport.OCR (MonadOCR (..))
import Control.Monad (void)
import Control.Monad.IO.Class (MonadIO)
import Control.Monad.State (StateT (runStateT), gets)
import Data.Typeable (cast)
import Foreign.C (CInt)
import Mock
import Unsafe.Coerce (unsafeCoerce)

$(generateMock [''MonadDraw, ''MonadControl, ''MonadAppShell, ''MonadOCR])

mockWindowWidth :: CInt
mockWindowWidth = 1920

mockWindowHeight :: CInt
mockWindowHeight = 1080

mockWindowSize :: (CInt, CInt)
mockWindowSize = (mockWindowWidth, mockWindowHeight)

mockWindowOffsetX :: CInt
mockWindowOffsetX = 200

mockWindowOffsetY :: CInt
mockWindowOffsetY = 100

mockWindowPosition :: (CInt, CInt)
mockWindowPosition = (mockWindowOffsetX, mockWindowOffsetY)

mockTextWidth :: Int
mockTextWidth = 10

runWithMocks :: (MonadIO m) => TestM x m a -> m (a, MockCalls)
runWithMocks act = runTestMWithMocks $ do
  -- Default mocks
  Mock_windowSize `mockReturns` mockWindowSize
  Mock_windowPosition `mockReturns` mockWindowPosition
  act