[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] moving useful test helper to test_helpers.h



commit b95998ef0c31c78a9952621eb1f7365ceb1d2c84
Author: Chelsea H. Komlo <chelsea.komlo@xxxxxxxxx>
Date:   Sun Oct 16 06:40:37 2016 -0500

    moving useful test helper to test_helpers.h
---
 changes/ticket18873     |  3 +++
 src/test/test_helpers.c | 21 +++++++++++++++++++++
 src/test/test_helpers.h |  2 ++
 src/test/test_oom.c     | 19 +------------------
 4 files changed, 27 insertions(+), 18 deletions(-)

diff --git a/changes/ticket18873 b/changes/ticket18873
new file mode 100644
index 0000000..ada6798
--- /dev/null
+++ b/changes/ticket18873
@@ -0,0 +1,3 @@
+  o Code simplification and refactoring:
+    - Extracted dummy_origin_circuit_new so it can be used by other test
+      functions.
diff --git a/src/test/test_helpers.c b/src/test/test_helpers.c
index 130ec43..fbc09fa 100644
--- a/src/test/test_helpers.c
+++ b/src/test/test_helpers.c
@@ -10,6 +10,7 @@
 #include "orconfig.h"
 #include "or.h"
 
+#include "relay.h"
 #include "routerlist.h"
 #include "nodelist.h"
 #include "buffers.h"
@@ -23,6 +24,8 @@ DISABLE_GCC_WARNING(overlength-strings)
  * at large. */
 #endif
 #include "test_descriptors.inc"
+#include "or.h"
+#include "circuitlist.h"
 #ifdef HAVE_CFLAG_WOVERLENGTH_STRINGS
 ENABLE_GCC_WARNING(overlength-strings)
 #endif
@@ -105,3 +108,21 @@ connection_write_to_buf_mock(const char *string, size_t len,
   write_to_buf(string, len, conn->outbuf);
 }
 
+circuit_t *
+dummy_origin_circuit_new(int n_cells)
+{
+  origin_circuit_t *circ = origin_circuit_new();
+  int i;
+  cell_t cell;
+
+  for (i=0; i < n_cells; ++i) {
+    crypto_rand((void*)&cell, sizeof(cell));
+    cell_queue_append_packed_copy(TO_CIRCUIT(circ),
+                                  &TO_CIRCUIT(circ)->n_chan_cells,
+                                  1, &cell, 1, 0);
+  }
+
+  TO_CIRCUIT(circ)->purpose = CIRCUIT_PURPOSE_C_GENERAL;
+  return TO_CIRCUIT(circ);
+}
+
diff --git a/src/test/test_helpers.h b/src/test/test_helpers.h
index b77a459..ba93b10 100644
--- a/src/test/test_helpers.h
+++ b/src/test/test_helpers.h
@@ -6,6 +6,8 @@
 
 const char *get_yesterday_date_str(void);
 
+circuit_t * dummy_origin_circuit_new(int num_cells);
+
 /* Number of descriptors contained in test_descriptors.txt. */
 #define HELPER_NUMBER_OF_DESCRIPTORS 8
 
diff --git a/src/test/test_oom.c b/src/test/test_oom.c
index 6102af0..0f97972 100644
--- a/src/test/test_oom.c
+++ b/src/test/test_oom.c
@@ -15,6 +15,7 @@
 #include "config.h"
 #include "relay.h"
 #include "test.h"
+#include "test_helpers.h"
 
 /* small replacement mock for circuit_mark_for_close_ to avoid doing all
  * the other bookkeeping that comes with marking circuits. */
@@ -58,24 +59,6 @@ dummy_or_circuit_new(int n_p_cells, int n_n_cells)
   return TO_CIRCUIT(circ);
 }
 
-static circuit_t *
-dummy_origin_circuit_new(int n_cells)
-{
-  origin_circuit_t *circ = origin_circuit_new();
-  int i;
-  cell_t cell;
-
-  for (i=0; i < n_cells; ++i) {
-    crypto_rand((void*)&cell, sizeof(cell));
-    cell_queue_append_packed_copy(TO_CIRCUIT(circ),
-                                  &TO_CIRCUIT(circ)->n_chan_cells,
-                                  1, &cell, 1, 0);
-  }
-
-  TO_CIRCUIT(circ)->purpose = CIRCUIT_PURPOSE_C_GENERAL;
-  return TO_CIRCUIT(circ);
-}
-
 static void
 add_bytes_to_buf(buf_t *buf, size_t n_bytes)
 {



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits