summaryrefslogtreecommitdiff
path: root/Test
diff options
context:
space:
mode:
authorYves Fischer <yvesf-git@xapek.org>2012-09-28 23:50:52 +0200
committerYves Fischer <yvesf-git@xapek.org>2012-09-28 23:50:52 +0200
commit52d0b5284170588b24573164e60f99a4001f9b9d (patch)
tree45685caa51c80da564035e65717a19b9ca5b5298 /Test
parent1270abb4ce6842d3b66f792d23358b97a530c4d5 (diff)
downloadhaskell-ebus-52d0b5284170588b24573164e60f99a4001f9b9d.tar.gz
haskell-ebus-52d0b5284170588b24573164e60f99a4001f9b9d.zip
save modification - no ideaHEADmaster
Diffstat (limited to 'Test')
-rw-r--r--Test/Layer2.hs57
1 files changed, 57 insertions, 0 deletions
diff --git a/Test/Layer2.hs b/Test/Layer2.hs
new file mode 100644
index 0000000..d50535f
--- /dev/null
+++ b/Test/Layer2.hs
@@ -0,0 +1,57 @@
+module Test.Layer2 (tests) where
+
+import Data.ByteString (ByteString, pack)
+import Data.Enumerator (Enumerator, Iteratee, enumLists, run, ($$))
+import Data.Word (Word8)
+import Data.Attoparsec.Enumerator (iterParser, ParseError, errorContexts)
+import Control.Exception (SomeException)
+
+import Network.EBus.Layer2
+
+import Data.Either
+import Test.HUnit
+import Test.HUnit.Base
+
+import Control.Monad
+
+tests = [TestCase testcase]
+
+
+
+
+testcase :: IO()
+testcase = do
+ let x = parsePackageFromList [170,170,241,254,5,3,8,1,1,16,255,88,255,60,9,247]
+ join $ liftM foooo x
+ -- where
+ -- testResults :: (Monad m) => m(Either SomeException EbusPacket) -> m()
+ -- testResults s = do
+ -- let z = case s of
+ -- Right x -> print "true"
+ -- Left y -> print "false"
+ -- if z then print "foo" else print "bl"
+ where foooo xs = do
+ case xs of
+ Right _ -> print "success"
+ Left e -> fail (show e)
+
+
+-- * Utils
+
+-- | Take a list and parse as ebus datastream
+parsePackageFromList :: [Word8] -> IO (Either SomeException EbusPacket)
+parsePackageFromList xs =
+ run ( listEnumerator xs $$ parserIteratee )
+
+
+-- | Transform List xs into a Enumerator
+listEnumerator :: [Word8] -> Enumerator ByteString IO a
+listEnumerator xs = enumLists l
+ where l::[[ByteString]]
+ l = [[pack xs]]
+
+parserIteratee :: Iteratee ByteString IO EbusPacket
+parserIteratee = iterParser ebusParserLayer2
+
+
+