diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2013-12-24 23:50:23 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2013-12-24 23:50:23 +0400 |
commit | 46b6ba10202b73ba413d18bd21a284e3897c12b0 (patch) | |
tree | 6fee6300db0f0f0df55780946bc2a541caa9d421 /tests/Client.hs | |
parent | 10829a428735d034f927e45561dcf94703cd376a (diff) |
Update tests
Diffstat (limited to 'tests/Client.hs')
-rw-r--r-- | tests/Client.hs | 80 |
1 files changed, 0 insertions, 80 deletions
diff --git a/tests/Client.hs b/tests/Client.hs deleted file mode 100644 index 2b49bd82..00000000 --- a/tests/Client.hs +++ /dev/null | |||
@@ -1,80 +0,0 @@ | |||
1 | {-# LANGUAGE OverloadedStrings #-} | ||
2 | module Main (main) where | ||
3 | |||
4 | import Control.Concurrent | ||
5 | import Control.Exception | ||
6 | import qualified Data.ByteString as B | ||
7 | import Data.BEncode as BE | ||
8 | import Data.BEncode.BDict as BE | ||
9 | import System.Process | ||
10 | import System.FilePath | ||
11 | |||
12 | import Test.HUnit hiding (Test) | ||
13 | import Test.Framework | ||
14 | import Test.Framework.Providers.HUnit | ||
15 | |||
16 | import Network.KRPC | ||
17 | import Network.Socket | ||
18 | import Shared | ||
19 | |||
20 | |||
21 | addr :: SockAddr | ||
22 | addr = SockAddrInet 6000 0 | ||
23 | |||
24 | withServ :: FilePath -> IO () -> IO () | ||
25 | withServ serv_path = bracket up terminateProcess . const | ||
26 | where | ||
27 | up = do | ||
28 | (_, _, _, h) <- createProcess (proc serv_path []) | ||
29 | threadDelay 1000000 | ||
30 | return h | ||
31 | |||
32 | main :: IO () | ||
33 | main = do | ||
34 | let serv_path = "dist" </> "build" </> "test-server" </> "test-server" | ||
35 | withServ serv_path $ | ||
36 | defaultMain tests | ||
37 | |||
38 | |||
39 | (==?) :: (Eq a, Show a) => a -> IO a -> Assertion | ||
40 | expected ==? action = do | ||
41 | actual <- action | ||
42 | expected @=? actual | ||
43 | |||
44 | tests :: [Test] | ||
45 | tests = | ||
46 | [ testCase "unit" $ | ||
47 | () ==? call addr unitM () | ||
48 | |||
49 | , testCase "echo int" $ | ||
50 | 1234 ==? call addr echoM 1234 | ||
51 | |||
52 | , testCase "reverse 1..100" $ | ||
53 | reverse [1..100] ==? call addr reverseM [1..100] | ||
54 | |||
55 | , testCase "reverse empty list" $ | ||
56 | reverse [] ==? call addr reverseM [] | ||
57 | |||
58 | , testCase "reverse singleton list" $ | ||
59 | reverse [1] ==? call addr reverseM [1] | ||
60 | |||
61 | , testCase "swap pair" $ | ||
62 | (1, 0) ==? call addr swapM (0, 1) | ||
63 | |||
64 | , testCase "shift triple" $ | ||
65 | ([2..10], (), 1) ==? call addr shiftR ((), 1, [2..10]) | ||
66 | |||
67 | , testCase "echo bytestring" $ | ||
68 | let bs = B.replicate 400 0 in | ||
69 | bs ==? call addr echoBytes bs | ||
70 | |||
71 | , testCase "raw method" $ | ||
72 | BInteger 10 ==? call addr rawM (BInteger 10) | ||
73 | |||
74 | , testCase "raw dict" $ | ||
75 | let dict = BDict $ BE.fromAscList | ||
76 | [ ("some_int", BInteger 100) | ||
77 | , ("some_list", BList [BInteger 10]) | ||
78 | ] | ||
79 | in dict ==? call addr rawDictM dict | ||
80 | ] | ||