blob: 4aca275615008a21f9463663349a4d5139a50b2c [file] [log] [blame]
Anthony F. Molinaro71a58a82010-09-27 19:27:40 +00001{-# LANGUAGE ScopedTypeVariables #-}
2--
3-- Licensed to the Apache Software Foundation (ASF) under one
4-- or more contributor license agreements. See the NOTICE file
5-- distributed with this work for additional information
6-- regarding copyright ownership. The ASF licenses this file
7-- to you under the Apache License, Version 2.0 (the
8-- "License"); you may not use this file except in compliance
9-- with the License. You may obtain a copy of the License at
10--
11-- http://www.apache.org/licenses/LICENSE-2.0
12--
13-- Unless required by applicable law or agreed to in writing,
14-- software distributed under the License is distributed on an
15-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16-- KIND, either express or implied. See the License for the
17-- specific language governing permissions and limitations
18-- under the License.
19--
20
21module ThriftTest_TestClient where
22
23
24import Control.Exception as CE
25import qualified Data.Map as Map
26import qualified Data.Set as Set
27import Network
28
29import Thrift
30import Thrift.Transport.Handle
31import Thrift.Protocol.Binary
32
33import ThriftTest_Client
34import ThriftTest_Types
35
36
37serverAddress :: (String, PortID)
38serverAddress = ("127.0.0.1", PortNumber 9090)
39
40main :: IO ()
41main = do to <- hOpen serverAddress
42 let p = BinaryProtocol to
43 let ps = (p,p)
44 print =<< testString ps "bya"
45 print =<< testByte ps 8
46 print =<< testByte ps (-8)
47 print =<< testI32 ps 32
48 print =<< testI32 ps (-32)
49 print =<< testI64 ps 64
50 print =<< testI64 ps (-64)
51 print =<< testDouble ps 3.14
52 print =<< testDouble ps (-3.14)
53 print =<< testMap ps (Map.fromList [(1,1),(2,2),(3,3)])
54 print =<< testList ps [1,2,3,4,5]
55 print =<< testSet ps (Set.fromList [1,2,3,4,5])
56 print =<< testStruct ps (Xtruct (Just "hi") (Just 4) (Just 5) Nothing)
57 CE.catch (testException ps "e" >> print "bad") (\e -> print (e :: Xception))
58 CE.catch (testMultiException ps "e" "e2" >> print "ok") (\e -> print (e :: Xception))
59 CE.catch (CE.catch (testMultiException ps "e" "e2">> print "bad") (\e -> print (e :: Xception2))) (\(_ :: SomeException) -> print "ok")
60 tClose to
61