def test_simple_nomatch(self): cmpr = CCNxCompressorFixedLength() # This will match out to 3 of 4 bytes tlv = CCNxTlv(0x0005, 0x00FF, "foo") tlv_list = [tlv] encoded = cmpr.compress(tlv_list) self.assertTrue(encoded is None) # make sure we did not consume the token off the list self.assertTrue(len(tlv_list) == 1)
def test_crc32c(self): input = [0x80, 0x00] truth = [0x00, 0x02, 0x00, 0x00] a = array.array("B") a.fromlist(input) compressor = CCNxCompressorFixedLength() test = compressor.decompress(a) self.assertTrue(test == truth) # it should have only consumed 1 byte self.assertTrue(len(a) == 1)
def test_simple_match(self): cmpr = CCNxCompressorFixedLength() # This entry has no extension. It's a simple match # pairs.append(Pair([0x00, 0x05, 0x00, 0x01], 0x8F)) tlv = CCNxTlv(0x0005, 0x0001, "foo") tlv_list = [tlv] encoded = cmpr.compress(tlv_list) self.assertTrue(encoded is not None) self.assertTrue(encoded == [ 0x8F, 'f', 'o', 'o' ]) # make sure we consumed the token off the list self.assertTrue(len(tlv_list) == 0)
def test_pairs(self): """ Ensure that we can lookup all the token_strings and get the right compressed keys. """ cmpr = CCNxCompressorFixedLength() # We access some "private" data following the name manging rules for p in CCNxCompressorFixedLength._CCNxCompressorFixedLength__tuples: key = CCNxCompressorFixedLength._CCNxCompressorFixedLength__trie.search(p.token_string) self.assertTrue(p.compressed_key == key)
def test_sub_match(self): # pairs.append(Pair([0x00, 0x03, 0x00, 0x04], 0x83)) # pairs.append(Pair([0x00, 0x03, 0x00, 0x04, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04], 0x84)) # # The string 0x00030004 will match both 0x83 and the prefix of 0x84. # Test with the string 0x00030004000200FF. It should return 83 and only remove one item # from the TLV list cmpr = CCNxCompressorFixedLength() tlv1 = CCNxTlv(0x0003, 0x0004, None) tlv2 = CCNxTlv(0x0002, 0x00FF, None) tlv_list = [tlv1, tlv2] encoded = cmpr.compress(tlv_list) self.assertTrue(encoded is not None) self.assertTrue(encoded == [0x83]) # make sure we consumed the token off the list self.assertTrue(len(tlv_list) == 1)
def test_expiry(self): value = [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08] # setup the input with the compressed key, value, and extra junk at end input = [0x90] input.extend(value) input.append(0xFF) truth = [0x00, 0x06, 0x00, 0x08] a = array.array("B") a.fromlist(input) compressor = CCNxCompressorFixedLength() test = compressor.decompress(a) self.assertTrue(test == truth) # it should have only consumed 9 byte self.assertTrue(len(a) == 9)
def test_longest_match(self): # pairs.append(Pair([0x00, 0x03, 0x00, 0x04], 0x83)) # pairs.append(Pair([0x00, 0x03, 0x00, 0x04, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04], 0x84)) # # The string 0x00030004 will match both 0x83 and the prefix of 0x84. # Test with the full string match. It should return 84 and more 3 items from list # from the TLV list cmpr = CCNxCompressorFixedLength() tlv1 = CCNxTlv(0x0003, 0x0004, None) tlv2 = CCNxTlv(0x0002, 0x0000, None) tlv3 = CCNxTlv(0x0004, 0x0004, "foo") tlv4 = CCNxTlv(0x00FF, 0x00FF, None) tlv_list = [tlv1, tlv2, tlv3, tlv4] encoded = cmpr.compress(tlv_list) self.assertTrue(encoded is not None) self.assertTrue(encoded == [ 0x84, 'f', 'o', 'o' ]) # make sure we consumed the token off the list self.assertTrue(len(tlv_list) == 1)