Beispiel #1
0
    def test_sound_option(self):
        ONE_OPTION = [common.VORBIS, ]
        assert common.sound_option_or_all("unspecified", None, ONE_OPTION)==ONE_OPTION
        assert common.sound_option_or_all("unspecified", (), ONE_OPTION)==ONE_OPTION

        assert common.sound_option_or_all("valid", ONE_OPTION, ONE_OPTION)==ONE_OPTION
        with LoggerSilencer(common, ("error", "warn")):
            assert common.sound_option_or_all("invalid options", (common.VORBIS, common.OGG, ), ONE_OPTION)==ONE_OPTION
            assert common.sound_option_or_all("no valid options", (common.VORBIS, common.OGG, ), ())==[]
Beispiel #2
0
 def test_mmap(self):
     from xpra.server.source import mmap_connection
     import tempfile
     file = tempfile.NamedTemporaryFile(prefix="xpra-mmap-test")
     file.write(b"0"*1024*1024)
     for server_mmap_filename in (None, file.name, "/this-path/should-not-exist"):
         for supports_mmap in (False, True):
             for has_file in (True, False):
                 caps = {
                     "mmap.namespace"    : True,
                     "min_mmap_size"     : 128*1024,
                     }
                 if has_file:
                     caps["mmap.file"] = file.name
                     caps["mmap_file"] = file.name
                 with LoggerSilencer(mmap_connection, ("error", "warn")):
                     self._test_mixin_class(mmap_connection.MMAP_Connection, {
                         "mmap_filename" : server_mmap_filename,
                         "supports_mmap" : supports_mmap,
                         "min_mmap_size" : 10000,
                         }, caps)
Beispiel #3
0
    def test_run(self):
        assert get_worker(False) is None
        w = get_worker()
        assert repr(w)

        def error_item():
            raise Exception("work item test error")

        with silence_error(background_worker):
            add_work_item(error_item)
            time.sleep(0.1)
        #add the same item twice, with "no-duplicates"
        #(should only get added once)
        ndc = []

        def nodupe():
            ndc.append(True)

        w.add(nodupe, False)
        w.add(nodupe, False)
        time.sleep(1)
        with LoggerSilencer(background_worker, ("warn", "info")):
            #trigger the warning with more than 10 items:
            def slow_item():
                time.sleep(1)

            for _ in range(12):
                w.add(slow_item)
            stop_worker()
            stop_worker(True)
        #no-op:
        stop_worker(True)
        #let the worker print its messages:
        time.sleep(1)
        assert len(
            ndc) == 1, "nodupe item should have been run once only, got %i" % (
                len(ndc), )
Beispiel #4
0
 def test_rgb_reformat(self):
     from unit.test_util import LoggerSilencer
     from xpra.codecs.argb import argb  #pylint: disable=no-name-in-module
     with LoggerSilencer(rgb_transform):
         with LoggerSilencer(argb):
             self.do_test_rgb_reformat()
Beispiel #5
0
    def test_xsettings(self):
        from xpra.x11.xsettings_prop import (
            get_settings,
            set_settings,
            get_local_byteorder,
            XSettingsTypeInteger,
            XSettingsTypeString,
            XSettingsTypeColor,
        )
        for DEBUG_XSETTINGS in (True, False):
            with OSEnvContext():
                os.environ["XPRA_XSETTINGS_DEBUG"] = str(int(DEBUG_XSETTINGS))
                serial = 1
                data = b""
                l = len(data)
                v = struct.pack(b"=BBBBII", get_local_byteorder(), 0, 0, 0,
                                serial, l) + data + b"\0"
                v1 = get_settings(v)
                assert v
                #get from cache:
                v2 = get_settings(v)
                assert v1 == v2

                #test all types, set then get:
                #setting_type, prop_name, value, last_change_serial = setting
                settings = (
                    (XSettingsTypeInteger, "int1", 1, 0),
                    (XSettingsTypeString, "str1", "1", 0),
                    (XSettingsTypeColor, "color1", (128, 128, 64, 32), 0),
                )
                serial = 2
                data = set_settings((serial, settings))
                assert data
                #parse it back:
                v = get_settings(data)
                rserial, rsettings = v
                assert rserial == serial
                assert len(rsettings) == len(settings)
        from xpra.x11 import xsettings_prop
        with LoggerSilencer(xsettings_prop):
            #test error handling:
            for settings in (
                (
                    #invalid color causes exception
                    (XSettingsTypeColor, "bad-color", (128, ), 0), ),
                (
                    #invalid setting type is skipped with an error message:
                    (255, "invalid-setting-type", 0, 0), ),
            ):
                serial = 3
                data = set_settings((serial, settings))
                assert data
                v = get_settings(data)
                rserial, rsettings = v
                assert rserial == serial
                assert len(rsettings) == 0
            #parsing an invalid data type (9) should fail:
            hexdata = b"000000000200000001000000090004007374723100000000010000003100000000"
            data = binascii.unhexlify(hexdata)
            v = get_settings(data)
            rserial, rsettings = v
            assert len(rsettings) == 0