Esempio n. 1
0
 def test_glfw_modules(self) -> None:
     from kitty.constants import glfw_path, is_macos
     linux_backends = ['x11']
     if not self.is_ci:
         linux_backends.append('wayland')
     modules = ['cocoa'] if is_macos else linux_backends
     for name in modules:
         path = glfw_path(name)
         self.assertTrue(os.path.isfile(path), f'{path} is not a file')
         self.assertTrue(os.access(path, os.X_OK), f'{path} is not executable')
Esempio n. 2
0
    def test_utf_8_strndup(self):
        import ctypes
        from kitty.constants import glfw_path

        backend_utils = glfw_path('x11')
        lib = ctypes.CDLL(backend_utils)
        libc = ctypes.CDLL(None)

        class allocated_c_char_p(ctypes.c_char_p):
            def __del__(self):
                libc.free(self)

        utf_8_strndup = lib.utf_8_strndup
        utf_8_strndup.restype = allocated_c_char_p
        utf_8_strndup.argtypes = (ctypes.c_char_p, ctypes.c_size_t)

        def test(string):
            string_bytes = bytes(string, 'utf-8')
            prev_part_bytes = b''
            prev_length_bytes = -1
            for length in range(len(string) + 1):
                part = string[:length]
                part_bytes = bytes(part, 'utf-8')
                length_bytes = len(part_bytes)
                for length_bytes_2 in range(prev_length_bytes + 1,
                                            length_bytes):
                    self.ae(
                        utf_8_strndup(string_bytes, length_bytes_2).value,
                        prev_part_bytes)
                self.ae(
                    utf_8_strndup(string_bytes, length_bytes).value,
                    part_bytes)
                prev_part_bytes = part_bytes
                prev_length_bytes = length_bytes
            self.ae(
                utf_8_strndup(string_bytes,
                              len(string_bytes) + 1).value, string_bytes
            )  # Try to go one character after the end of the string

        self.ae(utf_8_strndup(None, 2).value, None)
        self.ae(utf_8_strndup(b'', 2).value, b'')

        test('ö')
        test('>a<')
        test('>ä<')
        test('>ế<')
        test('>�<')
        test('∮ E⋅da = Q,  n → ∞, �∑ f(i) = � g(i)')