1 {-# OPTIONS_GHC -fno-warn-missing-signatures #-}
3 module Main
(main
) where
5 import Network
.MPD
.Commands
6 import Network
.MPD
.Prim
(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 ,("urlHandlers", testUrlHandlers
)
30 test a b c
= liftM (showResult b
) $ testMPD a b
(return Nothing
) c
32 test_ a b
= test a
(Right
()) b
34 showResult
:: (Show a
) => Response a
-> Result a
-> String
35 showResult _ Ok
= "passed"
36 showResult expectedResult
(Failure result mms
) =
38 concatMap (\(x
,y
) -> "\n expected request: " ++ show x
++
39 "\n actual request: " ++ show y
) mms
++
40 "\n expected result: " ++ show expectedResult
++
41 "\n actual result: " ++ show result
47 testEnableOutput
= test_
[("enableoutput 1", Right
"OK")] (enableOutput
1)
49 testDisableOutput
= test_
[("disableoutput 1", Right
"OK")] (disableOutput
1)
52 test
[("outputs", Right
$ unlines ["outputid: 0"
53 ,"outputname: SoundCard0"
56 ,"outputname: SoundCard1"
59 (Right
[Device
{ dOutputID
= 0
60 , dOutputName
= "SoundCard0"
61 , dOutputEnabled
= True }
62 ,Device
{ dOutputID
= 1
63 , dOutputName
= "SoundCard1"
64 , dOutputEnabled
= False }])
67 testUpdate0
= test_
[("update", Right
"updating_db: 1\nOK")] (update
[])
70 test_
[("update \"foo\"", Right
"updating_db: 1\nOK")]
74 test_
[("command_list_begin\nupdate \"foo\"\nupdate \"bar\"\n\
75 \command_list_end", Right
"updating_db: 1\nOK")]
76 (update
["foo","bar"])
83 test
[("lsinfo \"\"", Right
"directory: Foo\ndirectory: Bar\nOK")]
84 (Right
[Left
"Bar", Left
"Foo"])
92 test
[("add \"foo\"", Right
"OK"),
93 ("listall \"foo\"", Right
"file: Foo\nfile: Bar\nOK")]
94 (Right
["Foo", "Bar"])
97 testAdd_
= test_
[("add \"foo\"", Right
"OK")] (add_
"" "foo")
99 testClear
= test_
[("playlistclear \"foo\"", Right
"OK")] (clear
"foo")
105 testPlay
= test_
[("play", Right
"OK")] (play Nothing
)
107 testStop
= test_
[("stop", Right
"OK")] stop
110 -- Miscellaneous commands
114 test
[("urlhandlers", Right
"urlhandler: foo\nurlhandler: bar")]
115 (Right
["foo", "bar"])
118 testPing
= test_
[("ping", Right
"OK")] ping
121 -- Extensions\/shortcuts