This commit is contained in:
emdee 2023-12-09 10:19:21 +00:00
parent 18195f287c
commit 9111a1def8
2 changed files with 312 additions and 227 deletions

View File

@ -27,6 +27,7 @@ def LOG_TRACE(a):
UINT32_MAX = 2 ** 32 -1 UINT32_MAX = 2 ** 32 -1
class ToxError(RuntimeError): pass class ToxError(RuntimeError): pass
TOX_MAX_STATUS_MESSAGE_LENGTH = 1007
global aTIMES global aTIMES
aTIMES=dict() aTIMES=dict()
@ -65,6 +66,7 @@ class ToxOptions(Structure):
('log_callback', c_void_p), ('log_callback', c_void_p),
('log_user_data', c_void_p), ('log_user_data', c_void_p),
('experimental_thread_safety', c_bool), ('experimental_thread_safety', c_bool),
('operating_system', c_void_p),
] ]
@ -517,7 +519,8 @@ class Tox:
:return: length of the current nickname :return: length of the current nickname
""" """
return Tox.libtoxcore.tox_self_get_name_size(self._tox_pointer) retval = Tox.libtoxcore.tox_self_get_name_size(self._tox_pointer)
return int(retval)
def self_get_name(self, name=None): def self_get_name(self, name=None):
""" """
@ -548,9 +551,10 @@ class Tox:
:return: True on success. :return: True on success.
""" """
tox_err_set_info = c_int() tox_err_set_info = c_int()
if len(status_message) > TOX_MAX_STATUS_MESSAGE_LENGTH:
status_message = status_message[:TOX_MAX_STATUS_MESSAGE_LENGTH]
if type(status_message) != bytes: if type(status_message) != bytes:
status_message = bytes(status_message, 'utf-8') status_message = bytes(status_message, 'utf-8')
status_message = status_message[:80]
LOG_DEBUG(f"tox.self_set_status_message") LOG_DEBUG(f"tox.self_set_status_message")
result = Tox.libtoxcore.tox_self_set_status_message(self._tox_pointer, result = Tox.libtoxcore.tox_self_set_status_message(self._tox_pointer,
c_char_p(status_message), c_char_p(status_message),
@ -559,9 +563,9 @@ class Tox:
tox_err_set_info = tox_err_set_info.value tox_err_set_info = tox_err_set_info.value
if tox_err_set_info == TOX_ERR_SET_INFO['OK']: if tox_err_set_info == TOX_ERR_SET_INFO['OK']:
return bool(result) return bool(result)
elif tox_err_set_info == TOX_ERR_SET_INFO['NULL']: if tox_err_set_info == TOX_ERR_SET_INFO['NULL']:
raise ArgumentError('One of the arguments to the function was NULL when it was not expected.') raise ArgumentError('One of the arguments to the function was NULL when it was not expected.')
elif tox_err_set_info == TOX_ERR_SET_INFO['TOO_LONG']: if tox_err_set_info == TOX_ERR_SET_INFO['TOO_LONG']:
raise ArgumentError('Information length exceeded maximum permissible size.') raise ArgumentError('Information length exceeded maximum permissible size.')
raise ToxError('The function did not return OK.') raise ToxError('The function did not return OK.')
@ -602,7 +606,8 @@ class Tox:
return return
if bTooSoon('self', 'tox_self_set_status', 5.0): return None if bTooSoon('self', 'tox_self_set_status', 5.0): return None
LOG_DEBUG(f"tox.self_set_status {status}") LOG_DEBUG(f"tox.self_set_status {status}")
Tox.libtoxcore.tox_self_set_status(self._tox_pointer, c_int(status)) Tox.libtoxcore.tox_self_set_status(self._tox_pointer, c_uint32(status))
return None
def self_get_status(self): def self_get_status(self):
""" """
@ -612,7 +617,8 @@ class Tox:
""" """
if bTooSoon('self', 'self_set_status', 10.0): return None if bTooSoon('self', 'self_set_status', 10.0): return None
LOG_TRACE(f"tox_get_status") LOG_TRACE(f"tox_get_status")
return Tox.libtoxcore.tox_self_get_status(self._tox_pointer) result = Tox.libtoxcore.tox_self_get_status(self._tox_pointer)
return int(result)
# ----------------------------------------------------------------------------------------------------------------- # -----------------------------------------------------------------------------------------------------------------
# Friend list management # Friend list management
@ -814,7 +820,8 @@ class Tox:
public_key = create_string_buffer(TOX_PUBLIC_KEY_SIZE) public_key = create_string_buffer(TOX_PUBLIC_KEY_SIZE)
tox_err_friend_get_public_key = c_int() tox_err_friend_get_public_key = c_int()
LOG_TRACE(f"tox_friend_get_public_key") LOG_TRACE(f"tox_friend_get_public_key")
Tox.libtoxcore.tox_friend_get_public_key(self._tox_pointer, c_uint32(friend_number), public_key, Tox.libtoxcore.tox_friend_get_public_key(self._tox_pointer,
c_uint32(friend_number), public_key,
byref(tox_err_friend_get_public_key)) byref(tox_err_friend_get_public_key))
tox_err_friend_get_public_key = tox_err_friend_get_public_key.value tox_err_friend_get_public_key = tox_err_friend_get_public_key.value
if tox_err_friend_get_public_key == TOX_ERR_FRIEND_GET_PUBLIC_KEY['OK']: if tox_err_friend_get_public_key == TOX_ERR_FRIEND_GET_PUBLIC_KEY['OK']:
@ -884,7 +891,8 @@ class Tox:
name = create_string_buffer(self.friend_get_name_size(friend_number)) name = create_string_buffer(self.friend_get_name_size(friend_number))
tox_err_friend_query = c_int() tox_err_friend_query = c_int()
LOG_DEBUG(f"tox.friend_get_name") LOG_DEBUG(f"tox.friend_get_name")
Tox.libtoxcore.tox_friend_get_name(self._tox_pointer, c_uint32(friend_number), name, Tox.libtoxcore.tox_friend_get_name(self._tox_pointer,
c_uint32(friend_number), name,
byref(tox_err_friend_query)) byref(tox_err_friend_query))
tox_err_friend_query = tox_err_friend_query.value tox_err_friend_query = tox_err_friend_query.value
if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']: if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']:
@ -958,7 +966,9 @@ class Tox:
status_message = create_string_buffer(self.friend_get_status_message_size(friend_number)) status_message = create_string_buffer(self.friend_get_status_message_size(friend_number))
tox_err_friend_query = c_int() tox_err_friend_query = c_int()
LOG_DEBUG(f"tox.friend_get_status_message") LOG_DEBUG(f"tox.friend_get_status_message")
Tox.libtoxcore.tox_friend_get_status_message(self._tox_pointer, c_uint32(friend_number), status_message, Tox.libtoxcore.tox_friend_get_status_message(self._tox_pointer,
c_uint32(friend_number),
status_message,
byref(tox_err_friend_query)) byref(tox_err_friend_query))
tox_err_friend_query = tox_err_friend_query.value tox_err_friend_query = tox_err_friend_query.value
if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']: if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']:
@ -1008,17 +1018,19 @@ class Tox:
""" """
tox_err_friend_query = c_int() tox_err_friend_query = c_int()
LOG_DEBUG(f"tox.friend_get_status") LOG_DEBUG(f"tox.friend_get_status")
result = Tox.libtoxcore.tox_friend_get_status(self._tox_pointer, c_uint32(friend_number), result = Tox.libtoxcore.tox_friend_get_status(self._tox_pointer,
c_uint32(friend_number),
byref(tox_err_friend_query)) byref(tox_err_friend_query))
tox_err_friend_query = tox_err_friend_query.value tox_err_friend_query = tox_err_friend_query.value
if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']: if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']:
return result return int(result)
elif tox_err_friend_query == TOX_ERR_FRIEND_QUERY['NULL']: elif tox_err_friend_query == TOX_ERR_FRIEND_QUERY['NULL']:
raise ArgumentError('The pointer parameter for storing the query result (name, message) was NULL. Unlike' raise ArgumentError('The pointer parameter for storing the query result (name, message) was NULL. Unlike'
' the `_self_` variants of these functions, which have no effect when a parameter is' ' the `_self_` variants of these functions, which have no effect when a parameter is'
' NULL, these functions return an error in that case.') ' NULL, these functions return an error in that case.')
elif tox_err_friend_query == TOX_ERR_FRIEND_QUERY['FRIEND_NOT_FOUND']: elif tox_err_friend_query == TOX_ERR_FRIEND_QUERY['FRIEND_NOT_FOUND']:
raise ArgumentError('The friend_number did not designate a valid friend.') raise ArgumentError('The friend_number did not designate a valid friend.')
raise ToxError('The function did not return OK.')
def callback_friend_status(self, callback): def callback_friend_status(self, callback):
""" """
@ -1054,11 +1066,12 @@ class Tox:
""" """
tox_err_friend_query = c_int() tox_err_friend_query = c_int()
LOG_DEBUG(f"tox.friend_get_connection_status") LOG_DEBUG(f"tox.friend_get_connection_status")
result = Tox.libtoxcore.tox_friend_get_connection_status(self._tox_pointer, c_uint32(friend_number), result = Tox.libtoxcore.tox_friend_get_connection_status(self._tox_pointer,
c_uint32(friend_number),
byref(tox_err_friend_query)) byref(tox_err_friend_query))
tox_err_friend_query = tox_err_friend_query.value tox_err_friend_query = tox_err_friend_query.value
if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']: if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']:
return result return int(result)
elif tox_err_friend_query == TOX_ERR_FRIEND_QUERY['NULL']: elif tox_err_friend_query == TOX_ERR_FRIEND_QUERY['NULL']:
raise ArgumentError('The pointer parameter for storing the query result (name, message) was NULL. Unlike' raise ArgumentError('The pointer parameter for storing the query result (name, message) was NULL. Unlike'
' the `_self_` variants of these functions, which have no effect when a parameter is' ' the `_self_` variants of these functions, which have no effect when a parameter is'
@ -1102,7 +1115,8 @@ class Tox:
""" """
tox_err_friend_query = c_int() tox_err_friend_query = c_int()
LOG_DEBUG(f"tox.friend_get_typing") LOG_DEBUG(f"tox.friend_get_typing")
result = Tox.libtoxcore.tox_friend_get_typing(self._tox_pointer, c_uint32(friend_number), result = Tox.libtoxcore.tox_friend_get_typing(self._tox_pointer,
c_uint32(friend_number),
byref(tox_err_friend_query)) byref(tox_err_friend_query))
tox_err_friend_query = tox_err_friend_query.value tox_err_friend_query = tox_err_friend_query.value
if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']: if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']:
@ -1194,7 +1208,7 @@ class Tox:
byref(tox_err_friend_send_message)) byref(tox_err_friend_send_message))
tox_err_friend_send_message = tox_err_friend_send_message.value tox_err_friend_send_message = tox_err_friend_send_message.value
if tox_err_friend_send_message == TOX_ERR_FRIEND_SEND_MESSAGE['OK']: if tox_err_friend_send_message == TOX_ERR_FRIEND_SEND_MESSAGE['OK']:
return result return int(result)
elif tox_err_friend_send_message == TOX_ERR_FRIEND_SEND_MESSAGE['NULL']: elif tox_err_friend_send_message == TOX_ERR_FRIEND_SEND_MESSAGE['NULL']:
raise ArgumentError('One of the arguments to the function was NULL when it was not expected.') raise ArgumentError('One of the arguments to the function was NULL when it was not expected.')
elif tox_err_friend_send_message == TOX_ERR_FRIEND_SEND_MESSAGE['FRIEND_NOT_FOUND']: elif tox_err_friend_send_message == TOX_ERR_FRIEND_SEND_MESSAGE['FRIEND_NOT_FOUND']:
@ -1311,7 +1325,7 @@ class Tox:
if hash is None: if hash is None:
hash = create_string_buffer(TOX_HASH_LENGTH) hash = create_string_buffer(TOX_HASH_LENGTH)
LOG_DEBUG(f"tox.hash") LOG_DEBUG(f"tox.hash")
Tox.libtoxcore.tox_hash(hash, c_char_p(data), len(data)) Tox.libtoxcore.tox_hash(hash, c_char_p(data), c_size_t(len(data)))
return bin_to_string(hash, TOX_HASH_LENGTH) return bin_to_string(hash, TOX_HASH_LENGTH)
def file_control(self, friend_number, file_number, control): def file_control(self, friend_number, file_number, control):
@ -1507,7 +1521,7 @@ class Tox:
err_file = tox_err_file_send.value err_file = tox_err_file_send.value
if err_file == TOX_ERR_FILE_SEND['OK']: if err_file == TOX_ERR_FILE_SEND['OK']:
# UINT32_MAX # UINT32_MAX
return result return int(result)
if err_file == TOX_ERR_FILE_SEND['NULL']: if err_file == TOX_ERR_FILE_SEND['NULL']:
raise ArgumentError('One of the arguments to the function was NULL when it was not expected.') raise ArgumentError('One of the arguments to the function was NULL when it was not expected.')
if err_file == TOX_ERR_FILE_SEND['FRIEND_NOT_FOUND']: if err_file == TOX_ERR_FILE_SEND['FRIEND_NOT_FOUND']:
@ -1833,7 +1847,7 @@ class Tox:
result = Tox.libtoxcore.tox_self_get_udp_port(self._tox_pointer, byref(tox_err_get_port)) result = Tox.libtoxcore.tox_self_get_udp_port(self._tox_pointer, byref(tox_err_get_port))
tox_err_get_port = tox_err_get_port.value tox_err_get_port = tox_err_get_port.value
if tox_err_get_port == TOX_ERR_GET_PORT['OK']: if tox_err_get_port == TOX_ERR_GET_PORT['OK']:
return result return int(result)
if tox_err_get_port == TOX_ERR_GET_PORT['NOT_BOUND']: if tox_err_get_port == TOX_ERR_GET_PORT['NOT_BOUND']:
raise ToxError('The instance was not bound to any port.') raise ToxError('The instance was not bound to any port.')
raise ToxError('The function did not return OK') raise ToxError('The function did not return OK')
@ -1848,7 +1862,7 @@ class Tox:
result = Tox.libtoxcore.tox_self_get_tcp_port(self._tox_pointer, byref(tox_err_get_port)) result = Tox.libtoxcore.tox_self_get_tcp_port(self._tox_pointer, byref(tox_err_get_port))
tox_err_get_port = tox_err_get_port.value tox_err_get_port = tox_err_get_port.value
if tox_err_get_port == TOX_ERR_GET_PORT['OK']: if tox_err_get_port == TOX_ERR_GET_PORT['OK']:
return result return int(result)
if tox_err_get_port == TOX_ERR_GET_PORT['NOT_BOUND']: if tox_err_get_port == TOX_ERR_GET_PORT['NOT_BOUND']:
raise ToxError('The instance was not bound to any port.') raise ToxError('The instance was not bound to any port.')
raise ToxError('The function did not return OK') raise ToxError('The function did not return OK')
@ -1889,7 +1903,7 @@ class Tox:
result = Tox.libtoxcore.tox_group_new(self._tox_pointer, result = Tox.libtoxcore.tox_group_new(self._tox_pointer,
privacy_state, privacy_state,
group_name, group_name,
len(group_name), c_size_t(len(group_name)),
peer_info, byref(error)) peer_info, byref(error))
else: else:
nick_length = len(nick) nick_length = len(nick)
@ -1898,9 +1912,9 @@ class Tox:
result = Tox.libtoxcore.tox_group_new(self._tox_pointer, result = Tox.libtoxcore.tox_group_new(self._tox_pointer,
privacy_state, privacy_state,
cgroup_name, cgroup_name,
len(group_name), c_size_t(len(group_name)),
cnick, cnick,
nick_length, c_size_t(nick_length),
byref(error)) byref(error))
if error.value: if error.value:
@ -1908,7 +1922,8 @@ class Tox:
LOG_ERROR(f"group_new {error.value} {s}") LOG_ERROR(f"group_new {error.value} {s}")
raise ToxError(f"group_new {s} {error.value}") raise ToxError(f"group_new {s} {error.value}")
return result # TypeError: '<' not supported between instances of 'c_uint' and 'int'
return int(result)
def group_join(self, chat_id, password, nick, status=''): def group_join(self, chat_id, password, nick, status=''):
"""Joins a group chat with specified Chat ID. """Joins a group chat with specified Chat ID.
@ -1945,7 +1960,6 @@ class Tox:
peer_info, peer_info,
byref(error)) byref(error))
else: else:
cnick = c_char_p(nick)
if not password: if not password:
# dunno # dunno
cpassword = POINTER(None)() cpassword = POINTER(None)()
@ -1953,19 +1967,19 @@ class Tox:
cpassword = c_char_p(password) cpassword = c_char_p(password)
result = Tox.libtoxcore.tox_group_join(self._tox_pointer, result = Tox.libtoxcore.tox_group_join(self._tox_pointer,
string_to_bin(chat_id), string_to_bin(chat_id),
cnick, c_char_p(nick),
len(nick), c_size_t(len(nick)),
cpassword, cpassword,
len(password) if password else 0, c_size_t(len(password)) if password else 0,
byref(error)) byref(error))
if error.value: if error.value:
s = sGetError(error.value, TOX_ERR_GROUP_JOIN) s = sGetError(error.value, TOX_ERR_GROUP_JOIN)
LOG_ERROR(f"group_new err={error.value} {s}") LOG_ERROR(f"group_new err={error.value} {s}")
raise ToxError(f"group_new {s} err={error.value}") raise ToxError(f"group_new {s} err={error.value}")
LOG_INFO(f"group_new result={result} {chat_id}") LOG_INFO(f"group_new result={result} chat_id={chat_id}")
return result return int(result)
def group_reconnect(self, group_number): def group_reconnect(self, group_number):
""" """
@ -1982,12 +1996,12 @@ class Tox:
raise ToxError(f"tox_group_ group_number < 0 {group_number}") raise ToxError(f"tox_group_ group_number < 0 {group_number}")
error = c_int() error = c_int()
LOG_DEBUG(f"tox.group_reconnect") LOG_DEBUG(f"tox.group_reconnect")
result = Tox.libtoxcore.tox_group_reconnect(self._tox_pointer, group_number, byref(error)) result = Tox.libtoxcore.tox_group_reconnect(self._tox_pointer, c_uint32(group_number), byref(error))
if error.value: if error.value:
s = sGetError(error.value, TOX_ERR_GROUP_RECONNECT) s = sGetError(error.value, TOX_ERR_GROUP_RECONNECT)
LOG_ERROR(f"group_new {error.value} {s}") LOG_ERROR(f"group_new {error.value} {s}")
raise ToxError(f"group_new {s} {error.value}") raise ToxError(f"group_new {s} {error.value}")
return result return bool(result)
def group_is_connected(self, group_number): def group_is_connected(self, group_number):
if group_number < 0: if group_number < 0:
@ -1995,25 +2009,25 @@ class Tox:
error = c_int() error = c_int()
LOG_DEBUG(f"tox.group_is_connected") LOG_DEBUG(f"tox.group_is_connected")
result = Tox.libtoxcore.tox_group_is_connected(self._tox_pointer, group_number, byref(error)) result = Tox.libtoxcore.tox_group_is_connected(self._tox_pointer, c_uint32(group_number), byref(error))
if error.value: if error.value:
# TOX_ERR_GROUP_IS_CONNECTED_GROUP_NOT_FOUND # TOX_ERR_GROUP_IS_CONNECTED_GROUP_NOT_FOUND
s = sGetError(error.value, TOX_ERR_GROUP_IS_CONNECTED) s = sGetError(error.value, TOX_ERR_GROUP_IS_CONNECTED)
LOG_ERROR(f"group_new err={error.value} {s}") LOG_ERROR(f"group_new err={error.value} {s}")
raise ToxError("group_is_connected err={error.value} {s}") raise ToxError("group_is_connected err={error.value} {s}")
return result return bool(result)
def group_disconnect(self, group_number): def group_disconnect(self, group_number):
if group_number < 0: if group_number < 0:
raise ToxError(f"tox_group_ group_number < 0 {group_number}") raise ToxError(f"tox_group_ group_number < 0 {group_number}")
error = c_int() error = c_int()
LOG_DEBUG(f"tox.group_disconnect") LOG_DEBUG(f"tox.group_disconnect")
result = Tox.libtoxcore.tox_group_disconnect(self._tox_pointer, group_number, byref(error)) result = Tox.libtoxcore.tox_group_disconnect(self._tox_pointer, c_uint32(group_number), byref(error))
if error.value: if error.value:
s = sGetError(error.value, TOX_ERR_GROUP_DISCONNECT) s = sGetError(error.value, TOX_ERR_GROUP_DISCONNECT)
LOG_ERROR(f"group_disconnect {error.value} {s}") LOG_ERROR(f"group_disconnect {error.value} {s}")
raise ToxError(f"group_disconnect {s} {error.value}") raise ToxError(f"group_disconnect {s} {error.value}")
return result return bool(result)
def group_leave(self, group_number, message=None): def group_leave(self, group_number, message=None):
"""Leaves a group. """Leaves a group.
@ -2039,12 +2053,12 @@ class Tox:
f.restype = c_bool f.restype = c_bool
if message is not None and type(message) != bytes: if message is not None and type(message) != bytes:
message = bytes(message, 'utf-8') message = bytes(message, 'utf-8')
result = f(self._tox_pointer, group_number, message, result = f(self._tox_pointer, c_uint32(group_number), message,
len(message) if message else 0, byref(error)) c_size_t(len(message)) if message else 0, byref(error))
if error.value: if error.value:
LOG_ERROR(f"group_leave {error.value}") LOG_ERROR(f"group_leave {error.value}")
raise ToxError("group_leave {error.value}") raise ToxError("group_leave {error.value}")
return result return bool(result)
# ----------------------------------------------------------------------------------------------------------------- # -----------------------------------------------------------------------------------------------------------------
# Group user-visible client information (nickname/status/role/public key) # Group user-visible client information (nickname/status/role/public key)
@ -2069,11 +2083,11 @@ class Tox:
if type(name) != bytes: if type(name) != bytes:
topic = bytes(name, 'utf-8') topic = bytes(name, 'utf-8')
LOG_DEBUG(f"tox.group_self_set_name") LOG_DEBUG(f"tox.group_self_set_name")
result = Tox.libtoxcore.tox_group_self_set_name(self._tox_pointer, group_number, name, len(name), byref(error)) result = Tox.libtoxcore.tox_group_self_set_name(self._tox_pointer, c_uint32(group_number), name, c_size_t(len(name)), byref(error))
if error.value: if error.value:
LOG_ERROR(f"group_self_set_name {error.value}") LOG_ERROR(f"group_self_set_name {error.value}")
raise ToxError("group_self_set_name {error.value}") raise ToxError("group_self_set_name {error.value}")
return result return bool(result)
def group_self_get_name_size(self, group_number): def group_self_get_name_size(self, group_number):
""" """
@ -2088,11 +2102,13 @@ class Tox:
error = c_int() error = c_int()
LOG_TRACE(f"tox_group_self_get_name_size") LOG_TRACE(f"tox_group_self_get_name_size")
result = Tox.libtoxcore.tox_group_self_get_name_size(self._tox_pointer, group_number, byref(error)) result = Tox.libtoxcore.tox_group_self_get_name_size(self._tox_pointer,
c_uint32(group_number),
byref(error))
if error.value: if error.value:
LOG_ERROR(f"group_self_get_name_size {error.value}") LOG_ERROR(f"group_self_get_name_size {error.value}")
raise ToxError("group_self_get_name_size {error.value}") raise ToxError("group_self_get_name_size {error.value}")
return result return int(result)
def group_self_get_name(self, group_number): def group_self_get_name(self, group_number):
"""Write the nickname set by tox_group_self_set_name to a byte array. """Write the nickname set by tox_group_self_set_name to a byte array.
@ -2110,13 +2126,16 @@ class Tox:
raise ToxError(f"tox_group_ group_number < 0 {group_number}") raise ToxError(f"tox_group_ group_number < 0 {group_number}")
error = c_int() error = c_int()
size = self.group_self_get_name_size(group_number) size = self.group_self_get_name_size(c_uint32(group_number))
name = create_string_buffer(size) name = create_string_buffer(size)
LOG_DEBUG(f"tox.group_self_get_name") LOG_DEBUG(f"tox.group_self_get_name")
result = Tox.libtoxcore.tox_group_self_get_name(self._tox_pointer, group_number, name, byref(error)) result = Tox.libtoxcore.tox_group_self_get_name(self._tox_pointer,
c_uint32(group_number),
name,
byref(error))
if error.value: if error.value:
LOG_ERROR(f"group_self_get_name {error.value}") LOG_ERROR(f"group_self_get_name err={error.value}")
raise ToxError("group_self_get_name {error.value}") raise ToxError("group_self_get_name err={error.value}")
return str(name[:size], 'utf-8', errors='ignore') return str(name[:size], 'utf-8', errors='ignore')
def group_self_set_status(self, group_number, status): def group_self_set_status(self, group_number, status):
@ -2130,11 +2149,11 @@ class Tox:
error = c_int() error = c_int()
LOG_DEBUG(f"tox.group_self_set_status") LOG_DEBUG(f"tox.group_self_set_status")
result = Tox.libtoxcore.tox_group_self_set_status(self._tox_pointer, group_number, status, byref(error)) result = Tox.libtoxcore.tox_group_self_set_status(self._tox_pointer, c_uint32(group_number), status, byref(error))
if error.value: if error.value:
LOG_ERROR(f"group_self_set_status {error.value}") LOG_ERROR(f"group_self_set_status {error.value}")
raise ToxError("group_self_set_status {error.value}") raise ToxError("group_self_set_status {error.value}")
return result return bool(result)
def group_self_get_status(self, group_number): def group_self_get_status(self, group_number):
""" """
@ -2146,11 +2165,11 @@ class Tox:
error = c_int() error = c_int()
LOG_DEBUG(f"tox.group_self_get_status") LOG_DEBUG(f"tox.group_self_get_status")
result = Tox.libtoxcore.tox_group_self_get_status(self._tox_pointer, group_number, byref(error)) result = Tox.libtoxcore.tox_group_self_get_status(self._tox_pointer, c_uint32(group_number), byref(error))
if error.value: if error.value:
LOG_ERROR(f"group_self_get_status {error.value}") LOG_ERROR(f"group_self_get_status {error.value}")
raise ToxError("group_self_get_status {error.value}") raise ToxError("group_self_get_status err={error.value}")
return result return int(result)
def group_self_get_role(self, group_number): def group_self_get_role(self, group_number):
""" """
@ -2162,11 +2181,11 @@ class Tox:
error = c_int() error = c_int()
LOG_DEBUG(f"tox.group_self_get_role") LOG_DEBUG(f"tox.group_self_get_role")
result = Tox.libtoxcore.tox_group_self_get_role(self._tox_pointer, group_number, byref(error)) result = Tox.libtoxcore.tox_group_self_get_role(self._tox_pointer, c_uint32(group_number), byref(error))
if error.value: if error.value:
LOG_ERROR(f" {error.value}") LOG_ERROR(f"group_self_get_role err={error.value}")
raise ToxError(f" {error.value}") raise ToxError(f"group_self_get_role err={error.value}")
return result return int(result)
def group_self_get_peer_id(self, group_number): def group_self_get_peer_id(self, group_number):
""" """
@ -2178,11 +2197,11 @@ class Tox:
error = c_int() error = c_int()
LOG_DEBUG(f"tox.group_self_get_peer_id") LOG_DEBUG(f"tox.group_self_get_peer_id")
result = Tox.libtoxcore.tox_group_self_get_peer_id(self._tox_pointer, group_number, byref(error)) result = Tox.libtoxcore.tox_group_self_get_peer_id(self._tox_pointer, c_uint32(group_number), byref(error))
if error.value: if error.value:
LOG_ERROR(f" {error.value}") LOG_ERROR(f"tox.group_self_get_peer_id err={error.value}")
raise ToxError("tox_group_self_get_peer_id {error.value}") raise ToxError("tox_group_self_get_peer_id {error.value}")
return result return int(result)
def group_self_get_public_key(self, group_number): def group_self_get_public_key(self, group_number):
""" """
@ -2202,11 +2221,11 @@ class Tox:
error = c_int() error = c_int()
key = create_string_buffer(TOX_GROUP_PEER_PUBLIC_KEY_SIZE) key = create_string_buffer(TOX_GROUP_PEER_PUBLIC_KEY_SIZE)
LOG_DEBUG(f"tox.group_self_get_public_key") LOG_DEBUG(f"tox.group_self_get_public_key")
result = Tox.libtoxcore.tox_group_self_get_public_key(self._tox_pointer, group_number, result = Tox.libtoxcore.tox_group_self_get_public_key(self._tox_pointer, c_uint32(group_number),
key, byref(error)) key, byref(error))
if error.value: if error.value:
LOG_ERROR(f" {TOX_ERR_FRIEND_GET_PUBLIC_KEY[error.value]}") LOG_ERROR(f"tox.group_self_get_public_key {TOX_ERR_FRIEND_GET_PUBLIC_KEY[error.value]}")
raise ToxError(f"{TOX_ERR_FRIEND_GET_PUBLIC_KEY[error.value]}") raise ToxError(f"tox.group_self_get_public_key {TOX_ERR_FRIEND_GET_PUBLIC_KEY[error.value]}")
return bin_to_string(key, TOX_GROUP_PEER_PUBLIC_KEY_SIZE) return bin_to_string(key, TOX_GROUP_PEER_PUBLIC_KEY_SIZE)
# ----------------------------------------------------------------------------------------------------------------- # -----------------------------------------------------------------------------------------------------------------
@ -2225,12 +2244,12 @@ class Tox:
raise ToxError(f"tox_group_ group_number < 0 {group_number}") raise ToxError(f"tox_group_ group_number < 0 {group_number}")
error = c_int() error = c_int()
result = Tox.libtoxcore.tox_group_peer_get_name_size(self._tox_pointer, group_number, peer_id, byref(error)) result = Tox.libtoxcore.tox_group_peer_get_name_size(self._tox_pointer, c_uint32(group_number), c_uint32(peer_id), byref(error))
if error.value: if error.value:
LOG_ERROR(f" {error.value}") LOG_ERROR(f" {error.value}")
raise ToxError(f" {error.value}") raise ToxError(f" {error.value}")
LOG_TRACE(f"tox_group_peer_get_name_size") LOG_TRACE(f"tox_group_peer_get_name_size")
return result return int(result)
def group_peer_get_name(self, group_number, peer_id): def group_peer_get_name(self, group_number, peer_id):
"""Write the name of the peer designated by the given ID to a byte """Write the name of the peer designated by the given ID to a byte
@ -2254,10 +2273,13 @@ class Tox:
size = self.group_peer_get_name_size(group_number, peer_id) size = self.group_peer_get_name_size(group_number, peer_id)
name = create_string_buffer(size) name = create_string_buffer(size)
LOG_DEBUG(f"tox.group_peer_get_name") LOG_DEBUG(f"tox.group_peer_get_name")
result = Tox.libtoxcore.tox_group_peer_get_name(self._tox_pointer, group_number, peer_id, name, byref(error)) result = Tox.libtoxcore.tox_group_peer_get_name(self._tox_pointer,
c_uint32(group_number),
c_uint32(peer_id),
name, byref(error))
if error.value: if error.value:
LOG_ERROR(f" {error.value}") LOG_ERROR(f"tox.group_peer_get_name err={error.value}")
raise ToxError(f"tox_group_peer_get_name {error.value}") raise ToxError(f"tox_group_peer_get_name err={error.value}")
sRet = str(name[:], 'utf-8', errors='ignore') sRet = str(name[:], 'utf-8', errors='ignore')
return sRet return sRet
@ -2270,14 +2292,17 @@ class Tox:
`group_peer_status` callback. `group_peer_status` callback.
""" """
if group_number < 0: if group_number < 0:
raise ToxError(f"tox_group_ group_number < 0 {group_number}") raise ToxError(f"tox_group_ group_number < 0 group_number={group_number}")
error = c_int() error = c_int()
LOG_DEBUG(f"tox.group_peer_get_status") LOG_DEBUG(f"tox.group_peer_get_status")
result = Tox.libtoxcore.tox_group_peer_get_status(self._tox_pointer, group_number, peer_id, byref(error)) result = Tox.libtoxcore.tox_group_peer_get_status(self._tox_pointer,
c_uint32(group_number),
c_uint32(peer_id),
byref(error))
if error.value: if error.value:
LOG_ERROR(f" {error.value}") LOG_ERROR(f"tox.group_peer_get_status {error.value}")
raise ToxError(f" {error.value}") raise ToxError(f"tox.group_peer_get_status {error.value}")
return result return result
def group_peer_get_role(self, group_number, peer_id): def group_peer_get_role(self, group_number, peer_id):
@ -2293,11 +2318,14 @@ class Tox:
error = c_int() error = c_int()
LOG_DEBUG(f"tox.group_peer_get_role") LOG_DEBUG(f"tox.group_peer_get_role")
result = Tox.libtoxcore.tox_group_peer_get_role(self._tox_pointer, group_number, peer_id, byref(error)) result = Tox.libtoxcore.tox_group_peer_get_role(self._tox_pointer,
c_uint32(group_number),
c_uint32(peer_id),
byref(error))
if error.value: if error.value:
LOG_ERROR(f" {error.value}") LOG_ERROR(f"tox.group_peer_get_role {error.value}")
raise ToxError(f" {error.value}") raise ToxError(f"tox.group_peer_get_role {error.value}")
return result return int(result)
def group_peer_get_public_key(self, group_number, peer_id): def group_peer_get_public_key(self, group_number, peer_id):
"""Write the group public key with the designated peer_id for the designated group number to public_key. """Write the group public key with the designated peer_id for the designated group number to public_key.
@ -2318,11 +2346,13 @@ class Tox:
error = c_int() error = c_int()
key = create_string_buffer(TOX_GROUP_PEER_PUBLIC_KEY_SIZE) key = create_string_buffer(TOX_GROUP_PEER_PUBLIC_KEY_SIZE)
LOG_DEBUG(f"tox.group_peer_get_public_key") LOG_DEBUG(f"tox.group_peer_get_public_key")
result = Tox.libtoxcore.tox_group_peer_get_public_key(self._tox_pointer, group_number, peer_id, result = Tox.libtoxcore.tox_group_peer_get_public_key(self._tox_pointer,
c_uint32(group_number),
c_uint32(peer_id),
key, byref(error)) key, byref(error))
if error.value: if error.value:
LOG_ERROR(f" {error.value}") LOG_ERROR(f"tox.group_peer_get_public_key err={error.value}")
raise ToxError(f" {error.value}") raise ToxError(f"tox.group_peer_get_public_key err={error.value}")
return bin_to_string(key, TOX_GROUP_PEER_PUBLIC_KEY_SIZE) return bin_to_string(key, TOX_GROUP_PEER_PUBLIC_KEY_SIZE)
def callback_group_peer_name(self, callback, user_data): def callback_group_peer_name(self, callback, user_data):
@ -2343,6 +2373,7 @@ class Tox:
Tox.libtoxcore.tox_callback_group_peer_name(self._tox_pointer, self.group_peer_name_cb) Tox.libtoxcore.tox_callback_group_peer_name(self._tox_pointer, self.group_peer_name_cb)
except Exception as e: # AttributeError except Exception as e: # AttributeError
LOG_ERROR(f"tox.callback_conference_peer_name") LOG_ERROR(f"tox.callback_conference_peer_name")
return None
def callback_group_peer_status(self, callback, user_data): def callback_group_peer_status(self, callback, user_data):
""" """
@ -2365,6 +2396,7 @@ class Tox:
Tox.libtoxcore.tox_callback_group_peer_status(self._tox_pointer, self.group_peer_status_cb) Tox.libtoxcore.tox_callback_group_peer_status(self._tox_pointer, self.group_peer_status_cb)
except Exception as e: except Exception as e:
LOG_WARN(f"callback_group_peer_status Exception {e}") LOG_WARN(f"callback_group_peer_status Exception {e}")
return None
# ----------------------------------------------------------------------------------------------------------------- # -----------------------------------------------------------------------------------------------------------------
# Group chat state queries and events. # Group chat state queries and events.
@ -2387,15 +2419,18 @@ class Tox:
topic = bytes(topic, 'utf-8') topic = bytes(topic, 'utf-8')
try: try:
LOG_DEBUG(f"tox.group_set_topic") LOG_DEBUG(f"tox.group_set_topic")
result = Tox.libtoxcore.tox_group_set_topic(self._tox_pointer, group_number, topic, len(topic), byref(error)) result = Tox.libtoxcore.tox_group_set_topic(self._tox_pointer,
c_uint32(group_number),
c_char_p(topic),
c_size_t(len(topic)),
byref(error))
except Exception as e: except Exception as e:
LOG_WARN(f" Exception {e}") LOG_WARN(f" Exception {e}")
result = None return None
else: if error.value:
if error.value: LOG_ERROR(f"group_set_topic err={error.value}")
LOG_ERROR(f"group_set_topic {error.value}") raise ToxError("group_set_topic err={error.value}")
raise ToxError("group_set_topic {error.value}") return bool(result)
return result
def group_get_topic_size(self, group_number): def group_get_topic_size(self, group_number):
""" """
@ -2411,15 +2446,16 @@ class Tox:
error = c_int() error = c_int()
LOG_TRACE(f"tox_group_get_topic_size") LOG_TRACE(f"tox_group_get_topic_size")
try: try:
result = Tox.libtoxcore.tox_group_get_topic_size(self._tox_pointer, group_number, byref(error)) result = Tox.libtoxcore.tox_group_get_topic_size(self._tox_pointer,
c_uint32(group_number),
byref(error))
except Exception as e: except Exception as e:
LOG_WARN(f" Exception {e}") LOG_WARN(f" Exception {e}")
result = None return None
else: if error.value:
if error.value: LOG_ERROR(f"tox_group_get_topic_size err={error.value}")
LOG_ERROR(f" {error.value}") raise ToxError(f"tox_group_get_topic_size err={error.value}")
raise ToxError(f" {error.value}") return int(result)
return result
def group_get_topic(self, group_number): def group_get_topic(self, group_number):
""" """
@ -2437,7 +2473,7 @@ class Tox:
size = self.group_get_topic_size(group_number) size = self.group_get_topic_size(group_number)
topic = create_string_buffer(size) topic = create_string_buffer(size)
LOG_DEBUG(f"tox.group_get_topic") LOG_DEBUG(f"tox.group_get_topic")
result = Tox.libtoxcore.tox_group_get_topic(self._tox_pointer, group_number, topic, byref(error)) result = Tox.libtoxcore.tox_group_get_topic(self._tox_pointer, c_uint32(group_number), topic, byref(error))
if error.value: if error.value:
LOG_ERROR(f" {error.value}") LOG_ERROR(f" {error.value}")
raise ToxError(f" {error.value}") raise ToxError(f" {error.value}")
@ -2451,7 +2487,9 @@ class Tox:
if group_number < 0: if group_number < 0:
raise ToxError(f"tox_group_ group_number < 0 {group_number}") raise ToxError(f"tox_group_ group_number < 0 {group_number}")
error = c_int() error = c_int()
result = Tox.libtoxcore.tox_group_get_name_size(self._tox_pointer, group_number, byref(error)) result = Tox.libtoxcore.tox_group_get_name_size(self._tox_pointer,
c_uint32(group_number),
byref(error))
if error.value: if error.value:
LOG_ERROR(f" {error.value}") LOG_ERROR(f" {error.value}")
raise ToxError(f" {error.value}") raise ToxError(f" {error.value}")
@ -2471,7 +2509,7 @@ class Tox:
size = self.group_get_name_size(group_number) size = self.group_get_name_size(group_number)
name = create_string_buffer(size) name = create_string_buffer(size)
LOG_DEBUG(f"tox.group_get_name") LOG_DEBUG(f"tox.group_get_name")
result = Tox.libtoxcore.tox_group_get_name(self._tox_pointer, group_number, result = Tox.libtoxcore.tox_group_get_name(self._tox_pointer, c_uint32(group_number),
name, byref(error)) name, byref(error))
if error.value: if error.value:
LOG_ERROR(f" {error.value}") LOG_ERROR(f" {error.value}")
@ -2492,7 +2530,7 @@ class Tox:
error = c_int() error = c_int()
buff = create_string_buffer(TOX_GROUP_CHAT_ID_SIZE) buff = create_string_buffer(TOX_GROUP_CHAT_ID_SIZE)
result = Tox.libtoxcore.tox_group_get_chat_id(self._tox_pointer, result = Tox.libtoxcore.tox_group_get_chat_id(self._tox_pointer,
group_number, c_uint32(group_number),
buff, byref(error)) buff, byref(error))
if error.value: if error.value:
if error.value == 1: if error.value == 1:
@ -2519,9 +2557,10 @@ class Tox:
try: try:
result = Tox.libtoxcore.tox_group_get_number_groups(self._tox_pointer) result = Tox.libtoxcore.tox_group_get_number_groups(self._tox_pointer)
except Exception as e: except Exception as e:
LOG_WARN(f" Exception {e}") LOG_WARN(f"tox.group_get_number_groups EXCEPTION {e}")
result = 0 result = 0
return result LOG_DEBUG(f"tox.group_get_number_groups returning {result}")
return int(result)
def groups_get_list(self): def groups_get_list(self):
raise NotImplementedError('tox_groups_get_list') raise NotImplementedError('tox_groups_get_list')
@ -2547,11 +2586,13 @@ class Tox:
error = c_int() error = c_int()
LOG_DEBUG(f"tox.group_get_privacy_state") LOG_DEBUG(f"tox.group_get_privacy_state")
result = Tox.libtoxcore.tox_group_get_privacy_state(self._tox_pointer, group_number, byref(error)) result = Tox.libtoxcore.tox_group_get_privacy_state(self._tox_pointer,
c_uint32(group_number),
byref(error))
if error.value: if error.value:
LOG_ERROR(f" {error.value}") LOG_ERROR(f"tox.group_get_privacy_state {error.value}")
raise ToxError(f" {error.value}") raise ToxError(f"tox.group_get_privacy_state {error.value}")
return result return int(result)
def group_get_peer_limit(self, group_number): def group_get_peer_limit(self, group_number):
""" """
@ -2568,11 +2609,13 @@ class Tox:
error = c_int() error = c_int()
LOG_DEBUG(f"tox.group_get_peer_limit") LOG_DEBUG(f"tox.group_get_peer_limit")
result = Tox.libtoxcore.tox_group_get_peer_limit(self._tox_pointer, group_number, byref(error)) result = Tox.libtoxcore.tox_group_get_peer_limit(self._tox_pointer,
c_uint(group_number),
byref(error))
if error.value: if error.value:
LOG_ERROR(f" {error.value}") LOG_ERROR(f"tox.group_get_peer_limit {error.value}")
raise ToxError(f" {error.value}") raise ToxError(f"tox.group_get_peer_limit {error.value}")
return result return int(result)
def group_get_password_size(self, group_number): def group_get_password_size(self, group_number):
""" """
@ -2584,7 +2627,8 @@ class Tox:
error = c_int() error = c_int()
LOG_TRACE(f"tox_group_get_password_size") LOG_TRACE(f"tox_group_get_password_size")
result = Tox.libtoxcore.tox_group_get_password_size(self._tox_pointer, group_number, byref(error)) result = Tox.libtoxcore.tox_group_get_password_size(self._tox_pointer,
c_uint(group_number), byref(error))
if error.value: if error.value:
LOG_ERROR(f" {error.value}") LOG_ERROR(f" {error.value}")
raise ToxError(f" {error.value}") raise ToxError(f" {error.value}")
@ -2610,7 +2654,7 @@ class Tox:
size = self.group_get_password_size(group_number) size = self.group_get_password_size(group_number)
password = create_string_buffer(size) password = create_string_buffer(size)
LOG_DEBUG(f"tox.group_get_password") LOG_DEBUG(f"tox.group_get_password")
result = Tox.libtoxcore.tox_group_get_password(self._tox_pointer, group_number, result = Tox.libtoxcore.tox_group_get_password(self._tox_pointer, c_uint(group_number),
password, byref(error)) password, byref(error))
if error.value: if error.value:
LOG_ERROR(f" {error.value}") LOG_ERROR(f" {error.value}")
@ -2722,13 +2766,16 @@ class Tox:
""" """
if group_number < 0: if group_number < 0:
raise ToxError(f"tox_group_ group_number < 0 {group_number}") raise ToxError(f"tox_group_ group_number < 0 {group_number}")
if type(data) != bytes:
data = bytes(data, 'utf-8')
error = c_int() error = c_int()
LOG_DEBUG(f"tox.group_send_custom_packet") LOG_DEBUG(f"tox.group_send_custom_packet")
result = Tox.libtoxcore.tox_group_send_custom_packet(self._tox_pointer, result = Tox.libtoxcore.tox_group_send_custom_packet(self._tox_pointer,
group_number, c_uint(group_number),
lossless, data, lossless,
len(data), data,
c_size_t(len(data)),
byref(error)) byref(error))
if error.value: if error.value:
LOG_ERROR(f" {error.value}") LOG_ERROR(f" {error.value}")
@ -2759,9 +2806,12 @@ class Tox:
message = bytes(message, 'utf-8') message = bytes(message, 'utf-8')
error = c_int() error = c_int()
LOG_DEBUG(f"group_send_private_message") LOG_DEBUG(f"group_send_private_message")
result = Tox.libtoxcore.tox_group_send_private_message(self._tox_pointer, group_number, peer_id, result = Tox.libtoxcore.tox_group_send_private_message(self._tox_pointer,
c_uint(group_number),
c_uint32(peer_id),
message_type, message, message_type, message,
len(message), byref(error)) c_size_t(len(message)),
byref(error))
if error.value: if error.value:
s = sGetError(error.value, TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE) s = sGetError(error.value, TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE)
LOG_ERROR(f"group_send_private_message {error.value} {s}") LOG_ERROR(f"group_send_private_message {error.value} {s}")
@ -2797,10 +2847,10 @@ class Tox:
LOG_DEBUG(f"tox.group_send_message") LOG_DEBUG(f"tox.group_send_message")
# bool tox_group_send_message(const Tox *tox, uint32_t group_number, Tox_Message_Type type, const uint8_t *message, size_t length, uint32_t *message_id, Tox_Err_Group_Send_Message *error) # bool tox_group_send_message(const Tox *tox, uint32_t group_number, Tox_Message_Type type, const uint8_t *message, size_t length, uint32_t *message_id, Tox_Err_Group_Send_Message *error)
result = Tox.libtoxcore.tox_group_send_message(self._tox_pointer, result = Tox.libtoxcore.tox_group_send_message(self._tox_pointer,
group_number, c_uint(group_number),
type_, type_,
message, message,
len(message), c_size_t(len(message)),
# dunno # dunno
byref(message_id), byref(message_id),
byref(error)) byref(error))
@ -2894,7 +2944,7 @@ class Tox:
error = c_int() error = c_int()
LOG_DEBUG(f"tox.group_invite_friend") LOG_DEBUG(f"tox.group_invite_friend")
result = Tox.libtoxcore.tox_group_invite_friend(self._tox_pointer, group_number, c_uint32(friend_number), byref(error)) result = Tox.libtoxcore.tox_group_invite_friend(self._tox_pointer, c_uint(group_number), c_uint32(friend_number), byref(error))
if error.value: if error.value:
s = sGetError(error.value, TOX_ERR_GROUP_INVITE_FRIEND) s = sGetError(error.value, TOX_ERR_GROUP_INVITE_FRIEND)
LOG_ERROR(f"group_invite_friend {error.value} {s}") LOG_ERROR(f"group_invite_friend {error.value} {s}")
@ -2945,8 +2995,10 @@ class Tox:
assert type(invite_data) == bytes assert type(invite_data) == bytes
result = f(self._tox_pointer, result = f(self._tox_pointer,
c_uint32(friend_number), c_uint32(friend_number),
invite_data, len(invite_data), invite_data,
c_char_p(nick), len(nick), c_size_t(len(invite_data)),
c_char_p(nick),
c_size_t(len(nick)),
c_char_p(password), len(password) if password is not None else 0, c_char_p(password), len(password) if password is not None else 0,
byref(error)) byref(error))
except Exception as e: except Exception as e:
@ -3111,8 +3163,9 @@ class Tox:
error = c_int() error = c_int()
LOG_DEBUG(f"tox.group_founder_set_password") LOG_DEBUG(f"tox.group_founder_set_password")
result = Tox.libtoxcore.tox_group_founder_set_password(self._tox_pointer, group_number, password, result = Tox.libtoxcore.tox_group_founder_set_password(self._tox_pointer, c_uint(group_number), password,
len(password), byref(error)) c_size_t(len(password)),
byref(error))
if error.value: if error.value:
s = sGetError(error.value, TOX_ERR_GROUP_FOUNDER_SET_PASSWORD) s = sGetError(error.value, TOX_ERR_GROUP_FOUNDER_SET_PASSWORD)
LOG_ERROR(f"group_founder_set_password {error.value} {s}") LOG_ERROR(f"group_founder_set_password {error.value} {s}")
@ -3139,7 +3192,7 @@ class Tox:
error = c_int() error = c_int()
LOG_DEBUG(f"tox.group_founder_set_privacy_state") LOG_DEBUG(f"tox.group_founder_set_privacy_state")
result = Tox.libtoxcore.tox_group_founder_set_privacy_state(self._tox_pointer, group_number, privacy_state, result = Tox.libtoxcore.tox_group_founder_set_privacy_state(self._tox_pointer, c_uint(group_number), privacy_state,
byref(error)) byref(error))
if error.value: if error.value:
LOG_ERROR(f" {error.value}") LOG_ERROR(f" {error.value}")
@ -3164,7 +3217,7 @@ class Tox:
error = c_int() error = c_int()
LOG_DEBUG(f"tox.group_founder_set_peer_limit") LOG_DEBUG(f"tox.group_founder_set_peer_limit")
result = Tox.libtoxcore.tox_group_founder_set_peer_limit(self._tox_pointer, result = Tox.libtoxcore.tox_group_founder_set_peer_limit(self._tox_pointer,
group_number, c_uint(group_number),
max_peers, max_peers,
byref(error)) byref(error))
if error.value: if error.value:
@ -3195,7 +3248,7 @@ class Tox:
error = c_int() error = c_int()
LOG_DEBUG(f"tox.group_mod_set_role") LOG_DEBUG(f"tox.group_mod_set_role")
result = Tox.libtoxcore.tox_group_mod_set_role(self._tox_pointer, group_number, peer_id, role, byref(error)) result = Tox.libtoxcore.tox_group_mod_set_role(self._tox_pointer, c_uint(group_number), c_uint32(peer_id), role, byref(error))
if error.value: if error.value:
LOG_ERROR(f" {error.value}") LOG_ERROR(f" {error.value}")
raise ToxError(f" {error.value}") raise ToxError(f" {error.value}")
@ -3245,7 +3298,11 @@ class Tox:
error = c_int() error = c_int()
LOG_DEBUG(f"tox.group_set_ignore") LOG_DEBUG(f"tox.group_set_ignore")
result = Tox.libtoxcore.tox_group_set_ignore(self._tox_pointer, group_number, peer_id, ignore, byref(error)) result = Tox.libtoxcore.tox_group_set_ignore(self._tox_pointer,
c_uint32(group_number),
c_uint32(peer_id),
c_bool(ignore),
byref(error))
if error.value: if error.value:
LOG_ERROR(f"tox.group_set_ignore {error.value}") LOG_ERROR(f"tox.group_set_ignore {error.value}")
raise ToxError("tox_group_set_ignore {error.value}") raise ToxError("tox_group_set_ignore {error.value}")

