Browse Source

Add scheduler_channel_has_waiting_cells_mock() and some mock counter queries

Andrea Shepard 10 years ago
parent
commit
46ff91b6ec
2 changed files with 46 additions and 0 deletions
  1. 6 0
      src/test/fakechans.h
  2. 40 0
      src/test/test_channel.c

+ 6 - 0
src/test/fakechans.h

@@ -14,6 +14,12 @@ void make_fake_var_cell(var_cell_t *c);
 channel_t * new_fake_channel(void);
 channel_t * new_fake_channel(void);
 
 
 /* Also exposes some a mock used by both test_channel.c and test_relay.c */
 /* Also exposes some a mock used by both test_channel.c and test_relay.c */
+void scheduler_channel_has_waiting_cells_mock(channel_t *ch);
 void scheduler_release_channel_mock(channel_t *ch);
 void scheduler_release_channel_mock(channel_t *ch);
 
 
+/* Query some counters used by the exposed mocks */
+int get_mock_scheduler_has_waiting_cells_count(void);
+int get_mock_scheduler_release_channel_count(void);
+
 #endif /* !defined(TOR_FAKECHANS_H) */
 #endif /* !defined(TOR_FAKECHANS_H) */
+

+ 40 - 0
src/test/test_channel.c

@@ -22,6 +22,7 @@ static int test_chan_accept_cells = 0;
 static int test_cells_written = 0;
 static int test_cells_written = 0;
 static int test_destroy_not_pending_calls = 0;
 static int test_destroy_not_pending_calls = 0;
 static int test_doesnt_want_writes_count = 0;
 static int test_doesnt_want_writes_count = 0;
+static int test_has_waiting_cells_count = 0;
 static double test_overhead_estimate = 1.0f;
 static double test_overhead_estimate = 1.0f;
 static int test_releases_count = 0;
 static int test_releases_count = 0;
 
 
@@ -206,6 +207,31 @@ new_fake_channel(void)
   return chan;
   return chan;
 }
 }
 
 
+/**
+ * Counter query for scheduler_channel_has_waiting_cells_mock()
+ */
+
+int
+get_mock_scheduler_has_waiting_cells_count(void)
+{
+  return test_has_waiting_cells_count;
+}
+
+/**
+ * Mock for scheduler_channel_has_waiting_cells()
+ */
+
+void
+scheduler_channel_has_waiting_cells_mock(channel_t *ch)
+{
+  (void)ch;
+
+  /* Increment counter */
+  ++test_has_waiting_cells_count;
+
+  return;
+}
+
 static void
 static void
 scheduler_channel_doesnt_want_writes_mock(channel_t *ch)
 scheduler_channel_doesnt_want_writes_mock(channel_t *ch)
 {
 {
@@ -217,6 +243,20 @@ scheduler_channel_doesnt_want_writes_mock(channel_t *ch)
   return;
   return;
 }
 }
 
 
+/**
+ * Counter query for scheduler_release_channel_mock()
+ */
+
+int
+get_mock_scheduler_release_channel_count(void)
+{
+  return test_releases_count;
+}
+
+/**
+ * Mock for scheduler_release_channel()
+ */
+
 void
 void
 scheduler_release_channel_mock(channel_t *ch)
 scheduler_release_channel_mock(channel_t *ch)
 {
 {