Decoder_new, /* tp_new */
};
-static PyMethodDef fec_methods[] = {
+PyObject*
+test_from_agl() {
+ unsigned char b1c[8], b2c[8];
+ unsigned char b1[8], b2[8], b3[8], b4[8], b5[8];
+ memset(b1, 1, 8);
+ memset(b2, 2, 8);
+ memset(b3, 3, 8);
+ const unsigned char *blocks[3] = {b1, b2, b3};
+ unsigned char *outblocks[2] = {b4, b5};
+ unsigned block_nums[] = {3, 4};
+
+ fec_t *const fec = fec_new(3, 5);
+ fec_encode(fec, blocks, outblocks, block_nums, 2, 8);
+
+ write(1, b1, 8);
+ write(1, b2, 8);
+ write(1, b3, 8);
+ write(1, b4, 8);
+ write(1, b5, 8);
+
+ memcpy(b1c, b1, 8); memcpy(b2c, b2, 8);
+
+ const unsigned char *inpkts[] = {b3, b4, b5};
+ unsigned char *outpkts[] = {b1, b2};
+ unsigned indexes[] = {2, 3, 4};
+
+ fec_decode(fec, inpkts, outpkts, indexes, 8);
+
+ write(1, b1, 8);
+ write(1, b2, 8);
+
+ if ((memcmp(b1, b1c,8) == 0) && (memcmp(b2, b2c,8) == 0))
+ Py_RETURN_TRUE;
+ else
+ Py_RETURN_FALSE;
+}
+
+static PyMethodDef fec_functions[] = {
+ {"test_from_agl", test_from_agl, METH_NOARGS, NULL},
{NULL}
};
if (PyType_Ready(&Decoder_type) < 0)
return;
- module = Py_InitModule3("_fec", fec_methods, fec__doc__);
+ module = Py_InitModule3("_fec", fec_functions, fec__doc__);
if (module == NULL)
return;
_h_easy(k, m, s)
class ZFecTest(unittest.TestCase):
+ def test_from_agl_c(self):
+ self.failUnless(zfec._fec.test_from_agl())
+
+ def test_from_agl_py(self):
+ e = zfec.Encoder(3, 5)
+ b1 = '\x01'*8 ; b2 = '\x02'*8 ; b3 = '\x03'*8
+ b4, b5 = e.encode([b1, b2, b3], (3, 4))
+ d = zfec.Decoder(3, 5)
+ resblocks = d.decode((b3, b4, b5), (2, 3, 4))
+
+ print "b1: %r, b2: %r, b3: %r, b4: %r, b5: %r, resblocks: %r" % (b1, b2, b3, b4, b5, resblocks)
+
def test_small(self):
for i in range(16):
_help_test_random_with_l(i)