forked from mandiant/flare-floss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_memdiff.py
59 lines (49 loc) · 1.58 KB
/
test_memdiff.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# Copyright (C) 2017 Mandiant, Inc. All Rights Reserved.
import pytest
import envi.memory
from floss.string_decoder import memdiff
basic_tests = [
# Empty strings
("", ""),
# Single byte matching
("a", "a"),
# Single byte diffing
("a", "b"),
# Multi-byte first character diff
("aaa", "baa"),
# Multi-byte mid character diff
("aaa", "aba"),
# multi-byte last character diff
("aaa", "aab"),
# Multi-byte multi-diff
("aaaa", "abab"),
]
def test_basics():
for a, b in basic_tests:
assert envi.memory.memdiff(a, b) == memdiff(a, b)
# Make sure we're throwing an exception on different length strings
with pytest.raises(Exception):
memdiff("a", "aa")
complex_tests = [
# 32 byte diff in the second half of the input string
("A" * 800, ("A" * 512) + ("B" * 32) + ("A" * 256)),
# 32 byte diff in the first half of the input string
("A" * 800, ("A" * 256) + ("B" * 32) + ("A" * 512)),
# early 512 byte diff
("A" * 800, ("A" * 32) + ("B" * 512) + ("A" * 256)),
# End of line diff
("A" * 800, ("A" * 799) + "B"),
# Beginning of line diff
("A" * 800, "B" + ("A" * 799)),
# Midpoint diff
("A" * 800, ("A" * 400) + "B" + ("A" * 399)),
# Midpoint diff
("A" * 800, ("A" * 399) + "B" + ("A" * 400)),
# Midpoint diff
("A" * 800, ("A" * 399) + "BB" + ("A" * 399)),
# 7 diffs, each 100 characters apart
("A" * 800, ((("A" * 100) + "B") * 7) + ("A" * 93)),
]
def test_complex():
for a, b in complex_tests:
assert envi.memory.memdiff(a, b) == memdiff(a, b)