[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r25528 - in gnunet-update/src: gnunet_update tests
From: |
gnunet |
Subject: |
[GNUnet-SVN] r25528 - in gnunet-update/src: gnunet_update tests |
Date: |
Tue, 18 Dec 2012 18:36:51 +0100 |
Author: harsha
Date: 2012-12-18 18:36:51 +0100 (Tue, 18 Dec 2012)
New Revision: 25528
Modified:
gnunet-update/src/gnunet_update/util.py
gnunet-update/src/tests/Makefile.am
gnunet-update/src/tests/test_util.py
Log:
- encode_data_to_string(); neede for generating URI from CHK blocks
Modified: gnunet-update/src/gnunet_update/util.py
===================================================================
--- gnunet-update/src/gnunet_update/util.py 2012-12-18 16:35:24 UTC (rev
25527)
+++ gnunet-update/src/gnunet_update/util.py 2012-12-18 17:36:51 UTC (rev
25528)
@@ -353,6 +353,36 @@
return -1
return ret
+def encode_data_to_string (data):
+ """Returns an ASCII encoding of the given data block like
+ GNUNET_STRINGS_data_to_string() function.
+
+ data: The block of data which has to be encoded
+ """
+ echart = "0123456789ABCDEFGHIJKLMNOPQRSTUV"
+ assert (None != data)
+ size = len(data)
+ assert (0 != size)
+ vbit = 0
+ wpos = 0
+ rpos = 0
+ bits = 0
+ out = ""
+ while (rpos < size) or (vbit > 0):
+ if (rpos < size) and (vbit < 5):
+ bits = (bits << 8) | ord (data[rpos]) # eat 8 more bits
+ rpos += 1
+ vbit += 8
+ if (vbit < 5):
+ bits <<= (5 - vbit) # zero-padding
+ assert (vbit == ((size * 8) % 5))
+ vbit = 5
+ out += echart[(bits >> (vbit - 5)) & 31]
+ wpos += 1
+ vbit -= 5
+ assert (0 == vbit)
+ return out;
+
# From
http://love-python.blogspot.de/2010/03/getch-in-python-get-single-character.html
import sys
import termios
Modified: gnunet-update/src/tests/Makefile.am
===================================================================
--- gnunet-update/src/tests/Makefile.am 2012-12-18 16:35:24 UTC (rev 25527)
+++ gnunet-update/src/tests/Makefile.am 2012-12-18 17:36:51 UTC (rev 25528)
@@ -5,6 +5,9 @@
check_DATA = \
gen_user_home
+check_PROGRAMS = \
+ test_data_to_string
+
gen_user_home: gen_user_home.sh.in Makefile
$(do_subst) < $(srcdir)/gen_user_home.sh.in > gen_user_home.sh
chmod +x gen_user_home.sh
@@ -92,3 +95,8 @@
dist-hook:
rm -rf `find $(distdir)/keys -type d -name .svn`
rm -rf `find $(distdir)/confs -type d -name .svn`
+
+test_data_to_string_SOURCES = \
+ test_data_to_string.c
+test_data_to_string_LDADD = \
+ -lgnunetutil
Modified: gnunet-update/src/tests/test_util.py
===================================================================
--- gnunet-update/src/tests/test_util.py 2012-12-18 16:35:24 UTC (rev
25527)
+++ gnunet-update/src/tests/test_util.py 2012-12-18 17:36:51 UTC (rev
25528)
@@ -28,6 +28,7 @@
from textwrap import dedent
import gpgme
import shutil
+import subprocess
import __init__
import gnunet_update.util as util
@@ -227,5 +228,18 @@
self.assertEqual(ret, 0)
self.assertTrue(util.gpg_key_exists(fpr))
+ def test_encode_data_to_string (self):
+ """Tests whether our function behaves similar to
+ GNUNET_STRING_data_to_string() function"""
+
+ proc = subprocess.Popen (["./test_data_to_string"],
+ stdout = subprocess.PIPE)
+ (proc_out, proc_err) = proc.communicate ()
+ proc.stdout.close()
+ data = "This is some test data"
+ out = util.encode_data_to_string (data);
+ self.assertFalse (out is None)
+ self.assertEqual (proc_out, out)
+
if __name__ == '__main__':
unittest.main()
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r25528 - in gnunet-update/src: gnunet_update tests,
gnunet <=