-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also upgrade saltine (libsodium) to the latest version.
- Loading branch information
Showing
10 changed files
with
273 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
--- | ||
packages: [.] | ||
resolver: lts-18.18 | ||
resolver: lts-20.9 | ||
extra-deps: | ||
- monad-validate-1.2.0.0@sha256:9850f408431098b28806dd464b6825a88a0b56c84f380d7fe0454c1df9d6f881,3505 | ||
- msgpack-arbitrary-0.1.0@sha256:449b21af020b6667b52851df6f2066ef1b36fa06ad19429d62562b4d92711c5b,1648 | ||
- msgpack-arbitrary-0.1.3 | ||
- msgpack-binary-0.0.16 | ||
- msgpack-types-0.3.0 | ||
- msgpack-types-0.3.2 | ||
- saltine-0.2.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
module Main (main) where | ||
|
||
import qualified Data.Binary as Binary | ||
import qualified Data.ByteString as BS | ||
import qualified Data.ByteString.Lazy as LBS | ||
import Foreign.C.String (CString, peekCString) | ||
import Foreign.C.Types (CInt (..), CSize (..)) | ||
import Foreign.Ptr (FunPtr, Ptr, nullPtr) | ||
import Network.Tox.SaveData (SaveData) | ||
import Test.QuickCheck (Args (..), Property, quickCheckWith, | ||
stdArgs) | ||
import Test.QuickCheck.Monadic (assert, monadicIO, run) | ||
|
||
foreign import ccall tox_options_new :: Ptr () -> IO (Ptr ()) | ||
foreign import ccall tox_options_free :: Ptr () -> IO () | ||
|
||
foreign import ccall tox_options_set_savedata_type :: Ptr () -> CInt -> IO () | ||
foreign import ccall tox_options_set_savedata_data :: Ptr () -> CString -> CSize -> IO () | ||
|
||
foreign import ccall tox_new :: Ptr () -> Ptr () -> IO (Ptr ()) | ||
foreign import ccall tox_kill :: Ptr () -> IO () | ||
|
||
type LogCb = Ptr () -> CInt -> CString -> CInt -> CString -> CString -> Ptr () -> IO () | ||
foreign import ccall tox_options_set_log_callback :: Ptr () -> FunPtr LogCb -> IO () | ||
foreign import ccall "wrapper" wrapLogCb :: LogCb -> IO (FunPtr LogCb) | ||
|
||
logLevelName :: CInt -> Char | ||
logLevelName 0 = 'T' | ||
logLevelName 1 = 'D' | ||
logLevelName 2 = 'I' | ||
logLevelName 3 = 'W' | ||
logLevelName 4 = 'E' | ||
logLevelName _ = '?' | ||
|
||
logHandler :: LogCb | ||
logHandler _ cLevel cFile line cFunc cMsg _ = do | ||
file <- peekCString cFile | ||
func <- peekCString cFunc | ||
msg <- peekCString cMsg | ||
case cLevel of | ||
0 -> return () | ||
_ -> putStrLn $ logLevelName cLevel : ' ' : file <> ":" <> show line <> "(" <> func <> "): " <> msg | ||
|
||
prop_Save :: SaveData -> Property | ||
prop_Save save = monadicIO $ do | ||
ok <- run $ BS.useAsCStringLen (LBS.toStrict (Binary.encode save)) $ \(saveData, saveLenInt) -> do | ||
putStrLn $ "\nsavedata size: " <> show saveLenInt | ||
opts <- tox_options_new nullPtr | ||
tox_options_set_savedata_type opts 1 | ||
tox_options_set_savedata_data opts saveData (fromIntegral saveLenInt) | ||
tox_options_set_log_callback opts =<< wrapLogCb logHandler | ||
tox <- tox_new opts nullPtr | ||
tox_kill tox | ||
tox_options_free opts | ||
return $ tox /= nullPtr | ||
assert ok | ||
|
||
|
||
main :: IO () | ||
main = quickCheckWith stdArgs{maxSuccess=100, maxSize=30} prop_Save |
Oops, something went wrong.