From aedf36cda2e079be430f37303cb097f7e026e273 Mon Sep 17 00:00:00 2001 From: emdee Date: Sun, 10 Dec 2023 01:20:38 +0000 Subject: [PATCH] updates --- wrapper/tox.py | 19 +++++------ wrapper_tests/tests_wrapper.py | 61 ++++++++++++++++++++++++++-------- 2 files changed, 55 insertions(+), 25 deletions(-) diff --git a/wrapper/tox.py b/wrapper/tox.py index 5b9b986..41e3d56 100644 --- a/wrapper/tox.py +++ b/wrapper/tox.py @@ -1906,15 +1906,13 @@ class Tox: c_size_t(len(group_name)), peer_info, byref(error)) else: - nick_length = len(nick) - cnick = c_char_p(nick) cgroup_name = c_char_p(group_name) result = Tox.libtoxcore.tox_group_new(self._tox_pointer, privacy_state, cgroup_name, c_size_t(len(group_name)), - cnick, - c_size_t(nick_length), + c_char_p(nick), + c_size_t(len(nick)), byref(error)) if error.value: @@ -1961,8 +1959,7 @@ class Tox: byref(error)) else: if not password: - # dunno - cpassword = POINTER(None)() + cpassword = None else: cpassword = c_char_p(password) result = Tox.libtoxcore.tox_group_join(self._tox_pointer, @@ -1996,7 +1993,9 @@ class Tox: raise ToxError(f"tox_group_ group_number < 0 {group_number}") error = c_int() LOG_DEBUG(f"tox.group_reconnect") - result = Tox.libtoxcore.tox_group_reconnect(self._tox_pointer, c_uint32(group_number), byref(error)) + result = Tox.libtoxcore.tox_group_reconnect(self._tox_pointer, + c_uint32(group_number), + byref(error)) if error.value: s = sGetError(error.value, TOX_ERR_GROUP_RECONNECT) LOG_ERROR(f"group_new {error.value} {s}") @@ -2543,13 +2542,11 @@ class Tox: # QObject::installEventFilter(): Cannot filter events for objects in a different thread. # QBasicTimer::start: Timers cannot be started from another thread result = bin_to_string(buff, TOX_GROUP_CHAT_ID_SIZE) - LOG_INFO(f"tox.group_get_chat_id group_number={group_number} result={result}") + LOG_DEBUG(f"tox.group_get_chat_id group_number={group_number} result={result}") - LOG_TRACE(f"tox_group_get_chat_id") return result def group_get_number_groups(self): - #? 0 based or 1 based """ Return the number of groups in the Tox chats array. """ @@ -2559,7 +2556,7 @@ class Tox: except Exception as e: LOG_WARN(f"tox.group_get_number_groups EXCEPTION {e}") result = 0 - LOG_DEBUG(f"tox.group_get_number_groups returning {result}") + LOG_INFO(f"tox.group_get_number_groups returning {result}") return int(result) def groups_get_list(self): diff --git a/wrapper_tests/tests_wrapper.py b/wrapper_tests/tests_wrapper.py index d6d15b7..6dff561 100644 --- a/wrapper_tests/tests_wrapper.py +++ b/wrapper_tests/tests_wrapper.py @@ -423,12 +423,12 @@ 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): + def group_until_connected(self, group_number, num=None, iMax=THRESHOLD): """ """ i = 0 bRet = None - while i <= THRESHOLD : + while i <= iMax : iRet = self.bob.group_is_connected(group_number) if iRet == True or iRet == 0: bRet = True @@ -450,13 +450,15 @@ class ToxSuite(unittest.TestCase): 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" BOB={self.bob.self_get_connection_status()}" \ - +f" last={int(self.bob.mycon_time)}" ) + +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): @@ -532,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: @@ -550,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]) @@ -838,14 +840,16 @@ class ToxSuite(unittest.TestCase): assert otox.group_get_privacy_state(iGrp) == privacy_state assert otox.group_get_number_groups() > 0 - LOG.info(f"group pK={sPk} iGrp={iGrp}") + LOG.info(f"group pK={sPk} iGrp={iGrp} n={otox.group_get_number_groups()}") return iGrp + # 360497DA684BCE2A500C1AF9B3A5CE949BBB9F6FB1F91589806FB04CA039E313 + # 75D2163C19FEFFE51508046398202DDC321E6F9B6654E99BAE45FFEC134F05DE def otox_test_groups_join(self, otox, - chat_id="360497DA684BCE2A500C1AF9B3A5CE949BBB9F6FB1F91589806FB04CA039E313", - nick='nick', - topic='Test Topic', # str - ): + chat_id="75d2163c19feffe51508046398202ddc321e6f9b6654e99bae45ffec134f05de", + nick='nick', + topic='Test Topic', # str + ): status = '' password = '' LOG.debug(f"group_join nick={nick} chat_id={chat_id}") @@ -855,6 +859,10 @@ class ToxSuite(unittest.TestCase): 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}") @@ -865,12 +873,22 @@ class ToxSuite(unittest.TestCase): except Exception as e: LOG.error(f"group_is_connected EXCEPTION {e}") return -1 - LOG.debug(f"group_is_connected group_number={group_number} bRet={bRet}") # chat->connection_state == CS_CONNECTED || chat->connection_state == CS_CONNECTING; if bRet: - LOG.warn(f"group_is_connected WARN group_number={group_number} ") + LOG.warn(f"group_is_connected WARN not connected group_number={group_number} n={otox.group_get_number_groups()}") else: - LOG.info(f"group_is_connected SUCCESS group_number={group_number} ") + 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 @@ -908,6 +926,17 @@ class ToxSuite(unittest.TestCase): LOG.error(f"group_is_connected ERROR {e}") 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: + 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') @@ -1359,6 +1388,10 @@ class ToxSuite(unittest.TestCase): 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}"