packages feed

hscdio-0.1.0.0: test/Test/Libcdio/Unit/Foreign/CarolusRex.hs

{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}

{-|
Description:    Tests of multi-block CDTEXT in the Foreign interface.

Copyright:      (c) 2019-2021 Sam May
License:        GPL-3.0-or-later
Maintainer:     ag@eitilt.life

Stability:      experimental
Portability:    portable

The CDTEXT file used in this module was generated using the tool written by
Pigeon at <https://pigeonsnest.co.uk/stuff/cdtext.html> (warning for a /lot/ of
swearing).  The encoding was later manually set to ASCII.
-}
module Test.Libcdio.Unit.Foreign.CarolusRex (tests) where


import qualified Test.HUnit as U
import Test.HUnit ( (@?), (@?=), (~:) )

import qualified Data.ByteString as BS
import qualified Data.Maybe as Y

import Foreign.Libcdio.CdText

import Test.Libcdio.Unit.Common


testFile :: FilePath
testFile = dataFile "carolus-rex.cdtext"


tests :: U.Test
tests = "Foreign.Libcdio.Test.CarolusRex" ~: U.TestList
    [ parse
    ]

parse :: U.Test
parse = "Binary CDTEXT is read properly" ~: U.TestCase $ do
    bs <- BS.readFile testFile
    x' <- cdTextDataInit bs
    
    Y.isJust x' @? "Failed to read binary CdText"
    let Just x = x'
    
    checkLanguage x English
    checkLanguage x Swedish

checkLanguage :: Cdio -> Language -> U.Assertion
checkLanguage x l = do
    b <- selectLanguage x l
    b @? "Unable to change language to " ++ show l
    
    l' <- language x
    l' @?= Just l
    
    t1 <- firstTrack x
    t1 @?= Just 1
    
    tl <- lastTrack x
    tl @?= Just (fromIntegral $ length titlesEnglish)
    
    t <- cdTextGet x Title Nothing
    t @?= Just "Carolus Rex"
    
    p <- cdTextGet x Performer Nothing
    p @?= Just "Sabaton"
    
    ts <- mapM (cdTextGet x Title . Just . fromIntegral) [1 .. length titlesEnglish]
    ts @?= if l == English then titlesEnglish else titlesSwedish

titlesEnglish :: [Maybe String]
titlesEnglish = map Just
        [ "Dominium maris Baltici"
        , "The Lion from the North"
        , "Gott mit uns"
        , "A Lifetime of War"
        , "1648"
        , "The Carolean's Prayer"
        , "Carolus Rex"
        , "Killing Ground"
        , "Poltava"
        , "Long Live the King"
        , "Ruina Imperii"
        ]

titlesSwedish :: [Maybe String]
titlesSwedish = map Just
    [ "Dominium maris Baltici"
    , "Lejonet fraan Norden"
    , "Gott mit uns"
    , "En Livstid i krig"
    , "1648"
    , "Karolinens bo:n"
    , "Carolus Rex"
    , "Ett slag fa:rgat ro:tt"
    , "Poltava"
    , "Konungens likfa:rd"
    , "Ruina Imperii"
    ]