{-# OPTIONS_GHC -XFlexibleInstances -XTypeSynonymInstances #-} {- Author: Wishnu Prasetya Copyright 2011 Wishnu Prasetya The use of this sofware is free under the GNU General Public License (GPL) version 3. -} -- | This module provides a represetation of test values. module CTy.TestVal where -- | A representation of test value. data TestVal = -- | string of arbitrary size String String -- | string of size N | StringN Int String | Bool Bool -- | 32 bytes integer | Int32 Integer -- | fragment injection, for anything else not supported by the above representation | Frag String deriving (Eq,Show) -- | Checking the validity of a given test value. checkTV :: TestVal -> TestVal checkTV v@(Int32 i) = if -2147483648<=i && i<=2147483647 then v else error "Invalid test value" checkTV v@(StringN n s) = if n>=0 && length s <=n then v else error "Invalid test value" checkTV v = v -- | Produces a string representing a test value, which should be a valid -- string in Haskell. tv2haskell :: TestVal -> String tv2haskell (String s) = show s tv2haskell (StringN n s) = show s tv2haskell (Int32 i) = show i tv2haskell (Frag fragment) = fragment tv2java = tv2haskell