1 {-# OPTIONS_GHC -fno-warn-missing-signatures #-}
3 module Main
(main
) where
5 import Network
.MPD
.Commands
6 import Network
.MPD
.Core
(Response
)
7 import Network
.MPD
.StringConn
13 main
= mapM_ (\(n
, f
) -> f
>>= \x
-> printf
"%-14s: %s\n" n x
) tests
14 where tests
= [("enableOutput", testEnableOutput
)
15 ,("disableOutput", testDisableOutput
)
16 ,("outputs", testOutputs
)
17 ,("update0", testUpdate0
)
18 ,("update1", testUpdate1
)
19 ,("updateMany", testUpdateMany
)
20 ,("lsInfo", testLsInfo
)
26 ,("commands", testCommands
)
27 ,("notCommands", testNotCommands
)
28 ,("tagTypes", testTagTypes
)
29 ,("urlHandlers", testUrlHandlers
)
33 test a b c
= liftM (showResult b
) $ testMPD a b
(return Nothing
) c
35 test_ a b
= test a
(Right
()) b
37 showResult
:: (Show a
) => Response a
-> Result a
-> String
38 showResult _ Ok
= "passed"
39 showResult expectedResult
(Failure result mms
) =
41 concatMap (\(x
,y
) -> "\n expected request: " ++ show x
++
42 "\n actual request: " ++ show y
) mms
++
43 "\n expected result: " ++ show expectedResult
++
44 "\n actual result: " ++ show result
50 testEnableOutput
= test_
[("enableoutput 1", Right
"OK")] (enableOutput
1)
52 testDisableOutput
= test_
[("disableoutput 1", Right
"OK")] (disableOutput
1)
55 test
[("outputs", Right
$ unlines ["outputid: 0"
56 ,"outputname: SoundCard0"
59 ,"outputname: SoundCard1"
62 (Right
[Device
{ dOutputID
= 0
63 , dOutputName
= "SoundCard0"
64 , dOutputEnabled
= True }
65 ,Device
{ dOutputID
= 1
66 , dOutputName
= "SoundCard1"
67 , dOutputEnabled
= False }])
70 testUpdate0
= test_
[("update", Right
"updating_db: 1\nOK")] (update
[])
73 test_
[("update \"foo\"", Right
"updating_db: 1\nOK")]
77 test_
[("command_list_begin\nupdate \"foo\"\nupdate \"bar\"\n\
78 \command_list_end", Right
"updating_db: 1\nOK")]
79 (update
["foo","bar"])
86 test
[("lsinfo \"\"", Right
"directory: Foo\ndirectory: Bar\nOK")]
87 (Right
[Left
"Bar", Left
"Foo"])
95 test
[("add \"foo\"", Right
"OK"),
96 ("listall \"foo\"", Right
"file: Foo\nfile: Bar\nOK")]
97 (Right
["Foo", "Bar"])
100 testAdd_
= test_
[("add \"foo\"", Right
"OK")] (add_
"" "foo")
102 testClear
= test_
[("playlistclear \"foo\"", Right
"OK")] (clear
"foo")
108 testPlay
= test_
[("play", Right
"OK")] (play Nothing
)
110 testStop
= test_
[("stop", Right
"OK")] stop
113 -- Miscellaneous commands
117 test
[("commands", Right
"command: foo\ncommand: bar")]
118 (Right
["foo", "bar"])
122 test
[("notcommands", Right
"command: foo\ncommand: bar")]
123 (Right
["foo", "bar"])
127 test
[("tagtypes", Right
"tagtype: foo\ntagtype: bar")]
128 (Right
["foo", "bar"])
132 test
[("urlhandlers", Right
"urlhandler: foo\nurlhandler: bar")]
133 (Right
["foo", "bar"])
136 testPing
= test_
[("ping", Right
"OK")] ping
139 -- Extensions\/shortcuts