diff options
Diffstat (limited to 'tests/suite.hs')
-rw-r--r-- | tests/suite.hs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/suite.hs b/tests/suite.hs new file mode 100644 index 0000000..272295a --- /dev/null +++ b/tests/suite.hs | |||
@@ -0,0 +1,44 @@ | |||
1 | import Test.Framework (defaultMain, testGroup) | ||
2 | import Test.Framework.Providers.HUnit | ||
3 | |||
4 | import Test.HUnit | ||
5 | |||
6 | import Codec.Encryption.OpenPGP.ASCIIArmor (armor, decodeArmor) | ||
7 | import Codec.Encryption.OpenPGP.ASCIIArmor.Types | ||
8 | |||
9 | import Data.ByteString (ByteString) | ||
10 | import qualified Data.ByteString as B | ||
11 | import qualified Data.ByteString.Char8 as BC8 | ||
12 | import Data.Digest.CRC24 (crc24) | ||
13 | import Data.Word (Word32) | ||
14 | |||
15 | testCRC24 :: ByteString -> Word32 -> Assertion | ||
16 | testCRC24 bs crc = assertEqual "crc24" crc (crc24 bs) | ||
17 | |||
18 | testArmorDecode :: FilePath -> FilePath -> Assertion | ||
19 | testArmorDecode fp target = do | ||
20 | bs <- B.readFile $ "tests/data/" ++ fp | ||
21 | tbs <- B.readFile $ "tests/data/" ++ target | ||
22 | case decodeArmor bs of | ||
23 | Left e -> assertFailure $ "Decode failed (" ++ e ++ ") on " ++ fp | ||
24 | Right (Armor at hdrs pl) -> do assertEqual ("for " ++ fp) tbs pl | ||
25 | |||
26 | testArmorEncode :: FilePath -> FilePath -> Assertion | ||
27 | testArmorEncode fp target = do | ||
28 | bs <- B.readFile $ "tests/data/" ++ fp | ||
29 | tbs <- B.readFile $ "tests/data/" ++ target | ||
30 | assertEqual ("literaldata") (armor (Armor ArmorMessage [("Version","OpenPrivacy 0.99")] bs)) tbs | ||
31 | |||
32 | tests = [ | ||
33 | testGroup "CRC24" [ | ||
34 | testCase "CRC24: A" (testCRC24 (BC8.pack "A") 16680698) | ||
35 | , testCase "CRC24: Haskell" (testCRC24 (BC8.pack "Haskell") 15612750) | ||
36 | , testCase "CRC24: hOpenPGP and friends" (testCRC24 (BC8.pack "hOpenPGP and friends") 11940960) | ||
37 | ] | ||
38 | , testGroup "ASCII armor" [ | ||
39 | testCase "Decode sample armor" (testArmorDecode "msg1.asc" "msg1.gpg") | ||
40 | , testCase "Encode sample armor" (testArmorEncode "msg1.gpg" "msg1.asc") | ||
41 | ] | ||
42 | ] | ||
43 | |||
44 | main = defaultMain tests | ||