summaryrefslogtreecommitdiff
path: root/tests/Data/Torrent
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Data/Torrent')
-rw-r--r--tests/Data/Torrent/BitfieldSpec.hs13
-rw-r--r--tests/Data/Torrent/InfoHashSpec.hs40
-rw-r--r--tests/Data/Torrent/LayoutSpec.hs30
-rw-r--r--tests/Data/Torrent/MagnetSpec.hs44
-rw-r--r--tests/Data/Torrent/MetainfoSpec.hs80
-rw-r--r--tests/Data/Torrent/PieceSpec.hs13
-rw-r--r--tests/Data/Torrent/ProgressSpec.hs13
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 #-}
2module Data.Torrent.BitfieldSpec (spec) where
3import Control.Applicative
4import Test.Hspec
5import Test.QuickCheck
6
7import Data.Torrent.Bitfield
8
9instance Arbitrary Bitfield where
10 arbitrary = fromBitmap <$> arbitrary
11
12spec :: Spec
13spec = 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 #-}
2module Data.Torrent.InfoHashSpec (spec) where
3
4import Control.Applicative
5import Data.ByteString as BS
6import Data.Convertible
7import System.FilePath
8import Test.Hspec
9import Test.QuickCheck
10import Test.QuickCheck.Instances ()
11
12import Data.Torrent
13import Data.Torrent.InfoHash as IH
14
15
16instance Arbitrary InfoHash where
17 arbitrary = do
18 bs <- BS.pack <$> vectorOf 20 arbitrary
19 pure $ either (const (error "arbitrary infohash")) id $ safeConvert bs
20
21type TestPair = (FilePath, String)
22
23-- TODO add a few more torrents here
24torrentList :: [TestPair]
25torrentList =
26 [ ( "res" </> "dapper-dvd-amd64.iso.torrent"
27 , "0221caf96aa3cb94f0f58d458e78b0fc344ad8bf")
28 ]
29
30infohashSpec :: (FilePath, String) -> Spec
31infohashSpec (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
37spec :: Spec
38spec = 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 #-}
3module Data.Torrent.LayoutSpec (spec) where
4
5import Control.Applicative
6import Test.Hspec
7import Test.QuickCheck
8import System.Posix.Types
9
10import Data.Torrent.Layout
11
12
13instance Arbitrary COff where
14 arbitrary = fromIntegral <$> (arbitrary :: Gen Int)
15
16instance Arbitrary a => Arbitrary (FileInfo a) where
17 arbitrary = FileInfo <$> arbitrary <*> arbitrary <*> arbitrary
18
19instance Arbitrary LayoutInfo where
20 arbitrary = oneof
21 [ SingleFile <$> arbitrary
22 , MultiFile <$> arbitrary <*> arbitrary
23 ]
24
25spec :: Spec
26spec = 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 #-}
2module Data.Torrent.MagnetSpec (spec) where
3
4import Control.Applicative
5import Data.Maybe
6import Data.Monoid
7import Test.Hspec
8import Test.QuickCheck
9import Test.QuickCheck.Instances ()
10import Network.URI
11
12import Data.Torrent.Magnet
13import Data.Torrent.InfoHashSpec ()
14
15
16instance Arbitrary URIAuth where
17 arbitrary = URIAuth <$> arbitrary <*> arbitrary <*> arbitrary
18
19instance Arbitrary URI where
20 arbitrary
21 = pure $ fromJust $ parseURI "http://ietf.org/1737.txt?a=1&b=h#123"
22
23instance Arbitrary Magnet where
24 arbitrary = Magnet <$> arbitrary <*> arbitrary
25 <*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary
26 <*> arbitrary <*> arbitrary <*> pure mempty
27
28magnetEncoding :: Magnet -> IO ()
29magnetEncoding m = parseMagnet (renderMagnet m) `shouldBe` Just m
30
31spec :: Spec
32spec = 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 #-}
3module Data.Torrent.MetainfoSpec (spec) where
4
5import Control.Applicative
6import Data.ByteString as BS
7import Data.ByteString.Lazy as BL
8import Data.BEncode
9import Data.Maybe
10import Data.Time
11import Network.URI
12import Test.Hspec
13import Test.QuickCheck
14import Test.QuickCheck.Instances ()
15
16import Data.Torrent.Piece
17import Data.Torrent.Layout
18import Data.Torrent
19import Data.Torrent.LayoutSpec ()
20import Network.BitTorrent.Core.NodeInfoSpec ()
21
22{-----------------------------------------------------------------------
23-- Common
24-----------------------------------------------------------------------}
25
26data T a = T
27
28prop_properBEncode :: Show a => BEncode a => Eq a
29 => T a -> a -> IO ()
30prop_properBEncode _ expected = actual `shouldBe` Right expected
31 where
32 actual = decode $ BL.toStrict $ encode expected
33
34instance Arbitrary URI where
35 arbitrary = pure $ fromJust
36 $ parseURI "http://exsample.com:80/123365_asd"
37
38{-----------------------------------------------------------------------
39-- Instances
40-----------------------------------------------------------------------}
41
42instance Arbitrary HashList where
43 arbitrary = HashList <$> arbitrary
44
45instance Arbitrary PieceInfo where
46 arbitrary = PieceInfo <$> arbitrary <*> arbitrary
47
48instance Arbitrary InfoDict where
49 arbitrary = infoDictionary <$> arbitrary <*> arbitrary <*> arbitrary
50
51pico :: Gen (Maybe NominalDiffTime)
52pico = oneof
53 [ pure Nothing
54 , (Just . fromIntegral) <$> (arbitrary :: Gen Int)
55 ]
56
57instance 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
68spec :: Spec
69spec = 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 #-}
2module Data.Torrent.PieceSpec (spec) where
3import Control.Applicative
4import Test.Hspec
5import Test.QuickCheck
6import Data.Torrent.Piece
7
8
9instance Arbitrary a => Arbitrary (Piece a) where
10 arbitrary = Piece <$> arbitrary <*> arbitrary
11
12spec :: Spec
13spec = 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 #-}
2module Data.Torrent.ProgressSpec (spec) where
3import Control.Applicative
4import Test.Hspec
5import Test.QuickCheck
6import Data.Torrent.Progress
7
8
9instance Arbitrary Progress where
10 arbitrary = Progress <$> arbitrary <*> arbitrary <*> arbitrary
11
12spec :: Spec
13spec = return ()