Anthony F. Molinaro | 71a58a8 | 2010-09-27 19:27:40 +0000 | [diff] [blame] | 1 | {-# 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 | |
| 21 | module ThriftTest_TestClient where |
| 22 | |
| 23 | |
| 24 | import Control.Exception as CE |
| 25 | import qualified Data.Map as Map |
| 26 | import qualified Data.Set as Set |
| 27 | import Network |
| 28 | |
| 29 | import Thrift |
| 30 | import Thrift.Transport.Handle |
| 31 | import Thrift.Protocol.Binary |
| 32 | |
| 33 | import ThriftTest_Client |
| 34 | import ThriftTest_Types |
| 35 | |
| 36 | |
| 37 | serverAddress :: (String, PortID) |
| 38 | serverAddress = ("127.0.0.1", PortNumber 9090) |
| 39 | |
| 40 | main :: IO () |
| 41 | main = 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 | |