Coverage for src/lib/python/isc/bind10/tests/sockcreator_test : 92%
        
        
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
| 
 # Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC") # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM # DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL # INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING # FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 
 Tests for the bind10.sockcreator module. """ 
 
 """ Class emulating the socket to the socket creator. It can be given expected data to receive (and check) and responses to give to the Parser class during testing. """ 
 """ Raised when someone wants to recv when sending is planned or vice versa. """ 
 """ Raises when the data passed to sendall are not the same as expected. """ 
 """ Create the object. The plan variable contains list of expected actions, in form: 
 [('r', 'Data to return from recv'), ('s', 'Data expected on sendall'), , ('d', 'File descriptor number to return from read_sock'), ('e', None), ...] 
 It modifies the array as it goes. """ 
 raise InvalidPlan('Nothing more planned') raise InvalidPlan('Planned ' + kind + ', but ' + expected + 'requested') 
 """ Emulate recv. Returs maxsize bytes from the current recv plan. If there are data left from previous recv call, it is used first. 
 If no recv is planned, raises InvalidPlan. """ else: 
 """ Emulate the reading of file descriptor. Returns one from a plan. 
 It raises InvalidPlan if no socket is planned now. """ 
 """ Checks that the data passed are correct according to plan. It raises InvalidData if the data differs or InvalidPlan when sendall is not expected. """ raise InvalidData('Expected "' + str(prefix)+ '", got "' + str(data) + '"') self.__plan[0] = ('s', rest) else: 
 """ Returns if the whole plan was consumed. """ 
 """ Testcases for the Parser class. 
 A lot of these test could be done by `with self.assertRaises(CreatorError) as cm`. But some versions of python take the scope wrong and don't work, so we use the primitive way of try-except. """ 
 """ Test if the command to terminate is correct and it waits for reading the EOF. """ 
 """ Check that terminate() raises a fatal exception. """ self.fail("Not raised") 
 """ Test it reports an exception when there's error terminating the creator. This one raises an error when receiving the EOF. """ 
 """ Test it reports an exception when there's error terminating the creator. This one raises an error when sending data. """ 
 """ Test it reports an exception when there's error terminating the creator. This one sends data when it should have terminated. """ 
 """ Test we can't terminate twice. """ 
 """ Tests that the parser correctly raises exception when it crashes unexpectedly. """ self.fail("Not raised") # Is the exception correct? 
 """ Tests that the parser correctly raises non-fatal exception when the socket can not be created. """ # We split the int to see if it can cope with data coming in # different packets intpart[:1]), ('r', intpart[1:])]) self.fail("Not raised") # Is the exception correct? 
 self.fail("Not raised") 
 
 
 
 
 
 b'T6\0\x2A\x20\x01\x0d\xb8\0\0\0\0\0\0\0\0\0\0\0\0') 
 """ Test we can't request sockets after it was terminated. """ self.fail("Not raised") 
 """ Test invalid socket type is rejected """ IPAddr('0.0.0.0'), 42, 'RAW') 
 """ Test it rejects invalid address family. """ # Note: this produces a bad logger output, since this address # can not be converted to string, so the original message with # placeholders is output. This should not happen in practice, so # it is harmless. addr, 42, socket.SOCK_DGRAM) 
 """ Tests for the wrap_socket function. """ # We construct two pairs of socket. The receiving side of one pair will # be wrapped. Then we send one of the other pair through this pair and # check the received one can be used as a socket 
 # The transport socket # The payload socket 
 
 # Transfer the descriptor 
 # Now, pass some data trough the socket 
 # Test the wrapping didn't hurt the socket's usual methods 
  |