2022-09-26 00:58:57 +00:00
|
|
|
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
# @file tests.py
|
|
|
|
# @author Wei-Ning Huang (AZ) <aitjcize@gmail.com>
|
|
|
|
#
|
|
|
|
# Copyright (C) 2013 - 2014 Wei-Ning Huang (AZ) <aitjcize@gmail.com>
|
|
|
|
# All Rights reserved.
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software Foundation,
|
|
|
|
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
#
|
|
|
|
|
2022-10-23 22:14:35 +00:00
|
|
|
"""Originaly from https://github.com/oxij/PyTox c-toxcore-02 branch
|
2022-09-26 00:58:57 +00:00
|
|
|
which itself was forked from https://github.com/aitjcize/PyTox/
|
|
|
|
|
2022-11-23 20:02:29 +00:00
|
|
|
Modified to work with
|
2022-09-26 00:58:57 +00:00
|
|
|
"""
|
|
|
|
|
2022-11-17 14:18:51 +00:00
|
|
|
import ctypes
|
|
|
|
import faulthandler
|
2022-09-26 00:58:57 +00:00
|
|
|
import hashlib
|
2022-11-17 14:18:51 +00:00
|
|
|
import logging
|
2022-09-26 00:58:57 +00:00
|
|
|
import os
|
2022-11-17 14:18:51 +00:00
|
|
|
import random
|
2022-09-26 00:58:57 +00:00
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
import threading
|
2022-11-17 14:18:51 +00:00
|
|
|
import traceback
|
|
|
|
import unittest
|
2022-09-26 00:58:57 +00:00
|
|
|
from ctypes import *
|
2023-12-13 00:57:28 +00:00
|
|
|
from typing import Union, Callable, Union
|
2022-09-26 00:58:57 +00:00
|
|
|
|
|
|
|
faulthandler.enable()
|
|
|
|
|
|
|
|
import warnings
|
|
|
|
warnings.filterwarnings('ignore')
|
|
|
|
|
|
|
|
try:
|
|
|
|
from io import BytesIO
|
2022-11-17 14:18:51 +00:00
|
|
|
import certifi
|
|
|
|
import pycurl
|
2022-09-26 00:58:57 +00:00
|
|
|
except ImportError:
|
|
|
|
pycurl = None
|
|
|
|
|
2023-12-12 05:20:05 +00:00
|
|
|
from pyannotate_runtime import collect_types
|
|
|
|
|
2022-09-26 00:58:57 +00:00
|
|
|
try:
|
|
|
|
import coloredlogs
|
|
|
|
os.environ['COLOREDLOGS_LEVEL_STYLES'] = 'spam=22;debug=28;verbose=34;notice=220;warning=202;success=118,bold;error=124;critical=background=red'
|
|
|
|
except ImportError as e:
|
2023-07-14 14:07:08 +00:00
|
|
|
logging.log(logging.DEBUG, f"coloredlogs not available: {e}")
|
2022-09-26 00:58:57 +00:00
|
|
|
coloredlogs = None
|
|
|
|
|
|
|
|
try:
|
|
|
|
import color_runner
|
|
|
|
except ImportError as e:
|
2023-07-14 14:07:08 +00:00
|
|
|
logging.log(logging.DEBUG, f"color_runner not available: {e}")
|
2022-09-26 00:58:57 +00:00
|
|
|
color_runner = None
|
|
|
|
|
2023-12-16 23:23:00 +00:00
|
|
|
import tox_wrapper
|
|
|
|
import tox_wrapper.toxcore_enums_and_consts as enums
|
|
|
|
from tox_wrapper.tox import Tox, UINT32_MAX, ToxError
|
2023-12-08 19:37:22 +00:00
|
|
|
|
2023-12-16 23:23:00 +00:00
|
|
|
from tox_wrapper.toxcore_enums_and_consts import (TOX_ADDRESS_SIZE, TOX_CONNECTION,
|
2022-11-17 14:18:51 +00:00
|
|
|
TOX_FILE_CONTROL,
|
|
|
|
TOX_MESSAGE_TYPE,
|
|
|
|
TOX_SECRET_KEY_SIZE,
|
|
|
|
TOX_USER_STATUS)
|
2022-09-26 00:58:57 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
import support_testing as ts
|
|
|
|
except ImportError:
|
2023-12-16 23:23:00 +00:00
|
|
|
import tox_wrapper.tests.support_testing as ts
|
2022-09-26 00:58:57 +00:00
|
|
|
|
|
|
|
try:
|
2023-07-14 14:07:08 +00:00
|
|
|
from tests.toxygen_tests import test_sound_notification
|
2022-09-26 00:58:57 +00:00
|
|
|
bIS_NOT_TOXYGEN = False
|
|
|
|
except ImportError:
|
|
|
|
bIS_NOT_TOXYGEN = True
|
2022-10-11 09:33:39 +00:00
|
|
|
|
2022-09-26 00:58:57 +00:00
|
|
|
# from PyQt5 import QtCore
|
2022-11-17 14:18:51 +00:00
|
|
|
import time
|
|
|
|
|
|
|
|
sleep = time.sleep
|
2022-09-26 00:58:57 +00:00
|
|
|
|
|
|
|
global LOG
|
|
|
|
LOG = logging.getLogger('TestS')
|
2023-12-06 16:32:06 +00:00
|
|
|
if False:
|
2023-12-12 05:20:05 +00:00
|
|
|
def LOG_ERROR(l: str) -> None: LOG.error('+ '+l)
|
|
|
|
def LOG_WARN(l: str) -> None: LOG.warn('+ '+l)
|
|
|
|
def LOG_INFO(l: str) -> None: LOG.info('+ '+l)
|
|
|
|
def LOG_DEBUG(l: str) -> None: LOG.debug('+ '+l)
|
|
|
|
def LOG_TRACE(l: str) -> None: pass # print('+ '+l)
|
2023-07-17 02:36:30 +00:00
|
|
|
else:
|
2023-12-07 19:38:26 +00:00
|
|
|
# just print to stdout so there is NO complications from logging.
|
2023-12-12 05:20:05 +00:00
|
|
|
def LOG_ERROR(l: str) -> None: print('EROR+ '+l)
|
|
|
|
def LOG_WARN(l: str) -> None: print('WARN+ '+l)
|
|
|
|
def LOG_INFO(l: str) -> None: print('INFO+ '+l)
|
|
|
|
def LOG_DEBUG(l: str) -> None: print('DEBUG+ '+l)
|
|
|
|
def LOG_TRACE(l: str) -> None: pass # print('TRAC+ '+l)
|
2022-09-26 00:58:57 +00:00
|
|
|
|
|
|
|
ADDR_SIZE = 38 * 2
|
|
|
|
CLIENT_ID_SIZE = 32 * 2
|
2023-12-12 05:20:05 +00:00
|
|
|
THRESHOLD = 35 # >25
|
2023-12-07 19:38:26 +00:00
|
|
|
iN = 6
|
2022-09-26 00:58:57 +00:00
|
|
|
|
|
|
|
global oTOX_OPTIONS
|
|
|
|
oTOX_OPTIONS = {}
|
|
|
|
|
2023-12-06 16:32:06 +00:00
|
|
|
bIS_LOCAL = 'new' in sys.argv or 'local' in sys.argv or 'newlocal' in sys.argv
|
|
|
|
bUSE_NOREQUEST = None
|
2022-09-26 00:58:57 +00:00
|
|
|
|
2023-07-14 14:07:08 +00:00
|
|
|
def expectedFailure(test_item):
|
|
|
|
test_item.__unittest_expecting_failure__ = True
|
|
|
|
return test_item
|
|
|
|
|
2023-12-12 05:20:05 +00:00
|
|
|
def expectedFail(reason: str):
|
2023-07-17 02:36:30 +00:00
|
|
|
"""
|
|
|
|
expectedFailure with a reason
|
|
|
|
"""
|
|
|
|
def decorator(test_item):
|
|
|
|
test_item.__unittest_expecting_failure__ = True
|
|
|
|
return test_item
|
|
|
|
return decorator
|
|
|
|
|
2022-09-26 00:58:57 +00:00
|
|
|
class ToxOptions():
|
|
|
|
def __init__(self):
|
|
|
|
self.ipv6_enabled = True
|
|
|
|
self.udp_enabled = True
|
|
|
|
self.proxy_type = 0
|
|
|
|
self.proxy_host = ''
|
|
|
|
self.proxy_port = 0
|
|
|
|
self.start_port = 0
|
|
|
|
self.end_port = 0
|
|
|
|
self.tcp_port = 0
|
|
|
|
self.savedata_type = 0 # 1=toxsave, 2=secretkey
|
|
|
|
self.savedata_data = b''
|
|
|
|
self.savedata_length = 0
|
|
|
|
self.local_discovery_enabled = False
|
|
|
|
self.dht_announcements_enabled = True
|
|
|
|
self.hole_punching_enabled = False
|
|
|
|
self.experimental_thread_safety = False
|
|
|
|
|
|
|
|
class App():
|
|
|
|
def __init__(self):
|
|
|
|
self.mode = 0
|
|
|
|
oAPP = App()
|
|
|
|
|
|
|
|
class AliceTox(Tox):
|
|
|
|
|
|
|
|
def __init__(self, opts, app=None):
|
|
|
|
|
|
|
|
super(AliceTox, self).__init__(opts, app=app)
|
|
|
|
self._address = self.self_get_address()
|
|
|
|
self.name = 'alice'
|
|
|
|
self._opts = opts
|
|
|
|
self._app = app
|
|
|
|
|
|
|
|
class BobTox(Tox):
|
|
|
|
|
|
|
|
def __init__(self, opts, app=None):
|
|
|
|
super(BobTox, self).__init__(opts, app=app)
|
|
|
|
self._address = self.self_get_address()
|
|
|
|
self.name = 'bob'
|
|
|
|
self._opts = opts
|
|
|
|
self._app = app
|
|
|
|
|
|
|
|
class BaseThread(threading.Thread):
|
|
|
|
|
|
|
|
def __init__(self, name=None, target=None):
|
|
|
|
if name:
|
|
|
|
super().__init__(name=name, target=target)
|
|
|
|
else:
|
|
|
|
super().__init__(target=target)
|
|
|
|
self._stop_thread = False
|
|
|
|
self.name = name
|
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def stop_thread(self, timeout: int = -1) -> None:
|
2022-09-26 00:58:57 +00:00
|
|
|
self._stop_thread = True
|
|
|
|
if timeout < 0:
|
|
|
|
timeout = ts.iTHREAD_TIMEOUT
|
|
|
|
i = 0
|
|
|
|
while i < ts.iTHREAD_JOINS:
|
|
|
|
self.join(timeout)
|
|
|
|
if not self.is_alive(): break
|
|
|
|
i = i + 1
|
|
|
|
else:
|
2023-07-14 14:07:08 +00:00
|
|
|
LOG.warning(f"{self.name} BLOCKED")
|
2022-09-26 00:58:57 +00:00
|
|
|
|
|
|
|
class ToxIterateThread(BaseThread):
|
|
|
|
|
|
|
|
def __init__(self, tox):
|
|
|
|
super().__init__(name='ToxIterateThread')
|
|
|
|
self._tox = tox
|
|
|
|
|
2023-12-12 05:20:05 +00:00
|
|
|
def run(self) -> None:
|
2022-09-26 00:58:57 +00:00
|
|
|
while not self._stop_thread:
|
|
|
|
self._tox.iterate()
|
|
|
|
sleep(self._tox.iteration_interval() / 1000)
|
|
|
|
|
2023-07-14 14:07:08 +00:00
|
|
|
global bob, alice
|
|
|
|
bob = alice = None
|
2022-09-26 00:58:57 +00:00
|
|
|
|
2023-07-14 14:07:08 +00:00
|
|
|
def prepare(self):
|
|
|
|
global bob, alice
|
2023-12-13 00:57:28 +00:00
|
|
|
def bobs_on_self_connection_status(iTox, connection_state, *args) -> None:
|
2023-07-14 14:07:08 +00:00
|
|
|
status = connection_state
|
|
|
|
self.bob.dht_connected = status
|
|
|
|
self.bob.mycon_time = time.time()
|
|
|
|
try:
|
|
|
|
if status != TOX_CONNECTION['NONE']:
|
|
|
|
LOG_DEBUG(f"bobs_on_self_connection_status TRUE {status}" \
|
|
|
|
+f" last={int(self.bob.mycon_time)}" )
|
|
|
|
self.bob.mycon_status = True
|
|
|
|
else:
|
|
|
|
LOG_DEBUG(f"bobs_on_self_connection_status FALSE {status}" \
|
|
|
|
+f" last={int(self.bob.mycon_time)}" )
|
|
|
|
self.bob.mycon_status = False
|
|
|
|
except Exception as e:
|
|
|
|
LOG_ERROR(f"bobs_on_self_connection_status {e}")
|
|
|
|
else:
|
|
|
|
if self.bob.self_get_connection_status() != status:
|
|
|
|
LOG_WARN(f"bobs_on_self_connection_status DISAGREE {status}")
|
2023-12-16 23:23:00 +00:00
|
|
|
self.bob.dht_connected = status
|
2023-07-14 14:07:08 +00:00
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def alices_on_self_connection_status(iTox, connection_state: int, *args) -> None:
|
2023-07-14 14:07:08 +00:00
|
|
|
#FixMe connection_num
|
|
|
|
status = connection_state
|
|
|
|
self.alice.dht_connected = status
|
|
|
|
self.alice.mycon_time = time.time()
|
|
|
|
try:
|
|
|
|
if status != TOX_CONNECTION['NONE']:
|
|
|
|
LOG_DEBUG(f"alices_on_self_connection_status TRUE {status}" \
|
|
|
|
+f" last={int(self.alice.mycon_time)}" )
|
|
|
|
self.alice.mycon_status = True
|
|
|
|
else:
|
|
|
|
LOG_WARN(f"alices_on_self_connection_status FALSE {status}" \
|
|
|
|
+f" last={int(self.alice.mycon_time)}" )
|
|
|
|
self.alice.mycon_status = False
|
|
|
|
except Exception as e:
|
|
|
|
LOG_ERROR(f"alices_on_self_connection_status error={e}")
|
|
|
|
self.alice.dht_connected = status
|
|
|
|
|
2023-12-16 23:23:00 +00:00
|
|
|
opts = oTestsToxOptions(oTOX_OARGS)
|
2023-12-06 16:32:06 +00:00
|
|
|
global bUSE_NOREQUEST
|
|
|
|
bUSE_NOREQUEST = oTOX_OARGS.norequest == 'True'
|
|
|
|
|
2023-07-14 14:07:08 +00:00
|
|
|
alice = AliceTox(opts, app=oAPP)
|
|
|
|
alice.oArgs = opts
|
|
|
|
alice.dht_connected = -1
|
|
|
|
alice.mycon_status = False
|
|
|
|
alice.mycon_time = 1
|
|
|
|
alice.callback_self_connection_status(alices_on_self_connection_status)
|
|
|
|
|
2023-12-16 23:23:00 +00:00
|
|
|
# only bob logs trace_enabled
|
2023-12-18 21:45:22 +00:00
|
|
|
if oTOX_OARGS.trace_enabled:
|
2023-12-16 23:23:00 +00:00
|
|
|
LOG.info(f"toxcore trace_enabled")
|
2023-12-18 21:45:22 +00:00
|
|
|
ts.vAddLoggerCallback(opts)
|
2023-12-16 23:23:00 +00:00
|
|
|
else:
|
|
|
|
LOG.debug(f"toxcore trace_enabled")
|
|
|
|
|
2023-07-14 14:07:08 +00:00
|
|
|
bob = BobTox(opts, app=oAPP)
|
|
|
|
bob.oArgs = opts
|
|
|
|
bob.dht_connected = -1
|
|
|
|
bob.mycon_status = False
|
|
|
|
bob.mycon_time = 1
|
|
|
|
bob.callback_self_connection_status(bobs_on_self_connection_status)
|
|
|
|
if not bIS_LOCAL and not ts.bAreWeConnected():
|
|
|
|
LOG.warning(f"doOnce not local and NOT CONNECTED")
|
|
|
|
return [bob, alice]
|
2022-09-26 00:58:57 +00:00
|
|
|
|
2023-07-14 14:07:08 +00:00
|
|
|
class ToxSuite(unittest.TestCase):
|
2023-07-17 02:36:30 +00:00
|
|
|
failureException = AssertionError
|
2023-07-14 14:07:08 +00:00
|
|
|
|
|
|
|
@classmethod
|
2023-12-12 05:20:05 +00:00
|
|
|
def setUpClass(cls) -> None:
|
2023-07-14 14:07:08 +00:00
|
|
|
global oTOX_OARGS
|
2022-09-26 00:58:57 +00:00
|
|
|
assert oTOX_OPTIONS
|
|
|
|
assert oTOX_OARGS
|
2023-07-14 14:07:08 +00:00
|
|
|
|
|
|
|
cls.lUdp = ts.generate_nodes(
|
2022-10-08 18:01:52 +00:00
|
|
|
oArgs=oTOX_OARGS,
|
2023-07-14 14:07:08 +00:00
|
|
|
nodes_count=2*ts.iNODES,
|
2022-10-08 18:01:52 +00:00
|
|
|
ipv='ipv4',
|
|
|
|
udp_not_tcp=True)
|
|
|
|
|
2023-07-14 14:07:08 +00:00
|
|
|
cls.lTcp = ts.generate_nodes(
|
2022-10-08 18:01:52 +00:00
|
|
|
oArgs=oTOX_OARGS,
|
2023-07-14 14:07:08 +00:00
|
|
|
nodes_count=2*ts.iNODES,
|
2022-10-08 18:01:52 +00:00
|
|
|
ipv='ipv4',
|
|
|
|
udp_not_tcp=False)
|
2022-09-26 00:58:57 +00:00
|
|
|
|
2023-12-12 05:20:05 +00:00
|
|
|
def tearDown(self) -> None:
|
2023-12-09 10:19:21 +00:00
|
|
|
"""
|
|
|
|
"""
|
|
|
|
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()}")
|
2023-12-12 05:20:05 +00:00
|
|
|
for elt in self.bob.self_get_friend_list():
|
|
|
|
self.bob.friend_delete(elt)
|
2023-12-09 10:19:21 +00:00
|
|
|
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()}")
|
2023-12-12 05:20:05 +00:00
|
|
|
for elt in self.alice.self_get_friend_list():
|
|
|
|
self.alice.friend_delete(elt)
|
2023-12-09 10:19:21 +00:00
|
|
|
|
2023-12-16 23:23:00 +00:00
|
|
|
# LOG.debug(f"tearDown threads={threading.active_count()}")
|
2023-12-09 10:19:21 +00:00
|
|
|
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
|
|
|
|
|
2023-07-14 14:07:08 +00:00
|
|
|
@classmethod
|
2023-12-12 05:20:05 +00:00
|
|
|
def tearDownClass(cls) -> None:
|
2023-12-09 10:19:21 +00:00
|
|
|
if hasattr(cls, 'bob'):
|
|
|
|
cls.bob._main_loop.stop_thread()
|
2023-07-14 14:07:08 +00:00
|
|
|
cls.bob.kill()
|
|
|
|
del cls.bob
|
2023-12-09 10:19:21 +00:00
|
|
|
if hasattr(cls, 'alice'):
|
|
|
|
cls.alice._main_loop.stop_thread()
|
|
|
|
cls.alice.kill()
|
2023-07-14 14:07:08 +00:00
|
|
|
del cls.alice
|
2022-09-26 00:58:57 +00:00
|
|
|
|
2023-12-12 05:20:05 +00:00
|
|
|
def bBobNeedAlice(self) -> bool:
|
2022-09-26 00:58:57 +00:00
|
|
|
"""
|
|
|
|
"""
|
2023-07-14 14:07:08 +00:00
|
|
|
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")
|
2023-12-07 19:38:26 +00:00
|
|
|
return False
|
2023-12-09 10:19:21 +00:00
|
|
|
elif self.bob.self_get_friend_list_size() >= 1:
|
2023-07-14 14:07:08 +00:00
|
|
|
LOG.warn(f"setUp BOB STILL HAS A FRIEND LIST")
|
2023-12-07 19:38:26 +00:00
|
|
|
return False
|
|
|
|
return True
|
2023-07-14 14:07:08 +00:00
|
|
|
|
2023-12-12 05:20:05 +00:00
|
|
|
def bAliceNeedAddBob (self) -> bool:
|
2023-07-14 14:07:08 +00:00
|
|
|
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")
|
2023-12-07 19:38:26 +00:00
|
|
|
return False
|
2023-07-14 14:07:08 +00:00
|
|
|
elif self.alice.self_get_friend_list_size() >= 1:
|
|
|
|
LOG.warn(f"setUp ALICE STILL HAS A FRIEND LIST")
|
2023-12-07 19:38:26 +00:00
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
def setUp(self):
|
2023-12-09 10:19:21 +00:00
|
|
|
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()}
|
2022-09-26 00:58:57 +00:00
|
|
|
|
2023-12-09 10:19:21 +00:00
|
|
|
self.bBobNeedAlice()
|
|
|
|
self.bAliceNeedAddBob()
|
2023-07-14 14:07:08 +00:00
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def run(self, result=None) -> None:
|
2023-07-14 14:07:08 +00:00
|
|
|
""" Stop after first error """
|
|
|
|
if not result.errors:
|
|
|
|
super(ToxSuite, self).run(result)
|
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def get_connection_status(self) -> None:
|
2023-12-07 19:38:26 +00:00
|
|
|
if self.bob.mycon_time <= 1 or self.alice.mycon_time <= 1:
|
2023-07-14 14:07:08 +00:00
|
|
|
pass
|
|
|
|
# drop through
|
|
|
|
elif self.bob.dht_connected == TOX_CONNECTION['NONE']:
|
|
|
|
return False
|
|
|
|
elif self.alice.dht_connected == TOX_CONNECTION['NONE']:
|
|
|
|
return False
|
|
|
|
|
|
|
|
# if not self.connected
|
|
|
|
if self.bob.self_get_connection_status() == TOX_CONNECTION['NONE']:
|
|
|
|
return False
|
|
|
|
if self.alice.self_get_connection_status() == TOX_CONNECTION['NONE']:
|
|
|
|
return False
|
|
|
|
return True
|
2022-09-26 00:58:57 +00:00
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def loop(self, n) -> None:
|
2022-09-26 00:58:57 +00:00
|
|
|
"""
|
|
|
|
t:iterate
|
|
|
|
t:iteration_interval
|
|
|
|
"""
|
|
|
|
interval = self.bob.iteration_interval()
|
|
|
|
for i in range(n):
|
|
|
|
self.alice.iterate()
|
|
|
|
self.bob.iterate()
|
|
|
|
sleep(interval / 1000.0)
|
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def call_bootstrap(self, num: Union[int, None] = None, lToxes:list[int] =None, i:int =0) -> None:
|
2023-07-14 14:07:08 +00:00
|
|
|
if num == None: num=ts.iNODES
|
2023-12-07 19:38:26 +00:00
|
|
|
if lToxes is None:
|
|
|
|
lToxes = [self.alice, self.bob]
|
2023-07-14 14:07:08 +00:00
|
|
|
# LOG.debug(f"call_bootstrap network={oTOX_OARGS.network}")
|
2022-09-26 00:58:57 +00:00
|
|
|
if oTOX_OARGS.network in ['new', 'newlocal', 'localnew']:
|
2023-12-07 19:38:26 +00:00
|
|
|
ts.bootstrap_local(self.lUdp, lToxes)
|
2022-09-26 00:58:57 +00:00
|
|
|
elif not ts.bAreWeConnected():
|
2023-07-14 14:07:08 +00:00
|
|
|
LOG.warning('we are NOT CONNECTED')
|
2022-09-26 00:58:57 +00:00
|
|
|
else:
|
|
|
|
random.shuffle(self.lUdp)
|
2023-07-14 14:07:08 +00:00
|
|
|
if oTOX_OARGS.proxy_port > 0:
|
|
|
|
lElts = self.lUdp[:1]
|
|
|
|
else:
|
|
|
|
lElts = self.lUdp[:num+i]
|
|
|
|
LOG.debug(f"call_bootstrap ts.bootstrap_udp {len(lElts)}")
|
|
|
|
ts.bootstrap_udp(lElts, lToxes)
|
|
|
|
random.shuffle(self.lTcp)
|
|
|
|
lElts = self.lTcp[:num+i]
|
|
|
|
LOG.debug(f"call_bootstrap ts.bootstrap_tcp {len(lElts)}")
|
|
|
|
ts.bootstrap_tcp(lElts, lToxes)
|
2022-09-26 00:58:57 +00:00
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def group_until_connected(self, otox, group_number:int, num: Union[int, None] = None, iMax:int = THRESHOLD) -> None:
|
2023-12-08 19:37:22 +00:00
|
|
|
"""
|
|
|
|
"""
|
|
|
|
i = 0
|
|
|
|
bRet = None
|
2023-12-10 01:20:38 +00:00
|
|
|
while i <= iMax :
|
2023-12-10 15:59:53 +00:00
|
|
|
iRet = otox.group_is_connected(group_number)
|
2023-12-09 10:19:21 +00:00
|
|
|
if iRet == True or iRet == 0:
|
2023-12-08 19:37:22 +00:00
|
|
|
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) \
|
2023-12-10 15:59:53 +00:00
|
|
|
+f" BOBS={otox.mycon_status}" \
|
|
|
|
+f" last={int(otox.mycon_time)}" )
|
2023-12-08 19:37:22 +00:00
|
|
|
i += 1
|
|
|
|
self.loop(100)
|
|
|
|
else:
|
|
|
|
bRet = False
|
|
|
|
|
|
|
|
if bRet:
|
2023-12-10 15:59:53 +00:00
|
|
|
LOG.info(f"group_until_connected True i={i}" \
|
|
|
|
+f" iMax={iMax}" \
|
|
|
|
+f" BOB={otox.self_get_connection_status()}" \
|
|
|
|
+f" last={int(otox.mycon_time)}" )
|
2023-12-08 19:37:22 +00:00
|
|
|
return True
|
|
|
|
else:
|
2023-12-10 15:59:53 +00:00
|
|
|
LOG.warning(f"group_until_connected False i={i}" \
|
|
|
|
+f" iMax={iMax}" \
|
|
|
|
+f" BOB={otox.self_get_connection_status()}" \
|
|
|
|
+f" last={int(otox.mycon_time)}" )
|
2023-12-08 19:37:22 +00:00
|
|
|
return False
|
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def loop_until_connected(self, num: Union[int, None] = None) -> None:
|
2022-09-26 00:58:57 +00:00
|
|
|
"""
|
|
|
|
t:on_self_connection_status
|
|
|
|
t:self_get_connection_status
|
|
|
|
"""
|
2023-12-10 15:59:53 +00:00
|
|
|
global THRESHOLD
|
2022-09-26 00:58:57 +00:00
|
|
|
i = 0
|
|
|
|
bRet = None
|
2023-07-14 14:07:08 +00:00
|
|
|
while i <= THRESHOLD :
|
|
|
|
if (self.alice.mycon_status and self.bob.mycon_status):
|
|
|
|
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+"loop_until_connected " \
|
|
|
|
+" #" + str(i) \
|
|
|
|
+" BOB=" +repr(self.bob.self_get_connection_status()) \
|
|
|
|
+" ALICE=" +repr(self.alice.self_get_connection_status())
|
|
|
|
+f" BOBS={self.bob.mycon_status}" \
|
|
|
|
+f" ALICES={self.alice.mycon_status}" \
|
|
|
|
+f" last={int(self.bob.mycon_time)}" )
|
|
|
|
if (self.alice.mycon_status and self.bob.mycon_status):
|
|
|
|
bRet = True
|
|
|
|
break
|
|
|
|
if (self.alice.self_get_connection_status() and
|
|
|
|
self.bob.self_get_connection_status()):
|
|
|
|
LOG_WARN(f"loop_until_connected disagree status() DISAGREE" \
|
|
|
|
+f' self.bob.mycon_status={self.bob.mycon_status}' \
|
|
|
|
+f' alice.mycon_status={self.alice.mycon_status}' \
|
|
|
|
+f" last={int(self.bob.mycon_time)}" )
|
|
|
|
bRet = True
|
|
|
|
break
|
|
|
|
i += 1
|
|
|
|
self.loop(100)
|
|
|
|
else:
|
|
|
|
bRet = False
|
2022-09-26 00:58:57 +00:00
|
|
|
|
|
|
|
if bRet or \
|
|
|
|
( self.bob.self_get_connection_status() != TOX_CONNECTION['NONE'] and \
|
|
|
|
self.alice.self_get_connection_status() != TOX_CONNECTION['NONE'] ):
|
2023-07-14 14:07:08 +00:00
|
|
|
LOG.info(f"loop_until_connected returning True {i}" \
|
2022-09-26 00:58:57 +00:00
|
|
|
+f" BOB={self.bob.self_get_connection_status()}" \
|
2023-07-14 14:07:08 +00:00
|
|
|
+f" ALICE={self.alice.self_get_connection_status()}" \
|
|
|
|
+f" last={int(self.bob.mycon_time)}" )
|
2022-09-26 00:58:57 +00:00
|
|
|
return True
|
|
|
|
else:
|
2023-12-10 15:59:53 +00:00
|
|
|
THRESHOLD += 5
|
2023-07-14 14:07:08 +00:00
|
|
|
LOG.warning(f"loop_until_connected returning False {i}" \
|
2022-09-26 00:58:57 +00:00
|
|
|
+f" BOB={self.bob.self_get_connection_status()}" \
|
2023-07-14 14:07:08 +00:00
|
|
|
+f" ALICE={self.alice.self_get_connection_status()}" \
|
|
|
|
+f" last={int(self.bob.mycon_time)}" )
|
|
|
|
return False
|
2022-09-26 00:58:57 +00:00
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def wait_objs_attr(self, objs: list, attr: str) -> bool:
|
2023-12-10 15:59:53 +00:00
|
|
|
global THRESHOLD
|
2022-09-26 00:58:57 +00:00
|
|
|
i = 0
|
|
|
|
while i <= THRESHOLD:
|
2023-07-14 14:07:08 +00:00
|
|
|
if i % 5 == 0:
|
|
|
|
num = None
|
2023-07-17 02:36:30 +00:00
|
|
|
j = 0
|
2023-07-14 14:07:08 +00:00
|
|
|
j = i//5
|
|
|
|
self.call_bootstrap(num, objs, i=j)
|
2023-07-17 02:36:30 +00:00
|
|
|
LOG.debug(f"wait_objs_attr {objs} for {attr} {i}")
|
2022-09-26 00:58:57 +00:00
|
|
|
if all([getattr(obj, attr) for obj in objs]):
|
|
|
|
return True
|
|
|
|
self.loop(100)
|
|
|
|
i += 1
|
|
|
|
else:
|
2023-12-10 15:59:53 +00:00
|
|
|
THRESHOLD += 1
|
|
|
|
LOG.warn(f"wait_objs_attr for {attr} i >= {THRESHOLD}")
|
2022-09-26 00:58:57 +00:00
|
|
|
|
2023-07-17 02:36:30 +00:00
|
|
|
return all([getattr(obj, attr) is not None for obj in objs])
|
2022-09-26 00:58:57 +00:00
|
|
|
|
2023-12-14 20:46:56 +00:00
|
|
|
def wait_otox_attrs(self, obj, attrs: list[str]) -> bool:
|
2023-12-10 01:20:38 +00:00
|
|
|
assert all(attrs), f"wait_otox_attrs {attrs}"
|
2022-09-26 00:58:57 +00:00
|
|
|
i = 0
|
|
|
|
while i <= THRESHOLD:
|
2023-07-14 14:07:08 +00:00
|
|
|
if i % 5 == 0:
|
|
|
|
num = None
|
|
|
|
j = 0
|
|
|
|
if obj.mycon_time == 1:
|
|
|
|
num = 4
|
|
|
|
j = i//5
|
2023-12-06 16:32:06 +00:00
|
|
|
if obj.self_get_connection_status() == TOX_CONNECTION['NONE']:
|
|
|
|
self.call_bootstrap(num, [obj], i=j)
|
2023-07-14 14:07:08 +00:00
|
|
|
LOG.debug(f"wait_otox_attrs {obj.name} for {attrs} {i}" \
|
|
|
|
+f" last={int(obj.mycon_time)}")
|
|
|
|
if all([getattr(obj, attr) is not None for attr in attrs]):
|
2022-09-26 00:58:57 +00:00
|
|
|
return True
|
|
|
|
self.loop(100)
|
|
|
|
i += 1
|
|
|
|
else:
|
2023-12-10 01:20:38 +00:00
|
|
|
LOG.warning(f"wait_otox_attrs i >= {THRESHOLD} results={[getattr(obj, attr) for attr in attrs]}")
|
2022-09-26 00:58:57 +00:00
|
|
|
|
|
|
|
return all([getattr(obj, attr) for attr in attrs])
|
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def wait_ensure_exec(self, method, args:list) -> bool:
|
2022-09-26 00:58:57 +00:00
|
|
|
i = 0
|
|
|
|
oRet = None
|
|
|
|
while i <= THRESHOLD:
|
2023-07-14 14:07:08 +00:00
|
|
|
if i % 5 == 0:
|
|
|
|
j = i//5
|
|
|
|
self.call_bootstrap(num=None, lToxes=None, i=j)
|
2022-09-26 00:58:57 +00:00
|
|
|
LOG.debug("wait_ensure_exec " \
|
|
|
|
+" " +str(method)
|
|
|
|
+" " +str(i))
|
|
|
|
try:
|
|
|
|
oRet = method(*args)
|
|
|
|
if oRet:
|
|
|
|
LOG.info(f"wait_ensure_exec oRet {oRet!r}")
|
|
|
|
return True
|
|
|
|
except ArgumentError as e:
|
|
|
|
# ArgumentError('This client is currently NOT CONNECTED to the friend.')
|
|
|
|
# dunno
|
2023-07-14 14:07:08 +00:00
|
|
|
LOG.warning(f"wait_ensure_exec ArgumentError {e}")
|
2022-09-26 00:58:57 +00:00
|
|
|
return False
|
|
|
|
except Exception as e:
|
2023-07-14 14:07:08 +00:00
|
|
|
LOG.warning(f"wait_ensure_exec EXCEPTION {e}")
|
2022-09-26 00:58:57 +00:00
|
|
|
return False
|
|
|
|
sleep(3)
|
|
|
|
i += 1
|
|
|
|
else:
|
2023-07-14 14:07:08 +00:00
|
|
|
LOG.error(f"wait_ensure_exec i >= {1*THRESHOLD}")
|
2022-09-26 00:58:57 +00:00
|
|
|
return False
|
|
|
|
|
|
|
|
return oRet
|
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def bob_add_alice_as_friend_norequest(self) -> bool:
|
2023-12-09 10:19:21 +00:00
|
|
|
if not self.bBobNeedAlice(): return True
|
2023-07-14 14:07:08 +00:00
|
|
|
|
2022-09-26 00:58:57 +00:00
|
|
|
MSG = 'Hi, this is Bob.'
|
|
|
|
iRet = self.bob.friend_add_norequest(self.alice._address)
|
2023-12-06 16:32:06 +00:00
|
|
|
if iRet < 0:
|
|
|
|
return False
|
2022-09-26 00:58:57 +00:00
|
|
|
self.baid = self.bob.friend_by_public_key(self.alice._address)
|
|
|
|
assert self.baid >= 0, self.baid
|
|
|
|
assert self.bob.friend_exists(self.baid), "bob.friend_exists"
|
|
|
|
assert not self.bob.friend_exists(self.baid + 1)
|
|
|
|
assert self.baid in self.bob.self_get_friend_list()
|
|
|
|
assert self.bob.self_get_friend_list_size() >= 1
|
2023-12-06 16:32:06 +00:00
|
|
|
return True
|
2022-09-26 00:58:57 +00:00
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def alice_add_bob_as_friend_norequest(self) -> bool:
|
2023-12-09 10:19:21 +00:00
|
|
|
if not self.bAliceNeedAddBob(): return True
|
2023-07-14 14:07:08 +00:00
|
|
|
|
2022-09-26 00:58:57 +00:00
|
|
|
iRet = self.alice.friend_add_norequest(self.bob._address)
|
2023-12-06 16:32:06 +00:00
|
|
|
if iRet < 0:
|
|
|
|
return False
|
2022-09-26 00:58:57 +00:00
|
|
|
self.abid = self.alice.friend_by_public_key(self.bob._address)
|
|
|
|
assert self.abid >= 0, self.abid
|
2023-07-14 14:07:08 +00:00
|
|
|
assert self.abid in self.alice.self_get_friend_list()
|
2022-09-26 00:58:57 +00:00
|
|
|
assert self.alice.friend_exists(self.abid), "alice.friend_exists"
|
|
|
|
assert not self.alice.friend_exists(self.abid + 1)
|
|
|
|
assert self.alice.self_get_friend_list_size() >= 1
|
2023-12-06 16:32:06 +00:00
|
|
|
return True
|
2023-07-14 14:07:08 +00:00
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def both_add_as_friend(self) -> bool:
|
2023-12-09 10:19:21 +00:00
|
|
|
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.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
|
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def both_add_as_friend_norequest(self) -> bool:
|
2023-12-09 10:19:21 +00:00
|
|
|
if self.bBobNeedAlice():
|
2023-12-06 16:32:06 +00:00
|
|
|
assert self.bob_add_alice_as_friend_norequest()
|
2023-12-09 10:19:21 +00:00
|
|
|
if self.bAliceNeedAddBob():
|
2023-12-07 19:38:26 +00:00
|
|
|
assert self.alice_add_bob_as_friend_norequest()
|
2023-12-06 16:32:06 +00:00
|
|
|
if not hasattr(self, 'baid') or self.baid < 0:
|
2023-12-07 19:38:26 +00:00
|
|
|
LOG.warn("both_add_as_friend_norequest no bob, baid")
|
|
|
|
if not hasattr(self, 'abid') or self.abid < 0:
|
|
|
|
LOG.warn("both_add_as_friend_norequest no alice, abid")
|
2023-12-06 16:32:06 +00:00
|
|
|
|
2023-07-14 14:07:08 +00:00
|
|
|
#: Test last online
|
2023-12-07 19:38:26 +00:00
|
|
|
#? assert self.alice.friend_get_last_online(self.abid) is not None
|
|
|
|
#? assert self.bob.friend_get_last_online(self.baid) is not None
|
2023-07-14 14:07:08 +00:00
|
|
|
return True
|
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def bob_add_alice_as_friend(self) -> bool:
|
2022-09-26 00:58:57 +00:00
|
|
|
"""
|
|
|
|
t:friend_add
|
|
|
|
t:on_friend_request
|
|
|
|
t:friend_by_public_key
|
|
|
|
"""
|
|
|
|
MSG = 'Alice, this is Bob.'
|
|
|
|
sSlot = 'friend_request'
|
2023-12-09 10:19:21 +00:00
|
|
|
if not self.bBobNeedAlice(): return True
|
2022-09-26 00:58:57 +00:00
|
|
|
|
|
|
|
def alices_on_friend_request(iTox,
|
|
|
|
public_key,
|
|
|
|
message_data,
|
|
|
|
message_data_size,
|
2023-12-13 00:57:28 +00:00
|
|
|
*largs) -> None:
|
2023-07-14 14:07:08 +00:00
|
|
|
LOG_DEBUG(f"alices_on_friend_request: " +repr(message_data))
|
2022-09-26 00:58:57 +00:00
|
|
|
try:
|
|
|
|
assert str(message_data, 'UTF-8') == MSG
|
2023-12-12 05:20:05 +00:00
|
|
|
LOG_INFO(f"alices_on_friend_request: {sSlot} = True ")
|
2022-09-26 00:58:57 +00:00
|
|
|
except Exception as e:
|
2023-12-12 05:20:05 +00:00
|
|
|
LOG_WARN(f"alices_on_friend_request: EXCEPTION {e}")
|
2022-09-26 00:58:57 +00:00
|
|
|
# return
|
2023-07-14 14:07:08 +00:00
|
|
|
setattr(self.bob, sSlot, True)
|
2022-09-26 00:58:57 +00:00
|
|
|
|
2023-07-14 14:07:08 +00:00
|
|
|
setattr(self.bob, sSlot, None)
|
2022-09-26 00:58:57 +00:00
|
|
|
inum = -1
|
|
|
|
try:
|
|
|
|
inum = self.bob.friend_add(self.alice._address, bytes(MSG, 'UTF-8'))
|
2023-12-12 05:20:05 +00:00
|
|
|
assert inum >= 0, f"bob_add_alice_as_friend !>= 0 {inum}"
|
2023-12-08 19:37:22 +00:00
|
|
|
self.alice.callback_friend_request(alices_on_friend_request)
|
2023-07-14 14:07:08 +00:00
|
|
|
if not self.wait_otox_attrs(self.bob, [sSlot]):
|
2023-12-12 05:20:05 +00:00
|
|
|
LOG_WARN(f"bob_add_alice_as_friend NO {sSlot}")
|
2023-12-06 16:32:06 +00:00
|
|
|
# return False
|
|
|
|
self.baid = self.bob.friend_by_public_key(self.alice._address)
|
|
|
|
assert self.baid >= 0, self.baid
|
|
|
|
assert self.bob.friend_exists(self.baid)
|
|
|
|
assert not self.bob.friend_exists(self.baid + 1)
|
|
|
|
assert self.bob.self_get_friend_list_size() >= 1
|
|
|
|
assert self.baid in self.bob.self_get_friend_list()
|
2022-09-26 00:58:57 +00:00
|
|
|
except Exception as e:
|
2023-12-12 05:20:05 +00:00
|
|
|
LOG.error(f"bob_add_alice_as_friend EXCEPTION {e}")
|
2022-09-26 00:58:57 +00:00
|
|
|
return False
|
2023-07-14 14:07:08 +00:00
|
|
|
finally:
|
|
|
|
self.bob.callback_friend_message(None)
|
2022-09-26 00:58:57 +00:00
|
|
|
|
|
|
|
return True
|
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def alice_add_bob_as_friend(self) -> bool:
|
2022-09-26 00:58:57 +00:00
|
|
|
"""
|
|
|
|
t:friend_add
|
|
|
|
t:on_friend_request
|
|
|
|
t:friend_by_public_key
|
|
|
|
"""
|
|
|
|
MSG = 'Bob, this is Alice.'
|
2023-07-14 14:07:08 +00:00
|
|
|
sSlot = 'friend_request'
|
2023-12-09 10:19:21 +00:00
|
|
|
if not self.bAliceNeedAddBob(): return True
|
2022-09-26 00:58:57 +00:00
|
|
|
|
|
|
|
def bobs_on_friend_request(iTox,
|
|
|
|
public_key,
|
|
|
|
message_data,
|
|
|
|
message_data_size,
|
2023-12-13 00:57:28 +00:00
|
|
|
*largs) -> None:
|
2023-07-14 14:07:08 +00:00
|
|
|
LOG_DEBUG(f"bobs_on_friend_request: " +repr(message_data))
|
2022-09-26 00:58:57 +00:00
|
|
|
try:
|
|
|
|
assert str(message_data, 'UTF-8') == MSG
|
|
|
|
except Exception as e:
|
2023-07-14 14:07:08 +00:00
|
|
|
LOG_WARN(f"bobs_on_friend_request: Exception {e}")
|
|
|
|
# return
|
2023-12-06 16:32:06 +00:00
|
|
|
setattr(self.alice, sSlot, True)
|
2022-09-26 00:58:57 +00:00
|
|
|
|
2023-12-12 05:20:05 +00:00
|
|
|
LOG_INFO(f"bobs_on_friend_request: {sSlot} = True ")
|
2023-07-14 14:07:08 +00:00
|
|
|
setattr(self.alice, sSlot, None)
|
2022-09-26 00:58:57 +00:00
|
|
|
inum = -1
|
|
|
|
try:
|
|
|
|
inum = self.alice.friend_add(self.bob._address, bytes(MSG, 'UTF-8'))
|
2023-12-08 19:37:22 +00:00
|
|
|
assert inum >= 0, f"alice.friend_add !>= 0 {inum}"
|
|
|
|
self.bob.callback_friend_request(bobs_on_friend_request)
|
2023-07-17 02:36:30 +00:00
|
|
|
if not self.wait_otox_attrs(self.alice, [sSlot]):
|
2023-12-07 19:38:26 +00:00
|
|
|
LOG_WARN(f"alice.friend_add NO wait {sSlot}")
|
2023-12-06 16:32:06 +00:00
|
|
|
#? return False
|
|
|
|
self.abid = self.alice.friend_by_public_key(self.bob._address)
|
|
|
|
assert self.abid >= 0, self.abid
|
|
|
|
assert self.alice.friend_exists(self.abid), "not exists"
|
|
|
|
assert not self.alice.friend_exists(self.abid + 1), "exists +1"
|
|
|
|
assert self.abid in self.alice.self_get_friend_list(), "not in list"
|
|
|
|
assert self.alice.self_get_friend_list_size() >= 1, "list size"
|
2022-09-26 00:58:57 +00:00
|
|
|
except Exception as e:
|
2023-07-14 14:07:08 +00:00
|
|
|
LOG.error(f"alice.friend_add EXCEPTION {e}")
|
2022-09-26 00:58:57 +00:00
|
|
|
return False
|
|
|
|
finally:
|
2023-07-14 14:07:08 +00:00
|
|
|
self.bob.callback_friend_message(None)
|
2022-09-26 00:58:57 +00:00
|
|
|
return True
|
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def bob_add_alice_as_friend_and_status(self) -> bool:
|
2023-12-06 16:32:06 +00:00
|
|
|
if bUSE_NOREQUEST:
|
2023-07-14 14:07:08 +00:00
|
|
|
assert self.bob_add_alice_as_friend_norequest()
|
|
|
|
else:
|
|
|
|
assert self.bob_add_alice_as_friend()
|
2022-09-26 00:58:57 +00:00
|
|
|
|
|
|
|
#: Wait until both are online
|
2023-12-08 19:37:22 +00:00
|
|
|
sSlot = 'friend_conn_status'
|
|
|
|
setattr(self.bob, sSlot, False)
|
2023-12-13 00:57:28 +00:00
|
|
|
def bobs_on_friend_connection_status(iTox, friend_id, iStatus, *largs) -> None:
|
2023-07-14 14:07:08 +00:00
|
|
|
LOG_INFO(f"bobs_on_friend_connection_status {friend_id} ?>=0" +repr(iStatus))
|
2023-12-13 00:57:28 +00:00
|
|
|
setattr(self.bob, sSlot, False)
|
2022-09-26 00:58:57 +00:00
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
sSlot = 'friend_status'
|
|
|
|
setattr(self.bob, sSlot, None)
|
|
|
|
def bobs_on_friend_status(iTox, friend_id, iStatus, *largs) -> None:
|
2023-07-14 14:07:08 +00:00
|
|
|
LOG_INFO(f"bobs_on_friend_status {friend_id} ?>=0" +repr(iStatus))
|
2023-12-13 00:57:28 +00:00
|
|
|
setattr(self.bob, sSlot, False)
|
2022-09-26 00:58:57 +00:00
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
sSlot = 'friend_conn_status'
|
|
|
|
setattr(self.alice, sSlot, None)
|
|
|
|
def alices_on_friend_connection_status(iTox, friend_id, iStatus, *largs) -> None:
|
2022-09-26 00:58:57 +00:00
|
|
|
LOG_INFO(f"alices_on_friend_connection_status {friend_id} ?>=0 " +repr(iStatus))
|
2023-12-13 00:57:28 +00:00
|
|
|
setattr(self.alice, sSlot, False)
|
2022-09-26 00:58:57 +00:00
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
sSlot = 'friend_status'
|
|
|
|
setattr(self.alice, sSlot, None)
|
|
|
|
def alices_on_friend_status(iTox, friend_id, iStatus, *largs) -> None:
|
2022-09-26 00:58:57 +00:00
|
|
|
LOG_INFO(f"alices_on_friend_status {friend_id} ?>=0 " +repr(iStatus))
|
2023-12-13 00:57:28 +00:00
|
|
|
setattr(self.alice, sSlot, False)
|
2022-09-26 00:58:57 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
LOG.info("bob_add_alice_as_friend_and_status waiting for alice connections")
|
2023-07-14 14:07:08 +00:00
|
|
|
if not self.wait_otox_attrs(self.alice,
|
2022-09-26 00:58:57 +00:00
|
|
|
['friend_conn_status',
|
|
|
|
'friend_status']):
|
|
|
|
return False
|
|
|
|
|
|
|
|
self.bob.callback_friend_connection_status(bobs_on_friend_connection_status)
|
|
|
|
self.bob.callback_friend_status(bobs_on_friend_status)
|
2023-12-13 00:57:28 +00:00
|
|
|
self.alice.callback_friend_connection_status(alices_on_friend_connection_status)
|
|
|
|
self.alice.callback_friend_status(alices_on_friend_status)
|
2022-09-26 00:58:57 +00:00
|
|
|
|
|
|
|
LOG.info("bob_add_alice_as_friend_and_status waiting for bob connections")
|
2023-07-14 14:07:08 +00:00
|
|
|
if not self.wait_otox_attrs(self.bob,
|
2022-09-26 00:58:57 +00:00
|
|
|
['friend_conn_status',
|
|
|
|
'friend_status']):
|
2023-12-07 19:38:26 +00:00
|
|
|
LOG_WARN('bob_add_alice_as_friend_and_status NO')
|
|
|
|
# return False
|
2022-09-26 00:58:57 +00:00
|
|
|
except Exception as e:
|
|
|
|
LOG.error(f"bob_add_alice_as_friend_and_status ERROR {e}")
|
|
|
|
return False
|
|
|
|
finally:
|
|
|
|
self.alice.callback_friend_connection_status(None)
|
|
|
|
self.bob.callback_friend_connection_status(None)
|
|
|
|
self.alice.callback_friend_status(None)
|
|
|
|
self.bob.callback_friend_status(None)
|
|
|
|
return True
|
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def bob_to_alice_connected(self) -> bool:
|
2023-07-17 02:36:30 +00:00
|
|
|
assert hasattr(self, 'baid')
|
|
|
|
iRet = self.bob.friend_get_connection_status(self.baid)
|
|
|
|
if iRet == TOX_CONNECTION['NONE']:
|
|
|
|
LOG.warn("bob.friend_get_connection_status")
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def alice_to_bob_connected(self) -> bool:
|
2023-07-17 02:36:30 +00:00
|
|
|
assert hasattr(self, 'abid')
|
|
|
|
iRet = self.alice.friend_get_connection_status(self.abid)
|
|
|
|
if iRet == TOX_CONNECTION['NONE']:
|
|
|
|
LOG.error("alice.friend_get_connection_status")
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
2023-12-08 19:37:22 +00:00
|
|
|
def otox_test_groups_create(self,
|
2023-07-17 02:36:30 +00:00
|
|
|
otox,
|
|
|
|
group_name='test_group',
|
|
|
|
nick='test_nick',
|
|
|
|
topic='Test Topic', # str
|
2023-12-13 00:57:28 +00:00
|
|
|
) -> int:
|
2023-07-17 02:36:30 +00:00
|
|
|
privacy_state = enums.TOX_GROUP_PRIVACY_STATE['PUBLIC']
|
|
|
|
|
|
|
|
iGrp = otox.group_new(privacy_state, group_name, nick)
|
|
|
|
assert iGrp >= 0
|
2023-12-06 16:32:06 +00:00
|
|
|
LOG.info(f"group iGrp={iGrp}")
|
2023-07-17 02:36:30 +00:00
|
|
|
|
|
|
|
otox.group_set_topic(iGrp, topic)
|
|
|
|
assert otox.group_get_topic(iGrp) == topic
|
|
|
|
assert otox.group_get_topic_size(iGrp) == len(topic)
|
|
|
|
|
2023-12-09 10:19:21 +00:00
|
|
|
name = otox.group_get_name(iGrp)
|
2023-12-10 15:59:53 +00:00
|
|
|
if type(name) == bytes:
|
|
|
|
name = str(name, 'utf-8')
|
2023-12-09 10:19:21 +00:00
|
|
|
assert name == group_name, name
|
2023-07-17 02:36:30 +00:00
|
|
|
assert otox.group_get_name_size(iGrp) == len(group_name)
|
|
|
|
|
|
|
|
sPk = otox.group_self_get_public_key(iGrp)
|
|
|
|
assert otox.group_get_password_size(iGrp) >= 0
|
|
|
|
sP = otox.group_get_password(iGrp)
|
|
|
|
assert otox.group_get_privacy_state(iGrp) == privacy_state
|
|
|
|
|
2023-12-14 20:46:56 +00:00
|
|
|
assert otox.group_get_number_groups() > 0, "numg={otox.group_get_number_groups()}"
|
|
|
|
LOG.info(f"group pK={sPk} iGrp={iGrp} numg={otox.group_get_number_groups()}")
|
2023-12-08 19:37:22 +00:00
|
|
|
return iGrp
|
2023-07-17 02:36:30 +00:00
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def otox_verify_group(self, otox, iGrp) -> int:
|
2023-12-10 15:59:53 +00:00
|
|
|
"""
|
|
|
|
group_self_get_name
|
|
|
|
group_self_get_peer_id
|
|
|
|
group_self_get_public_key
|
|
|
|
group_self_get_role
|
|
|
|
group_self_get_status
|
2023-12-13 00:57:28 +00:00
|
|
|
group_self_set_name
|
2023-12-10 15:59:53 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
group_number = iGrp
|
|
|
|
try:
|
2023-12-13 00:57:28 +00:00
|
|
|
assert type(iGrp) == int, "otox_test_groups_join iGrp not an int"
|
|
|
|
assert iGrp < UINT32_MAX, "otox_test_groups_join iGrp failure UINT32_MAX"
|
|
|
|
assert iGrp >= 0, f"otox_test_groups_join iGrp={iGrp} < 0"
|
|
|
|
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}"
|
|
|
|
sPk = otox.group_self_get_public_key(iGrp)
|
|
|
|
LOG.info(f"otox_verify_group sPk={sPk} iGrp={iGrp} n={otox.group_get_number_groups()}")
|
|
|
|
|
|
|
|
sName = otox.group_self_get_name(iGrp)
|
|
|
|
iStat = otox.group_self_get_status(iGrp)
|
|
|
|
iId = otox.group_self_get_peer_id(iGrp)
|
|
|
|
iRole = otox.group_self_get_role(iGrp)
|
|
|
|
iStat = otox.group_self_get_status(iGrp)
|
|
|
|
LOG.info(f"otox_verify_group sName={sName} iStat={iStat} iId={iId} iRole={iRole} iStat={iStat}")
|
|
|
|
|
|
|
|
assert otox.group_self_set_name(iGrp, "NewName")
|
|
|
|
|
2023-12-10 15:59:53 +00:00
|
|
|
bRet = otox.group_is_connected(iGrp)
|
|
|
|
except Exception as e:
|
|
|
|
LOG.warn(f"group_is_connected EXCEPTION {e}")
|
|
|
|
return -1
|
|
|
|
# chat->connection_state == CS_CONNECTED || chat->connection_state == CS_CONNECTING;
|
|
|
|
if not bRet:
|
|
|
|
LOG.warn(f"group_is_connected WARN not connected iGrp={iGrp} n={otox.group_get_number_groups()}")
|
|
|
|
else:
|
|
|
|
LOG.info(f"group_is_connected SUCCESS connected iGrp={iGrp} n={otox.group_get_number_groups()}")
|
|
|
|
try:
|
|
|
|
bRet = self.group_until_connected(otox, iGrp, 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 iGrp={iGrp} n={otox.group_get_number_groups()}")
|
|
|
|
else:
|
|
|
|
LOG.info(f"group_until_connected SUCCESS connected iGrp={iGrp} n={otox.group_get_number_groups()}")
|
|
|
|
|
|
|
|
message = bytes('hello', 'utf-8')
|
|
|
|
bRet = otox.group_send_message(iGrp, TOX_MESSAGE_TYPE['NORMAL'], message)
|
|
|
|
if not bRet:
|
|
|
|
LOG.warn(f"group_send_message {bRet}")
|
|
|
|
else:
|
|
|
|
LOG.debug(f"group_send_message {bRet}")
|
|
|
|
|
2023-12-10 01:20:38 +00:00
|
|
|
# 360497DA684BCE2A500C1AF9B3A5CE949BBB9F6FB1F91589806FB04CA039E313
|
|
|
|
# 75D2163C19FEFFE51508046398202DDC321E6F9B6654E99BAE45FFEC134F05DE
|
2023-12-08 19:37:22 +00:00
|
|
|
def otox_test_groups_join(self, otox,
|
2023-12-10 01:20:38 +00:00
|
|
|
chat_id="75d2163c19feffe51508046398202ddc321e6f9b6654e99bae45ffec134f05de",
|
|
|
|
nick='nick',
|
|
|
|
topic='Test Topic', # str
|
|
|
|
):
|
2023-12-08 19:37:22 +00:00
|
|
|
status = ''
|
|
|
|
password = ''
|
|
|
|
LOG.debug(f"group_join nick={nick} chat_id={chat_id}")
|
|
|
|
try:
|
2023-12-10 15:59:53 +00:00
|
|
|
iGrp = otox.group_join(chat_id, password, nick, status)
|
|
|
|
LOG.info(f"otox_test_groups_join SUCCESS iGrp={iGrp} chat_id={chat_id}")
|
|
|
|
self.otox_verify_group(otox, iGrp)
|
2023-12-10 01:20:38 +00:00
|
|
|
|
2023-12-08 19:37:22 +00:00
|
|
|
except Exception as e:
|
|
|
|
# gui
|
|
|
|
LOG.error(f"otox_test_groups_join EXCEPTION {e}")
|
|
|
|
raise
|
|
|
|
|
2023-12-10 15:59:53 +00:00
|
|
|
return iGrp
|
2023-12-08 19:37:22 +00:00
|
|
|
|
|
|
|
def otox_test_groups(self,
|
|
|
|
otox,
|
|
|
|
group_name='test_group',
|
|
|
|
nick='test_nick',
|
|
|
|
topic='Test Topic', # str
|
2023-12-13 00:57:28 +00:00
|
|
|
) -> int:
|
2023-07-17 02:36:30 +00:00
|
|
|
|
2023-12-10 01:20:38 +00:00
|
|
|
try:
|
2023-12-10 15:59:53 +00:00
|
|
|
iGrp = self.otox_test_groups_create(otox, group_name, nick, topic)
|
|
|
|
self.otox_verify_group(otox, iGrp)
|
2023-12-10 01:20:38 +00:00
|
|
|
except Exception as e:
|
2023-12-10 15:59:53 +00:00
|
|
|
LOG.error(f"otox_test_groups ERROR {e}")
|
|
|
|
raise
|
2023-07-17 02:36:30 +00:00
|
|
|
|
|
|
|
# unfinished
|
|
|
|
# tox_group_peer_exit_cb
|
|
|
|
# tox_callback_group_peer_join
|
|
|
|
# tox.callback_group_peer_status
|
|
|
|
# tox.callback_group_peer_name
|
|
|
|
# tox.callback_group_peer_exit
|
|
|
|
# tox.callback_group_peer_join
|
|
|
|
return iGrp
|
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def wait_friend_get_connection_status(self, otox, fid:int, n:int = iN) -> int:
|
2023-07-17 02:36:30 +00:00
|
|
|
i = 0
|
|
|
|
while i < n:
|
|
|
|
iRet = otox.friend_get_connection_status(fid)
|
2023-12-07 19:38:26 +00:00
|
|
|
if iRet == TOX_CONNECTION['NONE']:
|
2023-12-09 10:19:21 +00:00
|
|
|
# LOG.debug(f"wait_friend_get_connection_status NOT CONNECTED i={i} {iRet}")
|
2023-07-17 02:36:30 +00:00
|
|
|
self.loop_until_connected()
|
|
|
|
else:
|
2023-12-07 19:38:26 +00:00
|
|
|
LOG.info("wait_friend_get_connection_status {iRet}")
|
2023-07-17 02:36:30 +00:00
|
|
|
return True
|
|
|
|
i += 1
|
|
|
|
else:
|
2023-12-08 19:37:22 +00:00
|
|
|
LOG.error(f"wait_friend_get_connection_status n={n}")
|
2023-07-17 02:36:30 +00:00
|
|
|
return False
|
2022-09-26 00:58:57 +00:00
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def warn_if_no_cb(self, alice, sSlot:str) -> None:
|
2022-09-26 00:58:57 +00:00
|
|
|
if not hasattr(alice, sSlot+'_cb') or \
|
|
|
|
not getattr(alice, sSlot+'_cb'):
|
2023-07-14 14:07:08 +00:00
|
|
|
LOG.warning(f"self.bob.{sSlot}_cb NOT EXIST")
|
2022-09-26 00:58:57 +00:00
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def warn_if_cb(self, alice, sSlot:str) -> None:
|
2022-09-26 00:58:57 +00:00
|
|
|
if hasattr(self.bob, sSlot+'_cb') and \
|
|
|
|
getattr(self.bob, sSlot+'_cb'):
|
2023-07-14 14:07:08 +00:00
|
|
|
LOG.warning(f"self.bob.{sSlot}_cb EXIST")
|
2022-09-26 00:58:57 +00:00
|
|
|
|
|
|
|
# tests are executed in order
|
2023-12-13 00:57:28 +00:00
|
|
|
def test_notice_log(self) -> None: # works
|
2023-07-14 14:07:08 +00:00
|
|
|
notice = '/var/lib/tor/.SelekTOR/3xx/cache/9050/notice.log'
|
2023-07-17 02:36:30 +00:00
|
|
|
if os.path.exists(notice):
|
2023-07-14 14:07:08 +00:00
|
|
|
iRet = os.system(f"sudo sed -e '1,/.notice. Bootstrapped 100%/d' {notice}" + \
|
|
|
|
"| grep 'Tried for 120 seconds to get a connection to :0.'")
|
|
|
|
if iRet == 0:
|
|
|
|
raise SystemExit("seconds to get a connection to :0")
|
|
|
|
else:
|
|
|
|
LOG.debug(f"checked {notice}")
|
|
|
|
|
2022-09-26 00:58:57 +00:00
|
|
|
def test_tests_logging(self): # works
|
|
|
|
with self.assertLogs('foo', level='INFO') as cm:
|
|
|
|
logging.getLogger('foo').info('first message')
|
|
|
|
logging.getLogger('foo.bar').error('second message')
|
|
|
|
logging.getLogger('foo.bar.baz').debug('third message')
|
|
|
|
self.assertEqual(cm.output, ['INFO:foo:first message',
|
|
|
|
'ERROR:foo.bar:second message'])
|
|
|
|
|
2023-12-14 20:46:56 +00:00
|
|
|
def test_hash(self): # works
|
|
|
|
otox = self.bob
|
|
|
|
string = 'abcdef'
|
2023-12-16 23:23:00 +00:00
|
|
|
name = otox.hash(bytes(string, 'utf-8'))
|
2023-12-14 20:46:56 +00:00
|
|
|
assert name
|
|
|
|
string = b'abcdef'
|
|
|
|
name = otox.hash(string)
|
|
|
|
assert name
|
|
|
|
LOG.info(f"test_hash: {string} -> {name} ")
|
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def test_tests_start(self) -> None: # works
|
2023-12-06 16:32:06 +00:00
|
|
|
"""
|
|
|
|
t:hash
|
|
|
|
t:kill
|
|
|
|
t:libtoxcore
|
|
|
|
t:options_default
|
|
|
|
t:options_free
|
|
|
|
t:options_new
|
|
|
|
t:self_get_toxid
|
|
|
|
"""
|
2022-09-26 00:58:57 +00:00
|
|
|
LOG.info("test_tests_start " )
|
|
|
|
port = ts.tox_bootstrapd_port()
|
|
|
|
|
|
|
|
assert len(self.bob._address) == 2*TOX_ADDRESS_SIZE, len(self.bob._address)
|
|
|
|
assert len(self.alice._address) == 2*TOX_ADDRESS_SIZE, \
|
|
|
|
len(self.alice._address)
|
|
|
|
|
2023-12-06 16:32:06 +00:00
|
|
|
assert self.bob.self_get_address() == self.bob._address
|
2023-12-14 20:46:56 +00:00
|
|
|
assert self.alice.self_get_address() == self.alice._address
|
2023-12-06 16:32:06 +00:00
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def test_bootstrap_local_netstat(self) -> None: # works
|
2022-09-26 00:58:57 +00:00
|
|
|
"""
|
2023-12-06 16:32:06 +00:00
|
|
|
t:callback_file_chunk_request
|
|
|
|
t:callback_file_recv
|
|
|
|
t:callback_file_recv_chunk
|
|
|
|
t:callback_file_recv_control
|
|
|
|
t:callback_friend_connection_status
|
|
|
|
t:callback_friend_lossless_packet
|
|
|
|
t:callback_friend_lossy_packet
|
|
|
|
t:callback_friend_message
|
|
|
|
t:callback_friend_name
|
|
|
|
t:callback_friend_read_receipt
|
|
|
|
t:callback_friend_request
|
|
|
|
t:callback_friend_status
|
|
|
|
t:callback_friend_status_message
|
|
|
|
t:callback_friend_typing
|
|
|
|
t:callback_group_custom_packet
|
|
|
|
t:callback_group_invite
|
2022-09-26 00:58:57 +00:00
|
|
|
"""
|
|
|
|
if oTOX_OARGS.network not in ['new', 'newlocal', 'local']:
|
|
|
|
return
|
|
|
|
|
|
|
|
port = ts.tox_bootstrapd_port()
|
|
|
|
if not port:
|
|
|
|
return
|
|
|
|
iStatus = os.system(f"""netstat -nle4 | grep :{port}""")
|
|
|
|
if iStatus == 0:
|
|
|
|
LOG.info(f"bootstrap_local_netstat port {port} iStatus={iStatus}")
|
|
|
|
else:
|
2023-07-14 14:07:08 +00:00
|
|
|
LOG.warning(f"bootstrap_local_netstat NOT {port} iStatus={iStatus}")
|
2022-09-26 00:58:57 +00:00
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def test_bootstrap_local(self) -> None: # works
|
2022-09-26 00:58:57 +00:00
|
|
|
"""
|
2023-12-06 16:32:06 +00:00
|
|
|
t:call_bootstrap
|
|
|
|
t:add_tcp_relay
|
|
|
|
t:self_get_dht_id
|
2022-09-26 00:58:57 +00:00
|
|
|
"""
|
|
|
|
# get port from /etc/tox-bootstrapd.conf 33445
|
|
|
|
self.call_bootstrap()
|
|
|
|
# ts.bootstrap_local(self, self.lUdp)
|
|
|
|
i = 0
|
|
|
|
iStatus = -1
|
|
|
|
while i < 10:
|
|
|
|
i = i + 1
|
|
|
|
iStatus = self.bob.self_get_connection_status()
|
|
|
|
if iStatus != TOX_CONNECTION['NONE']:
|
|
|
|
break
|
|
|
|
sleep(3)
|
|
|
|
else:
|
|
|
|
pass
|
|
|
|
|
|
|
|
o1 = self.alice.self_get_dht_id()
|
|
|
|
assert len(o1) == 64
|
|
|
|
o2 = self.bob.self_get_dht_id()
|
|
|
|
assert len(o2) == 64
|
|
|
|
|
2023-07-14 14:07:08 +00:00
|
|
|
# if o1 != o2: LOG.warning(f"bootstrap_local DHT NOT same {o1} {o2} iStatus={iStatus}")
|
2022-11-23 20:02:29 +00:00
|
|
|
|
2022-09-26 00:58:57 +00:00
|
|
|
iStatus = self.bob.self_get_connection_status()
|
|
|
|
if iStatus != TOX_CONNECTION['NONE']:
|
|
|
|
LOG.info(f"bootstrap_local connected iStatus={iStatus}")
|
|
|
|
return True
|
|
|
|
iStatus = self.alice.self_get_connection_status()
|
|
|
|
if iStatus != TOX_CONNECTION['NONE']:
|
|
|
|
LOG.info(f"bootstrap_local connected iStatus={iStatus}")
|
|
|
|
return True
|
2023-07-14 14:07:08 +00:00
|
|
|
LOG.warning(f"bootstrap_local NOT CONNECTED iStatus={iStatus}")
|
2022-09-26 00:58:57 +00:00
|
|
|
return False
|
2022-11-23 20:02:29 +00:00
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def test_bootstrap_iNmapInfo(self) -> None: # works
|
2023-12-06 16:32:06 +00:00
|
|
|
# if os.environ['USER'] != 'root':
|
|
|
|
# return
|
|
|
|
iStatus = self.bob.self_get_connection_status()
|
|
|
|
LOG.info(f"test_bootstrap_iNmapInfo connected bob iStatus={iStatus}")
|
2022-09-29 06:48:31 +00:00
|
|
|
if oTOX_OARGS.network in ['new', 'newlocal', 'localnew']:
|
|
|
|
lElts = self.lUdp
|
|
|
|
elif oTOX_OARGS.proxy_port > 0:
|
|
|
|
lElts = self.lTcp
|
|
|
|
else:
|
|
|
|
lElts = self.lUdp
|
|
|
|
lRetval = []
|
|
|
|
random.shuffle(lElts)
|
2022-11-23 20:02:29 +00:00
|
|
|
# assert
|
2022-10-18 00:16:56 +00:00
|
|
|
ts.bootstrap_iNmapInfo(lElts, oTOX_OARGS, bIS_LOCAL, iNODES=8)
|
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def test_self_get_secret_key(self) -> None: # works
|
2022-09-26 00:58:57 +00:00
|
|
|
"""
|
|
|
|
t:self_get_secret_key
|
|
|
|
"""
|
|
|
|
# test_self_get_secret_key
|
|
|
|
CRYPTO_SECRET_KEY_SIZE = 32
|
|
|
|
secret_key = create_string_buffer(CRYPTO_SECRET_KEY_SIZE)
|
|
|
|
oRet0 = self.alice.self_get_secret_key(secret_key)
|
|
|
|
assert oRet0, repr(oRet0)
|
|
|
|
LOG.info('test_self_get_secret_key ' +repr(oRet0))
|
|
|
|
assert len(str(oRet0))
|
|
|
|
del secret_key
|
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def test_self_get_public_keys(self) -> None: # works
|
2022-09-26 00:58:57 +00:00
|
|
|
"""
|
|
|
|
t:self_get_secret_key
|
|
|
|
t:self_get_public_key
|
|
|
|
"""
|
|
|
|
|
|
|
|
LOG.info('test_self_get_public_keys self.alice.self_get_secret_key')
|
|
|
|
oRet0 = self.alice.self_get_secret_key()
|
|
|
|
assert len(oRet0)
|
|
|
|
LOG.info('test_self_get_public_keys ' +repr(oRet0))
|
|
|
|
oRet1 = self.alice.self_get_public_key()
|
|
|
|
assert len(oRet1)
|
|
|
|
LOG.info('test_self_get_public_keys ' +repr(oRet1))
|
|
|
|
assert oRet0 != oRet1, repr(oRet0) +' != ' +repr(oRet1)
|
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def test_self_name(self) -> None: # works
|
2022-09-26 00:58:57 +00:00
|
|
|
"""
|
|
|
|
t:self_set_name
|
|
|
|
t:self_get_name
|
|
|
|
t:self_get_name_size
|
|
|
|
"""
|
|
|
|
self.alice.self_set_name('Alice')
|
|
|
|
assert self.alice.self_get_name() == 'Alice'
|
|
|
|
assert self.alice.self_get_name_size() == len('Alice')
|
2023-07-14 14:07:08 +00:00
|
|
|
self.bob.self_set_name('Bob')
|
|
|
|
assert self.bob.self_get_name() == 'Bob'
|
|
|
|
assert self.bob.self_get_name_size() == len('Bob')
|
2022-09-26 00:58:57 +00:00
|
|
|
|
|
|
|
@unittest.skip('loud')
|
2022-09-26 03:32:07 +00:00
|
|
|
@unittest.skipIf(bIS_NOT_TOXYGEN or oTOX_OARGS.mode == 0, 'not testing in toxygen')
|
2023-12-13 00:57:28 +00:00
|
|
|
def test_sound_notification(self) -> None: # works
|
2022-09-26 00:58:57 +00:00
|
|
|
"""
|
|
|
|
Plays sound notification
|
|
|
|
:param type of notification
|
|
|
|
"""
|
2023-07-14 14:07:08 +00:00
|
|
|
from tests.toxygen_tests import test_sound_notification
|
2022-09-26 00:58:57 +00:00
|
|
|
test_sound_notification(self)
|
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def test_address(self) -> None: # works
|
2023-07-14 14:07:08 +00:00
|
|
|
"""
|
|
|
|
t:self_get_address
|
|
|
|
t:self_get_nospam
|
|
|
|
t:self_set_nospam
|
|
|
|
t:self_get_keys
|
|
|
|
"""
|
|
|
|
assert len(self.alice.self_get_address()) == ADDR_SIZE
|
|
|
|
assert len(self.bob.self_get_address()) == ADDR_SIZE
|
|
|
|
|
|
|
|
self.alice.self_set_nospam(0x12345678)
|
|
|
|
assert self.alice.self_get_nospam() == 0x12345678
|
|
|
|
self.loop(50)
|
|
|
|
|
|
|
|
if hasattr(self.alice, 'self_get_keys'):
|
|
|
|
pk, sk = self.alice.self_get_keys()
|
|
|
|
assert pk == self.alice.self_get_address()[:CLIENT_ID_SIZE]
|
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def test_status_message(self) -> None: # works
|
2023-12-06 16:32:06 +00:00
|
|
|
"""
|
|
|
|
t:self_get_status_message
|
|
|
|
t:self_get_status_message_size
|
|
|
|
"""
|
2023-07-14 14:07:08 +00:00
|
|
|
MSG = 'Happy'
|
|
|
|
self.alice.self_set_status_message(MSG)
|
|
|
|
self.loop(100)
|
|
|
|
assert self.alice.self_get_status_message() == MSG, \
|
|
|
|
self.alice.self_get_status_message() +' is not ' +MSG
|
|
|
|
assert self.alice.self_get_status_message_size() == len(MSG)
|
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def test_self_get_udp_port(self) -> None: # works
|
2022-09-26 00:58:57 +00:00
|
|
|
"""
|
|
|
|
t:self_get_udp_port
|
|
|
|
"""
|
|
|
|
if hasattr(oTOX_OPTIONS, 'udp_port') and oTOX_OPTIONS.udp_port:
|
|
|
|
o = self.alice.self_get_udp_port()
|
2023-07-14 14:07:08 +00:00
|
|
|
LOG.info('self_get_udp_port alice ' +repr(o))
|
|
|
|
assert o > 0
|
|
|
|
o = self.bob.self_get_udp_port()
|
|
|
|
LOG.info('self_get_udp_port bob ' +repr(o))
|
2022-09-26 00:58:57 +00:00
|
|
|
assert o > 0
|
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def test_self_get_tcp_port(self) -> None: # works
|
2022-09-26 00:58:57 +00:00
|
|
|
"""
|
|
|
|
t:self_get_tcp_port
|
|
|
|
"""
|
|
|
|
if hasattr(oTOX_OPTIONS, 'tcp_port') and oTOX_OPTIONS.tcp_port:
|
|
|
|
# errors if tcp_port <= 0
|
|
|
|
o = self.alice.self_get_tcp_port()
|
|
|
|
LOG.info('self_get_tcp_port ' +repr(o))
|
2023-07-14 14:07:08 +00:00
|
|
|
o = self.bob.self_get_tcp_port()
|
|
|
|
LOG.info('self_get_tcp_port ' +repr(o))
|
2022-09-26 00:58:57 +00:00
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def test_get_dht_id(self) -> None: # works
|
2022-09-26 00:58:57 +00:00
|
|
|
"""
|
|
|
|
t:self_get_dht_id
|
|
|
|
"""
|
|
|
|
o1 = self.alice.self_get_dht_id()
|
|
|
|
assert len(o1) == 64
|
|
|
|
o2 = self.bob.self_get_dht_id()
|
|
|
|
assert len(o2) == 64
|
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def test_bob_add_alice_as_friend_norequest(self) -> None: # works
|
2023-07-17 02:36:30 +00:00
|
|
|
"""
|
|
|
|
t:friend_delete
|
|
|
|
t:friend_exists
|
2023-12-06 16:32:06 +00:00
|
|
|
t:friend_add_norequest
|
2023-07-17 02:36:30 +00:00
|
|
|
t:friend_get_public_key
|
|
|
|
t:self_get_friend_list
|
|
|
|
t:self_get_friend_list_size
|
|
|
|
"""
|
2023-12-06 16:32:06 +00:00
|
|
|
i = len(self.bob.self_get_friend_list())
|
2023-07-14 14:07:08 +00:00
|
|
|
assert self.bob_add_alice_as_friend_norequest()
|
2023-12-06 16:32:06 +00:00
|
|
|
assert len(self.bob.self_get_friend_list()) == i + 1
|
2022-09-26 00:58:57 +00:00
|
|
|
#: Test last online
|
|
|
|
assert self.bob.friend_get_last_online(self.baid) is not None
|
2023-12-06 16:32:06 +00:00
|
|
|
if hasattr(self, 'baid') and self.baid >= 0:
|
|
|
|
self.bob.friend_delete(self.baid)
|
2022-09-26 00:58:57 +00:00
|
|
|
|
2023-12-07 19:38:26 +00:00
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def test_alice_add_bob_as_friend_norequest(self) -> None: # works - intermittent failures
|
2023-07-17 02:36:30 +00:00
|
|
|
"""
|
|
|
|
t:friend_delete
|
|
|
|
t:friend_exists
|
|
|
|
t:friend_get_public_key
|
|
|
|
t:self_get_friend_list
|
|
|
|
t:self_get_friend_list_size
|
|
|
|
"""
|
2023-12-06 16:32:06 +00:00
|
|
|
i = len(self.alice.self_get_friend_list())
|
2023-07-14 14:07:08 +00:00
|
|
|
assert self.alice_add_bob_as_friend_norequest()
|
2023-12-06 16:32:06 +00:00
|
|
|
assert len(self.alice.self_get_friend_list()) == i + 1
|
2022-09-26 00:58:57 +00:00
|
|
|
#: Test last online
|
|
|
|
assert self.alice.friend_get_last_online(self.abid) is not None
|
2023-12-06 16:32:06 +00:00
|
|
|
if hasattr(self, 'abid') and self.abid >= 0:
|
|
|
|
self.alice.friend_delete(self.abid)
|
2022-09-26 00:58:57 +00:00
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def test_both_add_as_friend_norequest(self) -> None: # works
|
2023-07-17 02:36:30 +00:00
|
|
|
"""
|
|
|
|
t:friend_delete
|
|
|
|
t:friend_exists
|
|
|
|
t:friend_get_public_key
|
|
|
|
t:self_get_friend_list
|
|
|
|
t:self_get_friend_list_size
|
|
|
|
"""
|
2023-12-06 16:32:06 +00:00
|
|
|
try:
|
|
|
|
self.both_add_as_friend_norequest()
|
2023-12-07 19:38:26 +00:00
|
|
|
assert len(self.bob.self_get_friend_list()) > 0
|
|
|
|
assert len(self.alice.self_get_friend_list()) > 0
|
|
|
|
except AssertionError as e:
|
|
|
|
LOG.error(f"Failed test {e}")
|
|
|
|
raise
|
|
|
|
except Exception as e:
|
|
|
|
LOG.error(f"Failed test {e}")
|
|
|
|
raise
|
2023-12-06 16:32:06 +00:00
|
|
|
finally:
|
|
|
|
if hasattr(self, 'baid') and self.baid >= 0:
|
|
|
|
self.bob.friend_delete(self.baid)
|
|
|
|
assert len(self.bob.self_get_friend_list()) == 0
|
|
|
|
if hasattr(self, 'abid') and self.abid >= 0:
|
|
|
|
self.alice.friend_delete(self.abid)
|
|
|
|
assert len(self.alice.self_get_friend_list()) == 0
|
2022-09-26 00:58:57 +00:00
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def test_bob_add_alice_as_friend_and_status(self) -> None:
|
2023-07-17 02:36:30 +00:00
|
|
|
"""
|
|
|
|
t:friend_delete
|
|
|
|
t:friend_exists
|
|
|
|
t:friend_get_public_key
|
|
|
|
t:self_get_friend_list
|
|
|
|
t:self_get_friend_list_size
|
|
|
|
"""
|
2023-07-14 14:07:08 +00:00
|
|
|
self.bob_add_alice_as_friend_and_status()
|
2023-12-06 16:32:06 +00:00
|
|
|
if hasattr(self, 'baid') and self.baid >= 0:
|
|
|
|
self.bob.friend_delete(self.baid)
|
2022-09-26 00:58:57 +00:00
|
|
|
|
2023-12-08 19:37:22 +00:00
|
|
|
@unittest.skip('unfinished')
|
2023-12-13 00:57:28 +00:00
|
|
|
def test_alice_add_bob_as_friend_and_status(self) -> None:
|
2023-12-08 19:37:22 +00:00
|
|
|
assert self.alice_add_bob_as_friend_and_status()
|
|
|
|
if hasattr(self, 'abid') and self.abid >= 0:
|
|
|
|
self.alice.friend_delete(self.abid)
|
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def test_loop_until_connected(self) -> None: # works
|
2023-07-17 02:36:30 +00:00
|
|
|
assert self.loop_until_connected()
|
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def test_bob_assert_connection_status(self) -> None: # works
|
2023-07-17 02:36:30 +00:00
|
|
|
if self.bob.self_get_connection_status() == TOX_CONNECTION['NONE']:
|
|
|
|
AssertionError("ERROR: NOT CONNECTED " \
|
|
|
|
+repr(self.bob.self_get_connection_status()))
|
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def test_alice_assert_connection_status(self) -> None: # works
|
2023-07-17 02:36:30 +00:00
|
|
|
if self.alice.self_get_connection_status() == TOX_CONNECTION['NONE']:
|
|
|
|
AssertionError("ERROR: NOT CONNECTED " \
|
|
|
|
+repr(self.alice.self_get_connection_status()))
|
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def test_bob_assert_mycon_status(self) -> None: # works
|
2023-07-17 02:36:30 +00:00
|
|
|
if self.bob.mycon_status == False:
|
|
|
|
AssertionError("ERROR: NOT CONNECTED " \
|
|
|
|
+repr(self.bob.mycon_status))
|
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def test_alice_assert_mycon_status(self) -> None: # works
|
2023-07-17 02:36:30 +00:00
|
|
|
if self.alice.mycon_status == False:
|
|
|
|
AssertionError("ERROR: NOT CONNECTED " \
|
|
|
|
+repr(self.alice.mycon_status))
|
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def test_bob_add_alice_as_friend(self) -> None: # works?
|
2023-07-14 14:07:08 +00:00
|
|
|
try:
|
2023-12-09 10:19:21 +00:00
|
|
|
if bUSE_NOREQUEST:
|
|
|
|
assert self.bob_add_alice_as_friend_norequest()
|
|
|
|
else:
|
|
|
|
assert self.bob_add_alice_as_friend()
|
2023-07-14 14:07:08 +00:00
|
|
|
#: Test last online
|
|
|
|
assert self.bob.friend_get_last_online(self.baid) is not None
|
|
|
|
except AssertionError as e:
|
2023-07-17 02:36:30 +00:00
|
|
|
LOG.error(f"Failed test {e}")
|
|
|
|
raise
|
|
|
|
except Exception as e:
|
|
|
|
LOG.error(f"Failed test {e}")
|
|
|
|
raise
|
2023-07-14 14:07:08 +00:00
|
|
|
finally:
|
2023-07-17 02:36:30 +00:00
|
|
|
if hasattr(self, 'baid') and self.baid >= 0:
|
|
|
|
self.bob.friend_delete(self.baid)
|
|
|
|
if len(self.bob.self_get_friend_list()) > 0:
|
|
|
|
LOG.warn(f"WTF bob.self_get_friend_list() {bob.self_get_friend_list()}")
|
2023-07-14 14:07:08 +00:00
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def test_alice_add_bob_as_friend(self) -> None: # works!
|
2023-07-14 14:07:08 +00:00
|
|
|
try:
|
2023-12-09 10:19:21 +00:00
|
|
|
if bUSE_NOREQUEST:
|
|
|
|
assert self.alice_add_bob_as_friend_norequest()
|
|
|
|
else:
|
|
|
|
assert self.alice_add_bob_as_friend()
|
2023-07-14 14:07:08 +00:00
|
|
|
#: Test last online
|
|
|
|
assert self.alice.friend_get_last_online(self.abid) is not None
|
|
|
|
except AssertionError as e:
|
2023-07-17 02:36:30 +00:00
|
|
|
#WTF?
|
|
|
|
if hasattr(self, 'abid') and self.abid >= 0:
|
|
|
|
self.alice.friend_delete(self.abid)
|
|
|
|
LOG.error(f"Failed test {e}")
|
|
|
|
raise
|
2023-07-14 14:07:08 +00:00
|
|
|
except Exception as e:
|
2023-07-17 02:36:30 +00:00
|
|
|
#WTF?
|
2023-07-14 14:07:08 +00:00
|
|
|
LOG.error(f"test_alice_add_bob_as_friend EXCEPTION {e}")
|
|
|
|
raise
|
|
|
|
finally:
|
2023-12-07 19:38:26 +00:00
|
|
|
if hasattr(self, 'baid') and self.baid >= 0:
|
|
|
|
self.bob.friend_delete(self.baid)
|
2023-07-17 02:36:30 +00:00
|
|
|
if hasattr(self, 'abid') and self.abid >= 0:
|
|
|
|
self.alice.friend_delete(self.abid)
|
|
|
|
if len(self.alice.self_get_friend_list()) > 0:
|
|
|
|
LOG.warn(f"WTF alice.self_get_friend_list() {alice.self_get_friend_list()}")
|
2022-09-26 00:58:57 +00:00
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def test_both_add_as_friend(self) -> None: # works
|
2023-07-14 14:07:08 +00:00
|
|
|
try:
|
2023-12-09 10:19:21 +00:00
|
|
|
if bUSE_NOREQUEST:
|
|
|
|
assert self.both_add_as_friend_norequest()
|
|
|
|
else:
|
|
|
|
assert self.both_add_as_friend()
|
2023-07-14 14:07:08 +00:00
|
|
|
except AssertionError as e:
|
2023-07-17 02:36:30 +00:00
|
|
|
LOG.warn(f"Failed test {e}")
|
|
|
|
raise
|
2023-07-14 14:07:08 +00:00
|
|
|
except Exception as e:
|
|
|
|
LOG.error(f"test_both_add_as_friend EXCEPTION {e}")
|
|
|
|
raise
|
|
|
|
finally:
|
2023-12-07 19:38:26 +00:00
|
|
|
if hasattr(self,'baid') and self.baid >= 0:
|
2023-12-06 16:32:06 +00:00
|
|
|
self.bob.friend_delete(self.baid)
|
2023-12-07 19:38:26 +00:00
|
|
|
if hasattr(self,'abid') and self.abid >= 0:
|
2023-12-06 16:32:06 +00:00
|
|
|
self.alice.friend_delete(self.abid)
|
2022-09-26 00:58:57 +00:00
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def test_groups_join(self) -> None:
|
2023-12-08 19:37:22 +00:00
|
|
|
"""
|
|
|
|
t:group_join
|
|
|
|
t:group_disconnect
|
|
|
|
t:group_leave
|
2023-12-13 00:57:28 +00:00
|
|
|
t:group_self_set_name
|
2023-12-08 19:37:22 +00:00
|
|
|
"""
|
2023-12-10 01:20:38 +00:00
|
|
|
if not self.get_connection_status():
|
|
|
|
LOG.warning(f"test_groups_join NOT CONNECTED")
|
|
|
|
self.loop_until_connected()
|
|
|
|
|
2023-12-08 19:37:22 +00:00
|
|
|
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
|
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def test_groups(self) -> None:
|
2023-07-17 02:36:30 +00:00
|
|
|
"""
|
|
|
|
t:group_new
|
|
|
|
t:group_disconnect
|
|
|
|
t:group_get_name
|
|
|
|
t:group_get_name_size
|
|
|
|
t:group_get_topic
|
|
|
|
t:group_get_topic_size
|
|
|
|
t:group_get_privacy_state
|
2023-12-13 00:57:28 +00:00
|
|
|
t:group_self_set_name
|
|
|
|
t:group_get_number_groups
|
2023-07-17 02:36:30 +00:00
|
|
|
|
|
|
|
t:group_founder_set_password
|
|
|
|
t:group_founder_set_peer_limit
|
|
|
|
t:group_founder_set_privacy_state
|
|
|
|
t:group_get_chat_id
|
|
|
|
t:group_get_password
|
|
|
|
t:group_get_password_size
|
|
|
|
t:group_get_peer_limit
|
|
|
|
t:group_invite_accept
|
|
|
|
t:group_invite_friend
|
|
|
|
t:group_is_connected
|
|
|
|
t:group_leave
|
|
|
|
t:group_mod_set_role
|
|
|
|
"""
|
|
|
|
iGrp = self.otox_test_groups(self.bob)
|
|
|
|
LOG.info(f"test_groups iGrp={iGrp}")
|
|
|
|
if iGrp >= 0:
|
|
|
|
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
|
|
|
|
|
2023-12-10 15:59:53 +00:00
|
|
|
#? @unittest.skip("double free or corruption (fasttop)")
|
|
|
|
@expectedFail('fails') # assertion fails on == MSG
|
2023-12-13 00:57:28 +00:00
|
|
|
def test_on_friend_status_message(self) -> None: # fails
|
2022-09-26 00:58:57 +00:00
|
|
|
"""
|
|
|
|
t:self_set_status_message
|
|
|
|
t:self_get_status_message
|
|
|
|
t:self_get_status_message_size
|
|
|
|
t:friend_set_status_message
|
|
|
|
t:friend_get_status_message
|
|
|
|
t:friend_get_status_message_size
|
|
|
|
t:on_friend_status_message
|
|
|
|
"""
|
|
|
|
MSG = 'Happy'
|
|
|
|
sSlot = 'friend_status_message'
|
2022-11-23 20:02:29 +00:00
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def bob_on_friend_status_message(iTox, friend_id, new_status_message, new_status_size, *largs) -> None:
|
2023-12-06 16:32:06 +00:00
|
|
|
LOG_INFO(f"BOB_ON_friend_status_message friend_id={friend_id} " \
|
2023-07-17 02:36:30 +00:00
|
|
|
+f"new_status_message={new_status_message}")
|
2022-09-26 00:58:57 +00:00
|
|
|
try:
|
|
|
|
assert str(new_status_message, 'UTF-8') == MSG
|
|
|
|
assert friend_id == self.baid
|
|
|
|
except Exception as e:
|
2023-12-06 16:32:06 +00:00
|
|
|
LOG_ERROR(f"BOB_ON_friend_status_message EXCEPTION {e}")
|
2023-07-14 14:07:08 +00:00
|
|
|
setattr(self.bob, sSlot, True)
|
2022-09-26 00:58:57 +00:00
|
|
|
|
2023-07-14 14:07:08 +00:00
|
|
|
setattr(self.bob, sSlot, None)
|
2022-09-26 00:58:57 +00:00
|
|
|
try:
|
2023-12-06 16:32:06 +00:00
|
|
|
if bUSE_NOREQUEST:
|
2023-12-10 15:59:53 +00:00
|
|
|
assert self.bob_add_alice_as_friend_norequest()
|
2023-12-14 20:46:56 +00:00
|
|
|
assert self.alice_add_bob_as_friend_norequest()
|
2023-07-14 14:07:08 +00:00
|
|
|
else:
|
2023-12-10 15:59:53 +00:00
|
|
|
# no not connected error
|
|
|
|
assert self.bob_add_alice_as_friend()
|
2023-12-14 20:46:56 +00:00
|
|
|
assert self.alice_add_bob_as_friend_norequest()
|
2023-07-14 14:07:08 +00:00
|
|
|
|
2022-09-26 00:58:57 +00:00
|
|
|
self.bob.callback_friend_status_message(bob_on_friend_status_message)
|
|
|
|
self.warn_if_no_cb(self.bob, sSlot)
|
2023-12-06 16:32:06 +00:00
|
|
|
status_message = bytes(MSG, 'utf-8')
|
|
|
|
self.alice.self_set_status_message(status_message)
|
|
|
|
if not self.wait_otox_attrs(self.bob, [sSlot]):
|
2023-12-07 19:38:26 +00:00
|
|
|
LOG_WARN(f"on_friend_status_message NO {sSlot}")
|
2022-09-26 00:58:57 +00:00
|
|
|
|
2023-12-06 16:32:06 +00:00
|
|
|
assert self.bob.friend_get_status_message(self.baid) == MSG, \
|
|
|
|
f"message={self.bob.friend_get_status_message(self.baid)}"
|
|
|
|
assert self.bob.friend_get_status_message_size(self.baid) == len(MSG), \
|
|
|
|
f"message_len={self.bob.friend_get_status_message_size(self.baid)}"
|
2022-09-26 00:58:57 +00:00
|
|
|
|
|
|
|
except AssertionError as e:
|
2023-12-07 19:38:26 +00:00
|
|
|
LOG.error(f"test_on_friend_status_message FAILED {e}")
|
2023-07-17 02:36:30 +00:00
|
|
|
raise
|
2022-09-26 00:58:57 +00:00
|
|
|
except Exception as e:
|
|
|
|
LOG.error(f"test_on_friend_status_message EXCEPTION {e}")
|
|
|
|
raise
|
|
|
|
finally:
|
2023-07-17 02:36:30 +00:00
|
|
|
self.bob.callback_friend_status(None)
|
2023-12-06 16:32:06 +00:00
|
|
|
if hasattr(self, 'baid') and self.baid >= 0:
|
|
|
|
self.bob.friend_delete(self.baid)
|
|
|
|
if hasattr(self, 'abid') and self.abid >= 0:
|
2023-12-07 19:38:26 +00:00
|
|
|
self.alice.friend_delete(self.abid)
|
2022-09-26 00:58:57 +00:00
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def test_friend(self) -> None: # works! sometimes
|
2022-09-26 00:58:57 +00:00
|
|
|
"""
|
|
|
|
t:friend_get_name
|
|
|
|
t:friend_get_name_size
|
|
|
|
t:on_friend_name
|
2023-07-14 14:07:08 +00:00
|
|
|
"""
|
2022-09-26 00:58:57 +00:00
|
|
|
|
2023-07-14 14:07:08 +00:00
|
|
|
try:
|
2023-12-10 15:59:53 +00:00
|
|
|
#: Test friend request
|
|
|
|
if bUSE_NOREQUEST:
|
|
|
|
assert self.bob_add_alice_as_friend_norequest()
|
|
|
|
assert self.alice_add_bob_as_friend_norequest()
|
|
|
|
else:
|
|
|
|
# no not connected error
|
|
|
|
assert self.bob_add_alice_as_friend()
|
|
|
|
assert self.alice_add_bob_as_friend_norequest()
|
|
|
|
|
2023-12-06 16:32:06 +00:00
|
|
|
a = self.alice.self_get_address()[:CLIENT_ID_SIZE]
|
2023-12-07 19:38:26 +00:00
|
|
|
assert self.bob.friend_get_public_key(self.baid) == a, \
|
|
|
|
LOG.error(f"test_friend BAID {a}")
|
2023-12-06 16:32:06 +00:00
|
|
|
del a
|
2023-12-07 19:38:26 +00:00
|
|
|
|
2023-07-14 14:07:08 +00:00
|
|
|
#: Test friend_get_public_key
|
2023-12-06 16:32:06 +00:00
|
|
|
b = self.bob.self_get_address()[:CLIENT_ID_SIZE]
|
2023-12-07 19:38:26 +00:00
|
|
|
assert self.alice.friend_get_public_key(self.abid) == b, \
|
|
|
|
LOG.error(f"test_friend ABID {b}")
|
2023-12-06 16:32:06 +00:00
|
|
|
del b
|
2023-07-14 14:07:08 +00:00
|
|
|
except AssertionError as e:
|
2023-07-17 02:36:30 +00:00
|
|
|
LOG.error(f"Failed test {e}")
|
|
|
|
raise
|
2023-07-14 14:07:08 +00:00
|
|
|
except Exception as e:
|
|
|
|
LOG.error(f"test_friend EXCEPTION {e}")
|
|
|
|
raise
|
|
|
|
finally:
|
2023-12-06 16:32:06 +00:00
|
|
|
if hasattr(self, 'baid') and self.baid >= 0:
|
|
|
|
self.bob.friend_delete(self.baid)
|
|
|
|
if hasattr(self, 'abid') and self.abid >= 0:
|
|
|
|
self.alice.friend_delete(self.abid)
|
2022-09-26 00:58:57 +00:00
|
|
|
|
2023-12-09 10:19:21 +00:00
|
|
|
@expectedFail('fails') # assert self.bob.friend_get_status(self.baid) == TOX_USER_STATUS['BUSY']
|
2023-12-13 00:57:28 +00:00
|
|
|
def test_user_status(self) -> None: # fails
|
2022-09-26 00:58:57 +00:00
|
|
|
"""
|
|
|
|
t:self_get_status
|
|
|
|
t:self_set_status
|
|
|
|
t:friend_get_status
|
|
|
|
t:friend_get_status
|
|
|
|
t:on_friend_status
|
|
|
|
"""
|
|
|
|
sSlot = 'friend_status'
|
|
|
|
|
2023-07-14 14:07:08 +00:00
|
|
|
setattr(self.bob, sSlot, None)
|
2023-12-13 00:57:28 +00:00
|
|
|
def bobs_on_friend_set_status(iTox, friend_id, new_status, *largs) -> None:
|
2023-07-14 14:07:08 +00:00
|
|
|
LOG_INFO(f"bobs_on_friend_set_status {friend_id} {new_status}")
|
2022-09-26 00:58:57 +00:00
|
|
|
try:
|
|
|
|
assert friend_id == self.baid
|
2023-07-14 14:07:08 +00:00
|
|
|
assert new_status in [TOX_USER_STATUS['BUSY'], TOX_USER_STATUS['AWAY']]
|
2022-09-26 00:58:57 +00:00
|
|
|
except Exception as e:
|
2023-07-14 14:07:08 +00:00
|
|
|
LOG_WARN(f"bobs_on_friend_set_status EXCEPTION {e}")
|
2022-09-26 00:58:57 +00:00
|
|
|
setattr(self.bob, sSlot, True)
|
|
|
|
|
|
|
|
try:
|
2023-12-09 10:19:21 +00:00
|
|
|
if bUSE_NOREQUEST:
|
|
|
|
assert self.bob_add_alice_as_friend_norequest()
|
|
|
|
else:
|
|
|
|
assert self.bob_add_alice_as_friend()
|
2022-09-26 00:58:57 +00:00
|
|
|
if not self.get_connection_status():
|
2023-07-14 14:07:08 +00:00
|
|
|
LOG.warning(f"test_user_status NOT CONNECTED self.get_connection_status")
|
|
|
|
self.loop_until_connected()
|
2022-09-26 00:58:57 +00:00
|
|
|
|
|
|
|
self.bob.callback_friend_status(bobs_on_friend_set_status)
|
|
|
|
self.warn_if_no_cb(self.bob, sSlot)
|
2023-07-14 14:07:08 +00:00
|
|
|
sSTATUS = TOX_USER_STATUS['BUSY']
|
|
|
|
self.alice.self_set_status(sSTATUS)
|
2023-12-09 10:19:21 +00:00
|
|
|
sSlot = 'friend_status'
|
2023-12-06 16:32:06 +00:00
|
|
|
if not self.wait_otox_attrs(self.bob, [sSlot]):
|
2023-12-07 19:38:26 +00:00
|
|
|
# malloc(): unaligned tcache chunk detected
|
2023-12-09 10:19:21 +00:00
|
|
|
LOG_WARN(f'test_user_status NO {sSlot}')
|
2022-09-26 00:58:57 +00:00
|
|
|
|
2023-12-06 16:32:06 +00:00
|
|
|
assert self.bob.friend_get_status(self.baid) == TOX_USER_STATUS['BUSY'], \
|
2023-12-09 10:19:21 +00:00
|
|
|
f"friend_get_status {self.bob.friend_get_status(self.baid)} != {TOX_USER_STATUS['BUSY']}"
|
2023-07-14 14:07:08 +00:00
|
|
|
|
2022-09-26 00:58:57 +00:00
|
|
|
except AssertionError as e:
|
2023-12-09 10:19:21 +00:00
|
|
|
LOG.error(f"test_user_status FAILED {e}")
|
2023-07-17 02:36:30 +00:00
|
|
|
raise
|
2022-09-26 00:58:57 +00:00
|
|
|
except Exception as e:
|
|
|
|
LOG.error(f"test_user_status EXCEPTION {e}")
|
|
|
|
raise
|
|
|
|
finally:
|
|
|
|
self.bob.callback_friend_status(None)
|
|
|
|
self.warn_if_cb(self.bob, sSlot)
|
2023-12-06 16:32:06 +00:00
|
|
|
if hasattr(self, 'baid') and self.baid >= 0:
|
|
|
|
self.bob.friend_delete(self.baid)
|
2022-09-26 00:58:57 +00:00
|
|
|
|
2023-12-11 06:38:55 +00:00
|
|
|
@unittest.skip('crashes')
|
2023-12-13 00:57:28 +00:00
|
|
|
def test_kill_remake(self) -> None:
|
2022-09-26 00:58:57 +00:00
|
|
|
"""
|
2023-12-10 18:14:06 +00:00
|
|
|
t:friend_get_kill_remake
|
2022-09-26 00:58:57 +00:00
|
|
|
t:on_friend_connection_status
|
|
|
|
"""
|
|
|
|
sSlot = 'friend_connection_status'
|
2023-07-14 14:07:08 +00:00
|
|
|
setattr(self.bob, sSlot, None)
|
2022-09-26 00:58:57 +00:00
|
|
|
def bobs_on_friend_connection_status(iTox, friend_id, iStatus, *largs):
|
2023-07-14 14:07:08 +00:00
|
|
|
LOG_INFO(f"bobs_on_friend_connection_status " +repr(iStatus))
|
2022-09-26 00:58:57 +00:00
|
|
|
try:
|
|
|
|
assert friend_id == self.baid
|
|
|
|
except Exception as e:
|
2023-12-06 16:32:06 +00:00
|
|
|
LOG_ERROR(f"bobs_on_friend_connection_status ERROR {e}")
|
2023-12-07 19:38:26 +00:00
|
|
|
setattr(self.bob, sSlot, True)
|
2022-09-26 00:58:57 +00:00
|
|
|
|
2023-12-16 23:23:00 +00:00
|
|
|
opts = oTestsToxOptions(oTOX_OARGS)
|
2023-12-09 10:19:21 +00:00
|
|
|
setattr(self.bob, sSlot, True)
|
2022-09-26 00:58:57 +00:00
|
|
|
try:
|
2023-12-07 19:38:26 +00:00
|
|
|
if bUSE_NOREQUEST:
|
|
|
|
assert self.bob_add_alice_as_friend_norequest()
|
|
|
|
else:
|
|
|
|
assert self.bob_add_alice_as_friend()
|
|
|
|
|
2022-09-26 00:58:57 +00:00
|
|
|
self.bob.callback_friend_connection_status(bobs_on_friend_connection_status)
|
|
|
|
|
2023-12-10 18:14:06 +00:00
|
|
|
LOG.info("test_kill_remake killing alice")
|
2022-09-26 00:58:57 +00:00
|
|
|
self.alice.kill() #! bang
|
2023-12-10 18:14:06 +00:00
|
|
|
LOG.info("test_kill_remake making alice")
|
2022-09-26 00:58:57 +00:00
|
|
|
self.alice = Tox(opts, app=oAPP)
|
2023-12-10 18:14:06 +00:00
|
|
|
LOG.info("test_kill_remake maked alice")
|
2022-09-26 00:58:57 +00:00
|
|
|
|
2023-12-07 19:38:26 +00:00
|
|
|
if not self.wait_otox_attrs(self.bob, [sSlot]):
|
2023-12-14 20:46:56 +00:00
|
|
|
LOG_WARN(f'test_kill_remake NO {sSlot}')
|
2022-09-26 00:58:57 +00:00
|
|
|
except AssertionError as e:
|
2023-12-10 18:14:06 +00:00
|
|
|
LOG.error(f"test_kill_remake Failed test {e}")
|
2022-09-26 00:58:57 +00:00
|
|
|
raise
|
|
|
|
except Exception as e:
|
2023-07-14 14:07:08 +00:00
|
|
|
LOG.error(f"bobs_on_friend_connection_status {e}")
|
2022-09-26 00:58:57 +00:00
|
|
|
raise
|
|
|
|
finally:
|
|
|
|
self.bob.callback_friend_connection_status(None)
|
2023-12-06 16:32:06 +00:00
|
|
|
if hasattr(self, 'baid') and self.baid >= 0:
|
|
|
|
self.bob.friend_delete(self.baid)
|
2022-09-26 00:58:57 +00:00
|
|
|
|
2023-12-09 10:19:21 +00:00
|
|
|
@expectedFail('fails') # new name is empty
|
2023-12-13 00:57:28 +00:00
|
|
|
def test_friend_name(self) -> None: # works!
|
2022-09-26 00:58:57 +00:00
|
|
|
"""
|
|
|
|
t:self_set_name
|
|
|
|
t:friend_get_name
|
|
|
|
t:friend_get_name_size
|
|
|
|
t:on_friend_name
|
|
|
|
"""
|
|
|
|
|
|
|
|
sSlot= 'friend_name'
|
|
|
|
#: Test friend request
|
|
|
|
|
|
|
|
#: Test friend name
|
|
|
|
NEWNAME = 'Jenny'
|
2022-11-23 20:02:29 +00:00
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def bobs_on_friend_name(iTox, fid:int, newname, iNameSize, *largs) -> None:
|
2023-07-14 14:07:08 +00:00
|
|
|
LOG_INFO(f"bobs_on_friend_name {sSlot} {fid}")
|
2022-09-26 00:58:57 +00:00
|
|
|
try:
|
2023-07-14 14:07:08 +00:00
|
|
|
assert fid == self.baid
|
2022-09-26 00:58:57 +00:00
|
|
|
assert str(newname, 'UTF-8') == NEWNAME
|
|
|
|
except Exception as e:
|
2023-12-06 16:32:06 +00:00
|
|
|
LOG_ERROR(f"bobs_on_friend_name EXCEPTION {e}")
|
2022-09-26 00:58:57 +00:00
|
|
|
setattr(self.bob, sSlot, True)
|
|
|
|
|
2023-07-14 14:07:08 +00:00
|
|
|
setattr(self.bob, sSlot, None)
|
2022-09-26 00:58:57 +00:00
|
|
|
try:
|
2023-12-06 16:32:06 +00:00
|
|
|
LOG.info("test_friend_name")
|
|
|
|
if bUSE_NOREQUEST:
|
|
|
|
assert self.bob_add_alice_as_friend_norequest()
|
|
|
|
else:
|
|
|
|
assert self.bob_add_alice_as_friend()
|
2023-07-17 02:36:30 +00:00
|
|
|
|
|
|
|
self.bob.callback_friend_name(bobs_on_friend_name)
|
|
|
|
self.warn_if_no_cb(self.bob, sSlot)
|
2022-09-26 00:58:57 +00:00
|
|
|
self.alice.self_set_name(NEWNAME)
|
2023-12-06 16:32:06 +00:00
|
|
|
if not self.wait_otox_attrs(self.bob, [sSlot]):
|
2023-12-07 19:38:26 +00:00
|
|
|
LOG_WARN(f"bobs_on_friend_name NO {sSlot}")
|
|
|
|
|
2023-07-17 02:36:30 +00:00
|
|
|
# name=None
|
2023-12-07 19:38:26 +00:00
|
|
|
assert self.bob.friend_get_name(self.baid) == NEWNAME, \
|
|
|
|
f"{self.bob.friend_get_name(self.baid)} != {NEWNAME}"
|
|
|
|
assert self.bob.friend_get_name_size(self.baid) == len(NEWNAME), \
|
|
|
|
f"{self.bob.friend_get_name_size(self.baid)} != {len(NEWNAME)}"
|
2023-07-14 14:07:08 +00:00
|
|
|
|
2022-09-26 00:58:57 +00:00
|
|
|
except AssertionError as e:
|
2023-07-17 02:36:30 +00:00
|
|
|
LOG.error(f"test_friend_name Failed test {e}")
|
|
|
|
raise
|
2022-09-26 00:58:57 +00:00
|
|
|
except Exception as e:
|
2023-07-17 02:36:30 +00:00
|
|
|
LOG.error(f"test_friend EXCEPTION {e}")
|
|
|
|
raise
|
2022-09-26 00:58:57 +00:00
|
|
|
finally:
|
2023-12-06 16:32:06 +00:00
|
|
|
if hasattr(self, 'baid') and self.baid >= 0:
|
|
|
|
self.bob.friend_delete(self.baid)
|
2022-09-26 00:58:57 +00:00
|
|
|
self.bob.callback_friend_name(None)
|
2023-12-06 16:32:06 +00:00
|
|
|
self.warn_if_cb(self.bob, sSlot)
|
2022-09-26 00:58:57 +00:00
|
|
|
|
|
|
|
|
2023-12-09 10:19:21 +00:00
|
|
|
@expectedFail('fails') # This client is currently not connected to the friend.
|
2023-12-13 00:57:28 +00:00
|
|
|
def test_friend_message(self) -> None: # fails
|
2022-09-26 00:58:57 +00:00
|
|
|
"""
|
|
|
|
t:on_friend_action
|
|
|
|
t:on_friend_message
|
|
|
|
t:friend_send_message
|
|
|
|
"""
|
|
|
|
|
|
|
|
#: Test message
|
|
|
|
MSG = 'Hi, Bob!'
|
|
|
|
sSlot = 'friend_message'
|
2023-07-14 14:07:08 +00:00
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def alices_on_friend_message(iTox, fid:int, msg_type, message, iSize, *largs) -> None:
|
2023-07-14 14:07:08 +00:00
|
|
|
LOG_DEBUG(f"alices_on_friend_message {fid} {message}")
|
2022-09-26 00:58:57 +00:00
|
|
|
try:
|
2023-07-14 14:07:08 +00:00
|
|
|
assert fid == self.alice.abid
|
2022-09-26 00:58:57 +00:00
|
|
|
assert msg_type == TOX_MESSAGE_TYPE['NORMAL']
|
|
|
|
assert str(message, 'UTF-8') == MSG
|
|
|
|
except Exception as e:
|
|
|
|
LOG_ERROR(f"alices_on_friend_message EXCEPTION {e}")
|
|
|
|
else:
|
2023-07-14 14:07:08 +00:00
|
|
|
LOG_INFO(f"alices_on_friend_message {message}")
|
|
|
|
setattr(self.alice, sSlot, True)
|
2022-09-26 00:58:57 +00:00
|
|
|
|
2023-07-14 14:07:08 +00:00
|
|
|
setattr(self.alice, sSlot, None)
|
2023-07-17 02:36:30 +00:00
|
|
|
self.alice.callback_friend_message(None)
|
2022-09-26 00:58:57 +00:00
|
|
|
try:
|
2023-12-06 16:32:06 +00:00
|
|
|
if bUSE_NOREQUEST:
|
|
|
|
assert self.both_add_as_friend_norequest()
|
|
|
|
else:
|
|
|
|
assert self.both_add_as_friend()
|
2023-12-09 10:19:21 +00:00
|
|
|
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):
|
2023-12-06 16:32:06 +00:00
|
|
|
LOG.warn('abid not connected')
|
2022-09-26 00:58:57 +00:00
|
|
|
self.alice.callback_friend_message(alices_on_friend_message)
|
|
|
|
self.warn_if_no_cb(self.alice, sSlot)
|
2023-07-14 14:07:08 +00:00
|
|
|
|
|
|
|
# dunno - both This client is currently NOT CONNECTED to the friend.
|
2023-12-09 10:19:21 +00:00
|
|
|
iMesId = self.bob.friend_send_message(self.baid,
|
|
|
|
TOX_MESSAGE_TYPE['NORMAL'],
|
|
|
|
bytes(MSG, 'UTF-8'))
|
|
|
|
assert iMesId >= 0, "iMesId >= 0"
|
2023-12-06 16:32:06 +00:00
|
|
|
if not self.wait_otox_attrs(self.alice, [sSlot]):
|
2023-12-07 19:38:26 +00:00
|
|
|
LOG_WARN(f"alices_on_friend_message NO {sSlot}")
|
2022-09-26 00:58:57 +00:00
|
|
|
except ArgumentError as e:
|
|
|
|
# ArgumentError('This client is currently NOT CONNECTED to the friend.')
|
|
|
|
# dunno
|
2023-12-09 10:19:21 +00:00
|
|
|
LOG.error(f"test_friend_message ArgumentError {e}")
|
2022-09-26 00:58:57 +00:00
|
|
|
raise
|
2023-07-14 14:07:08 +00:00
|
|
|
except AssertionError as e:
|
2023-12-09 10:19:21 +00:00
|
|
|
LOG.error(f"test_friend_message AssertionError {e}")
|
2023-07-17 02:36:30 +00:00
|
|
|
raise
|
2022-09-26 00:58:57 +00:00
|
|
|
except Exception as e:
|
2023-12-09 10:19:21 +00:00
|
|
|
LOG.error(f"test_friend_message EXCEPTION {e}")
|
2022-09-26 00:58:57 +00:00
|
|
|
raise
|
|
|
|
finally:
|
|
|
|
self.alice.callback_friend_message(None)
|
|
|
|
self.warn_if_cb(self.alice, sSlot)
|
2023-12-06 16:32:06 +00:00
|
|
|
if hasattr(self, 'baid') and self.baid >= 0:
|
|
|
|
self.bob.friend_delete(self.baid)
|
|
|
|
if hasattr(self, 'abid') and self.abid >= 0:
|
|
|
|
self.alice.friend_delete(self.abid)
|
2022-09-26 00:58:57 +00:00
|
|
|
|
2023-12-06 16:32:06 +00:00
|
|
|
# This client is currently not connected to the friend.
|
2023-12-13 00:57:28 +00:00
|
|
|
def test_friend_action(self) -> None: # works! sometimes?
|
2022-09-26 00:58:57 +00:00
|
|
|
"""
|
|
|
|
t:on_friend_action
|
|
|
|
t:on_friend_message
|
|
|
|
t:friend_send_message
|
|
|
|
"""
|
|
|
|
|
|
|
|
#: Test action
|
|
|
|
ACTION = 'Kick'
|
2023-07-14 14:07:08 +00:00
|
|
|
sSlot = 'friend_read_action'
|
|
|
|
setattr(self.bob, sSlot, None)
|
2023-12-13 00:57:28 +00:00
|
|
|
def UNUSEDtheir_on_friend_action(iTox, fid:int, msg_type, action, *largs):
|
2023-12-14 20:46:56 +00:00
|
|
|
LOG_DEBUG(f"their_on_friend_action {fid} {msg_type} {sSlot} {action}")
|
2023-07-14 14:07:08 +00:00
|
|
|
try:
|
|
|
|
assert msg_type == TOX_MESSAGE_TYPE['ACTION']
|
|
|
|
assert action == ACTION
|
|
|
|
except Exception as e:
|
2023-12-14 20:46:56 +00:00
|
|
|
LOG_ERROR(f"their_on_friend_action EXCEPTION {sSlot} {e}")
|
2023-07-14 14:07:08 +00:00
|
|
|
else:
|
2023-12-14 20:46:56 +00:00
|
|
|
LOG_INFO(f"their_on_friend_action {sSlot} {action}")
|
|
|
|
setattr(self.bob, sSlot, True)
|
2022-09-26 00:58:57 +00:00
|
|
|
|
2023-07-14 14:07:08 +00:00
|
|
|
sSlot = 'friend_read_receipt'
|
|
|
|
setattr(self.alice, sSlot, None)
|
2023-12-13 00:57:28 +00:00
|
|
|
def their_on_read_reciept(iTox, fid:int, msg_id, *largs) -> None:
|
2023-07-17 02:36:30 +00:00
|
|
|
LOG_DEBUG(f"their_on_read_reciept {fid} {msg_id}")
|
2022-09-26 00:58:57 +00:00
|
|
|
sSlot = 'friend_read_receipt'
|
|
|
|
try:
|
2023-07-17 02:36:30 +00:00
|
|
|
# should be the receivers id
|
|
|
|
assert fid == bob.baid or fid == alice.abid
|
|
|
|
assert msg_id >= 0
|
2022-09-26 00:58:57 +00:00
|
|
|
except Exception as e:
|
2023-12-14 20:46:56 +00:00
|
|
|
LOG_ERROR(f"their_on_read_reciept {sSlot} {e}")
|
2023-07-14 14:07:08 +00:00
|
|
|
else:
|
2023-12-14 20:46:56 +00:00
|
|
|
LOG_INFO(f"their_on_read_reciept {sSlot} fid={fid}")
|
|
|
|
setattr(self.alice, sSlot, True)
|
2022-09-26 00:58:57 +00:00
|
|
|
|
|
|
|
try:
|
2023-12-06 16:32:06 +00:00
|
|
|
if bUSE_NOREQUEST:
|
|
|
|
assert self.both_add_as_friend_norequest()
|
|
|
|
else:
|
|
|
|
assert self.both_add_as_friend()
|
2023-07-17 02:36:30 +00:00
|
|
|
|
2023-12-07 19:38:26 +00:00
|
|
|
if not self.wait_friend_get_connection_status(self.bob, self.baid, n=iN):
|
2023-12-06 16:32:06 +00:00
|
|
|
LOG.warn('baid not connected')
|
2023-12-07 19:38:26 +00:00
|
|
|
if not self.wait_friend_get_connection_status(self.alice, self.abid, n=iN):
|
2023-12-06 16:32:06 +00:00
|
|
|
LOG.warn('abid not connected')
|
2022-11-23 20:02:29 +00:00
|
|
|
|
2023-07-17 02:36:30 +00:00
|
|
|
self.bob.callback_friend_read_receipt(their_on_read_reciept) #was their_on_friend_action
|
|
|
|
self.alice.callback_friend_read_receipt(their_on_read_reciept) #was their_on_friend_action
|
2023-12-06 16:32:06 +00:00
|
|
|
self.warn_if_no_cb(self.bob, 'friend_read_receipt')
|
|
|
|
self.warn_if_no_cb(self.alice, 'friend_read_receipt')
|
2023-07-17 02:36:30 +00:00
|
|
|
if True:
|
|
|
|
iMsg = self.bob.friend_send_message(self.baid,
|
|
|
|
TOX_MESSAGE_TYPE['ACTION'],
|
|
|
|
bytes(ACTION, 'UTF-8'))
|
|
|
|
assert iMsg >= 0
|
|
|
|
else:
|
|
|
|
assert self.wait_ensure_exec(self.bob.friend_send_message,
|
|
|
|
[self.baid,
|
|
|
|
TOX_MESSAGE_TYPE['ACTION'],
|
|
|
|
bytes(ACTION, 'UTF-8')])
|
2023-12-07 19:38:26 +00:00
|
|
|
if not self.wait_otox_attrs(self.alice, [sSlot]):
|
|
|
|
LOG_WARN(f"alice test_friend_action NO {sSlot}")
|
2022-09-26 00:58:57 +00:00
|
|
|
except AssertionError as e:
|
2023-07-17 02:36:30 +00:00
|
|
|
LOG.error(f"Failed test {e}")
|
|
|
|
raise
|
2022-09-26 00:58:57 +00:00
|
|
|
except ArgumentError as e:
|
|
|
|
# ArgumentError('This client is currently NOT CONNECTED to the friend.')
|
|
|
|
# dunno
|
2023-07-14 14:07:08 +00:00
|
|
|
LOG.warning(f"test_friend_action {e}")
|
2022-09-26 00:58:57 +00:00
|
|
|
except Exception as e:
|
|
|
|
LOG.error(f"test_friend_action {e}")
|
|
|
|
raise
|
|
|
|
finally:
|
|
|
|
self.alice.callback_friend_read_receipt(None)
|
2023-12-06 16:32:06 +00:00
|
|
|
if hasattr(self, 'baid') and self.baid >= 0:
|
|
|
|
self.bob.friend_delete(self.baid)
|
|
|
|
if hasattr(self, 'abid') and self.abid >= 0:
|
|
|
|
self.alice.friend_delete(self.abid)
|
2022-09-26 00:58:57 +00:00
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def test_alice_typing_status(self) -> None: # works
|
2022-09-26 00:58:57 +00:00
|
|
|
"""
|
|
|
|
t:on_friend_read_receipt
|
|
|
|
t:on_friend_typing
|
|
|
|
t:self_set_typing
|
|
|
|
t:friend_get_typing
|
|
|
|
t:friend_get_last_online
|
|
|
|
"""
|
|
|
|
|
2023-07-14 14:07:08 +00:00
|
|
|
sSlot = 'friend_typing'
|
2022-09-26 00:58:57 +00:00
|
|
|
LOG.info("test_typing_status bob adding alice")
|
|
|
|
#: Test typing status
|
2023-12-13 00:57:28 +00:00
|
|
|
def bob_on_friend_typing(iTox, fid:int, is_typing, *largs) -> None:
|
2023-12-06 16:32:06 +00:00
|
|
|
LOG_INFO(f"BOB_ON_friend_typing is_typing={is_typing} fid={fid}")
|
2022-09-26 00:58:57 +00:00
|
|
|
try:
|
2023-07-17 02:36:30 +00:00
|
|
|
assert fid == self.baid
|
|
|
|
if is_typing is True:
|
|
|
|
assert self.bob.friend_get_typing(fid) is True
|
2022-09-26 00:58:57 +00:00
|
|
|
except Exception as e:
|
2023-12-06 16:32:06 +00:00
|
|
|
LOG_ERROR(f"BOB_ON_friend_typing {e}")
|
2023-07-14 14:07:08 +00:00
|
|
|
setattr(self.bob, sSlot, True)
|
2022-09-26 00:58:57 +00:00
|
|
|
|
2023-07-14 14:07:08 +00:00
|
|
|
setattr(self.bob, sSlot, None)
|
2022-09-26 00:58:57 +00:00
|
|
|
try:
|
2023-12-06 16:32:06 +00:00
|
|
|
if bUSE_NOREQUEST:
|
|
|
|
assert self.both_add_as_friend_norequest()
|
|
|
|
else:
|
|
|
|
assert self.both_add_as_friend()
|
|
|
|
|
2022-09-26 00:58:57 +00:00
|
|
|
if not self.get_connection_status():
|
2023-12-06 16:32:06 +00:00
|
|
|
LOG.warning(f"test_friend_typing NOT CONNECTED")
|
2023-07-14 14:07:08 +00:00
|
|
|
self.loop_until_connected()
|
2022-09-26 00:58:57 +00:00
|
|
|
|
|
|
|
self.bob.callback_friend_typing(bob_on_friend_typing)
|
2023-12-06 16:32:06 +00:00
|
|
|
self.warn_if_no_cb(self.bob, sSlot)
|
2023-07-17 02:36:30 +00:00
|
|
|
self.alice.self_set_typing(self.abid, False)
|
2023-12-06 16:32:06 +00:00
|
|
|
if not self.wait_otox_attrs(self.bob, [sSlot]):
|
2023-12-07 19:38:26 +00:00
|
|
|
LOG_WARN(f"bobs_on_friend_typing NO {sSlot}")
|
2022-09-26 00:58:57 +00:00
|
|
|
except AssertionError as e:
|
2023-07-17 02:36:30 +00:00
|
|
|
LOG.error(f"Failed test {e}")
|
|
|
|
raise
|
2022-09-26 00:58:57 +00:00
|
|
|
except Exception as e:
|
|
|
|
LOG.error(f"test_alice_typing_status error={e}")
|
|
|
|
raise
|
|
|
|
finally:
|
|
|
|
self.bob.callback_friend_typing(None)
|
2023-12-06 16:32:06 +00:00
|
|
|
if hasattr(self, 'baid') and self.baid >= 0:
|
|
|
|
self.bob.friend_delete(self.baid)
|
|
|
|
if hasattr(self, 'abid') and self.abid >= 0:
|
|
|
|
self.alice.friend_delete(self.abid)
|
2022-09-26 00:58:57 +00:00
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
@expectedFail('fails') # @unittest.skip('unfinished')
|
|
|
|
def test_file_transfer(self) -> None: # unfinished
|
2022-09-26 00:58:57 +00:00
|
|
|
"""
|
|
|
|
t:file_send
|
|
|
|
t:file_send_chunk
|
|
|
|
t:file_control
|
|
|
|
t:file_seek
|
|
|
|
t:file_get_file_id
|
|
|
|
t:on_file_recv
|
|
|
|
t:on_file_recv_control
|
|
|
|
t:on_file_recv_chunk
|
|
|
|
t:on_file_chunk_request
|
|
|
|
"""
|
|
|
|
|
2023-12-06 16:32:06 +00:00
|
|
|
if bUSE_NOREQUEST:
|
2023-07-17 02:36:30 +00:00
|
|
|
assert self.both_add_as_friend_norequest()
|
2023-07-14 14:07:08 +00:00
|
|
|
else:
|
2023-07-17 02:36:30 +00:00
|
|
|
assert self.both_add_as_friend()
|
2022-11-23 20:02:29 +00:00
|
|
|
|
2022-09-26 00:58:57 +00:00
|
|
|
FRIEND_NUMBER = self.baid
|
|
|
|
FILE_NUMBER = 1
|
|
|
|
FILE = os.urandom(1024 * 1024)
|
|
|
|
FILE_NAME = b"/tmp/test.bin"
|
|
|
|
if not os.path.exists(FILE_NAME):
|
|
|
|
with open(FILE_NAME, 'wb') as oFd:
|
|
|
|
oFd.write(FILE)
|
|
|
|
FILE_SIZE = len(FILE)
|
|
|
|
OFFSET = 567
|
2023-12-14 20:46:56 +00:00
|
|
|
# was FILE_ID = FILE_NAME
|
|
|
|
FILE_ID = 32*'1' #
|
2022-09-26 00:58:57 +00:00
|
|
|
|
|
|
|
m = hashlib.md5()
|
|
|
|
m.update(FILE[OFFSET:])
|
|
|
|
FILE_DIGEST = m.hexdigest()
|
|
|
|
|
|
|
|
CONTEXT = { 'FILE': bytes(), 'RECEIVED': 0, 'START': False, 'SENT': 0 }
|
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def alice_on_file_recv(iTox, fid:int, file_number:int, kind, size, filename) -> None:
|
2022-09-26 00:58:57 +00:00
|
|
|
LOG_DEBUG(f"ALICE_ON_file_recv fid={fid} {file_number}")
|
|
|
|
try:
|
|
|
|
assert size == FILE_SIZE
|
|
|
|
assert filename == FILE_NAME
|
|
|
|
retv = self.alice.file_seek(fid, file_number, OFFSET)
|
|
|
|
assert retv is True
|
|
|
|
self.alice.file_control(fid, file_number, TOX_FILE_CONTROL['RESUME'])
|
|
|
|
except Exception as e:
|
2023-07-14 14:07:08 +00:00
|
|
|
LOG_ERROR(f"ALICE_ON_file_recv {e}")
|
2022-09-26 00:58:57 +00:00
|
|
|
else:
|
|
|
|
LOG_INFO(f"ALICE_ON_file_recv " + str(fid))
|
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def alice_on_file_recv_control(iTox, fid:int, file_number, control, *largs) -> None:
|
2022-09-26 00:58:57 +00:00
|
|
|
# TOX_FILE_CONTROL = { 'RESUME': 0, 'PAUSE': 1, 'CANCEL': 2,}
|
|
|
|
LOG_DEBUG(f"ALICE_ON_file_recv_control fid={fid} {file_number} {control}")
|
|
|
|
try:
|
|
|
|
assert FILE_NUMBER == file_number
|
2022-11-17 14:18:51 +00:00
|
|
|
# FixMe _FINISHED?
|
|
|
|
if False and control == TOX_FILE_CONTROL['RESUME']:
|
2023-07-14 14:07:08 +00:00
|
|
|
# assert CONTEXT['RECEIVED'] == FILE_SIZE
|
|
|
|
# m = hashlib.md5()
|
|
|
|
# m.update(CONTEXT['FILE'])
|
|
|
|
# assert m.hexdigest() == FILE_DIGEST
|
2022-09-26 00:58:57 +00:00
|
|
|
self.alice.completed = True
|
|
|
|
except Exception as e:
|
2023-07-14 14:07:08 +00:00
|
|
|
LOG_ERROR(f"ALICE_ON_file_recv {e}")
|
2022-09-26 00:58:57 +00:00
|
|
|
else:
|
|
|
|
LOG_INFO(f"ALICE_ON_file_recv " + str(fid))
|
|
|
|
|
|
|
|
self.alice.completed = False
|
2023-12-14 20:46:56 +00:00
|
|
|
def alice_on_file_recv_chunk(iTox, fid:int, file_number:int, position:int, iNumBytes, *largs) -> bool:
|
2022-09-26 00:58:57 +00:00
|
|
|
LOG_DEBUG(f"ALICE_ON_file_recv_chunk {fid} {file_number}")
|
|
|
|
# FixMe - use file_number and iNumBytes to get data?
|
|
|
|
data = ''
|
2023-07-17 02:36:30 +00:00
|
|
|
LOG_INFO(f"ALICE_ON_file_recv_chunk {fid}")
|
2022-09-26 00:58:57 +00:00
|
|
|
try:
|
|
|
|
if data is None:
|
|
|
|
assert CONTEXT['RECEIVED'] == (FILE_SIZE - OFFSET)
|
|
|
|
m = hashlib.md5()
|
|
|
|
m.update(CONTEXT['FILE'])
|
|
|
|
assert m.hexdigest() == FILE_DIGEST
|
|
|
|
self.alice.completed = True
|
|
|
|
self.alice.file_control(fid, file_number, TOX_FILE_CONTROL['CANCEL'])
|
2023-12-14 20:46:56 +00:00
|
|
|
return True
|
2022-11-23 20:02:29 +00:00
|
|
|
|
2022-09-26 00:58:57 +00:00
|
|
|
CONTEXT['FILE'] += data
|
|
|
|
CONTEXT['RECEIVED'] += len(data)
|
|
|
|
# if CONTEXT['RECEIVED'] < FILE_SIZE:
|
|
|
|
# assert self.file_data_remaining(
|
|
|
|
# fid, file_number, 1) == FILE_SIZE - CONTEXT['RECEIVED']
|
|
|
|
except Exception as e:
|
2023-07-14 14:07:08 +00:00
|
|
|
LOG_ERROR(f"ALICE_ON_file_recv_chunk {e}")
|
2023-12-14 20:46:56 +00:00
|
|
|
return False
|
|
|
|
return True
|
2022-09-26 00:58:57 +00:00
|
|
|
|
|
|
|
# AliceTox.on_file_send_request = on_file_send_request
|
|
|
|
# AliceTox.on_file_control = on_file_control
|
|
|
|
# AliceTox.on_file_data = on_file_data
|
|
|
|
|
|
|
|
try:
|
2023-12-16 23:23:00 +00:00
|
|
|
# required?
|
|
|
|
if not self.wait_friend_get_connection_status(self.bob, self.baid, n=2*iN):
|
|
|
|
LOG_WARN(f"bobs wait_friend_get_connection_status {2*iN}")
|
|
|
|
|
|
|
|
if not self.wait_friend_get_connection_status(self.alice, self.abid, n=2*iN):
|
|
|
|
LOG_WARN(f"alices' wait_friend_get_connection_status {2*iN}")
|
2023-12-14 20:46:56 +00:00
|
|
|
|
2022-09-26 00:58:57 +00:00
|
|
|
self.alice.callback_file_recv(alice_on_file_recv)
|
|
|
|
self.alice.callback_file_recv_control(alice_on_file_recv_control)
|
|
|
|
self.alice.callback_file_recv_chunk(alice_on_file_recv_chunk)
|
|
|
|
|
|
|
|
self.bob.completed = False
|
2023-12-13 00:57:28 +00:00
|
|
|
def bob_on_file_recv_control2(iTox, fid:int, file_number:int, control) -> None:
|
2022-09-26 00:58:57 +00:00
|
|
|
LOG_DEBUG(f"BOB_ON_file_recv_control2 {fid} {file_number} control={control}")
|
|
|
|
if control == TOX_FILE_CONTROL['RESUME']:
|
|
|
|
CONTEXT['START'] = True
|
|
|
|
elif control == TOX_FILE_CONTROL['CANCEL']:
|
|
|
|
self.bob.completed = True
|
|
|
|
pass
|
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def bob_on_file_chunk_request(iTox, fid:int, file_number:int, position:int, length, *largs) -> None:
|
2022-09-26 00:58:57 +00:00
|
|
|
LOG_DEBUG(f"BOB_ON_file_chunk_request {fid} {file_number}")
|
|
|
|
if length == 0:
|
|
|
|
return
|
|
|
|
data = FILE[position:(position + length)]
|
|
|
|
self.bob.file_send_chunk(fid, file_number, position, data)
|
2022-11-23 20:02:29 +00:00
|
|
|
|
2022-09-26 00:58:57 +00:00
|
|
|
sSlot = 'file_recv_control'
|
|
|
|
self.bob.callback_file_recv_control(bob_on_file_recv_control2)
|
|
|
|
self.bob.callback_file_chunk_request(bob_on_file_chunk_request)
|
|
|
|
|
|
|
|
i = 0
|
|
|
|
iKind = 0
|
|
|
|
while i < 2:
|
|
|
|
i += 1
|
|
|
|
try:
|
|
|
|
FN = self.bob.file_send(self.baid, iKind, FILE_SIZE, FILE_ID, FILE_NAME)
|
|
|
|
LOG.info(f"test_file_transfer bob.file_send {FN}")
|
|
|
|
except ArgumentError as e:
|
|
|
|
LOG.debug(f"test_file_transfer bob.file_send {e} {i}")
|
2023-07-17 02:36:30 +00:00
|
|
|
# ctypes.ArgumentError: This client is currently not connected to the friend
|
2022-09-26 00:58:57 +00:00
|
|
|
raise
|
|
|
|
else:
|
|
|
|
break
|
|
|
|
self.loop(100)
|
|
|
|
sleep(1)
|
|
|
|
else:
|
|
|
|
LOG.error(f"test_file_transfer bob.file_send 2")
|
2023-07-17 02:36:30 +00:00
|
|
|
raise AssertionError(f"test_file_transfer bob.file_send {THRESHOLD // 2}")
|
2022-11-23 20:02:29 +00:00
|
|
|
|
2022-09-26 00:58:57 +00:00
|
|
|
# UINT32_MAX
|
2023-07-17 02:36:30 +00:00
|
|
|
try:
|
|
|
|
FID = self.bob.file_get_file_id(self.baid, FN)
|
|
|
|
hexFID = "".join([hex(ord(c))[2:].zfill(2) for c in FILE_NAME])
|
|
|
|
assert FID.startswith(hexFID.upper())
|
|
|
|
except Exception as e:
|
|
|
|
LOG.warn(f"test_file_transfer:: {FILE_NAME} {hexFID} {e}")
|
|
|
|
LOG.debug('\n' + traceback.format_exc())
|
2022-09-26 00:58:57 +00:00
|
|
|
|
2023-07-17 02:36:30 +00:00
|
|
|
if not self.wait_otox_attrs(self.bob, ['completed']):
|
2023-12-07 19:38:26 +00:00
|
|
|
LOG_WARN(f"test_file_transfer Bob NO completed")
|
2022-09-26 00:58:57 +00:00
|
|
|
return False
|
2023-07-17 02:36:30 +00:00
|
|
|
if not self.wait_otox_attrs(self.alice, ['completed']):
|
2023-12-07 19:38:26 +00:00
|
|
|
LOG_WARN(f"test_file_transfer Alice NO completed")
|
2023-07-14 14:07:08 +00:00
|
|
|
return False
|
|
|
|
return True
|
2022-09-26 00:58:57 +00:00
|
|
|
|
|
|
|
except (ArgumentError, ValueError,) as e:
|
|
|
|
# ValueError: non-hexadecimal number found in fromhex() arg at position 0
|
2023-07-17 02:36:30 +00:00
|
|
|
LOG.error(f"test_file_transfer: {e}")
|
2022-09-26 00:58:57 +00:00
|
|
|
raise
|
2022-11-23 20:02:29 +00:00
|
|
|
|
2022-09-26 00:58:57 +00:00
|
|
|
except Exception as e:
|
2023-07-17 02:36:30 +00:00
|
|
|
LOG.error(f"test_file_transfer:: {e}")
|
|
|
|
LOG.debug('\n' + traceback.format_exc())
|
2022-09-26 00:58:57 +00:00
|
|
|
raise
|
2022-11-23 20:02:29 +00:00
|
|
|
|
2022-09-26 00:58:57 +00:00
|
|
|
finally:
|
|
|
|
self.alice.callback_file_recv(None)
|
|
|
|
self.alice.callback_file_recv_control(None)
|
|
|
|
self.alice.callback_file_recv_chunk(None)
|
|
|
|
self.bob.callback_file_recv_control(None)
|
|
|
|
self.bob.callback_file_chunk_request(None)
|
2023-12-06 16:32:06 +00:00
|
|
|
if hasattr(self, 'baid') and self.baid >= 0:
|
|
|
|
self.bob.friend_delete(self.baid)
|
|
|
|
if hasattr(self, 'abid') and self.abid >= 0:
|
|
|
|
self.alice.friend_delete(self.abid)
|
2022-09-26 00:58:57 +00:00
|
|
|
|
|
|
|
LOG_INFO(f"test_file_transfer:: self.wait_objs_attr completed")
|
|
|
|
|
2023-12-14 20:46:56 +00:00
|
|
|
@unittest.skip('crashes')
|
|
|
|
def test_tox_savedata(self) -> None: #
|
2022-09-26 00:58:57 +00:00
|
|
|
"""
|
|
|
|
t:get_savedata_size
|
|
|
|
t:get_savedata
|
|
|
|
"""
|
2023-07-14 14:07:08 +00:00
|
|
|
# Fatal Python error: Aborted
|
|
|
|
# "/var/local/src/toxygen_wrapper/wrapper/tox.py", line 180 in kill
|
2022-09-26 00:58:57 +00:00
|
|
|
|
|
|
|
assert self.alice.get_savedata_size() > 0
|
|
|
|
data = self.alice.get_savedata()
|
|
|
|
assert data is not None
|
|
|
|
addr = self.alice.self_get_address()
|
|
|
|
# self._address
|
2022-11-23 20:02:29 +00:00
|
|
|
|
2022-09-26 00:58:57 +00:00
|
|
|
try:
|
2023-07-14 14:07:08 +00:00
|
|
|
LOG.info("test_tox_savedata alice.kill")
|
|
|
|
# crashes
|
2022-09-26 00:58:57 +00:00
|
|
|
self.alice.kill()
|
2023-12-11 06:38:55 +00:00
|
|
|
del self.alice
|
2023-07-14 14:07:08 +00:00
|
|
|
except:
|
|
|
|
pass
|
2022-11-23 20:02:29 +00:00
|
|
|
|
2022-09-26 00:58:57 +00:00
|
|
|
oArgs = oTOX_OARGS
|
2023-12-16 23:23:00 +00:00
|
|
|
opts = oTestsToxOptions(oArgs)
|
2022-09-26 00:58:57 +00:00
|
|
|
opts.savedata_data = data
|
|
|
|
opts.savedata_length = len(data)
|
|
|
|
|
|
|
|
self.alice = Tox(tox_options=opts)
|
|
|
|
if addr != self.alice.self_get_address():
|
2023-07-14 14:07:08 +00:00
|
|
|
LOG.warning("test_tox_savedata " +
|
2022-09-26 00:58:57 +00:00
|
|
|
f"{addr} != {self.alice.self_get_address()}")
|
|
|
|
else:
|
|
|
|
LOG.info("passed test_tox_savedata")
|
2022-11-23 20:02:29 +00:00
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def test_kill(self) -> None: #
|
2023-12-09 10:19:21 +00:00
|
|
|
import threading
|
|
|
|
LOG.info(f"THE END {threading.active_count()}")
|
|
|
|
self.tearDown()
|
|
|
|
LOG.info(f"THE END {threading.enumerate()}")
|
|
|
|
|
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def vOargsToxPreamble(oArgs, Tox, ToxTest) -> None:
|
2022-10-23 22:14:35 +00:00
|
|
|
|
2023-07-14 14:07:08 +00:00
|
|
|
ts.vSetupLogging(oArgs)
|
2022-11-23 20:02:29 +00:00
|
|
|
|
2022-10-23 22:14:35 +00:00
|
|
|
methods = set([x for x in dir(Tox) if not x[0].isupper()
|
|
|
|
and not x[0] == '_'])
|
|
|
|
docs = "".join([getattr(ToxTest, x).__doc__ for x in dir(ToxTest)
|
|
|
|
if getattr(ToxTest, x).__doc__ is not None])
|
|
|
|
|
|
|
|
tested = set(re.findall(r't:(.*?)\n', docs))
|
|
|
|
not_tested = methods.difference(tested)
|
|
|
|
|
|
|
|
logging.info('Test Coverage: %.2f%%' % (len(tested) * 100.0 / len(methods)))
|
|
|
|
if len(not_tested):
|
|
|
|
logging.info('Not tested:\n %s' % "\n ".join(sorted(list(not_tested))))
|
|
|
|
|
2023-12-09 10:19:21 +00:00
|
|
|
|
2022-09-26 00:58:57 +00:00
|
|
|
###
|
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def iMain(oArgs, failfast=True) -> int:
|
2023-12-12 05:20:05 +00:00
|
|
|
|
|
|
|
# collect_types.init_types_collection()
|
2022-09-26 00:58:57 +00:00
|
|
|
|
2023-07-14 14:07:08 +00:00
|
|
|
vOargsToxPreamble(oArgs, Tox, ToxSuite)
|
2022-09-26 00:58:57 +00:00
|
|
|
# https://stackoverflow.com/questions/35930811/how-to-sort-unittest-testcases-properly/35930812#35930812
|
|
|
|
cases = ts.suiteFactory(*ts.caseFactory([ToxSuite]))
|
|
|
|
if color_runner:
|
2023-07-14 14:07:08 +00:00
|
|
|
runner = color_runner.runner.TextTestRunner(verbosity=2, failfast=failfast)
|
2022-09-26 00:58:57 +00:00
|
|
|
else:
|
2023-07-14 14:07:08 +00:00
|
|
|
runner = unittest.TextTestRunner(verbosity=2, failfast=failfast, warnings='ignore')
|
2023-12-12 05:20:05 +00:00
|
|
|
|
|
|
|
# with collect_types.collect():
|
2022-09-26 00:58:57 +00:00
|
|
|
runner.run(cases)
|
2023-12-12 05:20:05 +00:00
|
|
|
# collect_types.dump_stats('tests_wrapper.out')
|
2022-09-26 00:58:57 +00:00
|
|
|
|
2023-12-16 23:23:00 +00:00
|
|
|
def oTestsToxOptions(oArgs):
|
2022-09-26 00:58:57 +00:00
|
|
|
data = None
|
2023-12-16 23:23:00 +00:00
|
|
|
tox_options = tox_wrapper.tox.Tox.options_new()
|
2022-09-26 00:58:57 +00:00
|
|
|
if oArgs.proxy_type:
|
|
|
|
tox_options.contents.proxy_type = int(oArgs.proxy_type)
|
|
|
|
tox_options.contents.proxy_host = bytes(oArgs.proxy_host, 'UTF-8')
|
|
|
|
tox_options.contents.proxy_port = int(oArgs.proxy_port)
|
|
|
|
tox_options.contents.udp_enabled = False
|
|
|
|
else:
|
|
|
|
tox_options.contents.udp_enabled = oArgs.udp_enabled
|
|
|
|
if not os.path.exists('/proc/sys/net/ipv6'):
|
|
|
|
oArgs.ipv6_enabled = False
|
2023-07-14 14:07:08 +00:00
|
|
|
else:
|
|
|
|
tox_options.contents.ipv6_enabled = oArgs.ipv6_enabled
|
2022-09-26 00:58:57 +00:00
|
|
|
|
|
|
|
tox_options.contents.tcp_port = int(oArgs.tcp_port)
|
2023-07-14 14:07:08 +00:00
|
|
|
tox_options.contents.dht_announcements_enabled = oArgs.dht_announcements_enabled
|
|
|
|
tox_options.contents.hole_punching_enabled = oArgs.hole_punching_enabled
|
2022-09-26 00:58:57 +00:00
|
|
|
|
|
|
|
# overrides
|
|
|
|
tox_options.contents.local_discovery_enabled = False
|
|
|
|
tox_options.contents.experimental_thread_safety = False
|
|
|
|
# REQUIRED!!
|
|
|
|
if oArgs.ipv6_enabled and not os.path.exists('/proc/sys/net/ipv6'):
|
2023-07-14 14:07:08 +00:00
|
|
|
LOG.warning('Disabling IPV6 because /proc/sys/net/ipv6 does not exist' + repr(oArgs.ipv6_enabled))
|
2022-09-26 00:58:57 +00:00
|
|
|
tox_options.contents.ipv6_enabled = False
|
|
|
|
else:
|
|
|
|
tox_options.contents.ipv6_enabled = bool(oArgs.ipv6_enabled)
|
|
|
|
|
|
|
|
if data: # load existing profile
|
|
|
|
tox_options.contents.savedata_type = enums.TOX_SAVEDATA_TYPE['TOX_SAVE']
|
|
|
|
tox_options.contents.savedata_data = c_char_p(data)
|
|
|
|
tox_options.contents.savedata_length = len(data)
|
|
|
|
else: # create new profile
|
|
|
|
tox_options.contents.savedata_type = enums.TOX_SAVEDATA_TYPE['NONE']
|
|
|
|
tox_options.contents.savedata_data = None
|
|
|
|
tox_options.contents.savedata_length = 0
|
|
|
|
|
|
|
|
return tox_options
|
|
|
|
|
|
|
|
def oArgparse(lArgv):
|
|
|
|
parser = ts.oMainArgparser()
|
2023-12-06 16:32:06 +00:00
|
|
|
parser.add_argument('--norequest',type=str, default='False',
|
|
|
|
choices=['True','False'],
|
|
|
|
help='Use _norequest')
|
2022-09-26 00:58:57 +00:00
|
|
|
parser.add_argument('profile', type=str, nargs='?', default=None,
|
|
|
|
help='Path to Tox profile')
|
|
|
|
oArgs = parser.parse_args(lArgv)
|
|
|
|
|
|
|
|
for key in ts.lBOOLEANS:
|
|
|
|
if key not in oArgs: continue
|
|
|
|
val = getattr(oArgs, key)
|
|
|
|
setattr(oArgs, key, bool(val))
|
|
|
|
|
|
|
|
if hasattr(oArgs, 'sleep'):
|
|
|
|
if oArgs.sleep == 'qt':
|
|
|
|
pass # broken or gevent.sleep(idle_period)
|
|
|
|
elif oArgs.sleep == 'gevent':
|
|
|
|
pass # broken or gevent.sleep(idle_period)
|
|
|
|
else:
|
|
|
|
oArgs.sleep = 'time'
|
|
|
|
|
|
|
|
return oArgs
|
|
|
|
|
2023-12-13 00:57:28 +00:00
|
|
|
def main(lArgs=None) -> int:
|
2022-09-26 00:58:57 +00:00
|
|
|
global oTOX_OARGS
|
|
|
|
if lArgs is None: lArgs = []
|
|
|
|
oArgs = oArgparse(lArgs)
|
|
|
|
global bIS_LOCAL
|
|
|
|
bIS_LOCAL = oArgs.network in ['newlocal', 'localnew', 'local']
|
|
|
|
oTOX_OARGS = oArgs
|
|
|
|
setattr(oTOX_OARGS, 'bIS_LOCAL', bIS_LOCAL)
|
|
|
|
bIS_LOCAL = True
|
|
|
|
setattr(oTOX_OARGS, 'bIS_LOCAL', bIS_LOCAL)
|
|
|
|
# oTOX_OPTIONS = ToxOptions()
|
|
|
|
global oTOX_OPTIONS
|
2023-12-16 23:23:00 +00:00
|
|
|
oTOX_OPTIONS = oTestsToxOptions(oArgs)
|
2022-09-26 00:58:57 +00:00
|
|
|
if coloredlogs:
|
|
|
|
# https://pypi.org/project/coloredlogs/
|
|
|
|
coloredlogs.install(level=oArgs.loglevel,
|
|
|
|
logger=LOG,
|
|
|
|
# %(asctime)s,%(msecs)03d %(hostname)s [%(process)d]
|
|
|
|
fmt='%(name)s %(levelname)s %(message)s'
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
logging.basicConfig(level=oArgs.loglevel) # logging.INFO
|
|
|
|
|
|
|
|
return iMain(oArgs)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
sys.exit(main(sys.argv[1:]))
|