Skip to content

Commit

Permalink
#465: add tests for cyxor
Browse files Browse the repository at this point in the history
git-svn-id: https://xpra.org/svn/Xpra/trunk@9021 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Apr 16, 2015
1 parent 51bfc94 commit 5469bb3
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/tests/unit/codecs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env python
# This file is part of Xpra.
# Copyright (C) 2015 Antoine Martin <[email protected]>
50 changes: 50 additions & 0 deletions src/tests/unit/codecs/cyxor_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env python
# This file is part of Xpra.
# Copyright (C) 2015 Antoine Martin <[email protected]>
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
# later version. See the file COPYING for details.

import unittest

from xpra.codecs.xor.cyxor import xor_str
import binascii
def h(v):
return binascii.hexlify(v)

class TestHMAC(unittest.TestCase):

def fail_xor(self, in1, in2):
try:
xor_str(in1, in2)
except:
return
raise Exception("xor_str did not fail on %s / %s", h(in1), h(in2))

def check_xor(self, in1, in2, expected):
out = xor_str(in1, in2)
#print("xor_str(%s, %s)=%s" % (h(in1), h(in2), h(out)))
assert out==expected

def test_xor_str(self):
zeroes = chr(0)*16
ones = chr(1)*16
ff = chr(255)*16
fe = chr(254)*16
empty = ""
lstr = "\0x80"*64
self.check_xor(zeroes, zeroes, zeroes)
self.check_xor(ones, ones, zeroes)
self.check_xor(ff, ones, fe)
self.check_xor(fe, ones, ff)
#feed some invalid data:
self.fail_xor(ones, empty)
self.fail_xor(empty, zeroes)
self.fail_xor(lstr, ff)
self.fail_xor(bool, int)


def main():
unittest.main()

if __name__ == '__main__':
main()

0 comments on commit 5469bb3

Please sign in to comment.