def test_cows_padded(self): """ Tests that COWS works on a buffer that gets padded. """ array = self.__create_buffer(1023) original = array[:] # Stuff the array. cows.cows_stuff(array) self.__check_zero_free(array) # Now try unstuffing it. cows.cows_unstuff(array) # We should get the original back, except for the overhead, which we don't # care about. self.assertSequenceEqual(original[2:], array[2:])
def test_cows_all_zeros(self): """ Tests that COWS works on a buffer that's all zeros. """ array = bytearray([0, 0] * 512) original = array[:] # Stuff the array. cows.cows_stuff(array) self.__check_zero_free(array) # The entire array should be filled with ones. expected = bytearray([0, 1] * 512) self.assertSequenceEqual(expected, array) # Now try unstuffing it. cows.cows_unstuff(array) # We should get the original back, except for the overhead, which we don't # care about. self.assertSequenceEqual(original[2:], array[2:])
def test_cows_padded_no_zeros(self): """ Tests that COWS works on a buffer with no zeros that gets padded. """ array = bytearray([1] * 1023) original = array[:] # Stuff the array. cows.cows_stuff(array) self.__check_zero_free(array) # The array should be unchanged, aside from the overhead. expected = bytearray([2, 0]) + original[2:] self.assertSequenceEqual(expected, array) # Now try unstuffing it. cows.cows_unstuff(array) # We should get the original back, except for the overhead, which we don't # care about. self.assertSequenceEqual(original[2:], array[2:])
def test_cows_padded_all_zeros(self): """ Tests that COWS works on a zero buffer that gets padded. """ array = bytearray([0] * 1023) original = array[:] # Stuff the array. cows.cows_stuff(array) self.__check_zero_free(array) # The entire array should be filled with ones, except for the last word. # This should be 2, because we padded with a non-zero byte. expected = bytearray([0, 1] * 510) + bytearray([0, 2, 0]) self.assertSequenceEqual(expected, array) # Now try unstuffing it. cows.cows_unstuff(array) # We should get the original back, except for the overhead, which we don't # care about. self.assertSequenceEqual(original[2:], array[2:])