[tor-commits] [tor/master] Quick-and-dirty test for packed_cell_is_destroy

nickm at torproject.org nickm at torproject.org
Wed May 7 07:11:48 UTC 2014


commit e198faa633e8cecccfb3aa032f491cc4c740dd15
Author: Nick Mathewson <nickm at torproject.org>
Date:   Wed May 7 02:05:35 2014 -0400

    Quick-and-dirty test for packed_cell_is_destroy
---
 src/test/test_cell_formats.c |   44 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/src/test/test_cell_formats.c b/src/test/test_cell_formats.c
index b0eb2fc..d7f6068 100644
--- a/src/test/test_cell_formats.c
+++ b/src/test/test_cell_formats.c
@@ -8,7 +8,9 @@
 #define CONNECTION_EDGE_PRIVATE
 #define RELAY_PRIVATE
 #include "or.h"
+#include "channel.h"
 #include "connection_edge.h"
+#include "connection_or.h"
 #include "onion.h"
 #include "onion_tap.h"
 #include "onion_fast.h"
@@ -1212,6 +1214,47 @@ test_cfmt_resolved_cells(void *arg)
 #undef CLEAR_CELL
 }
 
+static void
+test_cfmt_is_destroy(void *arg)
+{
+  cell_t cell;
+  packed_cell_t packed;
+  circid_t circid = 0;
+  channel_t *chan;
+  (void)arg;
+
+  chan = tor_malloc_zero(sizeof(channel_t));
+
+  memset(&cell, 0xff, sizeof(cell));
+  cell.circ_id = 3003;
+  cell.command = CELL_RELAY;
+
+  cell_pack(&packed, &cell, 0);
+  chan->wide_circ_ids = 0;
+  tt_assert(! packed_cell_is_destroy(chan, &packed, &circid));
+  tt_int_op(circid, ==, 0);
+
+  cell_pack(&packed, &cell, 1);
+  chan->wide_circ_ids = 1;
+  tt_assert(! packed_cell_is_destroy(chan, &packed, &circid));
+  tt_int_op(circid, ==, 0);
+
+  cell.command = CELL_DESTROY;
+
+  cell_pack(&packed, &cell, 0);
+  chan->wide_circ_ids = 0;
+  tt_assert(packed_cell_is_destroy(chan, &packed, &circid));
+  tt_int_op(circid, ==, 3003);
+
+  circid = 0;
+  cell_pack(&packed, &cell, 1);
+  chan->wide_circ_ids = 1;
+  tt_assert(packed_cell_is_destroy(chan, &packed, &circid));
+
+ done:
+  tor_free(chan);
+}
+
 #define TEST(name, flags)                                               \
   { #name, test_cfmt_ ## name, flags, 0, NULL }
 
@@ -1224,6 +1267,7 @@ struct testcase_t cell_format_tests[] = {
   TEST(extend_cells, 0),
   TEST(extended_cells, 0),
   TEST(resolved_cells, 0),
+  TEST(is_destroy, 0),
   END_OF_TESTCASES
 };
 





More information about the tor-commits mailing list