import unittest import solter class TestSolter(unittest.TestCase): def test_get_commands_send_data(self): expected = ['call (int)send(3, "Hello World", 11, 0x4000)'] self.assertEqual(solter.get_commands_send_data(sockfd=3, data="Hello World"), expected) with self.assertRaises(ValueError): solter.get_commands_send_data(sockfd=3, data='Hello"World') with self.assertRaises(ValueError): solter.get_commands_send_data(sockfd=3, data='Hello\nWorld') def test_get_commands_change_tcp_option(self): expected = ( "set $rsp -= sizeof(int)", "set {int}$rsp = 137", "call (int)setsockopt(42, 6, 4, $rsp, sizeof(int))", "set $rsp += sizeof(int)", ) self.assertEqual(solter._get_commands_change_tcp_option(sockfd=42, value=137, param=4), expected) def test_get_commands_enable_keepalive(self): expected = ( "set $rsp -= sizeof(int)", "set {int}$rsp = 1", "call (int)setsockopt(13, 1, 9, $rsp, sizeof(int))", "set $rsp += sizeof(int)", ) self.assertEqual(solter.get_commands_enable_keepalive(sockfd=13), expected) def test_get_commands_disable_keepalive(self): expected = ( "set $rsp -= sizeof(int)", "set {int}$rsp = 0", "call (int)setsockopt(14, 1, 9, $rsp, sizeof(int))", "set $rsp += sizeof(int)", ) self.assertEqual(solter.get_commands_disable_keepalive(sockfd=14), expected) def test_get_commands_change_keepalive_time(self): expected = ( "set $rsp -= sizeof(int)", "set {int}$rsp = 60", "call (int)setsockopt(15, 6, 4, $rsp, sizeof(int))", "set $rsp += sizeof(int)", ) self.assertEqual(solter.get_commands_change_keepalive_time(sockfd=15, value=60), expected) def test_get_commands_change_keepalive_count(self): expected = ( "set $rsp -= sizeof(int)", "set {int}$rsp = 10", "call (int)setsockopt(16, 6, 6, $rsp, sizeof(int))", "set $rsp += sizeof(int)", ) self.assertEqual(solter.get_commands_change_keepalive_count(sockfd=16, value=10), expected) def test_get_commands_change_keepalive_interval(self): expected = ( "set $rsp -= sizeof(int)", "set {int}$rsp = 40", "call (int)setsockopt(17, 6, 5, $rsp, sizeof(int))", "set $rsp += sizeof(int)", ) self.assertEqual(solter.get_commands_change_keepalive_intvl(sockfd=17, value=40), expected)