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

A helper class for testing code which uses D-Bus without touching the user\'s
session bus.

Note that 'GI.Gio.Objects.TestDBus.TestDBus' modifies the user’s environment, calling @/setenv()/@.
This is not thread-safe, so all 'GI.Gio.Objects.TestDBus.TestDBus' calls should be completed before
threads are spawned, or should have appropriate locking to ensure no access
conflicts to environment variables shared between 'GI.Gio.Objects.TestDBus.TestDBus' and other
threads.

== Creating unit tests using GTestDBus

Testing of D-Bus services can be tricky because normally we only ever run
D-Bus services over an existing instance of the D-Bus daemon thus we
usually don\'t activate D-Bus services that are not yet installed into the
target system. The 'GI.Gio.Objects.TestDBus.TestDBus' object makes this easier for us by taking care
of the lower level tasks such as running a private D-Bus daemon and looking
up uninstalled services in customizable locations, typically in your source
code tree.

The first thing you will need is a separate service description file for the
D-Bus daemon. Typically a @services@ subdirectory of your @tests@ directory
is a good place to put this file.

The service file should list your service along with an absolute path to the
uninstalled service executable in your source tree. Using autotools we would
achieve this by adding a file such as @my-server.service.in@ in the services
directory and have it processed by configure.
>
>    [D-BUS Service]
>    Name=org.gtk.GDBus.Examples.ObjectManager
>    Exec=@abs_top_builddir@/gio/tests/gdbus-example-objectmanager-server

You will also need to indicate this service directory in your test
fixtures, so you will need to pass the path while compiling your
test cases. Typically this is done with autotools with an added
preprocessor flag specified to compile your tests such as:
>
>    -DTEST_SERVICES=\""$(abs_top_builddir)/tests/services"\"

    Once you have a service definition file which is local to your source tree,
you can proceed to set up a GTest fixture using the 'GI.Gio.Objects.TestDBus.TestDBus' scaffolding.

An example of a test fixture for D-Bus services can be found
here:
<https://git.gnome.org/browse/glib/tree/gio/tests/gdbus-test-fixture.c gdbus-test-fixture.c>

Note that these examples only deal with isolating the D-Bus aspect of your
service. To successfully run isolated unit tests on your service you may need
some additional modifications to your test case fixture. For example; if your
service uses GSettings and installs a schema then it is important that your test service
not load the schema in the ordinary installed location (chances are that your service
and schema files are not yet installed, or worse; there is an older version of the
schema file sitting in the install location).

Most of the time we can work around these obstacles using the
environment. Since the environment is inherited by the D-Bus daemon
created by 'GI.Gio.Objects.TestDBus.TestDBus' and then in turn inherited by any services the
D-Bus daemon activates, using the setup routine for your fixture is
a practical place to help sandbox your runtime environment. For the
rather typical GSettings case we can work around this by setting
@GSETTINGS_SCHEMA_DIR@ to the in tree directory holding your schemas
in the above @/fixture_setup()/@ routine.

The GSettings schemas need to be locally pre-compiled for this to work. This can be achieved
by compiling the schemas locally as a step before running test cases, an autotools setup might
do the following in the directory holding schemas:
>
>    all-am:
>            $(GLIB_COMPILE_SCHEMAS) .
>
>    CLEANFILES += gschemas.compiled


/Since: 2.34/
-}

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

