Browse Source

Add unknown cell queue entry type case to channel/queue_impossible unit test

Andrea Shepard 10 years ago
parent
commit
b5d4ef18e1
1 changed files with 26 additions and 0 deletions
  1. 26 0
      src/test/test_channel.c

+ 26 - 0
src/test/test_channel.c

@@ -896,6 +896,32 @@ test_channel_queue_impossible(void *arg)
   test_assert(test_cells_written == old_count);
   test_eq(chan_cell_queue_len(&(ch->outgoing_queue)), 0);
 
+  /* Unknown cell type case */
+  test_chan_accept_cells = 0;
+  ch->state = CHANNEL_STATE_MAINT;
+  cell = tor_malloc_zero(sizeof(cell_t));
+  make_fake_cell(cell);
+  channel_write_cell(ch, cell);
+
+  /* Check that it's queued */
+  test_eq(chan_cell_queue_len(&(ch->outgoing_queue)),1);
+  q = TOR_SIMPLEQ_FIRST(&(ch->outgoing_queue));
+  test_assert(q);
+  if (q) {
+    test_eq(q->type, CELL_QUEUE_FIXED);
+    test_eq(q->u.fixed.cell, cell);
+  }
+  /* Clobber it, including the queue entry type */
+  tor_free(q->u.fixed.cell);
+  q->u.fixed.cell = NULL;
+  q->type = CELL_QUEUE_PACKED + 1;
+
+  /* Let it drain and check that the bad entry is discarded */
+  test_chan_accept_cells = 1;
+  channel_change_state(ch, CHANNEL_STATE_OPEN);
+  test_assert(test_cells_written == old_count);
+  test_eq(chan_cell_queue_len(&(ch->outgoing_queue)), 0);
+
  done:
   tor_free(ch);
   free_cell_pool();