Compare commits

...

3 Commits

Author SHA1 Message Date
emdee
aedf36cda2 updates 2023-12-10 01:20:38 +00:00
emdee
9111a1def8 updates 2023-12-09 10:19:21 +00:00
emdee
18195f287c updates 2023-12-08 19:37:22 +00:00
3 changed files with 706 additions and 414 deletions

File diff suppressed because it is too large Load Diff

View File

@ -302,6 +302,11 @@ TOX_ERR_GROUP_JOIN = {
'TOX_ERR_GROUP_JOIN_TOO_LONG': 3,
}
TOX_ERR_GROUP_IS_CONNECTED = {
'TOX_ERR_GROUP_IS_CONNECTED_OK': 0,
'TOX_ERR_GROUP_IS_CONNECTED_GROUP_NOT_FOUND': 1
}
TOX_ERR_GROUP_RECONNECT = {
#
@ -451,7 +456,7 @@ TOX_ERR_GROUP_STATE_QUERIES = {
#
'TOX_ERR_GROUP_STATE_QUERIES_OK': 0,
#
#
# The group number passed did not designate a valid group.
#
'TOX_ERR_GROUP_STATE_QUERIES_GROUP_NOT_FOUND': 1

View File

@ -69,7 +69,8 @@ except ImportError as e:
import wrapper
import wrapper.toxcore_enums_and_consts as enums
from wrapper.tox import Tox
from wrapper.tox import Tox, UINT32_MAX, ToxError
from wrapper.toxcore_enums_and_consts import (TOX_ADDRESS_SIZE, TOX_CONNECTION,
TOX_FILE_CONTROL,
TOX_MESSAGE_TYPE,
@ -279,19 +280,6 @@ class ToxSuite(unittest.TestCase):
assert oTOX_OPTIONS
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(
oArgs=oTOX_OARGS,
nodes_count=2*ts.iNODES,
@ -304,29 +292,56 @@ class ToxSuite(unittest.TestCase):
ipv='ipv4',
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
def tearDownClass(cls):
cls.bob._main_loop.stop_thread()
cls.alice._main_loop.stop_thread()
if False:
cls.alice.kill()
if hasattr(cls, 'bob'):
cls.bob._main_loop.stop_thread()
cls.bob.kill()
del cls.bob
if hasattr(cls, 'alice'):
cls.alice._main_loop.stop_thread()
cls.alice.kill()
del cls.alice
def bBobSetUp(self):
def bBobNeedAlice(self):
"""
"""
if hasattr(self, 'baid') and self.baid >= 0 and \
self.baid in self.bob.self_get_friend_list():
LOG.warn(f"setUp ALICE IS ALREADY IN BOBS FRIEND LIST")
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")
return False
return True
def bAliceSetUp(self):
def bAliceNeedAddBob (self):
if hasattr(self, 'abid') and self.abid >= 0 and \
self.abid in self.alice.self_get_friend_list():
LOG.warn(f"setUp BOB IS ALREADY IN ALICES FRIEND LIST")
@ -337,18 +352,22 @@ class ToxSuite(unittest.TestCase):
return True
def setUp(self):
self.bBobSetUp()
self.bAliceSetUp()
cls = self
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):
"""
"""
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)
self.bBobNeedAlice()
self.bAliceNeedAddBob()
def run(self, result=None):
""" Stop after first error """
@ -404,6 +423,44 @@ class ToxSuite(unittest.TestCase):
LOG.debug(f"call_bootstrap ts.bootstrap_tcp {len(lElts)}")
ts.bootstrap_tcp(lElts, lToxes)
def group_until_connected(self, group_number, num=None, iMax=THRESHOLD):
"""
"""
i = 0
bRet = None
while i <= iMax :
iRet = self.bob.group_is_connected(group_number)
if iRet == True or iRet == 0:
bRet = True
break
if i % 5 == 0:
j = i//5
self.call_bootstrap(num, lToxes=None, i=j)
s = ''
if i == 0: s = '\n'
LOG.info(s+"group_until_connected " \
+" #" + str(i) \
+" iRet=" +repr(iRet) \
+f" BOBS={self.bob.mycon_status}" \
+f" last={int(self.bob.mycon_time)}" )
i += 1
self.loop(100)
else:
bRet = False
if bRet:
LOG.info(f"group_until_connected returning True {i}" \
+f"iMax={iMax}" \
+f" BOB={self.bob.self_get_connection_status()}" \
+f" last={int(self.bob.mycon_time)}" )
return True
else:
LOG.warning(f"group_until_connected returning False {i}" \
+f"iMax={iMax}" \
+f" BOB={self.bob.self_get_connection_status()}" \
+f" last={int(self.bob.mycon_time)}" )
return False
def loop_until_connected(self, num=None):
"""
t:on_self_connection_status
@ -477,7 +534,7 @@ class ToxSuite(unittest.TestCase):
return all([getattr(obj, attr) is not None for obj in objs])
def wait_otox_attrs(self, obj, attrs):
assert all(attrs)
assert all(attrs), f"wait_otox_attrs {attrs}"
i = 0
while i <= THRESHOLD:
if i % 5 == 0:
@ -495,7 +552,7 @@ class ToxSuite(unittest.TestCase):
self.loop(100)
i += 1
else:
LOG.warning(f"wait_otox_attrs i >= {THRESHOLD} {[getattr(obj, attr) for attr in attrs]}")
LOG.warning(f"wait_otox_attrs i >= {THRESHOLD} results={[getattr(obj, attr) for attr in attrs]}")
return all([getattr(obj, attr) for attr in attrs])
@ -531,7 +588,7 @@ class ToxSuite(unittest.TestCase):
return oRet
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.'
iRet = self.bob.friend_add_norequest(self.alice._address)
@ -546,7 +603,7 @@ class ToxSuite(unittest.TestCase):
return True
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)
if iRet < 0:
@ -559,10 +616,23 @@ class ToxSuite(unittest.TestCase):
assert self.alice.self_get_friend_list_size() >= 1
return True
def both_add_as_friend_norequest(self):
if self.bBobSetUp():
def both_add_as_friend(self):
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()
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()
if not hasattr(self, 'baid') or self.baid < 0:
LOG.warn("both_add_as_friend_norequest no bob, baid")
@ -582,7 +652,7 @@ class ToxSuite(unittest.TestCase):
"""
MSG = 'Alice, this is Bob.'
sSlot = 'friend_request'
if not self.bBobSetUp(): return True
if not self.bBobNeedAlice(): return True
def alices_on_friend_request(iTox,
public_key,
@ -600,11 +670,10 @@ class ToxSuite(unittest.TestCase):
setattr(self.bob, sSlot, None)
inum = -1
self.alice.callback_friend_request(alices_on_friend_request)
try:
inum = self.bob.friend_add(self.alice._address, bytes(MSG, 'UTF-8'))
if inum < 0:
LOG.warning('bob.friend_add !>= 0 ' +repr(inum))
assert inum >= 0, f"bob.friend_add !>= 0 {inum}"
self.alice.callback_friend_request(alices_on_friend_request)
if not self.wait_otox_attrs(self.bob, [sSlot]):
LOG_WARN(f"bob.friend_add NO {sSlot}")
# return False
@ -630,18 +699,7 @@ class ToxSuite(unittest.TestCase):
"""
MSG = 'Bob, this is Alice.'
sSlot = 'friend_request'
if not self.bAliceSetUp(): return True
try:
abid = self.alice.friend_by_public_key(self.bob._address)
except Exception as e:
# ctypes.ArgumentError
pass
else:
if abid and abid >= 0 and \
abid in self.alice.self_get_friend_list():
LOG.warning('alice friend exists ' +repr(abid))
return True
if not self.bAliceNeedAddBob(): return True
def bobs_on_friend_request(iTox,
public_key,
@ -659,11 +717,10 @@ class ToxSuite(unittest.TestCase):
setattr(self.alice, sSlot, None)
inum = -1
self.bob.callback_friend_request(bobs_on_friend_request)
try:
inum = self.alice.friend_add(self.bob._address, bytes(MSG, 'UTF-8'))
if not inum >= 0:
LOG.warning('alice.friend_add !>= 0 ' +repr(inum))
assert inum >= 0, f"alice.friend_add !>= 0 {inum}"
self.bob.callback_friend_request(bobs_on_friend_request)
if not self.wait_otox_attrs(self.alice, [sSlot]):
LOG_WARN(f"alice.friend_add NO wait {sSlot}")
#? return False
@ -680,11 +737,6 @@ class ToxSuite(unittest.TestCase):
self.bob.callback_friend_message(None)
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):
if bUSE_NOREQUEST:
assert self.bob_add_alice_as_friend_norequest()
@ -692,8 +744,8 @@ class ToxSuite(unittest.TestCase):
assert self.bob_add_alice_as_friend()
#: Wait until both are online
sSlot = friend_conn_status
self.bob.friend_conn_status = False
sSlot = 'friend_conn_status'
setattr(self.bob, sSlot, False)
def bobs_on_friend_connection_status(iTox, friend_id, iStatus, *largs):
LOG_INFO(f"bobs_on_friend_connection_status {friend_id} ?>=0" +repr(iStatus))
if iStatus > 0:
@ -761,7 +813,7 @@ class ToxSuite(unittest.TestCase):
return False
return True
def otox_test_groups(self,
def otox_test_groups_create(self,
otox,
group_name='test_group',
nick='test_nick',
@ -777,23 +829,80 @@ class ToxSuite(unittest.TestCase):
assert otox.group_get_topic(iGrp) == 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)
sPk = otox.group_self_get_public_key(iGrp)
LOG.info(f"group pK={sPk}")
assert otox.group_get_password_size(iGrp) >= 0
sP = otox.group_get_password(iGrp)
assert otox.group_get_privacy_state(iGrp) == privacy_state
assert otox.group_get_number_groups() > 0
LOG.info(f"group pK={sPk} iGrp={iGrp} n={otox.group_get_number_groups()}")
return iGrp
sGrp = otox.group_get_chat_id(iGrp)
if len(sGrp) != enums.TOX_GROUP_CHAT_ID_SIZE * 2:
LOG.error(f"group sGrp={sGrp} {len(sGrp)}")
return iGrp
# 360497DA684BCE2A500C1AF9B3A5CE949BBB9F6FB1F91589806FB04CA039E313
# 75D2163C19FEFFE51508046398202DDC321E6F9B6654E99BAE45FFEC134F05DE
def otox_test_groups_join(self, otox,
chat_id="75d2163c19feffe51508046398202ddc321e6f9b6654e99bae45ffec134f05de",
nick='nick',
topic='Test Topic', # str
):
status = ''
password = ''
LOG.debug(f"group_join nick={nick} chat_id={chat_id}")
try:
group_number = otox.group_join(chat_id, password, nick, status)
LOG.info(f"otox_test_groups_join SUCCESS group_number={group_number} chat_id={chat_id}")
assert type(group_number) == int, "otox_test_groups_join group_number not an int"
assert group_number < UINT32_MAX, "otox_test_groups_join group_number failure UINT32_MAX"
assert group_number >= 0, f"otox_test_groups_join group_number={group_number} < 0"
iGrp = group_number
sPk = otox.group_self_get_public_key(iGrp)
LOG.info(f"otox_test_groups_join pK={sPk} iGrp={iGrp} n={otox.group_get_number_groups()}")
except Exception as e:
# gui
LOG.error(f"otox_test_groups_join EXCEPTION {e}")
raise
try:
bRet = otox.group_is_connected(group_number)
except Exception as e:
LOG.error(f"group_is_connected EXCEPTION {e}")
return -1
# chat->connection_state == CS_CONNECTED || chat->connection_state == CS_CONNECTING;
if bRet:
LOG.warn(f"group_is_connected WARN not connected group_number={group_number} n={otox.group_get_number_groups()}")
else:
LOG.info(f"group sGrp={sGrp}")
LOG.info(f"group_is_connected SUCCESS connected group_number={group_number} n={otox.group_get_number_groups()}")
try:
bRet = self.group_until_connected(group_number, iMax=2*THRESHOLD)
except Exception as e:
LOG.error(f"group_until_connected EXCEPTION {e}")
return -1
# chat->connection_state == CS_CONNECTED || chat->connection_state == CS_CONNECTING;
if bRet:
LOG.warn(f"group_until_connected WARN not connected group_number={group_number} n={otox.group_get_number_groups()}")
else:
LOG.info(f"group_until_connected SUCCESS connected group_number={group_number} n={otox.group_get_number_groups()}")
return group_number
def otox_test_groups(self,
otox,
group_name='test_group',
nick='test_nick',
topic='Test Topic', # str
):
iGrp = self.otox_test_groups_create(otox, group_name, nick, topic)
sGrp = otox.group_get_chat_id(iGrp)
assert len(sGrp) == enums.TOX_GROUP_CHAT_ID_SIZE * 2, \
f"group sGrp={sGrp} {len(sGrp)} != {enums.TOX_GROUP_CHAT_ID_SIZE * 2}"
LOG.info(f"group sGrp={sGrp}")
if False:
# already joined
try:
@ -812,23 +921,29 @@ class ToxSuite(unittest.TestCase):
#?
group_number = iGrp
try:
iRet = otox.group_is_connected(group_number)
bRet = otox.group_is_connected(group_number)
except Exception as e:
LOG.error(f"group_is_connected ERROR {e}")
iRet = -1
return -1
try:
bRet = self.group_until_connected(group_number, iMax=2*THRESHOLD)
except Exception as e:
LOG.error(f"group_until_connected EXCEPTION {e}")
return -1
# chat->connection_state == CS_CONNECTED || chat->connection_state == CS_CONNECTING;
if bRet:
LOG.warn(f"group_until_connected WARN not connected group_number={group_number} n={otox.group_get_number_groups()}")
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
LOG.info(f"group_until_connected SUCCESS connected group_number={group_number} n={otox.group_get_number_groups()}")
message = bytes('hello', 'utf-8')
try:
bRet = otox.group_send_message(group_number, TOX_MESSAGE_TYPE['NORMAL'], 'hello')
if not bRet:
LOG.warn(f"group_send_message {bRet}")
else:
LOG.debug(f"group_send_message {bRet}")
except Exception as e:
LOG.error(f"group_send_message ERROR {e}")
@ -846,14 +961,14 @@ class ToxSuite(unittest.TestCase):
while i < n:
iRet = otox.friend_get_connection_status(fid)
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()
else:
LOG.info("wait_friend_get_connection_status {iRet}")
return True
i += 1
else:
LOG.error("wait_friend_get_connection_status n={n}")
LOG.error(f"wait_friend_get_connection_status n={n}")
return False
def warn_if_no_cb(self, alice, sSlot):
@ -935,7 +1050,6 @@ class ToxSuite(unittest.TestCase):
else:
LOG.warning(f"bootstrap_local_netstat NOT {port} iStatus={iStatus}")
#?? @unittest.skipIf(not bIS_LOCAL, "local test")
def test_bootstrap_local(self): # works
"""
t:call_bootstrap
@ -1175,6 +1289,12 @@ class ToxSuite(unittest.TestCase):
if hasattr(self, 'baid') and self.baid >= 0:
self.bob.friend_delete(self.baid)
@unittest.skip('unfinished')
def test_alice_add_bob_as_friend_and_status(self):
assert self.alice_add_bob_as_friend_and_status()
if hasattr(self, 'abid') and self.abid >= 0:
self.alice.friend_delete(self.abid)
def test_loop_until_connected(self): # works
assert self.loop_until_connected()
@ -1200,7 +1320,10 @@ class ToxSuite(unittest.TestCase):
def test_bob_add_alice_as_friend(self): # works?
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
assert self.bob.friend_get_last_online(self.baid) is not None
except AssertionError as e:
@ -1217,7 +1340,10 @@ class ToxSuite(unittest.TestCase):
def test_alice_add_bob_as_friend(self): # works!
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
assert self.alice.friend_get_last_online(self.abid) is not None
except AssertionError as e:
@ -1238,13 +1364,12 @@ class ToxSuite(unittest.TestCase):
if len(self.alice.self_get_friend_list()) > 0:
LOG.warn(f"WTF alice.self_get_friend_list() {alice.self_get_friend_list()}")
# @unittest.skip('crashes double free or corruption (fasttop)') on update
# @expectedFailure # fails
#? @unittest.skip('malloc(): unaligned tcache chunk detected')
#?? @unittest.skip('segv')
def test_both_add_as_friend(self): # works
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:
LOG.warn(f"Failed test {e}")
raise
@ -1257,6 +1382,30 @@ class ToxSuite(unittest.TestCase):
if hasattr(self,'abid') and self.abid >= 0:
self.alice.friend_delete(self.abid)
def test_groups_join(self):
"""
t:group_join
t:group_disconnect
t:group_leave
"""
if not self.get_connection_status():
LOG.warning(f"test_groups_join NOT CONNECTED")
self.loop_until_connected()
iGrp = self.otox_test_groups_join(self.bob)
LOG.info(f"test_groups_join iGrp={iGrp}")
assert iGrp >= 0, f"test_groups_join iGrp={iGrp}"
try:
self.bob.group_disconnect(iGrp)
except Exception as e:
LOG.error(f"bob.group_disconnect EXCEPTION {e}")
raise
try:
self.bob.group_leave(iGrp, None)
except Exception as e:
LOG.error(f"bob.group_leave EXCEPTION {e}")
raise
def test_groups(self):
"""
t:group_new
@ -1278,7 +1427,6 @@ class ToxSuite(unittest.TestCase):
t:group_invite_accept
t:group_invite_friend
t:group_is_connected
t:group_join
t:group_leave
t:group_mod_set_role
"""
@ -1296,12 +1444,8 @@ class ToxSuite(unittest.TestCase):
LOG.error(f"bob.group_leave EXCEPTION {e}")
raise
@unittest.skip('unfinished')
def test_bob_add_alice_as_friend_and_status(self):
assert self.bob_add_alice_as_friend_and_status()
if hasattr(self, 'baid') and self.baid >= 0:
self.bob.friend_delete(self.baid)
@unittest.skip("double free or corruption (fasttop)")
# @expectedFail('fails') # assertion fails on == MSG
def test_on_friend_status_message(self): # fails
"""
t:self_set_status_message
@ -1357,10 +1501,6 @@ class ToxSuite(unittest.TestCase):
if hasattr(self, 'abid') and self.abid >= 0:
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
"""
t:friend_get_name
@ -1399,8 +1539,7 @@ class ToxSuite(unittest.TestCase):
if hasattr(self, 'abid') and self.abid >= 0:
self.alice.friend_delete(self.abid)
#! @expectedFail('fails') # assert self.bob.friend_get_status(self.baid) == TOX_USER_STATUS['BUSY']
@unittest.skip('malloc(): unaligned tcache chunk detected')
@expectedFail('fails') # assert self.bob.friend_get_status(self.baid) == TOX_USER_STATUS['BUSY']
def test_user_status(self): # fails
"""
t:self_get_status
@ -1410,10 +1549,6 @@ class ToxSuite(unittest.TestCase):
t:on_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)
def bobs_on_friend_set_status(iTox, friend_id, new_status, *largs):
@ -1426,6 +1561,10 @@ class ToxSuite(unittest.TestCase):
setattr(self.bob, sSlot, True)
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():
LOG.warning(f"test_user_status NOT CONNECTED self.get_connection_status")
self.loop_until_connected()
@ -1434,15 +1573,16 @@ class ToxSuite(unittest.TestCase):
self.warn_if_no_cb(self.bob, sSlot)
sSTATUS = TOX_USER_STATUS['BUSY']
self.alice.self_set_status(sSTATUS)
sSlot = 'friend_status'
if not self.wait_otox_attrs(self.bob, [sSlot]):
# 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'], \
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:
LOG.error(f"Failed test_user_status {e}")
LOG.error(f"test_user_status FAILED {e}")
raise
except Exception as e:
LOG.error(f"test_user_status EXCEPTION {e}")
@ -1470,13 +1610,13 @@ class ToxSuite(unittest.TestCase):
setattr(self.bob, sSlot, True)
opts = oToxygenToxOptions(oTOX_OARGS)
setattr(self.bob, sSlot, True)
try:
if bUSE_NOREQUEST:
assert self.bob_add_alice_as_friend_norequest()
else:
assert self.bob_add_alice_as_friend()
setattr(self.bob, sSlot, True)
self.bob.callback_friend_connection_status(bobs_on_friend_connection_status)
LOG.info("test_connection_status killing alice")
@ -1498,10 +1638,8 @@ class ToxSuite(unittest.TestCase):
if hasattr(self, 'baid') and self.baid >= 0:
self.bob.friend_delete(self.baid)
# TestS DEBUG wait_otox_attrs bob for ['friend_name'] 5 last=1701826540
# @unittest.skip('crashes')
@expectedFail('fails') # new name if empty
def test_friend_name(self): # works! or crashes!
@expectedFail('fails') # new name is empty
def test_friend_name(self): # works!
"""
t:self_set_name
t:friend_get_name
@ -1557,9 +1695,7 @@ class ToxSuite(unittest.TestCase):
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
"""
t:on_friend_action
@ -1590,35 +1726,34 @@ class ToxSuite(unittest.TestCase):
assert self.both_add_as_friend_norequest()
else:
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')
self.alice.callback_friend_message(alices_on_friend_message)
self.warn_if_no_cb(self.alice, sSlot)
# dunno - both This client is currently NOT CONNECTED to the friend.
if True:
iMesId = self.bob.friend_send_message(self.baid,
TOX_MESSAGE_TYPE['NORMAL'],
bytes(MSG, 'UTF-8'))
# 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
iMesId = self.bob.friend_send_message(self.baid,
TOX_MESSAGE_TYPE['NORMAL'],
bytes(MSG, 'UTF-8'))
assert iMesId >= 0, "iMesId >= 0"
if not self.wait_otox_attrs(self.alice, [sSlot]):
LOG_WARN(f"alices_on_friend_message NO {sSlot}")
except ArgumentError as e:
# ArgumentError('This client is currently NOT CONNECTED to the friend.')
# dunno
LOG.error(f"test_friend_message {e}")
LOG.error(f"test_friend_message ArgumentError {e}")
raise
except AssertionError as e:
LOG.error(f"test_friend_message {e}")
LOG.error(f"test_friend_message AssertionError {e}")
raise
except Exception as e:
LOG.error(f"test_friend_message {e}")
LOG.error(f"test_friend_message EXCEPTION {e}")
raise
finally:
self.alice.callback_friend_message(None)
@ -1950,7 +2085,6 @@ class ToxSuite(unittest.TestCase):
@unittest.skip('crashes')
def test_tox_savedata(self): # works sorta
# but "{addr} != {self.alice.self_get_address()}"
"""
t:get_savedata_size
t:get_savedata
@ -1984,6 +2118,13 @@ class ToxSuite(unittest.TestCase):
else:
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):
ts.vSetupLogging(oArgs)
@ -2000,6 +2141,7 @@ def vOargsToxPreamble(oArgs, Tox, ToxTest):
if len(not_tested):
logging.info('Not tested:\n %s' % "\n ".join(sorted(list(not_tested))))
###
def iMain(oArgs):
@ -2112,6 +2254,3 @@ def main(lArgs=None):
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))
#Ran 38 tests in 194.492s
#OK (skipped=10, expected failures=4)