View File

@ -280,19 +280,6 @@ class ToxSuite(unittest.TestCase):
assert oTOX_OPTIONS assert oTOX_OPTIONS
assert oTOX_OARGS assert oTOX_OARGS
if not hasattr(cls, 'alice') and not hasattr(cls, 'bob'):
l = prepare(cls)
assert l
cls.bob, cls.alice = l
if not hasattr(cls.bob, '_main_loop'):
cls.bob._main_loop = ToxIterateThread(cls.bob)
cls.bob._main_loop.start()
LOG.debug(f"cls.bob._main_loop: ") # {threading.enumerate()}
if not hasattr(cls.alice, '_main_loop'):
cls.alice._main_loop = ToxIterateThread(cls.alice)
cls.alice._main_loop.start()
LOG.debug(f"cls.alice._main_loop: ") # {threading.enumerate()}
cls.lUdp = ts.generate_nodes( cls.lUdp = ts.generate_nodes(
oArgs=oTOX_OARGS, oArgs=oTOX_OARGS,
nodes_count=2*ts.iNODES, nodes_count=2*ts.iNODES,
@ -305,29 +292,56 @@ class ToxSuite(unittest.TestCase):
ipv='ipv4', ipv='ipv4',
udp_not_tcp=False) udp_not_tcp=False)
def tearDown(self):
"""
"""
if hasattr(self, 'bob') and self.bob.self_get_friend_list_size() >= 1:
LOG.warn(f"tearDown BOBS STILL HAS A FRIEND LIST {self.bob.self_get_friend_list()}")
for elt in self.bob.self_get_friend_list(): self.bob.friend_delete(elt)
if hasattr(self, 'alice') and self.alice.self_get_friend_list_size() >= 1:
LOG.warn(f"tearDown ALICE STILL HAS A FRIEND LIST {self.alice.self_get_friend_list()}")
for elt in self.alice.self_get_friend_list(): self.alice.friend_delete(elt)
LOG.debug(f"tearDown threads={threading.active_count()}")
if hasattr(self, 'bob'):
bob.callback_self_connection_status(None)
if hasattr(self.bob, 'main_loop'):
self.bob._main_loop.stop_thread()
del self.bob._main_loop
# self.bob.kill()
del self.bob
if hasattr(self, 'alice'):
alice.callback_self_connection_status(None)
if hasattr(self.alice, 'main_loop'):
self.alice._main_loop.stop_thread()
del self.alice._main_loop
# self.alice.kill()
del self.alice
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
cls.bob._main_loop.stop_thread() if hasattr(cls, 'bob'):
cls.alice._main_loop.stop_thread() cls.bob._main_loop.stop_thread()
if False:
cls.alice.kill()
cls.bob.kill() cls.bob.kill()
del cls.bob del cls.bob
if hasattr(cls, 'alice'):
cls.alice._main_loop.stop_thread()
cls.alice.kill()
del cls.alice del cls.alice
def bBobSetUp(self): def bBobNeedAlice(self):
""" """
""" """
if hasattr(self, 'baid') and self.baid >= 0 and \ if hasattr(self, 'baid') and self.baid >= 0 and \
self.baid in self.bob.self_get_friend_list(): self.baid in self.bob.self_get_friend_list():
LOG.warn(f"setUp ALICE IS ALREADY IN BOBS FRIEND LIST") LOG.warn(f"setUp ALICE IS ALREADY IN BOBS FRIEND LIST")
return False return False
elif self.bob.self_get_friend_list_size() >= 1: elif self.bob.self_get_friend_list_size() >= 1:
LOG.warn(f"setUp BOB STILL HAS A FRIEND LIST") LOG.warn(f"setUp BOB STILL HAS A FRIEND LIST")
return False return False
return True return True
def bAliceSetUp(self): def bAliceNeedAddBob (self):
if hasattr(self, 'abid') and self.abid >= 0 and \ if hasattr(self, 'abid') and self.abid >= 0 and \
self.abid in self.alice.self_get_friend_list(): self.abid in self.alice.self_get_friend_list():
LOG.warn(f"setUp BOB IS ALREADY IN ALICES FRIEND LIST") LOG.warn(f"setUp BOB IS ALREADY IN ALICES FRIEND LIST")
@ -338,18 +352,22 @@ class ToxSuite(unittest.TestCase):
return True return True
def setUp(self): def setUp(self):
self.bBobSetUp() cls = self
self.bAliceSetUp() if not hasattr(cls, 'alice') and not hasattr(cls, 'bob'):
l = prepare(cls)
assert l
cls.bob, cls.alice = l
if not hasattr(cls.bob, '_main_loop'):
#? cls.bob._main_loop = ToxIterateThread(cls.bob)
#? cls.bob._main_loop.start()
LOG.debug(f"cls.bob._main_loop: ") # {threading.enumerate()}
if not hasattr(cls.alice, '_main_loop'):
#? cls.alice._main_loop = ToxIterateThread(cls.alice)
#? cls.alice._main_loop.start()
LOG.debug(f"cls.alice._main_loop: ") # {threading.enumerate()}
def tearDown(self): self.bBobNeedAlice()
""" self.bAliceNeedAddBob()
"""
if self.bob.self_get_friend_list_size() >= 1:
LOG.warn(f"tearDown BOBS STILL HAS A FRIEND LIST {self.bob.self_get_friend_list()}")
for elt in self.bob.self_get_friend_list(): self.bob.friend_delete(elt)
if self.bob.self_get_friend_list_size() >= 1:
LOG.warn(f"tearDown ALICE STILL HAS A FRIEND LIST {self.alice.self_get_friend_list()}")
for elt in self.alice.self_get_friend_list(): self.alice.friend_delete(elt)
def run(self, result=None): def run(self, result=None):
""" Stop after first error """ """ Stop after first error """
@ -412,7 +430,7 @@ class ToxSuite(unittest.TestCase):
bRet = None bRet = None
while i <= THRESHOLD : while i <= THRESHOLD :
iRet = self.bob.group_is_connected(group_number) iRet = self.bob.group_is_connected(group_number)
if iRet == 0: if iRet == True or iRet == 0:
bRet = True bRet = True
break break
if i % 5 == 0: if i % 5 == 0:
@ -568,7 +586,7 @@ class ToxSuite(unittest.TestCase):
return oRet return oRet
def bob_add_alice_as_friend_norequest(self): def bob_add_alice_as_friend_norequest(self):
if not self.bBobSetUp(): return True if not self.bBobNeedAlice(): return True
MSG = 'Hi, this is Bob.' MSG = 'Hi, this is Bob.'
iRet = self.bob.friend_add_norequest(self.alice._address) iRet = self.bob.friend_add_norequest(self.alice._address)
@ -583,7 +601,7 @@ class ToxSuite(unittest.TestCase):
return True return True
def alice_add_bob_as_friend_norequest(self): def alice_add_bob_as_friend_norequest(self):
if not self.bAliceSetUp(): return True if not self.bAliceNeedAddBob(): return True
iRet = self.alice.friend_add_norequest(self.bob._address) iRet = self.alice.friend_add_norequest(self.bob._address)
if iRet < 0: if iRet < 0:
@ -596,10 +614,23 @@ class ToxSuite(unittest.TestCase):
assert self.alice.self_get_friend_list_size() >= 1 assert self.alice.self_get_friend_list_size() >= 1
return True return True
def both_add_as_friend_norequest(self): def both_add_as_friend(self):
if self.bBobSetUp(): if bUSE_NOREQUEST:
assert self.bob_add_alice_as_friend()
assert self.alice_add_bob_as_friend_norequest()
else:
assert self.bob_add_alice_as_friend_norequest() assert self.bob_add_alice_as_friend_norequest()
if self.bAliceSetUp(): assert self.alice_add_bob_as_friend_norequest()
if not hasattr(self, 'baid') or self.baid < 0:
LOG.warn("both_add_as_friend no bob, baid")
if not hasattr(self, 'abid') or self.abid < 0:
LOG.warn("both_add_as_friend no alice, abid")
return True
def both_add_as_friend_norequest(self):
if self.bBobNeedAlice():
assert self.bob_add_alice_as_friend_norequest()
if self.bAliceNeedAddBob():
assert self.alice_add_bob_as_friend_norequest() assert self.alice_add_bob_as_friend_norequest()
if not hasattr(self, 'baid') or self.baid < 0: if not hasattr(self, 'baid') or self.baid < 0:
LOG.warn("both_add_as_friend_norequest no bob, baid") LOG.warn("both_add_as_friend_norequest no bob, baid")
@ -619,7 +650,7 @@ class ToxSuite(unittest.TestCase):
""" """
MSG = 'Alice, this is Bob.' MSG = 'Alice, this is Bob.'
sSlot = 'friend_request' sSlot = 'friend_request'
if not self.bBobSetUp(): return True if not self.bBobNeedAlice(): return True
def alices_on_friend_request(iTox, def alices_on_friend_request(iTox,
public_key, public_key,
@ -666,7 +697,7 @@ class ToxSuite(unittest.TestCase):
""" """
MSG = 'Bob, this is Alice.' MSG = 'Bob, this is Alice.'
sSlot = 'friend_request' sSlot = 'friend_request'
if not self.bAliceSetUp(): return True if not self.bAliceNeedAddBob(): return True
def bobs_on_friend_request(iTox, def bobs_on_friend_request(iTox,
public_key, public_key,
@ -704,11 +735,6 @@ class ToxSuite(unittest.TestCase):
self.bob.callback_friend_message(None) self.bob.callback_friend_message(None)
return True return True
def both_add_as_friend(self):
assert self.bob_add_alice_as_friend()
assert self.alice_add_bob_as_friend_norequest()
return True
def bob_add_alice_as_friend_and_status(self): def bob_add_alice_as_friend_and_status(self):
if bUSE_NOREQUEST: if bUSE_NOREQUEST:
assert self.bob_add_alice_as_friend_norequest() assert self.bob_add_alice_as_friend_norequest()
@ -801,7 +827,9 @@ class ToxSuite(unittest.TestCase):
assert otox.group_get_topic(iGrp) == topic assert otox.group_get_topic(iGrp) == topic
assert otox.group_get_topic_size(iGrp) == len(topic) assert otox.group_get_topic_size(iGrp) == len(topic)
assert otox.group_get_name(iGrp) == group_name name = otox.group_get_name(iGrp)
if type(name) == bytes: name = str(name, 'utf-8')
assert name == group_name, name
assert otox.group_get_name_size(iGrp) == len(group_name) assert otox.group_get_name_size(iGrp) == len(group_name)
sPk = otox.group_self_get_public_key(iGrp) sPk = otox.group_self_get_public_key(iGrp)
@ -833,16 +861,16 @@ class ToxSuite(unittest.TestCase):
raise raise
try: try:
iRet = group_is_connected(group_number) bRet = otox.group_is_connected(group_number)
except Exception as e: except Exception as e:
LOG.error(f"group_is_connected EXCEPTION {e}") LOG.error(f"group_is_connected EXCEPTION {e}")
return -1 return -1
LOG.debug(f"group_is_connected group_number={group_number} iRet={iRet}") LOG.debug(f"group_is_connected group_number={group_number} bRet={bRet}")
# chat->connection_state == CS_CONNECTED || chat->connection_state == CS_CONNECTING; # chat->connection_state == CS_CONNECTED || chat->connection_state == CS_CONNECTING;
if iRet != 0: if bRet:
LOG.warn(f"group_is_connected WARN iRet={iRet} group_number={group_number} ") LOG.warn(f"group_is_connected WARN group_number={group_number} ")
else: else:
LOG.info(f"group_is_connected SUCCESS iRet={iRet} group_number={group_number} ") LOG.info(f"group_is_connected SUCCESS group_number={group_number} ")
return group_number return group_number
@ -875,23 +903,18 @@ class ToxSuite(unittest.TestCase):
#? #?
group_number = iGrp group_number = iGrp
try: try:
iRet = otox.group_is_connected(group_number) bRet = otox.group_is_connected(group_number)
except Exception as e: except Exception as e:
LOG.error(f"group_is_connected ERROR {e}") LOG.error(f"group_is_connected ERROR {e}")
iRet = -1 return -1
else:
if iRet != enums.TOX_ERR_GROUP_STATE_QUERIES['TOX_ERR_GROUP_STATE_QUERIES_OK']:
LOG.warn(f"group_is_connected WARN iRet={iRet}")
# The group number passed did not designate a valid group.
# TOX_ERR_GROUP_STATE_QUERIES['TOX_ERR_GROUP_STATE_QUERIES_GROUP_NOT_FOUND']
if iRet < 0:
return iGrp
message = bytes('hello', 'utf-8') message = bytes('hello', 'utf-8')
try: try:
bRet = otox.group_send_message(group_number, TOX_MESSAGE_TYPE['NORMAL'], 'hello') bRet = otox.group_send_message(group_number, TOX_MESSAGE_TYPE['NORMAL'], 'hello')
if not bRet: if not bRet:
LOG.warn(f"group_send_message {bRet}") LOG.warn(f"group_send_message {bRet}")
else:
LOG.debug(f"group_send_message {bRet}")
except Exception as e: except Exception as e:
LOG.error(f"group_send_message ERROR {e}") LOG.error(f"group_send_message ERROR {e}")
@ -909,7 +932,7 @@ class ToxSuite(unittest.TestCase):
while i < n: while i < n:
iRet = otox.friend_get_connection_status(fid) iRet = otox.friend_get_connection_status(fid)
if iRet == TOX_CONNECTION['NONE']: if iRet == TOX_CONNECTION['NONE']:
LOG.warning(f"wait_friend_get_connection_status NOT CONNECTED i={i} {iRet}") # LOG.debug(f"wait_friend_get_connection_status NOT CONNECTED i={i} {iRet}")
self.loop_until_connected() self.loop_until_connected()
else: else:
LOG.info("wait_friend_get_connection_status {iRet}") LOG.info("wait_friend_get_connection_status {iRet}")
@ -998,7 +1021,6 @@ class ToxSuite(unittest.TestCase):
else: else:
LOG.warning(f"bootstrap_local_netstat NOT {port} iStatus={iStatus}") LOG.warning(f"bootstrap_local_netstat NOT {port} iStatus={iStatus}")
#?? @unittest.skipIf(not bIS_LOCAL, "local test")
def test_bootstrap_local(self): # works def test_bootstrap_local(self): # works
""" """
t:call_bootstrap t:call_bootstrap
@ -1269,7 +1291,10 @@ class ToxSuite(unittest.TestCase):
def test_bob_add_alice_as_friend(self): # works? def test_bob_add_alice_as_friend(self): # works?
try: try:
assert self.bob_add_alice_as_friend() if bUSE_NOREQUEST:
assert self.bob_add_alice_as_friend_norequest()
else:
assert self.bob_add_alice_as_friend()
#: Test last online #: Test last online
assert self.bob.friend_get_last_online(self.baid) is not None assert self.bob.friend_get_last_online(self.baid) is not None
except AssertionError as e: except AssertionError as e:
@ -1286,7 +1311,10 @@ class ToxSuite(unittest.TestCase):
def test_alice_add_bob_as_friend(self): # works! def test_alice_add_bob_as_friend(self): # works!
try: try:
assert self.alice_add_bob_as_friend() if bUSE_NOREQUEST:
assert self.alice_add_bob_as_friend_norequest()
else:
assert self.alice_add_bob_as_friend()
#: Test last online #: Test last online
assert self.alice.friend_get_last_online(self.abid) is not None assert self.alice.friend_get_last_online(self.abid) is not None
except AssertionError as e: except AssertionError as e:
@ -1309,7 +1337,10 @@ class ToxSuite(unittest.TestCase):
def test_both_add_as_friend(self): # works def test_both_add_as_friend(self): # works
try: try:
assert self.both_add_as_friend() if bUSE_NOREQUEST:
assert self.both_add_as_friend_norequest()
else:
assert self.both_add_as_friend()
except AssertionError as e: except AssertionError as e:
LOG.warn(f"Failed test {e}") LOG.warn(f"Failed test {e}")
raise raise
@ -1380,6 +1411,8 @@ class ToxSuite(unittest.TestCase):
LOG.error(f"bob.group_leave EXCEPTION {e}") LOG.error(f"bob.group_leave EXCEPTION {e}")
raise raise
@unittest.skip("double free or corruption (fasttop)")
# @expectedFail('fails') # assertion fails on == MSG
def test_on_friend_status_message(self): # fails def test_on_friend_status_message(self): # fails
""" """
t:self_set_status_message t:self_set_status_message
@ -1435,10 +1468,6 @@ class ToxSuite(unittest.TestCase):
if hasattr(self, 'abid') and self.abid >= 0: if hasattr(self, 'abid') and self.abid >= 0:
self.alice.friend_delete(self.abid) self.alice.friend_delete(self.abid)
#? @unittest.skip('malloc(): unaligned tcache chunk detected')
#? @unittest.skip('double free or corruption (fasttop)')
#?segv after TestS DEBUG wait_otox_attrs alice for ['friend_request'] 0 last=1701822930
#?? @unittest.skip('segv')
def test_friend(self): # works! sometimes def test_friend(self): # works! sometimes
""" """
t:friend_get_name t:friend_get_name
@ -1477,8 +1506,7 @@ class ToxSuite(unittest.TestCase):
if hasattr(self, 'abid') and self.abid >= 0: if hasattr(self, 'abid') and self.abid >= 0:
self.alice.friend_delete(self.abid) self.alice.friend_delete(self.abid)
#! @expectedFail('fails') # assert self.bob.friend_get_status(self.baid) == TOX_USER_STATUS['BUSY'] @expectedFail('fails') # assert self.bob.friend_get_status(self.baid) == TOX_USER_STATUS['BUSY']
@unittest.skip('malloc(): unaligned tcache chunk detected')
def test_user_status(self): # fails def test_user_status(self): # fails
""" """
t:self_get_status t:self_get_status
@ -1488,10 +1516,6 @@ class ToxSuite(unittest.TestCase):
t:on_friend_status t:on_friend_status
""" """
sSlot = 'friend_status' sSlot = 'friend_status'
if bUSE_NOREQUEST:
assert self.bob_add_alice_as_friend_norequest()
else:
assert self.bob_add_alice_as_friend()
setattr(self.bob, sSlot, None) setattr(self.bob, sSlot, None)
def bobs_on_friend_set_status(iTox, friend_id, new_status, *largs): def bobs_on_friend_set_status(iTox, friend_id, new_status, *largs):
@ -1504,6 +1528,10 @@ class ToxSuite(unittest.TestCase):
setattr(self.bob, sSlot, True) setattr(self.bob, sSlot, True)
try: try:
if bUSE_NOREQUEST:
assert self.bob_add_alice_as_friend_norequest()
else:
assert self.bob_add_alice_as_friend()
if not self.get_connection_status(): if not self.get_connection_status():
LOG.warning(f"test_user_status NOT CONNECTED self.get_connection_status") LOG.warning(f"test_user_status NOT CONNECTED self.get_connection_status")
self.loop_until_connected() self.loop_until_connected()
@ -1512,15 +1540,16 @@ class ToxSuite(unittest.TestCase):
self.warn_if_no_cb(self.bob, sSlot) self.warn_if_no_cb(self.bob, sSlot)
sSTATUS = TOX_USER_STATUS['BUSY'] sSTATUS = TOX_USER_STATUS['BUSY']
self.alice.self_set_status(sSTATUS) self.alice.self_set_status(sSTATUS)
sSlot = 'friend_status'
if not self.wait_otox_attrs(self.bob, [sSlot]): if not self.wait_otox_attrs(self.bob, [sSlot]):
# malloc(): unaligned tcache chunk detected # malloc(): unaligned tcache chunk detected
LOG_WARN(f' NO {sSlot}') LOG_WARN(f'test_user_status NO {sSlot}')
assert self.bob.friend_get_status(self.baid) == TOX_USER_STATUS['BUSY'], \ assert self.bob.friend_get_status(self.baid) == TOX_USER_STATUS['BUSY'], \
f"{self.bob.friend_get_status(self.baid)} != {TOX_USER_STATUS['BUSY']}" f"friend_get_status {self.bob.friend_get_status(self.baid)} != {TOX_USER_STATUS['BUSY']}"
except AssertionError as e: except AssertionError as e:
LOG.error(f"Failed test_user_status {e}") LOG.error(f"test_user_status FAILED {e}")
raise raise
except Exception as e: except Exception as e:
LOG.error(f"test_user_status EXCEPTION {e}") LOG.error(f"test_user_status EXCEPTION {e}")
@ -1548,13 +1577,13 @@ class ToxSuite(unittest.TestCase):
setattr(self.bob, sSlot, True) setattr(self.bob, sSlot, True)
opts = oToxygenToxOptions(oTOX_OARGS) opts = oToxygenToxOptions(oTOX_OARGS)
setattr(self.bob, sSlot, True)
try: try:
if bUSE_NOREQUEST: if bUSE_NOREQUEST:
assert self.bob_add_alice_as_friend_norequest() assert self.bob_add_alice_as_friend_norequest()
else: else:
assert self.bob_add_alice_as_friend() assert self.bob_add_alice_as_friend()
setattr(self.bob, sSlot, True)
self.bob.callback_friend_connection_status(bobs_on_friend_connection_status) self.bob.callback_friend_connection_status(bobs_on_friend_connection_status)
LOG.info("test_connection_status killing alice") LOG.info("test_connection_status killing alice")
@ -1576,10 +1605,8 @@ class ToxSuite(unittest.TestCase):
if hasattr(self, 'baid') and self.baid >= 0: if hasattr(self, 'baid') and self.baid >= 0:
self.bob.friend_delete(self.baid) self.bob.friend_delete(self.baid)
# TestS DEBUG wait_otox_attrs bob for ['friend_name'] 5 last=1701826540 @expectedFail('fails') # new name is empty
# @unittest.skip('crashes') def test_friend_name(self): # works!
@expectedFail('fails') # new name if empty
def test_friend_name(self): # works! or crashes!
""" """
t:self_set_name t:self_set_name
t:friend_get_name t:friend_get_name
@ -1635,9 +1662,7 @@ class ToxSuite(unittest.TestCase):
self.warn_if_cb(self.bob, sSlot) self.warn_if_cb(self.bob, sSlot)
# wait_ensure_exec ArgumentError This client is currently not connected to the friend. @expectedFail('fails') # This client is currently not connected to the friend.
@expectedFail('fails')
# This client is currently not connected to the friend.
def test_friend_message(self): # fails def test_friend_message(self): # fails
""" """
t:on_friend_action t:on_friend_action
@ -1668,35 +1693,34 @@ class ToxSuite(unittest.TestCase):
assert self.both_add_as_friend_norequest() assert self.both_add_as_friend_norequest()
else: else:
assert self.both_add_as_friend() assert self.both_add_as_friend()
if not self.wait_friend_get_connection_status(self.alice, self.abid, n=iN): assert hasattr(self, 'baid'), \
"both_add_as_friend_norequest no bob, baid"
assert hasattr(self, 'abid'), \
"both_add_as_friend_norequest no alice, abid"
if not self.wait_friend_get_connection_status(self.bob, self.baid, n=2*iN):
LOG.warn('baid not connected')
if not self.wait_friend_get_connection_status(self.alice, self.abid, n=2*iN):
LOG.warn('abid not connected') LOG.warn('abid not connected')
self.alice.callback_friend_message(alices_on_friend_message) self.alice.callback_friend_message(alices_on_friend_message)
self.warn_if_no_cb(self.alice, sSlot) self.warn_if_no_cb(self.alice, sSlot)
# dunno - both This client is currently NOT CONNECTED to the friend. # dunno - both This client is currently NOT CONNECTED to the friend.
if True: iMesId = self.bob.friend_send_message(self.baid,
iMesId = self.bob.friend_send_message(self.baid, TOX_MESSAGE_TYPE['NORMAL'],
TOX_MESSAGE_TYPE['NORMAL'], bytes(MSG, 'UTF-8'))
bytes(MSG, 'UTF-8')) assert iMesId >= 0, "iMesId >= 0"
# ArgumentError('This client is currently NOT CONNECTED to the friend.')
else:
iMesId = self.wait_ensure_exec(self.bob.friend_send_message,
[self.baid,
TOX_MESSAGE_TYPE['NORMAL'],
bytes(MSG, 'UTF-8')])
assert iMesId >= 0
if not self.wait_otox_attrs(self.alice, [sSlot]): if not self.wait_otox_attrs(self.alice, [sSlot]):
LOG_WARN(f"alices_on_friend_message NO {sSlot}") LOG_WARN(f"alices_on_friend_message NO {sSlot}")
except ArgumentError as e: except ArgumentError as e:
# ArgumentError('This client is currently NOT CONNECTED to the friend.') # ArgumentError('This client is currently NOT CONNECTED to the friend.')
# dunno # dunno
LOG.error(f"test_friend_message {e}") LOG.error(f"test_friend_message ArgumentError {e}")
raise raise
except AssertionError as e: except AssertionError as e:
LOG.error(f"test_friend_message {e}") LOG.error(f"test_friend_message AssertionError {e}")
raise raise
except Exception as e: except Exception as e:
LOG.error(f"test_friend_message {e}") LOG.error(f"test_friend_message EXCEPTION {e}")
raise raise
finally: finally:
self.alice.callback_friend_message(None) self.alice.callback_friend_message(None)
@ -2028,7 +2052,6 @@ class ToxSuite(unittest.TestCase):
@unittest.skip('crashes') @unittest.skip('crashes')
def test_tox_savedata(self): # works sorta def test_tox_savedata(self): # works sorta
# but "{addr} != {self.alice.self_get_address()}"
""" """
t:get_savedata_size t:get_savedata_size
t:get_savedata t:get_savedata
@ -2062,6 +2085,13 @@ class ToxSuite(unittest.TestCase):
else: else:
LOG.info("passed test_tox_savedata") LOG.info("passed test_tox_savedata")
def test_kill(self): #
import threading
LOG.info(f"THE END {threading.active_count()}")
self.tearDown()
LOG.info(f"THE END {threading.enumerate()}")
def vOargsToxPreamble(oArgs, Tox, ToxTest): def vOargsToxPreamble(oArgs, Tox, ToxTest):
ts.vSetupLogging(oArgs) ts.vSetupLogging(oArgs)
@ -2078,6 +2108,7 @@ def vOargsToxPreamble(oArgs, Tox, ToxTest):
if len(not_tested): if len(not_tested):
logging.info('Not tested:\n %s' % "\n ".join(sorted(list(not_tested)))) logging.info('Not tested:\n %s' % "\n ".join(sorted(list(not_tested))))
### ###
def iMain(oArgs): def iMain(oArgs):
@ -2190,6 +2221,3 @@ def main(lArgs=None):
if __name__ == '__main__': if __name__ == '__main__':
sys.exit(main(sys.argv[1:])) sys.exit(main(sys.argv[1:]))
#Ran 38 tests in 194.492s
#OK (skipped=10, expected failures=4)