diff options
author | Stephen Paul Weber <singpolyma@singpolyma.net> | 2012-04-26 22:04:18 -0500 |
---|---|---|
committer | Stephen Paul Weber <singpolyma@singpolyma.net> | 2012-04-26 22:04:18 -0500 |
commit | 913c09eb763e35bfba79f655c3fe3a6cec593a56 (patch) | |
tree | 1b34c03e44da37c919605b67e9e84ad4af17d2a6 /tests | |
parent | a68241e614534c252fad871a32ac8296727ee7bf (diff) |
Second openpgp-cereal package using CPP
When you compile with make CEREAL=1
Diffstat (limited to 'tests')
-rw-r--r-- | tests/suite.hs | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/tests/suite.hs b/tests/suite.hs index f5c8946..3f15a75 100644 --- a/tests/suite.hs +++ b/tests/suite.hs | |||
@@ -1,3 +1,4 @@ | |||
1 | {-# LANGUAGE CPP #-} | ||
1 | import Test.Framework (defaultMain, testGroup, Test) | 2 | import Test.Framework (defaultMain, testGroup, Test) |
2 | import Test.Framework.Providers.HUnit | 3 | import Test.Framework.Providers.HUnit |
3 | import Test.Framework.Providers.QuickCheck2 | 4 | import Test.Framework.Providers.QuickCheck2 |
@@ -5,18 +6,30 @@ import Test.QuickCheck | |||
5 | import Test.HUnit hiding (Test) | 6 | import Test.HUnit hiding (Test) |
6 | 7 | ||
7 | import Data.Word | 8 | import Data.Word |
8 | import Data.Binary | ||
9 | import qualified Data.OpenPGP as OpenPGP | 9 | import qualified Data.OpenPGP as OpenPGP |
10 | import qualified Data.ByteString.Lazy as LZ | 10 | |
11 | #ifdef CEREAL | ||
12 | import Data.Serialize | ||
13 | import qualified Data.ByteString as B | ||
14 | |||
15 | decode' :: (Serialize a) => B.ByteString -> a | ||
16 | decode' x = let Right v = decode x in v | ||
17 | #else | ||
18 | import Data.Binary | ||
19 | import qualified Data.ByteString.Lazy as B | ||
20 | |||
21 | decode' :: (Binary a) => B.ByteString -> a | ||
22 | decode' = decode | ||
23 | #endif | ||
11 | 24 | ||
12 | instance Arbitrary OpenPGP.HashAlgorithm where | 25 | instance Arbitrary OpenPGP.HashAlgorithm where |
13 | arbitrary = elements [OpenPGP.MD5, OpenPGP.SHA1, OpenPGP.SHA256, OpenPGP.SHA384, OpenPGP.SHA512] | 26 | arbitrary = elements [OpenPGP.MD5, OpenPGP.SHA1, OpenPGP.SHA256, OpenPGP.SHA384, OpenPGP.SHA512] |
14 | 27 | ||
15 | testSerialization :: FilePath -> Assertion | 28 | testSerialization :: FilePath -> Assertion |
16 | testSerialization fp = do | 29 | testSerialization fp = do |
17 | bs <- LZ.readFile $ "tests/data/" ++ fp | 30 | bs <- B.readFile $ "tests/data/" ++ fp |
18 | nullShield "First" (decode bs) (\firstpass -> | 31 | nullShield "First" (decode' bs) (\firstpass -> |
19 | nullShield "Second" (decode $ encode firstpass) ( | 32 | nullShield "Second" (decode' $encode firstpass) ( |
20 | assertEqual ("for " ++ fp) firstpass | 33 | assertEqual ("for " ++ fp) firstpass |
21 | ) | 34 | ) |
22 | ) | 35 | ) |