1 | # this is a bunch of macro tests. If everything passes, there is no output. |
---|
2 | |
---|
3 | import fastsimplexordatastore |
---|
4 | |
---|
5 | size = 64 |
---|
6 | letterxordatastore = fastsimplexordatastore.XORDatastore(size, 16) |
---|
7 | |
---|
8 | startpos = 0 |
---|
9 | for char in range(ord("A"), ord("Q")): |
---|
10 | # put 1K of those chars in... |
---|
11 | letterxordatastore.set_data(startpos, chr(char) * size) |
---|
12 | startpos = startpos + size |
---|
13 | |
---|
14 | # can read data out... |
---|
15 | assert(letterxordatastore.get_data(size, 1) == 'B') |
---|
16 | |
---|
17 | # let's create a bitstring that uses A, C, and P. |
---|
18 | bitstring = chr(int('10100000', 2)) + chr(int('00000001',2)) |
---|
19 | xorresult = letterxordatastore.produce_xor_from_bitstring(bitstring) |
---|
20 | |
---|
21 | assert(xorresult[0] == 'R') |
---|
22 | |
---|
23 | letterxordatastore.set_data(10,"Hello there") |
---|
24 | |
---|
25 | mystring = letterxordatastore.get_data(9,13) |
---|
26 | |
---|
27 | assert(mystring == 'AHello thereA') |
---|
28 | |
---|
29 | |
---|
30 | letterxordatastore.set_data(1,"Hello there"*size) |
---|
31 | |
---|
32 | mystring = letterxordatastore.get_data(size*2 - (size*2 %11) + 1,11) |
---|
33 | |
---|
34 | assert(mystring == "Hello there") |
---|
35 | |
---|
36 | # let's try to read the last bytes of data |
---|
37 | mystring = letterxordatastore.get_data(size*15,size) |
---|
38 | |
---|
39 | |
---|
40 | |
---|
41 | try: |
---|
42 | letterxordatastore = fastsimplexordatastore.XORDatastore(127, 16) |
---|
43 | except TypeError: |
---|
44 | pass |
---|
45 | else: |
---|
46 | print "Was allowed to use a block size that isn't a multiple of 64" |
---|
47 | |
---|
48 | try: |
---|
49 | letterxordatastore.set_data(size*16, "hi") |
---|
50 | except TypeError: |
---|
51 | pass |
---|
52 | else: |
---|
53 | print "Was allowed to write past the end of the datastore" |
---|
54 | |
---|
55 | |
---|
56 | try: |
---|
57 | letterxordatastore.set_data(size*16, 1) |
---|
58 | except TypeError: |
---|
59 | pass |
---|
60 | else: |
---|
61 | print "Was allowed to read past the end of the datastore" |
---|
62 | |
---|
63 | |
---|
64 | for blockcount in [9,15,16]: |
---|
65 | letterxordatastore = fastsimplexordatastore.XORDatastore(size, blockcount) |
---|
66 | |
---|
67 | # is a 0 block the right size? |
---|
68 | assert( len(letterxordatastore.produce_xor_from_bitstring(chr(0)*2)) == size ) |
---|
69 | |
---|
70 | |
---|
71 | |
---|
72 | try: |
---|
73 | letterxordatastore.produce_xor_from_bitstring(chr(0)*1) |
---|
74 | except TypeError: |
---|
75 | pass |
---|
76 | else: |
---|
77 | print "didn't detect incorrect (short) bitstring length" |
---|
78 | |
---|
79 | |
---|
80 | try: |
---|
81 | letterxordatastore.produce_xor_from_bitstring(chr(0)*3) |
---|
82 | except TypeError: |
---|
83 | pass |
---|
84 | else: |
---|
85 | print "didn't detect incorrect (long) bitstring length" |
---|
86 | |
---|
87 | |
---|
88 | |
---|
89 | |
---|
90 | |
---|