{- |
Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
License    : LGPL-2.1
Maintainer : Iñaki García Etxebarria (inaki@blueleaf.cc)

An opaque structure representing a test suite.
-}

#define ENABLE_OVERLOADING (MIN_VERSION_haskell_gi_overloading(1,0,0) \
       && !defined(__HADDOCK_VERSION__))

module GI.GLib.Structs.TestSuite
    (

-- * Exported types
    TestSuite(..)                           ,
    noTestSuite                             ,


 -- * Methods
-- ** add #method:add#

#if ENABLE_OVERLOADING
    TestSuiteAddMethodInfo                  ,
#endif
    testSuiteAdd                            ,


-- ** addSuite #method:addSuite#

#if ENABLE_OVERLOADING
    TestSuiteAddSuiteMethodInfo             ,
#endif
    testSuiteAddSuite                       ,




    ) where

import Data.GI.Base.ShortPrelude
import qualified Data.GI.Base.ShortPrelude as SP
import qualified Data.GI.Base.Overloading as O
import qualified Prelude as P

import qualified Data.GI.Base.Attributes as GI.Attributes
import qualified Data.GI.Base.ManagedPtr as B.ManagedPtr
import qualified Data.GI.Base.GClosure as B.GClosure
import qualified Data.GI.Base.GError as B.GError
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GValue as B.GValue
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
import qualified Data.GI.Base.Properties as B.Properties
import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import qualified Foreign.Ptr as FP
import qualified GHC.OverloadedLabels as OL

import {-# SOURCE #-} qualified GI.GLib.Structs.TestCase as GLib.TestCase

-- | Memory-managed wrapper type.
newtype TestSuite = TestSuite (ManagedPtr TestSuite)
-- XXX Wrapping a foreign struct/union with no known destructor or size, leak?
instance WrappedPtr TestSuite where
    wrappedPtrCalloc = return nullPtr
    wrappedPtrCopy = return
    wrappedPtrFree = Nothing

-- | A convenience alias for `Nothing` :: `Maybe` `TestSuite`.
noTestSuite :: Maybe TestSuite
noTestSuite = Nothing


#if ENABLE_OVERLOADING
instance O.HasAttributeList TestSuite
type instance O.AttributeList TestSuite = TestSuiteAttributeList
type TestSuiteAttributeList = ('[ ] :: [(Symbol, *)])
#endif

-- method TestSuite::add
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "suite", argType = TInterface (Name {namespace = "GLib", name = "TestSuite"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GTestSuite", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "test_case", argType = TInterface (Name {namespace = "GLib", name = "TestCase"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GTestCase", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_test_suite_add" g_test_suite_add ::
    Ptr TestSuite ->                        -- suite : TInterface (Name {namespace = "GLib", name = "TestSuite"})
    Ptr GLib.TestCase.TestCase ->           -- test_case : TInterface (Name {namespace = "GLib", name = "TestCase"})
    IO ()

{- |
Adds /@testCase@/ to /@suite@/.

/Since: 2.16/
-}
testSuiteAdd ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    TestSuite
    {- ^ /@suite@/: a 'GI.GLib.Structs.TestSuite.TestSuite' -}
    -> GLib.TestCase.TestCase
    {- ^ /@testCase@/: a 'GI.GLib.Structs.TestCase.TestCase' -}
    -> m ()
testSuiteAdd suite testCase = liftIO $ do
    suite' <- unsafeManagedPtrGetPtr suite
    testCase' <- unsafeManagedPtrGetPtr testCase
    g_test_suite_add suite' testCase'
    touchManagedPtr suite
    touchManagedPtr testCase
    return ()

#if ENABLE_OVERLOADING
data TestSuiteAddMethodInfo
instance (signature ~ (GLib.TestCase.TestCase -> m ()), MonadIO m) => O.MethodInfo TestSuiteAddMethodInfo TestSuite signature where
    overloadedMethod _ = testSuiteAdd

#endif

-- method TestSuite::add_suite
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "suite", argType = TInterface (Name {namespace = "GLib", name = "TestSuite"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GTestSuite", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "nestedsuite", argType = TInterface (Name {namespace = "GLib", name = "TestSuite"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "another #GTestSuite", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_test_suite_add_suite" g_test_suite_add_suite ::
    Ptr TestSuite ->                        -- suite : TInterface (Name {namespace = "GLib", name = "TestSuite"})
    Ptr TestSuite ->                        -- nestedsuite : TInterface (Name {namespace = "GLib", name = "TestSuite"})
    IO ()

{- |
Adds /@nestedsuite@/ to /@suite@/.

/Since: 2.16/
-}
testSuiteAddSuite ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    TestSuite
    {- ^ /@suite@/: a 'GI.GLib.Structs.TestSuite.TestSuite' -}
    -> TestSuite
    {- ^ /@nestedsuite@/: another 'GI.GLib.Structs.TestSuite.TestSuite' -}
    -> m ()
testSuiteAddSuite suite nestedsuite = liftIO $ do
    suite' <- unsafeManagedPtrGetPtr suite
    nestedsuite' <- unsafeManagedPtrGetPtr nestedsuite
    g_test_suite_add_suite suite' nestedsuite'
    touchManagedPtr suite
    touchManagedPtr nestedsuite
    return ()

#if ENABLE_OVERLOADING
data TestSuiteAddSuiteMethodInfo
instance (signature ~ (TestSuite -> m ()), MonadIO m) => O.MethodInfo TestSuiteAddSuiteMethodInfo TestSuite signature where
    overloadedMethod _ = testSuiteAddSuite

#endif

#if ENABLE_OVERLOADING
type family ResolveTestSuiteMethod (t :: Symbol) (o :: *) :: * where
    ResolveTestSuiteMethod "add" o = TestSuiteAddMethodInfo
    ResolveTestSuiteMethod "addSuite" o = TestSuiteAddSuiteMethodInfo
    ResolveTestSuiteMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveTestSuiteMethod t TestSuite, O.MethodInfo info TestSuite p) => OL.IsLabel t (TestSuite -> p) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#else
    fromLabel _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#endif

#endif