module GI.Gio.Objects.TestDBus
    (

-- * Exported types
    TestDBus(..)                            ,
    IsTestDBus                              ,
    toTestDBus                              ,
    noTestDBus                              ,


 -- * Methods
-- ** addServiceDir #method:addServiceDir#

#if ENABLE_OVERLOADING
    TestDBusAddServiceDirMethodInfo         ,
#endif
    testDBusAddServiceDir                   ,


-- ** down #method:down#

#if ENABLE_OVERLOADING
    TestDBusDownMethodInfo                  ,
#endif
    testDBusDown                            ,


-- ** getBusAddress #method:getBusAddress#

#if ENABLE_OVERLOADING
    TestDBusGetBusAddressMethodInfo         ,
#endif
    testDBusGetBusAddress                   ,


-- ** getFlags #method:getFlags#

#if ENABLE_OVERLOADING
    TestDBusGetFlagsMethodInfo              ,
#endif
    testDBusGetFlags                        ,


-- ** new #method:new#

    testDBusNew                             ,


-- ** stop #method:stop#

#if ENABLE_OVERLOADING
    TestDBusStopMethodInfo                  ,
#endif
    testDBusStop                            ,


-- ** unset #method:unset#

    testDBusUnset                           ,


-- ** up #method:up#

#if ENABLE_OVERLOADING
    TestDBusUpMethodInfo                    ,
#endif
    testDBusUp                              ,




 -- * Properties
-- ** flags #attr:flags#
{- | 'GI.Gio.Flags.TestDBusFlags' specifying the behaviour of the D-Bus session.

/Since: 2.34/
-}
#if ENABLE_OVERLOADING
    TestDBusFlagsPropertyInfo               ,
#endif
    constructTestDBusFlags                  ,
    getTestDBusFlags                        ,
#if ENABLE_OVERLOADING
    testDBusFlags                           ,
#endif




    ) 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 qualified GI.GObject.Objects.Object as GObject.Object
import {-# SOURCE #-} qualified GI.Gio.Flags as Gio.Flags

-- | Memory-managed wrapper type.
newtype TestDBus = TestDBus (ManagedPtr TestDBus)
foreign import ccall "g_test_dbus_get_type"
    c_g_test_dbus_get_type :: IO GType

instance GObject TestDBus where
    gobjectType = c_g_test_dbus_get_type


-- | Type class for types which can be safely cast to `TestDBus`, for instance with `toTestDBus`.
class (GObject o, O.IsDescendantOf TestDBus o) => IsTestDBus o
instance (GObject o, O.IsDescendantOf TestDBus o) => IsTestDBus o

instance O.HasParentTypes TestDBus
type instance O.ParentTypes TestDBus = '[GObject.Object.Object]

-- | Cast to `TestDBus`, for types for which this is known to be safe. For general casts, use `Data.GI.Base.ManagedPtr.castTo`.
toTestDBus :: (MonadIO m, IsTestDBus o) => o -> m TestDBus
toTestDBus = liftIO . unsafeCastTo TestDBus

-- | A convenience alias for `Nothing` :: `Maybe` `TestDBus`.
noTestDBus :: Maybe TestDBus
noTestDBus = Nothing

#if ENABLE_OVERLOADING
type family ResolveTestDBusMethod (t :: Symbol) (o :: *) :: * where
    ResolveTestDBusMethod "addServiceDir" o = TestDBusAddServiceDirMethodInfo
    ResolveTestDBusMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveTestDBusMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveTestDBusMethod "down" o = TestDBusDownMethodInfo
    ResolveTestDBusMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveTestDBusMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveTestDBusMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
    ResolveTestDBusMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveTestDBusMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveTestDBusMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveTestDBusMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveTestDBusMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveTestDBusMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveTestDBusMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveTestDBusMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveTestDBusMethod "stop" o = TestDBusStopMethodInfo
    ResolveTestDBusMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveTestDBusMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveTestDBusMethod "up" o = TestDBusUpMethodInfo
    ResolveTestDBusMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveTestDBusMethod "getBusAddress" o = TestDBusGetBusAddressMethodInfo
    ResolveTestDBusMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveTestDBusMethod "getFlags" o = TestDBusGetFlagsMethodInfo
    ResolveTestDBusMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveTestDBusMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveTestDBusMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveTestDBusMethod "setDataFull" o = GObject.Object.ObjectSetDataFullMethodInfo
    ResolveTestDBusMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveTestDBusMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveTestDBusMethod t TestDBus, O.MethodInfo info TestDBus p) => OL.IsLabel t (TestDBus -> 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

-- VVV Prop "flags"
   -- Type: TInterface (Name {namespace = "Gio", name = "TestDBusFlags"})
   -- Flags: [PropertyReadable,PropertyWritable,PropertyConstructOnly]
   -- Nullable: (Just False,Nothing)

{- |
Get the value of the “@flags@” property.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.get' testDBus #flags
@
-}
getTestDBusFlags :: (MonadIO m, IsTestDBus o) => o -> m [Gio.Flags.TestDBusFlags]
getTestDBusFlags obj = liftIO $ B.Properties.getObjectPropertyFlags obj "flags"

{- |
Construct a `GValueConstruct` with valid value for the “@flags@” property. This is rarely needed directly, but it is used by `Data.GI.Base.Constructible.new`.
-}
constructTestDBusFlags :: (IsTestDBus o) => [Gio.Flags.TestDBusFlags] -> IO (GValueConstruct o)
constructTestDBusFlags val = B.Properties.constructObjectPropertyFlags "flags" val

#if ENABLE_OVERLOADING
data TestDBusFlagsPropertyInfo
instance AttrInfo TestDBusFlagsPropertyInfo where
    type AttrAllowedOps TestDBusFlagsPropertyInfo = '[ 'AttrConstruct, 'AttrGet]
    type AttrSetTypeConstraint TestDBusFlagsPropertyInfo = (~) [Gio.Flags.TestDBusFlags]
    type AttrBaseTypeConstraint TestDBusFlagsPropertyInfo = IsTestDBus
    type AttrGetType TestDBusFlagsPropertyInfo = [Gio.Flags.TestDBusFlags]
    type AttrLabel TestDBusFlagsPropertyInfo = "flags"
    type AttrOrigin TestDBusFlagsPropertyInfo = TestDBus
    attrGet _ = getTestDBusFlags
    attrSet _ = undefined
    attrConstruct _ = constructTestDBusFlags
    attrClear _ = undefined
#endif

#if ENABLE_OVERLOADING
instance O.HasAttributeList TestDBus
type instance O.AttributeList TestDBus = TestDBusAttributeList
type TestDBusAttributeList = ('[ '("flags", TestDBusFlagsPropertyInfo)] :: [(Symbol, *)])
#endif

