Merge branch 'master' of darcs.haskell.org:/srv/darcs//packages/base
[packages/base.git] / tests / cstring001.hs
1 import Control.Monad
2 import Foreign.C.String
3
4 test_strings = ["Hello World", replicate 10000 'a']
5
6 assertEqual :: (Eq a, Show a) => a -> a -> IO ()
7 assertEqual x y = if x == y then return () else error $ "assertEqual: " ++ show x ++ " /= " ++ show y
8
9 main = do
10 -- Try roundtripping some ASCII strings through the locale encoding
11 forM test_strings $ \try_str -> do
12 got_str <- withCString try_str peekCString
13 got_str `assertEqual` try_str
14
15 -- Try roundtripping some ASCII strings with lengths through the locale encoding
16 forM test_strings $ \try_str -> do
17 got_str <- withCStringLen try_str peekCStringLen
18 got_str `assertEqual` try_str