diff options
Diffstat (limited to 'tests/Data/Torrent')
-rw-r--r-- | tests/Data/Torrent/BitfieldSpec.hs | 13 | ||||
-rw-r--r-- | tests/Data/Torrent/InfoHashSpec.hs | 40 | ||||
-rw-r--r-- | tests/Data/Torrent/LayoutSpec.hs | 30 | ||||
-rw-r--r-- | tests/Data/Torrent/MagnetSpec.hs | 44 | ||||
-rw-r--r-- | tests/Data/Torrent/MetainfoSpec.hs | 80 | ||||
-rw-r--r-- | tests/Data/Torrent/PieceSpec.hs | 13 | ||||
-rw-r--r-- | tests/Data/Torrent/ProgressSpec.hs | 13 |
7 files changed, 0 insertions, 233 deletions
diff --git a/tests/Data/Torrent/BitfieldSpec.hs b/tests/Data/Torrent/BitfieldSpec.hs deleted file mode 100644 index 093f6f19..00000000 --- a/tests/Data/Torrent/BitfieldSpec.hs +++ /dev/null | |||
@@ -1,13 +0,0 @@ | |||
1 | {-# OPTIONS -fno-warn-orphans #-} | ||
2 | module Data.Torrent.BitfieldSpec (spec) where | ||
3 | import Control.Applicative | ||
4 | import Test.Hspec | ||
5 | import Test.QuickCheck | ||
6 | |||
7 | import Data.Torrent.Bitfield | ||
8 | |||
9 | instance Arbitrary Bitfield where | ||
10 | arbitrary = fromBitmap <$> arbitrary | ||
11 | |||
12 | spec :: Spec | ||
13 | spec = return () \ No newline at end of file | ||
diff --git a/tests/Data/Torrent/InfoHashSpec.hs b/tests/Data/Torrent/InfoHashSpec.hs deleted file mode 100644 index 06570ec9..00000000 --- a/tests/Data/Torrent/InfoHashSpec.hs +++ /dev/null | |||
@@ -1,40 +0,0 @@ | |||
1 | {-# OPTIONS -fno-warn-orphans #-} | ||
2 | module Data.Torrent.InfoHashSpec (spec) where | ||
3 | |||
4 | import Control.Applicative | ||
5 | import Data.ByteString as BS | ||
6 | import Data.Convertible | ||
7 | import System.FilePath | ||
8 | import Test.Hspec | ||
9 | import Test.QuickCheck | ||
10 | import Test.QuickCheck.Instances () | ||
11 | |||
12 | import Data.Torrent | ||
13 | import Data.Torrent.InfoHash as IH | ||
14 | |||
15 | |||
16 | instance Arbitrary InfoHash where | ||
17 | arbitrary = do | ||
18 | bs <- BS.pack <$> vectorOf 20 arbitrary | ||
19 | pure $ either (const (error "arbitrary infohash")) id $ safeConvert bs | ||
20 | |||
21 | type TestPair = (FilePath, String) | ||
22 | |||
23 | -- TODO add a few more torrents here | ||
24 | torrentList :: [TestPair] | ||
25 | torrentList = | ||
26 | [ ( "res" </> "dapper-dvd-amd64.iso.torrent" | ||
27 | , "0221caf96aa3cb94f0f58d458e78b0fc344ad8bf") | ||
28 | ] | ||
29 | |||
30 | infohashSpec :: (FilePath, String) -> Spec | ||
31 | infohashSpec (filepath, expectedHash) = do | ||
32 | it ("should match " ++ filepath) $ do | ||
33 | torrent <- fromFile filepath | ||
34 | let actualHash = show $ idInfoHash $ tInfoDict torrent | ||
35 | actualHash `shouldBe` expectedHash | ||
36 | |||
37 | spec :: Spec | ||
38 | spec = do | ||
39 | describe "info hash" $ do | ||
40 | mapM_ infohashSpec torrentList | ||
diff --git a/tests/Data/Torrent/LayoutSpec.hs b/tests/Data/Torrent/LayoutSpec.hs deleted file mode 100644 index d3966b3f..00000000 --- a/tests/Data/Torrent/LayoutSpec.hs +++ /dev/null | |||
@@ -1,30 +0,0 @@ | |||
1 | {-# LANGUAGE GeneralizedNewtypeDeriving #-} | ||
2 | {-# LANGUAGE StandaloneDeriving #-} | ||
3 | module Data.Torrent.LayoutSpec (spec) where | ||
4 | |||
5 | import Control.Applicative | ||
6 | import Test.Hspec | ||
7 | import Test.QuickCheck | ||
8 | import System.Posix.Types | ||
9 | |||
10 | import Data.Torrent.Layout | ||
11 | |||
12 | |||
13 | instance Arbitrary COff where | ||
14 | arbitrary = fromIntegral <$> (arbitrary :: Gen Int) | ||
15 | |||
16 | instance Arbitrary a => Arbitrary (FileInfo a) where | ||
17 | arbitrary = FileInfo <$> arbitrary <*> arbitrary <*> arbitrary | ||
18 | |||
19 | instance Arbitrary LayoutInfo where | ||
20 | arbitrary = oneof | ||
21 | [ SingleFile <$> arbitrary | ||
22 | , MultiFile <$> arbitrary <*> arbitrary | ||
23 | ] | ||
24 | |||
25 | spec :: Spec | ||
26 | spec = do | ||
27 | describe "accumPosition" $ do | ||
28 | it "" $ property $ \ p1 p2 p3 s1 s2 s3 -> | ||
29 | accumPositions [(p1, s1), (p2, s2), (p3, s3)] | ||
30 | `shouldBe` [(p1, (0, s1)), (p2, (s1, s2)), (p3, (s1 + s2, s3))] \ No newline at end of file | ||
diff --git a/tests/Data/Torrent/MagnetSpec.hs b/tests/Data/Torrent/MagnetSpec.hs deleted file mode 100644 index 13554455..00000000 --- a/tests/Data/Torrent/MagnetSpec.hs +++ /dev/null | |||
@@ -1,44 +0,0 @@ | |||
1 | {-# OPTIONS -fno-warn-orphans #-} | ||
2 | module Data.Torrent.MagnetSpec (spec) where | ||
3 | |||
4 | import Control.Applicative | ||
5 | import Data.Maybe | ||
6 | import Data.Monoid | ||
7 | import Test.Hspec | ||
8 | import Test.QuickCheck | ||
9 | import Test.QuickCheck.Instances () | ||
10 | import Network.URI | ||
11 | |||
12 | import Data.Torrent.Magnet | ||
13 | import Data.Torrent.InfoHashSpec () | ||
14 | |||
15 | |||
16 | instance Arbitrary URIAuth where | ||
17 | arbitrary = URIAuth <$> arbitrary <*> arbitrary <*> arbitrary | ||
18 | |||
19 | instance Arbitrary URI where | ||
20 | arbitrary | ||
21 | = pure $ fromJust $ parseURI "http://ietf.org/1737.txt?a=1&b=h#123" | ||
22 | |||
23 | instance Arbitrary Magnet where | ||
24 | arbitrary = Magnet <$> arbitrary <*> arbitrary | ||
25 | <*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary | ||
26 | <*> arbitrary <*> arbitrary <*> pure mempty | ||
27 | |||
28 | magnetEncoding :: Magnet -> IO () | ||
29 | magnetEncoding m = parseMagnet (renderMagnet m) `shouldBe` Just m | ||
30 | |||
31 | spec :: Spec | ||
32 | spec = do | ||
33 | describe "Magnet" $ do | ||
34 | it "properly encoded" $ property $ magnetEncoding | ||
35 | |||
36 | it "parse base32" $ do | ||
37 | let magnet = "magnet:?xt=urn:btih:CT76LXJDDCH5LS2TUHKH6EUJ3NYKX4Y6" | ||
38 | let ih = "CT76LXJDDCH5LS2TUHKH6EUJ3NYKX4Y6" | ||
39 | parseMagnet magnet `shouldBe` Just (nullMagnet ih) | ||
40 | |||
41 | it "parse base16" $ do | ||
42 | let magnet = "magnet:?xt=urn:btih:0123456789abcdef0123456789abcdef01234567" | ||
43 | let ih = "0123456789abcdef0123456789abcdef01234567" | ||
44 | parseMagnet magnet `shouldBe` Just (nullMagnet ih) | ||
diff --git a/tests/Data/Torrent/MetainfoSpec.hs b/tests/Data/Torrent/MetainfoSpec.hs deleted file mode 100644 index 369c5e0f..00000000 --- a/tests/Data/Torrent/MetainfoSpec.hs +++ /dev/null | |||
@@ -1,80 +0,0 @@ | |||
1 | {-# LANGUAGE TypeSynonymInstances #-} | ||
2 | {-# OPTIONS -fno-warn-orphans #-} | ||
3 | module Data.Torrent.MetainfoSpec (spec) where | ||
4 | |||
5 | import Control.Applicative | ||
6 | import Data.ByteString as BS | ||
7 | import Data.ByteString.Lazy as BL | ||
8 | import Data.BEncode | ||
9 | import Data.Maybe | ||
10 | import Data.Time | ||
11 | import Network.URI | ||
12 | import Test.Hspec | ||
13 | import Test.QuickCheck | ||
14 | import Test.QuickCheck.Instances () | ||
15 | |||
16 | import Data.Torrent.Piece | ||
17 | import Data.Torrent.Layout | ||
18 | import Data.Torrent | ||
19 | import Data.Torrent.LayoutSpec () | ||
20 | import Network.BitTorrent.Core.NodeInfoSpec () | ||
21 | |||
22 | {----------------------------------------------------------------------- | ||
23 | -- Common | ||
24 | -----------------------------------------------------------------------} | ||
25 | |||
26 | data T a = T | ||
27 | |||
28 | prop_properBEncode :: Show a => BEncode a => Eq a | ||
29 | => T a -> a -> IO () | ||
30 | prop_properBEncode _ expected = actual `shouldBe` Right expected | ||
31 | where | ||
32 | actual = decode $ BL.toStrict $ encode expected | ||
33 | |||
34 | instance Arbitrary URI where | ||
35 | arbitrary = pure $ fromJust | ||
36 | $ parseURI "http://exsample.com:80/123365_asd" | ||
37 | |||
38 | {----------------------------------------------------------------------- | ||
39 | -- Instances | ||
40 | -----------------------------------------------------------------------} | ||
41 | |||
42 | instance Arbitrary HashList where | ||
43 | arbitrary = HashList <$> arbitrary | ||
44 | |||
45 | instance Arbitrary PieceInfo where | ||
46 | arbitrary = PieceInfo <$> arbitrary <*> arbitrary | ||
47 | |||
48 | instance Arbitrary InfoDict where | ||
49 | arbitrary = infoDictionary <$> arbitrary <*> arbitrary <*> arbitrary | ||
50 | |||
51 | pico :: Gen (Maybe NominalDiffTime) | ||
52 | pico = oneof | ||
53 | [ pure Nothing | ||
54 | , (Just . fromIntegral) <$> (arbitrary :: Gen Int) | ||
55 | ] | ||
56 | |||
57 | instance Arbitrary Torrent where | ||
58 | arbitrary = Torrent <$> arbitrary | ||
59 | <*> arbitrary <*> arbitrary <*> arbitrary | ||
60 | <*> pico <*> arbitrary <*> arbitrary | ||
61 | <*> arbitrary | ||
62 | <*> arbitrary <*> pure Nothing <*> arbitrary | ||
63 | |||
64 | {----------------------------------------------------------------------- | ||
65 | -- Spec | ||
66 | -----------------------------------------------------------------------} | ||
67 | |||
68 | spec :: Spec | ||
69 | spec = do | ||
70 | describe "FileInfo" $ do | ||
71 | it "properly bencoded" $ property $ | ||
72 | prop_properBEncode (T :: T (FileInfo BS.ByteString)) | ||
73 | |||
74 | describe "LayoutInfo" $ do | ||
75 | it "properly bencoded" $ property $ | ||
76 | prop_properBEncode (T :: T LayoutInfo) | ||
77 | |||
78 | describe "Torrent" $ do | ||
79 | it "property bencoded" $ property $ | ||
80 | prop_properBEncode (T :: T Torrent) | ||
diff --git a/tests/Data/Torrent/PieceSpec.hs b/tests/Data/Torrent/PieceSpec.hs deleted file mode 100644 index ef1f2938..00000000 --- a/tests/Data/Torrent/PieceSpec.hs +++ /dev/null | |||
@@ -1,13 +0,0 @@ | |||
1 | {-# OPTIONS_GHC -fno-warn-orphans #-} | ||
2 | module Data.Torrent.PieceSpec (spec) where | ||
3 | import Control.Applicative | ||
4 | import Test.Hspec | ||
5 | import Test.QuickCheck | ||
6 | import Data.Torrent.Piece | ||
7 | |||
8 | |||
9 | instance Arbitrary a => Arbitrary (Piece a) where | ||
10 | arbitrary = Piece <$> arbitrary <*> arbitrary | ||
11 | |||
12 | spec :: Spec | ||
13 | spec = return () \ No newline at end of file | ||
diff --git a/tests/Data/Torrent/ProgressSpec.hs b/tests/Data/Torrent/ProgressSpec.hs deleted file mode 100644 index 32efbd7a..00000000 --- a/tests/Data/Torrent/ProgressSpec.hs +++ /dev/null | |||
@@ -1,13 +0,0 @@ | |||
1 | {-# OPTIONS -fno-warn-orphans #-} | ||
2 | module Data.Torrent.ProgressSpec (spec) where | ||
3 | import Control.Applicative | ||
4 | import Test.Hspec | ||
5 | import Test.QuickCheck | ||
6 | import Data.Torrent.Progress | ||
7 | |||
8 | |||
9 | instance Arbitrary Progress where | ||
10 | arbitrary = Progress <$> arbitrary <*> arbitrary <*> arbitrary | ||
11 | |||
12 | spec :: Spec | ||
13 | spec = return () | ||