def testRefCountCreate(self): """Tests if reference count is set correctly on creation""" # Not sure why, but the following statements need to be run once before # mem() is invoked to get a stable initial memory footprint. If these # statements are not run, the initial memory footprint is ***always*** # different from the one after the loop. I can only guess that these # statements have side-effects in Python that claim memory when they # are run for the first time... md5() mem() # The number of md5 objects to create. Should be high enough so that # the cumulative memory leak (if it exists) is greater than a memory # page size (see limitations of mem()). objectCount = 10000 # Get memory after all objects that remain in use have been created. # After this statement only objects must be created that are expected # to be destroyed before the next invocation of mem(). memory = mem() while objectCount > 0: objectCount -= 1 # Store no references. If the C implementation handles reference # counts correctly, it can be expected that the object will be # destroyed immediately. md5() self.assertEqual(memory, mem())
def testRefCountCopy(self): """Tests if reference count is set correctly on md5.copy()""" # See comment in the first test method above why these statements are # necessary md5() mem() # The actual test starts here objectCount = 10000 memory = mem() while objectCount > 0: objectCount -= 1 md5().copy() self.assertEqual(memory, mem())
def testRefCountHash(self): """Tests if no memory leaks occur when performing a hash operation""" # See comment in the first test method above why these statements are # necessary m = md5(self.inputNormal) mem() # The actual test starts here objectCount = 10000 memory = mem() while objectCount > 0: objectCount -= 1 m = md5(self.inputNormal) self.assertEqual(m.hexdigest(), self.expectedHexdigestInputNormal) self.assertEqual(memory, mem())
def testCopyAndDelete(self): m1 = md5(self.inputNormal) m2 = m1.copy() del m1 m2.update(self.inputNormal) hexdigest = m2.hexdigest() self.assertEqual(hexdigest, self.expectedHexdigestInputTwice)
def testCopyTwice(self): m1 = md5(self.inputNormal) m2 = m1.copy() m3 = m1.copy() self.assertNotEqual(m1, m2) self.assertNotEqual(m1, m3) self.assertNotEqual(m2, m3)
def testHexdigestTwice(self): m = md5() m.update(self.inputNormal) hexdigest1 = m.hexdigest() hexdigest2 = m.hexdigest() self.assertEqual(hexdigest1, self.expectedHexdigestInputNormal) self.assertEqual(hexdigest2, self.expectedHexdigestInputNormal)
def testHexdigest(self): # This test is somewhat pointless, the hexdigest() method has already # been thoroughly tested by other functions. We still perform this # test so that hexdigest() has at least one explicit test. m = md5() m.update(self.inputNormal) hexdigest = m.hexdigest() self.assertEqual(hexdigest, self.expectedHexdigestInputNormal)
def testCopy(self): m1 = md5(self.inputNormal) m2 = m1.copy() self.assertNotEqual(m1, m2) hexdigest1 = m1.hexdigest() hexdigest2 = m2.hexdigest() self.assertEqual(hexdigest1, self.expectedHexdigestInputNormal) self.assertEqual(hexdigest2, self.expectedHexdigestInputNormal) m1.update(self.inputNormal) hexdigest1 = m1.hexdigest() hexdigest2 = m2.hexdigest() self.assertEqual(hexdigest1, self.expectedHexdigestInputTwice) self.assertEqual(hexdigest2, self.expectedHexdigestInputNormal)
def testUpdateInputIsNone(self): m = md5() input = None self.assertRaises(TypeError, m.update, input)
def testUpdateInputIsEmpty(self): m = md5() m.update(self.inputEmpty) hexdigest = m.hexdigest() self.assertEqual(hexdigest, self.expectedHexdigestInputEmpty)
def testUpdate(self): m = md5() m.update(self.inputNormal) hexdigest = m.hexdigest() self.assertEqual(hexdigest, self.expectedHexdigestInputNormal)
def testDelete(self): # There's not much that we can test besides the bare fact that an md5 # object can be deleted without any error m = md5() del m
def testCreateTwice(self): m1 = md5() m2 = md5() self.assertNotEqual(m1, m2)
def testCreateInitInputIsEmpty(self): m = md5(self.inputEmpty) hexdigest = m.hexdigest() self.assertEqual(hexdigest, self.expectedHexdigestInputEmpty)
def testCreateKeywordInitInput(self): m = md5(input = self.inputNormal) hexdigest = m.hexdigest() self.assertEqual(hexdigest, self.expectedHexdigestInputNormal)
def testCreate(self): m = md5() hexdigest = m.hexdigest() self.assertEqual(hexdigest, self.expectedHexdigestInputEmpty)
def testName(self): m = md5() self.assertEqual(m.name, "md5")
def testBlockSize(self): m = md5() self.assertEqual(m.block_size, 64)
def testDigestSize(self): m = md5() self.assertEqual(m.digest_size, 16)
def testDigest(self): m = md5() m.update(self.inputNormal) digest = m.digest() self.assertEqual(digest, self.expectedDigestInputNormal)