[tor-commits] [tor/master] Add a test for n_cells_in_circuit_queues
nickm at torproject.org
nickm at torproject.org
Thu Jul 18 18:40:18 UTC 2013
commit 1e78100b250a55a925c7e8b510090a8ceee19025
Author: Nick Mathewson <nickm at torproject.org>
Date: Thu Jul 18 11:21:27 2013 -0400
Add a test for n_cells_in_circuit_queues
---
src/or/circuitlist.c | 2 +-
src/or/circuitlist.h | 1 +
src/test/test_cell_queue.c | 43 +++++++++++++++++++++++++++++++++++++++++++
3 files changed, 45 insertions(+), 1 deletion(-)
diff --git a/src/or/circuitlist.c b/src/or/circuitlist.c
index 2a85b7d..85bacce 100644
--- a/src/or/circuitlist.c
+++ b/src/or/circuitlist.c
@@ -1640,7 +1640,7 @@ marked_circuit_free_cells(circuit_t *circ)
}
/** Return the number of cells used by the circuit <b>c</b>'s cell queues. */
-static size_t
+STATIC size_t
n_cells_in_circ_queues(const circuit_t *c)
{
size_t n = c->n_chan_cells.n;
diff --git a/src/or/circuitlist.h b/src/or/circuitlist.h
index a5a5485..4e56f52 100644
--- a/src/or/circuitlist.h
+++ b/src/or/circuitlist.h
@@ -72,6 +72,7 @@ void channel_note_destroy_not_pending(channel_t *chan, circid_t id);
#ifdef CIRCUITLIST_PRIVATE
STATIC void circuit_free(circuit_t *circ);
+STATIC size_t n_cells_in_circ_queues(const circuit_t *c);
#endif
#endif
diff --git a/src/test/test_cell_queue.c b/src/test/test_cell_queue.c
index 8916b06..cf2d11a 100644
--- a/src/test/test_cell_queue.c
+++ b/src/test/test_cell_queue.c
@@ -97,7 +97,50 @@ test_cq_manip(void *arg)
free_cell_pool();
}
+static void
+test_circuit_n_cells(void *arg)
+{
+ packed_cell_t *pc1=NULL, *pc2=NULL, *pc3=NULL, *pc4=NULL, *pc5=NULL;
+ origin_circuit_t *origin_c=NULL;
+ or_circuit_t *or_c=NULL;
+
+ (void)arg;
+
+ init_cell_pool();
+
+ pc1 = packed_cell_new();
+ pc2 = packed_cell_new();
+ pc3 = packed_cell_new();
+ pc4 = packed_cell_new();
+ pc5 = packed_cell_new();
+ tt_assert(pc1 && pc2 && pc3 && pc4 && pc5);
+
+ or_c = or_circuit_new(0, NULL);
+ origin_c = origin_circuit_new();
+ origin_c->base_.purpose = CIRCUIT_PURPOSE_C_GENERAL;
+
+ tt_int_op(n_cells_in_circ_queues(TO_CIRCUIT(or_c)), ==, 0);
+ cell_queue_append(&or_c->p_chan_cells, pc1);
+ tt_int_op(n_cells_in_circ_queues(TO_CIRCUIT(or_c)), ==, 1);
+ cell_queue_append(&or_c->base_.n_chan_cells, pc2);
+ cell_queue_append(&or_c->base_.n_chan_cells, pc3);
+ tt_int_op(n_cells_in_circ_queues(TO_CIRCUIT(or_c)), ==, 3);
+
+ tt_int_op(n_cells_in_circ_queues(TO_CIRCUIT(origin_c)), ==, 0);
+ cell_queue_append(&origin_c->base_.n_chan_cells, pc4);
+ cell_queue_append(&origin_c->base_.n_chan_cells, pc5);
+ tt_int_op(n_cells_in_circ_queues(TO_CIRCUIT(origin_c)), ==, 2);
+
+ done:
+ circuit_free(TO_CIRCUIT(or_c));
+ circuit_free(TO_CIRCUIT(origin_c));
+
+ free_cell_pool();
+}
+
struct testcase_t cell_queue_tests[] = {
{ "basic", test_cq_manip, TT_FORK, NULL, NULL, },
+ { "circ_n_cells", test_circuit_n_cells, TT_FORK, NULL, NULL },
END_OF_TESTCASES
};
+
More information about the tor-commits
mailing list