From: warner Date: Wed, 28 Mar 2007 19:53:12 +0000 (+0530) Subject: pyfec: fix some error-checking, add more unit tests X-Git-Url: https://git.rkrishnan.org/pf/content/en/seg/about/-?a=commitdiff_plain;h=db8a2120e29ef28a131f9f7bda96a5361ab1f9f7;p=tahoe-lafs%2Fzfec.git pyfec: fix some error-checking, add more unit tests darcs-hash:6cb92d225fd5ebd7d1e00d5942ae03dc39b2672f --- diff --git a/pyfec/fec/_fecmodule.c b/pyfec/fec/_fecmodule.c index 66a6448..bf5174e 100644 --- a/pyfec/fec/_fecmodule.c +++ b/pyfec/fec/_fecmodule.c @@ -151,10 +151,14 @@ Encoder_encode(Encoder *self, PyObject *args) { unsigned c_desired_shares_ids[self->mm]; unsigned c_desired_checkshares_ids[self->mm - self->kk]; unsigned i; + PyObject* fastinshares = NULL; + for (i=0; imm - self->kk; i++) pystrs_produced[i] = NULL; if (desired_shares_ids) { fast_desired_shares_ids = PySequence_Fast(desired_shares_ids, "Second argument (optional) was not a sequence."); + if (!fast_desired_shares_ids) + goto err; num_desired_shares = PySequence_Fast_GET_SIZE(fast_desired_shares_ids); fast_desired_shares_ids_items = PySequence_Fast_ITEMS(fast_desired_shares_ids); for (i=0; imm - self->kk; } - PyObject* fastinshares = PySequence_Fast(inshares, "First argument was not a sequence."); + fastinshares = PySequence_Fast(inshares, "First argument was not a sequence."); if (!fastinshares) goto err; diff --git a/pyfec/fec/test/test_pyfec.py b/pyfec/fec/test/test_pyfec.py index d046c51..f957891 100755 --- a/pyfec/fec/test/test_pyfec.py +++ b/pyfec/fec/test/test_pyfec.py @@ -101,20 +101,42 @@ def test_random(): def test_bad_args_enc(): encer = fec.Encoder(2, 4) try: - encer.encode(["a", "b", ], ["c", "d",]) + encer.encode(["a", "b", ], ["c", "I am not an integer shareid",]) except fec.Error, e: - assert "econd argument is required to contain int" in str(e), e + assert "Precondition violation: second argument is required to contain int" in str(e), e else: raise "Should have gotten fec.Error for wrong type of second argument." + try: + encer.encode(["a", "b", ], 98) # not a sequence at all + except TypeError, e: + assert "Second argument (optional) was not a sequence" in str(e), e + else: + raise "Should have gotten TypeError for wrong type of second argument." + def test_bad_args_dec(): decer = fec.Decoder(2, 4) + + try: + decer.decode(98, [0, 1]) # first argument is not a sequence + except TypeError, e: + assert "First argument was not a sequence" in str(e), e + else: + raise "Should have gotten TypeError for wrong type of second argument." + try: decer.decode(["a", "b", ], ["c", "d",]) except fec.Error, e: - assert "econd argument is required to contain int" in str(e), e + assert "Precondition violation: second argument is required to contain int" in str(e), e else: raise "Should have gotten fec.Error for wrong type of second argument." + + try: + decer.decode(["a", "b", ], 98) # not a sequence at all + except TypeError, e: + assert "Second argument was not a sequence" in str(e), e + else: + raise "Should have gotten TypeError for wrong type of second argument." if __name__ == "__main__":