#if ENABLE_OVERLOADING
testDBusFlags :: AttrLabelProxy "flags"
testDBusFlags = AttrLabelProxy

#endif

#if ENABLE_OVERLOADING
type instance O.SignalList TestDBus = TestDBusSignalList
type TestDBusSignalList = ('[ '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

#endif

-- method TestDBus::new
-- method type : Constructor
-- Args : [Arg {argCName = "flags", argType = TInterface (Name {namespace = "Gio", name = "TestDBusFlags"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GTestDBusFlags", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gio", name = "TestDBus"}))
-- throws : False
-- Skip return : False

foreign import ccall "g_test_dbus_new" g_test_dbus_new ::
    CUInt ->                                -- flags : TInterface (Name {namespace = "Gio", name = "TestDBusFlags"})
    IO (Ptr TestDBus)

{- |
Create a new 'GI.Gio.Objects.TestDBus.TestDBus' object.
-}
testDBusNew ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    [Gio.Flags.TestDBusFlags]
    {- ^ /@flags@/: a 'GI.Gio.Flags.TestDBusFlags' -}
    -> m TestDBus
    {- ^ __Returns:__ a new 'GI.Gio.Objects.TestDBus.TestDBus'. -}
testDBusNew flags = liftIO $ do
    let flags' = gflagsToWord flags
    result <- g_test_dbus_new flags'
    checkUnexpectedReturnNULL "testDBusNew" result
    result' <- (wrapObject TestDBus) result
    return result'

#if ENABLE_OVERLOADING
#endif

-- method TestDBus::add_service_dir
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "self", argType = TInterface (Name {namespace = "Gio", name = "TestDBus"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GTestDBus", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "path", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "path to a directory containing .service files", 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_dbus_add_service_dir" g_test_dbus_add_service_dir ::
    Ptr TestDBus ->                         -- self : TInterface (Name {namespace = "Gio", name = "TestDBus"})
    CString ->                              -- path : TBasicType TUTF8
    IO ()

{- |
Add a path where dbus-daemon will look up .service files. This can\'t be
called after 'GI.Gio.Objects.TestDBus.testDBusUp'.
-}
testDBusAddServiceDir ::
    (B.CallStack.HasCallStack, MonadIO m, IsTestDBus a) =>
    a
    {- ^ /@self@/: a 'GI.Gio.Objects.TestDBus.TestDBus' -}
    -> T.Text
    {- ^ /@path@/: path to a directory containing .service files -}
    -> m ()
testDBusAddServiceDir self path = liftIO $ do
    self' <- unsafeManagedPtrCastPtr self
    path' <- textToCString path
    g_test_dbus_add_service_dir self' path'
    touchManagedPtr self
    freeMem path'
    return ()

#if ENABLE_OVERLOADING
data TestDBusAddServiceDirMethodInfo
instance (signature ~ (T.Text -> m ()), MonadIO m, IsTestDBus a) => O.MethodInfo TestDBusAddServiceDirMethodInfo a signature where
    overloadedMethod _ = testDBusAddServiceDir

#endif

-- method TestDBus::down
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "self", argType = TInterface (Name {namespace = "Gio", name = "TestDBus"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GTestDBus", 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_dbus_down" g_test_dbus_down ::
    Ptr TestDBus ->                         -- self : TInterface (Name {namespace = "Gio", name = "TestDBus"})
    IO ()

{- |
Stop the session bus started by 'GI.Gio.Objects.TestDBus.testDBusUp'.

This will wait for the singleton returned by 'GI.Gio.Functions.busGet' or 'GI.Gio.Functions.busGetSync'
is destroyed. This is done to ensure that the next unit test won\'t get a
leaked singleton from this test.
-}
testDBusDown ::
    (B.CallStack.HasCallStack, MonadIO m, IsTestDBus a) =>
    a
    {- ^ /@self@/: a 'GI.Gio.Objects.TestDBus.TestDBus' -}
    -> m ()
testDBusDown self = liftIO $ do
    self' <- unsafeManagedPtrCastPtr self
    g_test_dbus_down self'
    touchManagedPtr self
    return ()

#if ENABLE_OVERLOADING
data TestDBusDownMethodInfo
instance (signature ~ (m ()), MonadIO m, IsTestDBus a) => O.MethodInfo TestDBusDownMethodInfo a signature where
    overloadedMethod _ = testDBusDown

#endif

-- method TestDBus::get_bus_address
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "self", argType = TInterface (Name {namespace = "Gio", name = "TestDBus"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GTestDBus", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TUTF8)
-- throws : False
-- Skip return : False

foreign import ccall "g_test_dbus_get_bus_address" g_test_dbus_get_bus_address ::
    Ptr TestDBus ->                         -- self : TInterface (Name {namespace = "Gio", name = "TestDBus"})
    IO CString

{- |
Get the address on which dbus-daemon is running. If 'GI.Gio.Objects.TestDBus.testDBusUp' has not
been called yet, 'Nothing' is returned. This can be used with
'GI.Gio.Objects.DBusConnection.dBusConnectionNewForAddress'.
-}
testDBusGetBusAddress ::
    (B.CallStack.HasCallStack, MonadIO m, IsTestDBus a) =>
    a
    {- ^ /@self@/: a 'GI.Gio.Objects.TestDBus.TestDBus' -}
    -> m (Maybe T.Text)
    {- ^ __Returns:__ the address of the bus, or 'Nothing'. -}
testDBusGetBusAddress self = liftIO $ do
    self' <- unsafeManagedPtrCastPtr self
    result <- g_test_dbus_get_bus_address self'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- cstringToText result'
        return result''
    touchManagedPtr self
    return maybeResult

#if ENABLE_OVERLOADING
data TestDBusGetBusAddressMethodInfo
instance (signature ~ (m (Maybe T.Text)), MonadIO m, IsTestDBus a) => O.MethodInfo TestDBusGetBusAddressMethodInfo a signature where
    overloadedMethod _ = testDBusGetBusAddress

#endif

-- method TestDBus::get_flags
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "self", argType = TInterface (Name {namespace = "Gio", name = "TestDBus"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GTestDBus", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gio", name = "TestDBusFlags"}))
-- throws : False
-- Skip return : False

foreign import ccall "g_test_dbus_get_flags" g_test_dbus_get_flags ::
    Ptr TestDBus ->                         -- self : TInterface (Name {namespace = "Gio", name = "TestDBus"})
    IO CUInt

{- |
Get the flags of the 'GI.Gio.Objects.TestDBus.TestDBus' object.
-}
testDBusGetFlags ::
    (B.CallStack.HasCallStack, MonadIO m, IsTestDBus a) =>
    a
    {- ^ /@self@/: a 'GI.Gio.Objects.TestDBus.TestDBus' -}
    -> m [Gio.Flags.TestDBusFlags]
    {- ^ __Returns:__ the value of 'GI.Gio.Objects.TestDBus.TestDBus':@/flags/@ property -}
testDBusGetFlags self = liftIO $ do
    self' <- unsafeManagedPtrCastPtr self
    result <- g_test_dbus_get_flags self'
    let result' = wordToGFlags result
    touchManagedPtr self
    return result'

#if ENABLE_OVERLOADING
data TestDBusGetFlagsMethodInfo
instance (signature ~ (m [Gio.Flags.TestDBusFlags]), MonadIO m, IsTestDBus a) => O.MethodInfo TestDBusGetFlagsMethodInfo a signature where
    overloadedMethod _ = testDBusGetFlags

#endif

-- method TestDBus::stop
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "self", argType = TInterface (Name {namespace = "Gio", name = "TestDBus"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GTestDBus", 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_dbus_stop" g_test_dbus_stop ::
    Ptr TestDBus ->                         -- self : TInterface (Name {namespace = "Gio", name = "TestDBus"})
    IO ()

{- |
Stop the session bus started by 'GI.Gio.Objects.TestDBus.testDBusUp'.

Unlike 'GI.Gio.Objects.TestDBus.testDBusDown', this won\'t verify the 'GI.Gio.Objects.DBusConnection.DBusConnection'
singleton returned by 'GI.Gio.Functions.busGet' or 'GI.Gio.Functions.busGetSync' is destroyed. Unit
tests wanting to verify behaviour after the session bus has been stopped
can use this function but should still call 'GI.Gio.Objects.TestDBus.testDBusDown' when done.
-}
testDBusStop ::
    (B.CallStack.HasCallStack, MonadIO m, IsTestDBus a) =>
    a
    {- ^ /@self@/: a 'GI.Gio.Objects.TestDBus.TestDBus' -}
    -> m ()
testDBusStop self = liftIO $ do
    self' <- unsafeManagedPtrCastPtr self
    g_test_dbus_stop self'
    touchManagedPtr self
    return ()

#if ENABLE_OVERLOADING
data TestDBusStopMethodInfo
instance (signature ~ (m ()), MonadIO m, IsTestDBus a) => O.MethodInfo TestDBusStopMethodInfo a signature where
    overloadedMethod _ = testDBusStop

#endif

-- method TestDBus::up
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "self", argType = TInterface (Name {namespace = "Gio", name = "TestDBus"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GTestDBus", 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_dbus_up" g_test_dbus_up ::
    Ptr TestDBus ->                         -- self : TInterface (Name {namespace = "Gio", name = "TestDBus"})
    IO ()

{- |
Start a dbus-daemon instance and set DBUS_SESSION_BUS_ADDRESS. After this
call, it is safe for unit tests to start sending messages on the session bus.

If this function is called from setup callback of @/g_test_add()/@,
'GI.Gio.Objects.TestDBus.testDBusDown' must be called in its teardown callback.

If this function is called from unit test\'s @/main()/@, then 'GI.Gio.Objects.TestDBus.testDBusDown'
must be called after 'GI.GLib.Functions.testRun'.
-}
testDBusUp ::
    (B.CallStack.HasCallStack, MonadIO m, IsTestDBus a) =>
    a
    {- ^ /@self@/: a 'GI.Gio.Objects.TestDBus.TestDBus' -}
    -> m ()
testDBusUp self = liftIO $ do
    self' <- unsafeManagedPtrCastPtr self
    g_test_dbus_up self'
    touchManagedPtr self
    return ()

#if ENABLE_OVERLOADING
data TestDBusUpMethodInfo
instance (signature ~ (m ()), MonadIO m, IsTestDBus a) => O.MethodInfo TestDBusUpMethodInfo a signature where
    overloadedMethod _ = testDBusUp

#endif

-- method TestDBus::unset
-- method type : MemberFunction
-- Args : []
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_test_dbus_unset" g_test_dbus_unset ::
    IO ()

{- |
Unset DISPLAY and DBUS_SESSION_BUS_ADDRESS env variables to ensure the test
won\'t use user\'s session bus.

This is useful for unit tests that want to verify behaviour when no session
bus is running. It is not necessary to call this if unit test already calls
'GI.Gio.Objects.TestDBus.testDBusUp' before acquiring the session bus.
-}
testDBusUnset ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    m ()
testDBusUnset  = liftIO $ do
    g_test_dbus_unset
    return ()

#if ENABLE_OVERLOADING
#endif