File: HostAddress.hs

package info (click to toggle)
haskell-happstack-util 0.5.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 188 kB
  • sloc: haskell: 1,348; makefile: 2
file content (31 lines) | stat: -rw-r--r-- 957 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
module Happstack.Util.Tests.HostAddress
(propShowHostAddress, propShowHostAddress6)
where

import Happstack.Util.HostAddress
import System.IO.Unsafe
import Network.Socket (inet_ntoa, getNameInfo, NameInfoFlag(..), SockAddr(..), aNY_PORT)
import Data.Word (Word32)
import System.Random
import Test.QuickCheck

instance Arbitrary Word32 where
  arbitrary = choose (minBound, maxBound)

instance Random Word32 where
  randomR (a,b) g = (fromInteger i,g)
    where (i,_) = randomR (toInteger a, toInteger b) g
  random = randomR (minBound,maxBound)

propShowHostAddress :: HostAddress -> Bool
propShowHostAddress a = new == old
  where old = (unsafePerformIO . inet_ntoa) a
        new = showHostAddress a
  
propShowHostAddress6 :: HostAddress6 -> Bool
propShowHostAddress6 a = new == old
  where (Just old, _) =
          (unsafePerformIO . getNameInfo [NI_NUMERICHOST] True False) $
            SockAddrInet6 aNY_PORT 0 a 0
        new = showHostAddress6 a