summaryrefslogtreecommitdiffstats
path: root/tests/test_gsocket.py
blob: 9ac239825fbd172d34015ee7d9f21c90eef9b25a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# -*- Mode: Python -*-

import os
import unittest

from common import gio, glib, gobject


class TestSocket(unittest.TestCase):
    def setUp(self):
        self.sock = gio.Socket(gio.SOCKET_FAMILY_IPV4,
                               gio.SOCKET_TYPE_STREAM,
                               gio.SOCKET_PROTOCOL_TCP)

    def test_socket_condition_check(self):
        check = self.sock.condition_check(glib.IO_OUT)
        self.failUnless(isinstance(check, gobject.GFlags))
        self.failUnlessEqual(check, glib.IO_OUT | glib.IO_HUP)

    def test_socket_condition_wait(self):
        res = self.sock.condition_wait(glib.IO_OUT)
        self.failUnless(res)

    def tearDown(self):
        self.sock.close()

class TestSocketAddress(unittest.TestCase):
    def test_socket_address_enumerator_next_async(self):
        def callback(enumerator, result):
            try:
                address = enumerator.next_finish(result)
                self.failUnless(isinstance(address, gio.SocketAddress))
            finally:
                loop.quit()

        socket = gio.NetworkAddress("www.pygtk.org", 80)
        enumerator = socket.enumerate()
        enumerator.next_async(callback)

        loop = glib.MainLoop()
        loop.run()