module Main where import System.IO import qualified Data.UniversalBinary as U import Test.HUnit import Control.Monad import qualified Control.Exception as E import qualified Data.ByteString as B rightArchs (x:y:[]) | U.cputype x == 7 && U.cputype y == 12 = True rightArchs _ = False testUniversalBinary = withBinaryFile "./tests/a.out" ReadMode $ \h -> do fil <- B.hGetContents h res <- E.try (E.evaluate (U.parseUniversalBinary fil)) :: IO (Either E.SomeException [U.Object]) case res of Left e -> assertFailure $ "Exception while parsing universal binary: " ++ show e Right a -> case a of (x:y:[]) -> do assertEqual "Right architecture contents." (U.cputype x) 0x7 assertEqual "Right architecture contents." (U.cputype y) 0x12 tests = TestList [ TestLabel "Universal Binary" $ TestCase testUniversalBinary ] main = runTestTT tests