diff options
author | Sam T <pxqr.sta@gmail.com> | 2013-05-14 10:57:25 +0400 |
---|---|---|
committer | Sam T <pxqr.sta@gmail.com> | 2013-05-14 10:57:25 +0400 |
commit | 50490ccb9ac98dc03a499972e693da8514779be6 (patch) | |
tree | c19c9eadb07ecc742aa94dff1ccb3556a40bccb5 /tests | |
parent | e8ce2092f9738072ddee1a677b5c6e8923f8627e (diff) |
~ Move exsamples to tests.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Client.hs | 27 | ||||
-rw-r--r-- | tests/Server.hs | 16 | ||||
-rw-r--r-- | tests/Shared.hs | 50 |
3 files changed, 93 insertions, 0 deletions
diff --git a/tests/Client.hs b/tests/Client.hs new file mode 100644 index 00000000..ec86639e --- /dev/null +++ b/tests/Client.hs | |||
@@ -0,0 +1,27 @@ | |||
1 | {-# LANGUAGE OverloadedStrings #-} | ||
2 | module Main (main) where | ||
3 | |||
4 | import qualified Data.ByteString as B | ||
5 | import System.Environment | ||
6 | import Remote.KRPC | ||
7 | import Shared | ||
8 | |||
9 | |||
10 | addr :: RemoteAddr | ||
11 | addr = (0, 6000) | ||
12 | |||
13 | main :: IO () | ||
14 | main = do | ||
15 | print =<< call addr unitM () | ||
16 | print =<< call addr echoM 0 | ||
17 | call addr reverseM [1..1000] | ||
18 | print =<< call addr swapM (0, 1) | ||
19 | print =<< call addr shiftR ((), 1, [2..10]) | ||
20 | let bs = B.replicate (32 * 1024) 0 | ||
21 | bs' <- call addr echoBytes bs | ||
22 | print (bs == bs') | ||
23 | |||
24 | {- | ||
25 | forM_ [1..] $ const $ do | ||
26 | async addr myconcat (replicate 100 [1..10]) | ||
27 | -} | ||
diff --git a/tests/Server.hs b/tests/Server.hs new file mode 100644 index 00000000..f636b0be --- /dev/null +++ b/tests/Server.hs | |||
@@ -0,0 +1,16 @@ | |||
1 | {-# LANGUAGE IncoherentInstances #-} | ||
2 | module Main (main) where | ||
3 | |||
4 | import Remote.KRPC | ||
5 | import Shared | ||
6 | |||
7 | |||
8 | main :: IO () | ||
9 | main = server 6000 | ||
10 | [ unitM ==> return | ||
11 | , echoM ==> return | ||
12 | , echoBytes ==> return | ||
13 | , swapM ==> \(a, b) -> return (b, a) | ||
14 | , reverseM ==> return . reverse | ||
15 | , shiftR ==> \(a, b, c) -> return (c, a, b) | ||
16 | ] | ||
diff --git a/tests/Shared.hs b/tests/Shared.hs new file mode 100644 index 00000000..e0e5268c --- /dev/null +++ b/tests/Shared.hs | |||
@@ -0,0 +1,50 @@ | |||
1 | {-# LANGUAGE OverloadedStrings #-} | ||
2 | module Shared | ||
3 | (echoM, echoBytes, unitM, swapM, reverseM, shiftR | ||
4 | ) where | ||
5 | |||
6 | import Data.ByteString (ByteString) | ||
7 | import Remote.KRPC | ||
8 | |||
9 | unitM :: Method () () | ||
10 | unitM = method "unit" [] [] | ||
11 | |||
12 | echoM :: Method Int Int | ||
13 | echoM = method "echo" ["x"] ["x"] | ||
14 | |||
15 | echoBytes :: Method ByteString ByteString | ||
16 | echoBytes = method "echoBytes" ["x"] ["x"] | ||
17 | |||
18 | reverseM :: Method [Int] [Int] | ||
19 | reverseM = method "reverse" ["xs"] ["ys"] | ||
20 | |||
21 | swapM :: Method (Int, Int) (Int, Int) | ||
22 | swapM = method "swap" ["x", "y"] ["b", "a"] | ||
23 | |||
24 | shiftR :: Method ((), Int, [Int]) ([Int], (), Int) | ||
25 | shiftR = method "shiftR" ["x", "y", "z"] ["a", "b", "c"] | ||
26 | |||
27 | |||
28 | |||
29 | {- | ||
30 | type NodeId = Int | ||
31 | type InfoHashe = Int | ||
32 | type NodeAddr = Int | ||
33 | type Token = Int | ||
34 | type | ||
35 | |||
36 | ping :: Method NodeId NodeId | ||
37 | ping = method "ping" ["id"] ["id"] | ||
38 | |||
39 | find_node :: Method (NodeId, NodeId) (NodeId, NodeAddr) | ||
40 | find_node = method "find_node" ["id", "target"] ["id", "nodes"] | ||
41 | |||
42 | get_peers :: Method (NodeId :*: InfoHash) (NodeId, Token, NodeAddr :|: NodeAddr) | ||
43 | get_peers = method "get_peers" | ||
44 | ("id", "target") | ||
45 | ("id", "token", view ("values" :|: "nodes")) | ||
46 | view :: BEncodable -> Maybe BEncodable | ||
47 | view = undefined | ||
48 | announce_peer :: Method (NodeId, InfoHash, PortNumber, Token) NodeId | ||
49 | announce_peer = undefined | ||
50 | -} \ No newline at end of file | ||