@@ -9,12 +9,6 @@ class ToxTest(unittest.TestCase):
99 def test_version (self ) -> None :
1010 self .assertEqual (len (c .VERSION .split ("." )), 3 )
1111
12- def test_options (self ) -> None :
13- opts = c .Tox_Options_Ptr ()
14- self .assertTrue (opts .ipv6_enabled )
15- opts .ipv6_enabled = False
16- self .assertFalse (opts .ipv6_enabled )
17-
1812 def test_use_after_free (self ) -> None :
1913 opts = c .Tox_Options_Ptr ()
2014 with c .Tox_Ptr (opts ) as tox :
@@ -31,11 +25,26 @@ def test_pass_none(self) -> None:
3125 with c .Tox_Ptr (None ):
3226 pass
3327
28+ def test_pass_invalid_options (self ) -> None :
29+ opts = c .Tox_Options_Ptr ()
30+ opts .proxy_type = c .TOX_PROXY_TYPE_SOCKS5
31+ opts .proxy_host = "invalid-host"
32+ opts .proxy_port = 1234
33+ with self .assertRaises (c .ApiException ) as e :
34+ c .Tox_Ptr (opts )
35+ self .assertEqual (e .exception .code , c .TOX_ERR_NEW_PROXY_BAD_HOST )
36+
3437 def test_address (self ) -> None :
3538 opts = c .Tox_Options_Ptr ()
3639 with c .Tox_Ptr (opts ) as tox :
3740 self .assertEqual (tox .address , tox .address )
3841
42+ def test_nospam (self ) -> None :
43+ with c .Tox_Ptr (None ) as tox :
44+ tox .nospam = 0x12345678
45+ self .assertEqual (tox .nospam , 0x12345678 )
46+ self .assertEqual (tox .address [- 6 :- 2 ].hex (), "12345678" )
47+
3948 def test_public_key_is_address_prefix (self ) -> None :
4049 opts = c .Tox_Options_Ptr ()
4150 with c .Tox_Ptr (opts ) as tox :
@@ -89,6 +98,17 @@ def test_friend_add(self) -> None:
8998 with self .assertRaises (common .LengthException ):
9099 tox2 .friend_add (tox1 .public_key , b"oh no!" )
91100
101+ def test_invalid_bootstrap (self ) -> None :
102+ with c .Tox_Ptr () as tox :
103+ with self .assertRaises (c .ApiException ) as e :
104+ tox .bootstrap ("invalid-host" , 1234 , bytes (c .PUBLIC_KEY_SIZE ))
105+ self .assertEqual (e .exception .code , c .TOX_ERR_BOOTSTRAP_BAD_HOST )
106+
107+ def test_bootstrap_checks_key_length (self ) -> None :
108+ with c .Tox_Ptr () as tox :
109+ with self .assertRaises (common .LengthException ):
110+ tox .bootstrap ("localhost" , 1234 , bytes (c .PUBLIC_KEY_SIZE - 1 ))
111+
92112 def test_friend_delete (self ) -> None :
93113 with c .Tox_Ptr () as tox1 :
94114 with c .Tox_Ptr () as tox2 :
@@ -98,6 +118,30 @@ def test_friend_delete(self) -> None:
98118 # Deleting again: we don't have that friend anymore.
99119 tox1 .friend_delete (0 )
100120
121+ def test_udp_port_fails_when_udp_disabled (self ) -> None :
122+ with c .Tox_Options_Ptr () as opts :
123+ opts .udp_enabled = False
124+ with c .Tox_Ptr (opts ) as tox :
125+ with self .assertRaises (c .ApiException ) as e :
126+ print (tox .udp_port )
127+ self .assertEqual (e .exception .code ,
128+ c .TOX_ERR_GET_PORT_NOT_BOUND )
129+
130+ def test_tcp_port_fails_when_tcp_disabled (self ) -> None :
131+ with c .Tox_Options_Ptr () as opts :
132+ opts .tcp_port = 0
133+ with c .Tox_Ptr (opts ) as tox :
134+ with self .assertRaises (c .ApiException ) as e :
135+ print (tox .tcp_port )
136+ self .assertEqual (e .exception .code ,
137+ c .TOX_ERR_GET_PORT_NOT_BOUND )
138+
139+ def test_tcp_port (self ) -> None :
140+ with c .Tox_Options_Ptr () as opts :
141+ opts .tcp_port = 1234
142+ with c .Tox_Ptr (opts ) as tox :
143+ self .assertEqual (tox .tcp_port , 1234 )
144+
101145
102146if __name__ == "__main__" :
103147 unittest .main ()
0 commit comments