Skip to content
Snippets Groups Projects
Commit 35156ffc authored by Nick Mathewson's avatar Nick Mathewson :game_die:
Browse files

Merge remote-tracking branch 'public/ticket_13119_v3'

parents 64f65f23 ea72b4f6
No related branches found
No related tags found
No related merge requests found
Showing
with 1574 additions and 1551 deletions
o Code refactoring:
- Revise all unit tests that used the legacy test_* macros to
instead use the recommended tt_* macros. This patch was
generated with coccinelle, to avoid manual errors. Closes
ticket 13119.
This diff is collapsed.
......@@ -22,25 +22,6 @@
#define PRETTY_FUNCTION ""
#endif
#define test_fail_msg(msg) TT_DIE((msg))
#define test_fail() test_fail_msg("Assertion failed.")
#define test_assert(expr) tt_assert(expr)
#define test_eq(expr1, expr2) tt_int_op((expr1), ==, (expr2))
#define test_eq_ptr(expr1, expr2) tt_ptr_op((expr1), ==, (expr2))
#define test_neq(expr1, expr2) tt_int_op((expr1), !=, (expr2))
#define test_neq_ptr(expr1, expr2) tt_ptr_op((expr1), !=, (expr2))
#define test_streq(expr1, expr2) tt_str_op((expr1), ==, (expr2))
#define test_strneq(expr1, expr2) tt_str_op((expr1), !=, (expr2))
#define test_mem_op(expr1, op, expr2, len) \
tt_mem_op((expr1), op, (expr2), (len))
#define test_memeq(expr1, expr2, len) test_mem_op((expr1), ==, (expr2), len)
#define test_memneq(expr1, expr2, len) test_mem_op((expr1), !=, (expr2), len)
/* As test_mem_op, but decodes 'hex' before comparing. There must be a
* local char* variable called mem_op_hex_tmp for this to work. */
#define test_mem_op_hex(expr1, op, hex) \
......@@ -50,7 +31,7 @@
mem_op_hex_tmp = tor_malloc(length/2); \
tor_assert((length&1)==0); \
base16_decode(mem_op_hex_tmp, length/2, hex, length); \
test_mem_op(expr1, op, mem_op_hex_tmp, length/2); \
tt_mem_op(expr1, op, mem_op_hex_tmp, length/2); \
STMT_END
#define test_memeq_hex(expr1, hex) test_mem_op_hex(expr1, ==, hex)
......@@ -85,9 +66,6 @@
const char *get_fname(const char *name);
crypto_pk_t *pk_generate(int idx);
void legacy_test_helper(void *data);
extern const struct testcase_setup_t legacy_setup;
#define US2_CONCAT_2__(a, b) a ## __ ## b
#define US_CONCAT_2__(a, b) a ## _ ## b
#define US_CONCAT_3__(a, b, c) a ## _ ## b ## _ ## c
......
This diff is collapsed.
......@@ -27,10 +27,10 @@ test_buffers_basic(void *arg)
* buf_new
****/
if (!(buf = buf_new()))
test_fail();
TT_DIE(("Assertion failed."));
//test_eq(buf_capacity(buf), 4096);
test_eq(buf_datalen(buf), 0);
tt_int_op(buf_datalen(buf),==, 0);
/****
* General pointer frobbing
......@@ -40,16 +40,16 @@ test_buffers_basic(void *arg)
}
write_to_buf(str, 256, buf);
write_to_buf(str, 256, buf);
test_eq(buf_datalen(buf), 512);
tt_int_op(buf_datalen(buf),==, 512);
fetch_from_buf(str2, 200, buf);
test_memeq(str, str2, 200);
test_eq(buf_datalen(buf), 312);
tt_mem_op(str,==, str2, 200);
tt_int_op(buf_datalen(buf),==, 312);
memset(str2, 0, sizeof(str2));
fetch_from_buf(str2, 256, buf);
test_memeq(str+200, str2, 56);
test_memeq(str, str2+56, 200);
test_eq(buf_datalen(buf), 56);
tt_mem_op(str+200,==, str2, 56);
tt_mem_op(str,==, str2+56, 200);
tt_int_op(buf_datalen(buf),==, 56);
memset(str2, 0, sizeof(str2));
/* Okay, now we should be 512 bytes into the 4096-byte buffer. If we add
* another 3584 bytes, we hit the end. */
......@@ -57,16 +57,16 @@ test_buffers_basic(void *arg)
write_to_buf(str, 256, buf);
}
assert_buf_ok(buf);
test_eq(buf_datalen(buf), 3896);
tt_int_op(buf_datalen(buf),==, 3896);
fetch_from_buf(str2, 56, buf);
test_eq(buf_datalen(buf), 3840);
test_memeq(str+200, str2, 56);
tt_int_op(buf_datalen(buf),==, 3840);
tt_mem_op(str+200,==, str2, 56);
for (j=0;j<15;++j) {
memset(str2, 0, sizeof(str2));
fetch_from_buf(str2, 256, buf);
test_memeq(str, str2, 256);
tt_mem_op(str,==, str2, 256);
}
test_eq(buf_datalen(buf), 0);
tt_int_op(buf_datalen(buf),==, 0);
buf_free(buf);
buf = NULL;
......@@ -76,7 +76,7 @@ test_buffers_basic(void *arg)
write_to_buf(str+1, 255, buf);
//test_eq(buf_capacity(buf), 256);
fetch_from_buf(str2, 254, buf);
test_memeq(str+1, str2, 254);
tt_mem_op(str+1,==, str2, 254);
//test_eq(buf_capacity(buf), 256);
assert_buf_ok(buf);
write_to_buf(str, 32, buf);
......@@ -85,15 +85,15 @@ test_buffers_basic(void *arg)
write_to_buf(str, 256, buf);
assert_buf_ok(buf);
//test_eq(buf_capacity(buf), 512);
test_eq(buf_datalen(buf), 33+256);
tt_int_op(buf_datalen(buf),==, 33+256);
fetch_from_buf(str2, 33, buf);
test_eq(*str2, str[255]);
tt_int_op(*str2,==, str[255]);
test_memeq(str2+1, str, 32);
tt_mem_op(str2+1,==, str, 32);
//test_eq(buf_capacity(buf), 512);
test_eq(buf_datalen(buf), 256);
tt_int_op(buf_datalen(buf),==, 256);
fetch_from_buf(str2, 256, buf);
test_memeq(str, str2, 256);
tt_mem_op(str,==, str2, 256);
/* now try shrinking: case 1. */
buf_free(buf);
......@@ -102,10 +102,10 @@ test_buffers_basic(void *arg)
write_to_buf(str,255, buf);
}
//test_eq(buf_capacity(buf), 33668);
test_eq(buf_datalen(buf), 17085);
tt_int_op(buf_datalen(buf),==, 17085);
for (j=0; j < 40; ++j) {
fetch_from_buf(str2, 255,buf);
test_memeq(str2, str, 255);
tt_mem_op(str2,==, str, 255);
}
/* now try shrinking: case 2. */
......@@ -116,7 +116,7 @@ test_buffers_basic(void *arg)
}
for (j=0; j < 20; ++j) {
fetch_from_buf(str2, 255,buf);
test_memeq(str2, str, 255);
tt_mem_op(str2,==, str, 255);
}
for (j=0;j<80;++j) {
write_to_buf(str,255, buf);
......@@ -124,7 +124,7 @@ test_buffers_basic(void *arg)
//test_eq(buf_capacity(buf),33668);
for (j=0; j < 120; ++j) {
fetch_from_buf(str2, 255,buf);
test_memeq(str2, str, 255);
tt_mem_op(str2,==, str, 255);
}
/* Move from buf to buf. */
......@@ -133,27 +133,27 @@ test_buffers_basic(void *arg)
buf2 = buf_new_with_capacity(4096);
for (j=0;j<100;++j)
write_to_buf(str, 255, buf);
test_eq(buf_datalen(buf), 25500);
tt_int_op(buf_datalen(buf),==, 25500);
for (j=0;j<100;++j) {
r = 10;
move_buf_to_buf(buf2, buf, &r);
test_eq(r, 0);
tt_int_op(r,==, 0);
}
test_eq(buf_datalen(buf), 24500);
test_eq(buf_datalen(buf2), 1000);
tt_int_op(buf_datalen(buf),==, 24500);
tt_int_op(buf_datalen(buf2),==, 1000);
for (j=0;j<3;++j) {
fetch_from_buf(str2, 255, buf2);
test_memeq(str2, str, 255);
tt_mem_op(str2,==, str, 255);
}
r = 8192; /*big move*/
move_buf_to_buf(buf2, buf, &r);
test_eq(r, 0);
tt_int_op(r,==, 0);
r = 30000; /* incomplete move */
move_buf_to_buf(buf2, buf, &r);
test_eq(r, 13692);
tt_int_op(r,==, 13692);
for (j=0;j<97;++j) {
fetch_from_buf(str2, 255, buf2);
test_memeq(str2, str, 255);
tt_mem_op(str2,==, str, 255);
}
buf_free(buf);
buf_free(buf2);
......@@ -163,16 +163,16 @@ test_buffers_basic(void *arg)
cp = "Testing. This is a moderately long Testing string.";
for (j = 0; cp[j]; j++)
write_to_buf(cp+j, 1, buf);
test_eq(0, buf_find_string_offset(buf, "Testing", 7));
test_eq(1, buf_find_string_offset(buf, "esting", 6));
test_eq(1, buf_find_string_offset(buf, "est", 3));
test_eq(39, buf_find_string_offset(buf, "ing str", 7));
test_eq(35, buf_find_string_offset(buf, "Testing str", 11));
test_eq(32, buf_find_string_offset(buf, "ng ", 3));
test_eq(43, buf_find_string_offset(buf, "string.", 7));
test_eq(-1, buf_find_string_offset(buf, "shrdlu", 6));
test_eq(-1, buf_find_string_offset(buf, "Testing thing", 13));
test_eq(-1, buf_find_string_offset(buf, "ngx", 3));
tt_int_op(0,==, buf_find_string_offset(buf, "Testing", 7));
tt_int_op(1,==, buf_find_string_offset(buf, "esting", 6));
tt_int_op(1,==, buf_find_string_offset(buf, "est", 3));
tt_int_op(39,==, buf_find_string_offset(buf, "ing str", 7));
tt_int_op(35,==, buf_find_string_offset(buf, "Testing str", 11));
tt_int_op(32,==, buf_find_string_offset(buf, "ng ", 3));
tt_int_op(43,==, buf_find_string_offset(buf, "string.", 7));
tt_int_op(-1,==, buf_find_string_offset(buf, "shrdlu", 6));
tt_int_op(-1,==, buf_find_string_offset(buf, "Testing thing", 13));
tt_int_op(-1,==, buf_find_string_offset(buf, "ngx", 3));
buf_free(buf);
buf = NULL;
......@@ -240,16 +240,16 @@ test_buffer_pullup(void *arg)
/* Make room for 3000 bytes in the first chunk, so that the pullup-move code
* can get tested. */
tt_int_op(fetch_from_buf(tmp, 3000, buf), ==, 3000);
test_memeq(tmp, stuff, 3000);
tt_mem_op(tmp,==, stuff, 3000);
buf_pullup(buf, 2048, 0);
assert_buf_ok(buf);
buf_get_first_chunk_data(buf, &cp, &sz);
tt_ptr_op(cp, !=, NULL);
tt_int_op(sz, >=, 2048);
test_memeq(cp, stuff+3000, 2048);
tt_mem_op(cp,==, stuff+3000, 2048);
tt_int_op(3000, ==, buf_datalen(buf));
tt_int_op(fetch_from_buf(tmp, 3000, buf), ==, 0);
test_memeq(tmp, stuff+3000, 2048);
tt_mem_op(tmp,==, stuff+3000, 2048);
buf_free(buf);
......@@ -269,16 +269,16 @@ test_buffer_pullup(void *arg)
buf_get_first_chunk_data(buf, &cp, &sz);
tt_ptr_op(cp, !=, NULL);
tt_int_op(sz, >=, 12500);
test_memeq(cp, stuff, 12500);
tt_mem_op(cp,==, stuff, 12500);
tt_int_op(buf_datalen(buf), ==, 16000);
fetch_from_buf(tmp, 12400, buf);
test_memeq(tmp, stuff, 12400);
tt_mem_op(tmp,==, stuff, 12400);
tt_int_op(buf_datalen(buf), ==, 3600);
fetch_from_buf(tmp, 3500, buf);
test_memeq(tmp, stuff+12400, 3500);
tt_mem_op(tmp,==, stuff+12400, 3500);
fetch_from_buf(tmp, 100, buf);
test_memeq(tmp, stuff+15900, 10);
tt_mem_op(tmp,==, stuff+15900, 10);
buf_free(buf);
......@@ -292,7 +292,7 @@ test_buffer_pullup(void *arg)
buf_get_first_chunk_data(buf, &cp, &sz);
tt_ptr_op(cp, !=, NULL);
tt_int_op(sz, ==, 7900);
test_memeq(cp, stuff+100, 7900);
tt_mem_op(cp,==, stuff+100, 7900);
buf_free(buf);
buf = NULL;
......@@ -335,14 +335,14 @@ test_buffer_copy(void *arg)
tt_int_op(0, ==, generic_buffer_set_to_copy(&buf2, buf));
tt_int_op(len, ==, generic_buffer_len(buf2));
generic_buffer_get(buf2, b, len);
test_mem_op(b, ==, s, len);
tt_mem_op(b, ==, s, len);
/* Now free buf2 and retry so we can test allocating */
generic_buffer_free(buf2);
buf2 = NULL;
tt_int_op(0, ==, generic_buffer_set_to_copy(&buf2, buf));
tt_int_op(len, ==, generic_buffer_len(buf2));
generic_buffer_get(buf2, b, len);
test_mem_op(b, ==, s, len);
tt_mem_op(b, ==, s, len);
/* Clear buf for next test */
generic_buffer_get(buf, b, len);
tt_int_op(generic_buffer_len(buf),==,0);
......@@ -362,7 +362,7 @@ test_buffer_copy(void *arg)
for (i = 0; i < 256; ++i) {
generic_buffer_get(buf2, b, len+1);
tt_int_op((unsigned char)b[0],==,i);
test_mem_op(b+1, ==, s, len);
tt_mem_op(b+1, ==, s, len);
}
done:
......@@ -410,7 +410,7 @@ test_buffer_ext_or_cmd(void *arg)
tt_ptr_op(NULL, !=, cmd);
tt_int_op(0x1021, ==, cmd->cmd);
tt_int_op(6, ==, cmd->len);
test_mem_op("abcdef", ==, cmd->body, 6);
tt_mem_op("abcdef", ==, cmd->body, 6);
tt_int_op(0, ==, generic_buffer_len(buf));
ext_or_cmd_free(cmd);
cmd = NULL;
......@@ -422,7 +422,7 @@ test_buffer_ext_or_cmd(void *arg)
tt_ptr_op(NULL, !=, cmd);
tt_int_op(0xffff, ==, cmd->cmd);
tt_int_op(10, ==, cmd->len);
test_mem_op("loremipsum", ==, cmd->body, 10);
tt_mem_op("loremipsum", ==, cmd->body, 10);
tt_int_op(4, ==, generic_buffer_len(buf));
ext_or_cmd_free(cmd);
cmd = NULL;
......@@ -436,7 +436,7 @@ test_buffer_ext_or_cmd(void *arg)
tt_ptr_op(NULL, !=, cmd);
tt_int_op(0x1000, ==, cmd->cmd);
tt_int_op(0xffff, ==, cmd->len);
test_mem_op(tmp, ==, cmd->body, 65535);
tt_mem_op(tmp, ==, cmd->body, 65535);
tt_int_op(0, ==, generic_buffer_len(buf));
ext_or_cmd_free(cmd);
cmd = NULL;
......
......@@ -35,11 +35,11 @@ test_cfmt_relay_header(void *arg)
tt_int_op(rh.command, ==, 3);
tt_int_op(rh.recognized, ==, 0);
tt_int_op(rh.stream_id, ==, 0x2122);
test_mem_op(rh.integrity, ==, "ABCD", 4);
tt_mem_op(rh.integrity, ==, "ABCD", 4);
tt_int_op(rh.length, ==, 0x103);
relay_header_pack(hdr_out, &rh);
test_mem_op(hdr_out, ==, hdr_1, RELAY_HEADER_SIZE);
tt_mem_op(hdr_out, ==, hdr_1, RELAY_HEADER_SIZE);
done:
;
......@@ -402,10 +402,10 @@ test_cfmt_create_cells(void *arg)
tt_int_op(CELL_CREATE, ==, cc.cell_type);
tt_int_op(ONION_HANDSHAKE_TYPE_TAP, ==, cc.handshake_type);
tt_int_op(TAP_ONIONSKIN_CHALLENGE_LEN, ==, cc.handshake_len);
test_memeq(cc.onionskin, b, TAP_ONIONSKIN_CHALLENGE_LEN + 10);
tt_mem_op(cc.onionskin,==, b, TAP_ONIONSKIN_CHALLENGE_LEN + 10);
tt_int_op(0, ==, create_cell_format(&cell2, &cc));
tt_int_op(cell.command, ==, cell2.command);
test_memeq(cell.payload, cell2.payload, CELL_PAYLOAD_SIZE);
tt_mem_op(cell.payload,==, cell2.payload, CELL_PAYLOAD_SIZE);
/* A valid create_fast cell. */
memset(&cell, 0, sizeof(cell));
......@@ -417,10 +417,10 @@ test_cfmt_create_cells(void *arg)
tt_int_op(CELL_CREATE_FAST, ==, cc.cell_type);
tt_int_op(ONION_HANDSHAKE_TYPE_FAST, ==, cc.handshake_type);
tt_int_op(CREATE_FAST_LEN, ==, cc.handshake_len);
test_memeq(cc.onionskin, b, CREATE_FAST_LEN + 10);
tt_mem_op(cc.onionskin,==, b, CREATE_FAST_LEN + 10);
tt_int_op(0, ==, create_cell_format(&cell2, &cc));
tt_int_op(cell.command, ==, cell2.command);
test_memeq(cell.payload, cell2.payload, CELL_PAYLOAD_SIZE);
tt_mem_op(cell.payload,==, cell2.payload, CELL_PAYLOAD_SIZE);
/* A valid create2 cell with a TAP payload */
memset(&cell, 0, sizeof(cell));
......@@ -433,10 +433,10 @@ test_cfmt_create_cells(void *arg)
tt_int_op(CELL_CREATE2, ==, cc.cell_type);
tt_int_op(ONION_HANDSHAKE_TYPE_TAP, ==, cc.handshake_type);
tt_int_op(TAP_ONIONSKIN_CHALLENGE_LEN, ==, cc.handshake_len);
test_memeq(cc.onionskin, b, TAP_ONIONSKIN_CHALLENGE_LEN + 10);
tt_mem_op(cc.onionskin,==, b, TAP_ONIONSKIN_CHALLENGE_LEN + 10);
tt_int_op(0, ==, create_cell_format(&cell2, &cc));
tt_int_op(cell.command, ==, cell2.command);
test_memeq(cell.payload, cell2.payload, CELL_PAYLOAD_SIZE);
tt_mem_op(cell.payload,==, cell2.payload, CELL_PAYLOAD_SIZE);
/* A valid create2 cell with an ntor payload */
memset(&cell, 0, sizeof(cell));
......@@ -450,10 +450,10 @@ test_cfmt_create_cells(void *arg)
tt_int_op(CELL_CREATE2, ==, cc.cell_type);
tt_int_op(ONION_HANDSHAKE_TYPE_NTOR, ==, cc.handshake_type);
tt_int_op(NTOR_ONIONSKIN_LEN, ==, cc.handshake_len);
test_memeq(cc.onionskin, b, NTOR_ONIONSKIN_LEN + 10);
tt_mem_op(cc.onionskin,==, b, NTOR_ONIONSKIN_LEN + 10);
tt_int_op(0, ==, create_cell_format(&cell2, &cc));
tt_int_op(cell.command, ==, cell2.command);
test_memeq(cell.payload, cell2.payload, CELL_PAYLOAD_SIZE);
tt_mem_op(cell.payload,==, cell2.payload, CELL_PAYLOAD_SIZE);
#else
tt_int_op(-1, ==, create_cell_parse(&cc, &cell));
#endif
......@@ -470,10 +470,10 @@ test_cfmt_create_cells(void *arg)
tt_int_op(CELL_CREATE, ==, cc.cell_type);
tt_int_op(ONION_HANDSHAKE_TYPE_NTOR, ==, cc.handshake_type);
tt_int_op(NTOR_ONIONSKIN_LEN, ==, cc.handshake_len);
test_memeq(cc.onionskin, b, NTOR_ONIONSKIN_LEN + 10);
tt_mem_op(cc.onionskin,==, b, NTOR_ONIONSKIN_LEN + 10);
tt_int_op(0, ==, create_cell_format(&cell2, &cc));
tt_int_op(cell.command, ==, cell2.command);
test_memeq(cell.payload, cell2.payload, CELL_PAYLOAD_SIZE);
tt_mem_op(cell.payload,==, cell2.payload, CELL_PAYLOAD_SIZE);
#else
tt_int_op(-1, ==, create_cell_parse(&cc, &cell));
#endif
......@@ -527,10 +527,10 @@ test_cfmt_created_cells(void *arg)
tt_int_op(0, ==, created_cell_parse(&cc, &cell));
tt_int_op(CELL_CREATED, ==, cc.cell_type);
tt_int_op(TAP_ONIONSKIN_REPLY_LEN, ==, cc.handshake_len);
test_memeq(cc.reply, b, TAP_ONIONSKIN_REPLY_LEN + 10);
tt_mem_op(cc.reply,==, b, TAP_ONIONSKIN_REPLY_LEN + 10);
tt_int_op(0, ==, created_cell_format(&cell2, &cc));
tt_int_op(cell.command, ==, cell2.command);
test_memeq(cell.payload, cell2.payload, CELL_PAYLOAD_SIZE);
tt_mem_op(cell.payload,==, cell2.payload, CELL_PAYLOAD_SIZE);
/* A good CREATED_FAST cell */
memset(&cell, 0, sizeof(cell));
......@@ -541,10 +541,10 @@ test_cfmt_created_cells(void *arg)
tt_int_op(0, ==, created_cell_parse(&cc, &cell));
tt_int_op(CELL_CREATED_FAST, ==, cc.cell_type);
tt_int_op(CREATED_FAST_LEN, ==, cc.handshake_len);
test_memeq(cc.reply, b, CREATED_FAST_LEN + 10);
tt_mem_op(cc.reply,==, b, CREATED_FAST_LEN + 10);
tt_int_op(0, ==, created_cell_format(&cell2, &cc));
tt_int_op(cell.command, ==, cell2.command);
test_memeq(cell.payload, cell2.payload, CELL_PAYLOAD_SIZE);
tt_mem_op(cell.payload,==, cell2.payload, CELL_PAYLOAD_SIZE);
/* A good CREATED2 cell with short reply */
memset(&cell, 0, sizeof(cell));
......@@ -556,10 +556,10 @@ test_cfmt_created_cells(void *arg)
tt_int_op(0, ==, created_cell_parse(&cc, &cell));
tt_int_op(CELL_CREATED2, ==, cc.cell_type);
tt_int_op(64, ==, cc.handshake_len);
test_memeq(cc.reply, b, 80);
tt_mem_op(cc.reply,==, b, 80);
tt_int_op(0, ==, created_cell_format(&cell2, &cc));
tt_int_op(cell.command, ==, cell2.command);
test_memeq(cell.payload, cell2.payload, CELL_PAYLOAD_SIZE);
tt_mem_op(cell.payload,==, cell2.payload, CELL_PAYLOAD_SIZE);
/* A good CREATED2 cell with maximal reply */
memset(&cell, 0, sizeof(cell));
......@@ -571,10 +571,10 @@ test_cfmt_created_cells(void *arg)
tt_int_op(0, ==, created_cell_parse(&cc, &cell));
tt_int_op(CELL_CREATED2, ==, cc.cell_type);
tt_int_op(496, ==, cc.handshake_len);
test_memeq(cc.reply, b, 496);
tt_mem_op(cc.reply,==, b, 496);
tt_int_op(0, ==, created_cell_format(&cell2, &cc));
tt_int_op(cell.command, ==, cell2.command);
test_memeq(cell.payload, cell2.payload, CELL_PAYLOAD_SIZE);
tt_mem_op(cell.payload,==, cell2.payload, CELL_PAYLOAD_SIZE);
/* Bogus CREATED2 cell: too long! */
memset(&cell, 0, sizeof(cell));
......@@ -620,15 +620,15 @@ test_cfmt_extend_cells(void *arg)
tt_str_op("18.244.0.1", ==, fmt_addr(&ec.orport_ipv4.addr));
tt_int_op(258, ==, ec.orport_ipv4.port);
tt_int_op(AF_UNSPEC, ==, tor_addr_family(&ec.orport_ipv6.addr));
test_memeq(ec.node_id, "electroencephalogram", 20);
tt_mem_op(ec.node_id,==, "electroencephalogram", 20);
tt_int_op(cc->cell_type, ==, CELL_CREATE);
tt_int_op(cc->handshake_type, ==, ONION_HANDSHAKE_TYPE_TAP);
tt_int_op(cc->handshake_len, ==, TAP_ONIONSKIN_CHALLENGE_LEN);
test_memeq(cc->onionskin, b, TAP_ONIONSKIN_CHALLENGE_LEN+20);
tt_mem_op(cc->onionskin,==, b, TAP_ONIONSKIN_CHALLENGE_LEN+20);
tt_int_op(0, ==, extend_cell_format(&p2_cmd, &p2_len, p2, &ec));
tt_int_op(p2_cmd, ==, RELAY_COMMAND_EXTEND);
tt_int_op(p2_len, ==, 26+TAP_ONIONSKIN_CHALLENGE_LEN);
test_memeq(p2, p, RELAY_PAYLOAD_SIZE);
tt_mem_op(p2,==, p, RELAY_PAYLOAD_SIZE);
/* Let's do an ntor stuffed in a legacy EXTEND cell */
memset(p, 0, sizeof(p));
......@@ -644,15 +644,15 @@ test_cfmt_extend_cells(void *arg)
tt_str_op("18.244.0.1", ==, fmt_addr(&ec.orport_ipv4.addr));
tt_int_op(258, ==, ec.orport_ipv4.port);
tt_int_op(AF_UNSPEC, ==, tor_addr_family(&ec.orport_ipv6.addr));
test_memeq(ec.node_id, "electroencephalogram", 20);
tt_mem_op(ec.node_id,==, "electroencephalogram", 20);
tt_int_op(cc->cell_type, ==, CELL_CREATE2);
tt_int_op(cc->handshake_type, ==, ONION_HANDSHAKE_TYPE_NTOR);
tt_int_op(cc->handshake_len, ==, NTOR_ONIONSKIN_LEN);
test_memeq(cc->onionskin, b, NTOR_ONIONSKIN_LEN+20);
tt_mem_op(cc->onionskin,==, b, NTOR_ONIONSKIN_LEN+20);
tt_int_op(0, ==, extend_cell_format(&p2_cmd, &p2_len, p2, &ec));
tt_int_op(p2_cmd, ==, RELAY_COMMAND_EXTEND);
tt_int_op(p2_len, ==, 26+TAP_ONIONSKIN_CHALLENGE_LEN);
test_memeq(p2, p, RELAY_PAYLOAD_SIZE);
tt_mem_op(p2,==, p, RELAY_PAYLOAD_SIZE);
tt_int_op(0, ==, create_cell_format_relayed(&cell, cc));
/* Now let's do a minimal ntor EXTEND2 cell. */
......@@ -673,15 +673,15 @@ test_cfmt_extend_cells(void *arg)
tt_str_op("18.244.0.1", ==, fmt_addr(&ec.orport_ipv4.addr));
tt_int_op(61681, ==, ec.orport_ipv4.port);
tt_int_op(AF_UNSPEC, ==, tor_addr_family(&ec.orport_ipv6.addr));
test_memeq(ec.node_id, "anarchoindividualist", 20);
tt_mem_op(ec.node_id,==, "anarchoindividualist", 20);
tt_int_op(cc->cell_type, ==, CELL_CREATE2);
tt_int_op(cc->handshake_type, ==, ONION_HANDSHAKE_TYPE_NTOR);
tt_int_op(cc->handshake_len, ==, NTOR_ONIONSKIN_LEN);
test_memeq(cc->onionskin, b, NTOR_ONIONSKIN_LEN+20);
tt_mem_op(cc->onionskin,==, b, NTOR_ONIONSKIN_LEN+20);
tt_int_op(0, ==, extend_cell_format(&p2_cmd, &p2_len, p2, &ec));
tt_int_op(p2_cmd, ==, RELAY_COMMAND_EXTEND2);
tt_int_op(p2_len, ==, 35+NTOR_ONIONSKIN_LEN);
test_memeq(p2, p, RELAY_PAYLOAD_SIZE);
tt_mem_op(p2,==, p, RELAY_PAYLOAD_SIZE);
/* Now let's do a fanciful EXTEND2 cell. */
memset(&ec, 0xff, sizeof(ec));
......@@ -706,11 +706,11 @@ test_cfmt_extend_cells(void *arg)
tt_int_op(61681, ==, ec.orport_ipv4.port);
tt_str_op("2002::f0:c51e", ==, fmt_addr(&ec.orport_ipv6.addr));
tt_int_op(4370, ==, ec.orport_ipv6.port);
test_memeq(ec.node_id, "anthropomorphization", 20);
tt_mem_op(ec.node_id,==, "anthropomorphization", 20);
tt_int_op(cc->cell_type, ==, CELL_CREATE2);
tt_int_op(cc->handshake_type, ==, 0x105);
tt_int_op(cc->handshake_len, ==, 99);
test_memeq(cc->onionskin, b, 99+20);
tt_mem_op(cc->onionskin,==, b, 99+20);
tt_int_op(0, ==, extend_cell_format(&p2_cmd, &p2_len, p2, &ec));
tt_int_op(p2_cmd, ==, RELAY_COMMAND_EXTEND2);
/* We'll generate it minus the IPv6 address and minus the konami code */
......@@ -722,7 +722,7 @@ test_cfmt_extend_cells(void *arg)
"0214616e7468726f706f6d6f727068697a6174696f6e"
/* Now the handshake prologue */
"01050063");
test_memeq(p2+1+8+22+4, b, 99+20);
tt_mem_op(p2+1+8+22+4,==, b, 99+20);
tt_int_op(0, ==, create_cell_format_relayed(&cell, cc));
/* == Now try parsing some junk */
......@@ -836,11 +836,11 @@ test_cfmt_extended_cells(void *arg)
tt_int_op(RELAY_COMMAND_EXTENDED, ==, ec.cell_type);
tt_int_op(cc->cell_type, ==, CELL_CREATED);
tt_int_op(cc->handshake_len, ==, TAP_ONIONSKIN_REPLY_LEN);
test_memeq(cc->reply, b, TAP_ONIONSKIN_REPLY_LEN);
tt_mem_op(cc->reply,==, b, TAP_ONIONSKIN_REPLY_LEN);
tt_int_op(0, ==, extended_cell_format(&p2_cmd, &p2_len, p2, &ec));
tt_int_op(RELAY_COMMAND_EXTENDED, ==, p2_cmd);
tt_int_op(TAP_ONIONSKIN_REPLY_LEN, ==, p2_len);
test_memeq(p2, p, sizeof(p2));
tt_mem_op(p2,==, p, sizeof(p2));
/* Try an EXTENDED2 cell */
memset(&ec, 0xff, sizeof(ec));
......@@ -853,11 +853,11 @@ test_cfmt_extended_cells(void *arg)
tt_int_op(RELAY_COMMAND_EXTENDED2, ==, ec.cell_type);
tt_int_op(cc->cell_type, ==, CELL_CREATED2);
tt_int_op(cc->handshake_len, ==, 42);
test_memeq(cc->reply, b, 42+10);
tt_mem_op(cc->reply,==, b, 42+10);
tt_int_op(0, ==, extended_cell_format(&p2_cmd, &p2_len, p2, &ec));
tt_int_op(RELAY_COMMAND_EXTENDED2, ==, p2_cmd);
tt_int_op(2+42, ==, p2_len);
test_memeq(p2, p, sizeof(p2));
tt_mem_op(p2,==, p, sizeof(p2));
/* Try an almost-too-long EXTENDED2 cell */
memcpy(p, "\x01\xf0", 2);
......
......@@ -69,15 +69,15 @@ test_cq_manip(void *arg)
pc_tmp = cell_queue_pop(&cq);
tt_int_op(cq.n, ==, 1);
tt_ptr_op(pc_tmp, !=, NULL);
test_mem_op(pc_tmp->body, ==, "\x12\x34\x56\x78\x0a", 5);
test_mem_op(pc_tmp->body+5, ==, cell.payload, sizeof(cell.payload));
tt_mem_op(pc_tmp->body, ==, "\x12\x34\x56\x78\x0a", 5);
tt_mem_op(pc_tmp->body+5, ==, cell.payload, sizeof(cell.payload));
packed_cell_free(pc_tmp);
pc_tmp = cell_queue_pop(&cq);
tt_int_op(cq.n, ==, 0);
tt_ptr_op(pc_tmp, !=, NULL);
test_mem_op(pc_tmp->body, ==, "\x20\x13\x0a", 3);
test_mem_op(pc_tmp->body+3, ==, cell.payload, sizeof(cell.payload));
tt_mem_op(pc_tmp->body, ==, "\x20\x13\x0a", 3);
tt_mem_op(pc_tmp->body+3, ==, cell.payload, sizeof(cell.payload));
packed_cell_free(pc_tmp);
pc_tmp = NULL;
......
......@@ -251,7 +251,7 @@ test_rend_token_maps(void *arg)
tt_ptr_op(c3->rendinfo, ==, NULL);
tt_ptr_op(c4->rendinfo, !=, NULL);
test_mem_op(c4->rendinfo, ==, tok3, REND_TOKEN_LEN);
tt_mem_op(c4->rendinfo, ==, tok3, REND_TOKEN_LEN);
/* Now clear c4's cookie. */
circuit_set_intro_point_digest(c4, NULL);
......
......@@ -65,7 +65,7 @@ test_cmux_destroy_cell_queue(void *arg)
pc = cell_queue_pop(cq);
tt_assert(pc);
test_mem_op(pc->body, ==, "\x00\x00\x00\x64\x04\x0a\x00\x00\x00", 9);
tt_mem_op(pc->body, ==, "\x00\x00\x00\x64\x04\x0a\x00\x00\x00", 9);
packed_cell_free(pc);
pc = NULL;
......
......@@ -53,57 +53,57 @@ test_config_addressmap(void *arg)
/* MapAddress .invalidwildcard.com .torserver.exit - no match */
strlcpy(address, "www.invalidwildcard.com", sizeof(address));
test_assert(!addressmap_rewrite(address, sizeof(address), &expires, NULL));
tt_assert(!addressmap_rewrite(address, sizeof(address), &expires, NULL));
/* MapAddress *invalidasterisk.com .torserver.exit - no match */
strlcpy(address, "www.invalidasterisk.com", sizeof(address));
test_assert(!addressmap_rewrite(address, sizeof(address), &expires, NULL));
tt_assert(!addressmap_rewrite(address, sizeof(address), &expires, NULL));
/* Where no mapping for FQDN match on top-level domain */
/* MapAddress .google.com .torserver.exit */
strlcpy(address, "reader.google.com", sizeof(address));
test_assert(addressmap_rewrite(address, sizeof(address), &expires, NULL));
test_streq(address, "reader.torserver.exit");
tt_assert(addressmap_rewrite(address, sizeof(address), &expires, NULL));
tt_str_op(address,==, "reader.torserver.exit");
/* MapAddress *.yahoo.com *.google.com.torserver.exit */
strlcpy(address, "reader.yahoo.com", sizeof(address));
test_assert(addressmap_rewrite(address, sizeof(address), &expires, NULL));
test_streq(address, "reader.google.com.torserver.exit");
tt_assert(addressmap_rewrite(address, sizeof(address), &expires, NULL));
tt_str_op(address,==, "reader.google.com.torserver.exit");
/*MapAddress *.cnn.com www.cnn.com */
strlcpy(address, "cnn.com", sizeof(address));
test_assert(addressmap_rewrite(address, sizeof(address), &expires, NULL));
test_streq(address, "www.cnn.com");
tt_assert(addressmap_rewrite(address, sizeof(address), &expires, NULL));
tt_str_op(address,==, "www.cnn.com");
/* MapAddress .cn.com www.cnn.com */
strlcpy(address, "www.cn.com", sizeof(address));
test_assert(addressmap_rewrite(address, sizeof(address), &expires, NULL));
test_streq(address, "www.cnn.com");
tt_assert(addressmap_rewrite(address, sizeof(address), &expires, NULL));
tt_str_op(address,==, "www.cnn.com");
/* MapAddress ex.com www.cnn.com - no match */
strlcpy(address, "www.ex.com", sizeof(address));
test_assert(!addressmap_rewrite(address, sizeof(address), &expires, NULL));
tt_assert(!addressmap_rewrite(address, sizeof(address), &expires, NULL));
/* MapAddress ey.com *.cnn.com - invalid expression */
strlcpy(address, "ey.com", sizeof(address));
test_assert(!addressmap_rewrite(address, sizeof(address), &expires, NULL));
tt_assert(!addressmap_rewrite(address, sizeof(address), &expires, NULL));
/* Where mapping for FQDN match on FQDN */
strlcpy(address, "www.google.com", sizeof(address));
test_assert(addressmap_rewrite(address, sizeof(address), &expires, NULL));
test_streq(address, "3.3.3.3");
tt_assert(addressmap_rewrite(address, sizeof(address), &expires, NULL));
tt_str_op(address,==, "3.3.3.3");
strlcpy(address, "www.torproject.org", sizeof(address));
test_assert(addressmap_rewrite(address, sizeof(address), &expires, NULL));
test_streq(address, "1.1.1.1");
tt_assert(addressmap_rewrite(address, sizeof(address), &expires, NULL));
tt_str_op(address,==, "1.1.1.1");
strlcpy(address, "other.torproject.org", sizeof(address));
test_assert(addressmap_rewrite(address, sizeof(address), &expires, NULL));
test_streq(address, "this.torproject.org.otherserver.exit");
tt_assert(addressmap_rewrite(address, sizeof(address), &expires, NULL));
tt_str_op(address,==, "this.torproject.org.otherserver.exit");
strlcpy(address, "test.torproject.org", sizeof(address));
test_assert(addressmap_rewrite(address, sizeof(address), &expires, NULL));
test_streq(address, "2.2.2.2");
tt_assert(addressmap_rewrite(address, sizeof(address), &expires, NULL));
tt_str_op(address,==, "2.2.2.2");
/* Test a chain of address mappings and the order in which they were added:
"MapAddress www.example.org 4.4.4.4"
......@@ -111,17 +111,17 @@ test_config_addressmap(void *arg)
"MapAddress 4.4.4.4 5.5.5.5"
*/
strlcpy(address, "www.example.org", sizeof(address));
test_assert(addressmap_rewrite(address, sizeof(address), &expires, NULL));
test_streq(address, "5.5.5.5");
tt_assert(addressmap_rewrite(address, sizeof(address), &expires, NULL));
tt_str_op(address,==, "5.5.5.5");
/* Test infinite address mapping results in no change */
strlcpy(address, "www.infiniteloop.org", sizeof(address));
test_assert(addressmap_rewrite(address, sizeof(address), &expires, NULL));
test_streq(address, "www.infiniteloop.org");
tt_assert(addressmap_rewrite(address, sizeof(address), &expires, NULL));
tt_str_op(address,==, "www.infiniteloop.org");
/* Test we don't find false positives */
strlcpy(address, "www.example.com", sizeof(address));
test_assert(!addressmap_rewrite(address, sizeof(address), &expires, NULL));
tt_assert(!addressmap_rewrite(address, sizeof(address), &expires, NULL));
/* Test top-level-domain matching a bit harder */
config_free_lines(get_options_mutable()->AddressMap);
......@@ -134,24 +134,24 @@ test_config_addressmap(void *arg)
config_register_addressmaps(get_options());
strlcpy(address, "www.abc.com", sizeof(address));
test_assert(addressmap_rewrite(address, sizeof(address), &expires, NULL));
test_streq(address, "www.abc.torserver.exit");
tt_assert(addressmap_rewrite(address, sizeof(address), &expires, NULL));
tt_str_op(address,==, "www.abc.torserver.exit");
strlcpy(address, "www.def.com", sizeof(address));
test_assert(addressmap_rewrite(address, sizeof(address), &expires, NULL));
test_streq(address, "www.def.torserver.exit");
tt_assert(addressmap_rewrite(address, sizeof(address), &expires, NULL));
tt_str_op(address,==, "www.def.torserver.exit");
strlcpy(address, "www.torproject.org", sizeof(address));
test_assert(addressmap_rewrite(address, sizeof(address), &expires, NULL));
test_streq(address, "1.1.1.1");
tt_assert(addressmap_rewrite(address, sizeof(address), &expires, NULL));
tt_str_op(address,==, "1.1.1.1");
strlcpy(address, "test.torproject.org", sizeof(address));
test_assert(addressmap_rewrite(address, sizeof(address), &expires, NULL));
test_streq(address, "1.1.1.1");
tt_assert(addressmap_rewrite(address, sizeof(address), &expires, NULL));
tt_str_op(address,==, "1.1.1.1");
strlcpy(address, "torproject.net", sizeof(address));
test_assert(addressmap_rewrite(address, sizeof(address), &expires, NULL));
test_streq(address, "2.2.2.2");
tt_assert(addressmap_rewrite(address, sizeof(address), &expires, NULL));
tt_str_op(address,==, "2.2.2.2");
/* We don't support '*' as a mapping directive */
config_free_lines(get_options_mutable()->AddressMap);
......@@ -161,13 +161,13 @@ test_config_addressmap(void *arg)
config_register_addressmaps(get_options());
strlcpy(address, "www.abc.com", sizeof(address));
test_assert(!addressmap_rewrite(address, sizeof(address), &expires, NULL));
tt_assert(!addressmap_rewrite(address, sizeof(address), &expires, NULL));
strlcpy(address, "www.def.net", sizeof(address));
test_assert(!addressmap_rewrite(address, sizeof(address), &expires, NULL));
tt_assert(!addressmap_rewrite(address, sizeof(address), &expires, NULL));
strlcpy(address, "www.torproject.org", sizeof(address));
test_assert(!addressmap_rewrite(address, sizeof(address), &expires, NULL));
tt_assert(!addressmap_rewrite(address, sizeof(address), &expires, NULL));
#undef addressmap_rewrite
......@@ -220,13 +220,13 @@ test_config_check_or_create_data_subdir(void *arg)
// The subdirectory shouldn't exist yet,
// but should be created by the call to check_or_create_data_subdir.
test_assert(r && (errno == ENOENT));
test_assert(!check_or_create_data_subdir(subdir));
test_assert(is_private_dir(subpath));
tt_assert(r && (errno == ENOENT));
tt_assert(!check_or_create_data_subdir(subdir));
tt_assert(is_private_dir(subpath));
// The check should return 0, if the directory already exists
// and is private to the user.
test_assert(!check_or_create_data_subdir(subdir));
tt_assert(!check_or_create_data_subdir(subdir));
r = stat(subpath, &st);
if (r) {
......@@ -243,9 +243,9 @@ test_config_check_or_create_data_subdir(void *arg)
// If the directory exists, but its mode is too permissive
// a call to check_or_create_data_subdir should reset the mode.
test_assert(!is_private_dir(subpath));
test_assert(!check_or_create_data_subdir(subdir));
test_assert(is_private_dir(subpath));
tt_assert(!is_private_dir(subpath));
tt_assert(!check_or_create_data_subdir(subdir));
tt_assert(is_private_dir(subpath));
#endif
done:
......@@ -291,20 +291,20 @@ test_config_write_to_data_subdir(void *arg)
#endif
// Write attempt shoudl fail, if subdirectory doesn't exist.
test_assert(write_to_data_subdir(subdir, fname, str, NULL));
test_assert(! check_or_create_data_subdir(subdir));
tt_assert(write_to_data_subdir(subdir, fname, str, NULL));
tt_assert(! check_or_create_data_subdir(subdir));
// Content of file after write attempt should be
// equal to the original string.
test_assert(!write_to_data_subdir(subdir, fname, str, NULL));
tt_assert(!write_to_data_subdir(subdir, fname, str, NULL));
cp = read_file_to_str(filepath, 0, NULL);
test_streq(cp, str);
tt_str_op(cp,==, str);
tor_free(cp);
// A second write operation should overwrite the old content.
test_assert(!write_to_data_subdir(subdir, fname, str, NULL));
tt_assert(!write_to_data_subdir(subdir, fname, str, NULL));
cp = read_file_to_str(filepath, 0, NULL);
test_streq(cp, str);
tt_str_op(cp,==, str);
tor_free(cp);
done:
......@@ -325,48 +325,48 @@ good_bridge_line_test(const char *string, const char *test_addrport,
{
char *tmp = NULL;
bridge_line_t *bridge_line = parse_bridge_line(string);
test_assert(bridge_line);
tt_assert(bridge_line);
/* test addrport */
tmp = tor_strdup(fmt_addrport(&bridge_line->addr, bridge_line->port));
test_streq(test_addrport, tmp);
tt_str_op(test_addrport,==, tmp);
tor_free(tmp);
/* If we were asked to validate a digest, but we did not get a
digest after parsing, we failed. */
if (test_digest && tor_digest_is_zero(bridge_line->digest))
test_assert(0);
tt_assert(0);
/* If we were not asked to validate a digest, and we got a digest
after parsing, we failed again. */
if (!test_digest && !tor_digest_is_zero(bridge_line->digest))
test_assert(0);
tt_assert(0);
/* If we were asked to validate a digest, and we got a digest after
parsing, make sure it's correct. */
if (test_digest) {
tmp = tor_strdup(hex_str(bridge_line->digest, DIGEST_LEN));
tor_strlower(tmp);
test_streq(test_digest, tmp);
tt_str_op(test_digest,==, tmp);
tor_free(tmp);
}
/* If we were asked to validate a transport name, make sure tha it
matches with the transport name that was parsed. */
if (test_transport && !bridge_line->transport_name)
test_assert(0);
tt_assert(0);
if (!test_transport && bridge_line->transport_name)
test_assert(0);
tt_assert(0);
if (test_transport)
test_streq(test_transport, bridge_line->transport_name);
tt_str_op(test_transport,==, bridge_line->transport_name);
/* Validate the SOCKS argument smartlist. */
if (test_socks_args && !bridge_line->socks_args)
test_assert(0);
tt_assert(0);
if (!test_socks_args && bridge_line->socks_args)
test_assert(0);
tt_assert(0);
if (test_socks_args)
test_assert(smartlist_strings_eq(test_socks_args,
tt_assert(smartlist_strings_eq(test_socks_args,
bridge_line->socks_args));
done:
......@@ -382,7 +382,7 @@ bad_bridge_line_test(const char *string)
bridge_line_t *bridge_line = parse_bridge_line(string);
if (bridge_line)
TT_FAIL(("%s was supposed to fail, but it didn't.", string));
test_assert(!bridge_line);
tt_assert(!bridge_line);
done:
bridge_line_free(bridge_line);
......@@ -490,18 +490,18 @@ test_config_parse_transport_options_line(void *arg)
{ /* too small line */
options_sl = get_options_from_transport_options_line("valley", NULL);
test_assert(!options_sl);
tt_assert(!options_sl);
}
{ /* no k=v values */
options_sl = get_options_from_transport_options_line("hit it!", NULL);
test_assert(!options_sl);
tt_assert(!options_sl);
}
{ /* correct line, but wrong transport specified */
options_sl =
get_options_from_transport_options_line("trebuchet k=v", "rook");
test_assert(!options_sl);
tt_assert(!options_sl);
}
{ /* correct -- no transport specified */
......@@ -512,8 +512,8 @@ test_config_parse_transport_options_line(void *arg)
options_sl =
get_options_from_transport_options_line("rook ladi=dadi weliketo=party",
NULL);
test_assert(options_sl);
test_assert(smartlist_strings_eq(options_sl, sl_tmp));
tt_assert(options_sl);
tt_assert(smartlist_strings_eq(options_sl, sl_tmp));
SMARTLIST_FOREACH(sl_tmp, char *, s, tor_free(s));
smartlist_free(sl_tmp);
......@@ -531,8 +531,8 @@ test_config_parse_transport_options_line(void *arg)
options_sl =
get_options_from_transport_options_line("rook ladi=dadi weliketo=party",
"rook");
test_assert(options_sl);
test_assert(smartlist_strings_eq(options_sl, sl_tmp));
tt_assert(options_sl);
tt_assert(smartlist_strings_eq(options_sl, sl_tmp));
SMARTLIST_FOREACH(sl_tmp, char *, s, tor_free(s));
smartlist_free(sl_tmp);
sl_tmp = NULL;
......@@ -576,7 +576,7 @@ test_config_fix_my_family(void *arg)
TT_FAIL(("options_validate failed: %s", err));
}
test_streq(options->MyFamily, "$1111111111111111111111111111111111111111, "
tt_str_op(options->MyFamily,==, "$1111111111111111111111111111111111111111, "
"$1111111111111111111111111111111111111112, "
"$1111111111111111111111111111111111111113");
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -139,7 +139,7 @@ test_choose_random_entry_no_guards(void *arg)
/* Unintuitively, we actually pick a random node as our entry,
because router_choose_random_node() relaxes its constraints if it
can't find a proper entry guard. */
test_assert(chosen_entry);
tt_assert(chosen_entry);
done:
;
......@@ -201,7 +201,7 @@ populate_live_entry_guards_test_helper(int num_needed)
SMARTLIST_FOREACH_BEGIN(our_nodelist, const node_t *, node) {
const node_t *node_tmp;
node_tmp = add_an_entry_guard(node, 0, 1, 0, 0);
test_assert(node_tmp);
tt_assert(node_tmp);
} SMARTLIST_FOREACH_END(node);
/* Make sure the nodes were added as entry guards. */
......@@ -650,7 +650,7 @@ test_entry_is_live(void *arg)
SMARTLIST_FOREACH_BEGIN(our_nodelist, const node_t *, node) {
const node_t *node_tmp;
node_tmp = add_an_entry_guard(node, 0, 1, 0, 0);
test_assert(node_tmp);
tt_assert(node_tmp);
tt_int_op(node->is_stable, ==, 0);
tt_int_op(node->is_fast, ==, 0);
......@@ -670,22 +670,22 @@ test_entry_is_live(void *arg)
test_node = entry_is_live(test_entry,
ENTRY_NEED_UPTIME | ENTRY_ASSUME_REACHABLE,
&msg);
test_assert(!test_node);
tt_assert(!test_node);
/* Require the node to be fast, but it's not. Should fail. */
test_node = entry_is_live(test_entry,
ENTRY_NEED_CAPACITY | ENTRY_ASSUME_REACHABLE,
&msg);
test_assert(!test_node);
tt_assert(!test_node);
/* Don't impose any restrictions on the node. Should succeed. */
test_node = entry_is_live(test_entry, 0, &msg);
test_assert(test_node);
tt_assert(test_node);
tt_ptr_op(test_node, ==, node_get_by_id(test_entry->identity));
/* Require descriptor for this node. It has one so it should succeed. */
test_node = entry_is_live(test_entry, ENTRY_NEED_DESCRIPTOR, &msg);
test_assert(test_node);
tt_assert(test_node);
tt_ptr_op(test_node, ==, node_get_by_id(test_entry->identity));
done:
......
......@@ -42,7 +42,7 @@ test_ext_or_id_map(void *arg)
/* Give c2 a new ID. */
connection_or_set_ext_or_identifier(c2);
test_mem_op(idp, !=, c2->ext_or_conn_id, EXT_OR_CONN_ID_LEN);
tt_mem_op(idp, !=, c2->ext_or_conn_id, EXT_OR_CONN_ID_LEN);
idp2 = tor_memdup(c2->ext_or_conn_id, EXT_OR_CONN_ID_LEN);
tt_assert(!tor_digest_is_zero(idp2));
......@@ -119,7 +119,7 @@ test_ext_or_write_command(void *arg)
==, 0);
cp = buf_get_contents(TO_CONN(c1)->outbuf, &sz);
tt_int_op(sz, ==, 4);
test_mem_op(cp, ==, "\x00\x99\x00\x00", 4);
tt_mem_op(cp, ==, "\x00\x99\x00\x00", 4);
tor_free(cp);
/* Medium command. */
......@@ -127,7 +127,7 @@ test_ext_or_write_command(void *arg)
"Wai\0Hello", 9), ==, 0);
cp = buf_get_contents(TO_CONN(c1)->outbuf, &sz);
tt_int_op(sz, ==, 13);
test_mem_op(cp, ==, "\x00\x99\x00\x09Wai\x00Hello", 13);
tt_mem_op(cp, ==, "\x00\x99\x00\x09Wai\x00Hello", 13);
tor_free(cp);
/* Long command */
......@@ -137,8 +137,8 @@ test_ext_or_write_command(void *arg)
buf, 65535), ==, 0);
cp = buf_get_contents(TO_CONN(c1)->outbuf, &sz);
tt_int_op(sz, ==, 65539);
test_mem_op(cp, ==, "\xf0\x0d\xff\xff", 4);
test_mem_op(cp+4, ==, buf, 65535);
tt_mem_op(cp, ==, "\xf0\x0d\xff\xff", 4);
tt_mem_op(cp+4, ==, buf, 65535);
tor_free(cp);
done:
......@@ -181,7 +181,7 @@ test_ext_or_init_auth(void *arg)
/* Shouldn't be initialized already, or our tests will be a bit
* meaningless */
ext_or_auth_cookie = tor_malloc_zero(32);
test_assert(tor_mem_is_zero((char*)ext_or_auth_cookie, 32));
tt_assert(tor_mem_is_zero((char*)ext_or_auth_cookie, 32));
/* Now make sure we use a temporary file */
fn = get_fname("ext_cookie_file");
......@@ -203,14 +203,14 @@ test_ext_or_init_auth(void *arg)
cp = read_file_to_str(fn, RFTS_BIN, &st);
tt_ptr_op(cp, !=, NULL);
tt_u64_op((uint64_t)st.st_size, ==, 64);
test_memeq(cp, "! Extended ORPort Auth Cookie !\x0a", 32);
test_memeq(cp+32, ext_or_auth_cookie, 32);
tt_mem_op(cp,==, "! Extended ORPort Auth Cookie !\x0a", 32);
tt_mem_op(cp+32,==, ext_or_auth_cookie, 32);
memcpy(cookie0, ext_or_auth_cookie, 32);
test_assert(!tor_mem_is_zero((char*)ext_or_auth_cookie, 32));
tt_assert(!tor_mem_is_zero((char*)ext_or_auth_cookie, 32));
/* Operation should be idempotent. */
tt_int_op(0, ==, init_ext_or_cookie_authentication(1));
test_memeq(cookie0, ext_or_auth_cookie, 32);
tt_mem_op(cookie0,==, ext_or_auth_cookie, 32);
done:
tor_free(cp);
......@@ -280,15 +280,15 @@ test_ext_or_cookie_auth(void *arg)
46+32+32);
crypto_hmac_sha256(hmac2, (char*)ext_or_auth_cookie, 32, client_hash_input,
46+32+32);
test_memeq(hmac1, reply, 32);
test_memeq(hmac2, client_hash, 32);
tt_mem_op(hmac1,==, reply, 32);
tt_mem_op(hmac2,==, client_hash, 32);
/* Now do it again and make sure that the results are *different* */
tt_int_op(0, ==,
handle_client_auth_nonce(client_nonce, 32, &client_hash2, &reply2,
&reply_len));
test_memneq(reply2, reply, reply_len);
test_memneq(client_hash2, client_hash, 32);
tt_mem_op(reply2,!=, reply, reply_len);
tt_mem_op(client_hash2,!=, client_hash, 32);
/* But that this one checks out too. */
memcpy(server_hash_input+46+32, reply2+32, 32);
memcpy(client_hash_input+46+32, reply2+32, 32);
......@@ -297,8 +297,8 @@ test_ext_or_cookie_auth(void *arg)
46+32+32);
crypto_hmac_sha256(hmac2, (char*)ext_or_auth_cookie, 32, client_hash_input,
46+32+32);
test_memeq(hmac1, reply2, 32);
test_memeq(hmac2, client_hash2, 32);
tt_mem_op(hmac1,==, reply2, 32);
tt_mem_op(hmac2,==, client_hash2, 32);
done:
tor_free(reply);
......@@ -339,7 +339,7 @@ test_ext_or_cookie_auth_testvec(void *arg)
&reply_len));
tt_ptr_op(reply, !=, NULL );
tt_uint_op(reply_len, ==, 64);
test_memeq(reply+32, "te road There is always another ", 32);
tt_mem_op(reply+32,==, "te road There is always another ", 32);
/* HMACSHA256("Gliding wrapt in a brown mantle,"
* "ExtORPort authentication server-to-client hash"
* "But when I look ahead up the write road There is always another ");
......@@ -406,7 +406,7 @@ handshake_start(or_connection_t *conn, int receiving)
tt_int_op(buf_datalen(TO_CONN(conn)->outbuf), ==, (n)); \
if ((n)) { \
fetch_from_buf(b, (n), TO_CONN(conn)->outbuf); \
test_memeq(b, (s), (n)); \
tt_mem_op(b, ==, (s), (n)); \
} \
} while (0)
......
......@@ -84,8 +84,8 @@ test_hs_desc_event(void *arg)
STR_HS_ID);
expected_msg = "650 HS_DESC REQUESTED "STR_HS_ADDR" NO_AUTH "\
STR_HSDIR_EXIST_LONGNAME" "STR_HS_ID"\r\n";
test_assert(received_msg);
test_streq(received_msg, expected_msg);
tt_assert(received_msg);
tt_str_op(received_msg,==, expected_msg);
tor_free(received_msg);
/* test received event */
......@@ -93,8 +93,8 @@ test_hs_desc_event(void *arg)
control_event_hs_descriptor_received(&rend_query, HSDIR_EXIST_ID);
expected_msg = "650 HS_DESC RECEIVED "STR_HS_ADDR" BASIC_AUTH "\
STR_HSDIR_EXIST_LONGNAME"\r\n";
test_assert(received_msg);
test_streq(received_msg, expected_msg);
tt_assert(received_msg);
tt_str_op(received_msg,==, expected_msg);
tor_free(received_msg);
/* test failed event */
......@@ -102,8 +102,8 @@ test_hs_desc_event(void *arg)
control_event_hs_descriptor_failed(&rend_query, HSDIR_NONE_EXIST_ID);
expected_msg = "650 HS_DESC FAILED "STR_HS_ADDR" STEALTH_AUTH "\
STR_HSDIR_NONE_EXIST_LONGNAME"\r\n";
test_assert(received_msg);
test_streq(received_msg, expected_msg);
tt_assert(received_msg);
tt_str_op(received_msg,==, expected_msg);
tor_free(received_msg);
/* test invalid auth type */
......@@ -111,8 +111,8 @@ test_hs_desc_event(void *arg)
control_event_hs_descriptor_failed(&rend_query, HSDIR_EXIST_ID);
expected_msg = "650 HS_DESC FAILED "STR_HS_ADDR" UNKNOWN "\
STR_HSDIR_EXIST_LONGNAME"\r\n";
test_assert(received_msg);
test_streq(received_msg, expected_msg);
tt_assert(received_msg);
tt_str_op(received_msg,==, expected_msg);
tor_free(received_msg);
done:
......
......@@ -290,48 +290,48 @@ do_parse_test(uint8_t *plaintext, size_t plaintext_len, int phase)
/* Get a key */
k = crypto_pk_new();
test_assert(k);
tt_assert(k);
r = crypto_pk_read_private_key_from_string(k, AUTHORITY_SIGNKEY_1, -1);
test_assert(!r);
tt_assert(!r);
/* Get digest for future comparison */
r = crypto_pk_get_digest(k, digest);
test_assert(r >= 0);
tt_assert(r >= 0);
/* Make a cell out of it */
r = make_intro_from_plaintext(
plaintext, plaintext_len,
k, (void **)(&cell));
test_assert(r > 0);
test_assert(cell);
tt_assert(r > 0);
tt_assert(cell);
cell_len = r;
/* Do early parsing */
parsed_req = rend_service_begin_parse_intro(cell, cell_len, 2, &err_msg);
test_assert(parsed_req);
test_assert(!err_msg);
test_memeq(parsed_req->pk, digest, DIGEST_LEN);
test_assert(parsed_req->ciphertext);
test_assert(parsed_req->ciphertext_len > 0);
tt_assert(parsed_req);
tt_assert(!err_msg);
tt_mem_op(parsed_req->pk,==, digest, DIGEST_LEN);
tt_assert(parsed_req->ciphertext);
tt_assert(parsed_req->ciphertext_len > 0);
if (phase == EARLY_PARSE_ONLY)
goto done;
/* Do decryption */
r = rend_service_decrypt_intro(parsed_req, k, &err_msg);
test_assert(!r);
test_assert(!err_msg);
test_assert(parsed_req->plaintext);
test_assert(parsed_req->plaintext_len > 0);
tt_assert(!r);
tt_assert(!err_msg);
tt_assert(parsed_req->plaintext);
tt_assert(parsed_req->plaintext_len > 0);
if (phase == DECRYPT_ONLY)
goto done;
/* Do late parsing */
r = rend_service_parse_intro_plaintext(parsed_req, &err_msg);
test_assert(!r);
test_assert(!err_msg);
test_assert(parsed_req->parsed);
tt_assert(!r);
tt_assert(!err_msg);
tt_assert(parsed_req->parsed);
done:
tor_free(cell);
......@@ -371,14 +371,14 @@ make_intro_from_plaintext(
/* Compute key digest (will be first DIGEST_LEN octets of cell) */
r = crypto_pk_get_digest(key, cell);
test_assert(r >= 0);
tt_assert(r >= 0);
/* Do encryption */
r = crypto_pk_public_hybrid_encrypt(
key, cell + DIGEST_LEN, ciphertext_size,
buf, len,
PK_PKCS1_OAEP_PADDING, 0);
test_assert(r >= 0);
tt_assert(r >= 0);
/* Figure out cell length */
cell_len = DIGEST_LEN + r;
......@@ -394,8 +394,9 @@ make_intro_from_plaintext(
*/
static void
test_introduce_decrypt_v0(void)
test_introduce_decrypt_v0(void *arg)
{
(void)arg;
do_decrypt_test(v0_test_plaintext, sizeof(v0_test_plaintext));
}
......@@ -403,8 +404,9 @@ test_introduce_decrypt_v0(void)
*/
static void
test_introduce_decrypt_v1(void)
test_introduce_decrypt_v1(void *arg)
{
(void)arg;
do_decrypt_test(v1_test_plaintext, sizeof(v1_test_plaintext));
}
......@@ -412,8 +414,9 @@ test_introduce_decrypt_v1(void)
*/
static void
test_introduce_decrypt_v2(void)
test_introduce_decrypt_v2(void *arg)
{
(void)arg;
do_decrypt_test(v2_test_plaintext, sizeof(v2_test_plaintext));
}
......@@ -421,8 +424,9 @@ test_introduce_decrypt_v2(void)
*/
static void
test_introduce_decrypt_v3(void)
test_introduce_decrypt_v3(void *arg)
{
(void)arg;
do_decrypt_test(
v3_no_auth_test_plaintext, sizeof(v3_no_auth_test_plaintext));
do_decrypt_test(
......@@ -433,8 +437,9 @@ test_introduce_decrypt_v3(void)
*/
static void
test_introduce_early_parse_v0(void)
test_introduce_early_parse_v0(void *arg)
{
(void)arg;
do_early_parse_test(v0_test_plaintext, sizeof(v0_test_plaintext));
}
......@@ -442,8 +447,9 @@ test_introduce_early_parse_v0(void)
*/
static void
test_introduce_early_parse_v1(void)
test_introduce_early_parse_v1(void *arg)
{
(void)arg;
do_early_parse_test(v1_test_plaintext, sizeof(v1_test_plaintext));
}
......@@ -451,8 +457,9 @@ test_introduce_early_parse_v1(void)
*/
static void
test_introduce_early_parse_v2(void)
test_introduce_early_parse_v2(void *arg)
{
(void)arg;
do_early_parse_test(v2_test_plaintext, sizeof(v2_test_plaintext));
}
......@@ -460,8 +467,9 @@ test_introduce_early_parse_v2(void)
*/
static void
test_introduce_early_parse_v3(void)
test_introduce_early_parse_v3(void *arg)
{
(void)arg;
do_early_parse_test(
v3_no_auth_test_plaintext, sizeof(v3_no_auth_test_plaintext));
do_early_parse_test(
......@@ -472,8 +480,9 @@ test_introduce_early_parse_v3(void)
*/
static void
test_introduce_late_parse_v0(void)
test_introduce_late_parse_v0(void *arg)
{
(void)arg;
do_late_parse_test(v0_test_plaintext, sizeof(v0_test_plaintext));
}
......@@ -481,8 +490,9 @@ test_introduce_late_parse_v0(void)
*/
static void
test_introduce_late_parse_v1(void)
test_introduce_late_parse_v1(void *arg)
{
(void)arg;
do_late_parse_test(v1_test_plaintext, sizeof(v1_test_plaintext));
}
......@@ -490,8 +500,9 @@ test_introduce_late_parse_v1(void)
*/
static void
test_introduce_late_parse_v2(void)
test_introduce_late_parse_v2(void *arg)
{
(void)arg;
do_late_parse_test(v2_test_plaintext, sizeof(v2_test_plaintext));
}
......@@ -499,8 +510,9 @@ test_introduce_late_parse_v2(void)
*/
static void
test_introduce_late_parse_v3(void)
test_introduce_late_parse_v3(void *arg)
{
(void)arg;
do_late_parse_test(
v3_no_auth_test_plaintext, sizeof(v3_no_auth_test_plaintext));
do_late_parse_test(
......@@ -508,7 +520,7 @@ test_introduce_late_parse_v3(void)
}
#define INTRODUCE_LEGACY(name) \
{ #name, legacy_test_helper, 0, &legacy_setup, test_introduce_ ## name }
{ #name, test_introduce_ ## name , 0, NULL, NULL }
struct testcase_t introduce_tests[] = {
INTRODUCE_LEGACY(early_parse_v0),
......
......@@ -108,7 +108,7 @@ test_md_cache(void *data)
md2 = smartlist_get(added, 0);
/* And it should have gotten removed from 'wanted' */
tt_int_op(smartlist_len(wanted), ==, 1);
test_mem_op(smartlist_get(wanted, 0), ==, d3, DIGEST256_LEN);
tt_mem_op(smartlist_get(wanted, 0), ==, d3, DIGEST256_LEN);
smartlist_free(added);
added = NULL;
......@@ -144,18 +144,18 @@ test_md_cache(void *data)
tt_int_op(md1->bodylen, ==, strlen(test_md1));
tt_int_op(md2->bodylen, ==, strlen(test_md2));
tt_int_op(md3->bodylen, ==, strlen(test_md3_noannotation));
test_mem_op(md1->body, ==, test_md1, strlen(test_md1));
test_mem_op(md2->body, ==, test_md2, strlen(test_md2));
test_mem_op(md3->body, ==, test_md3_noannotation,
tt_mem_op(md1->body, ==, test_md1, strlen(test_md1));
tt_mem_op(md2->body, ==, test_md2, strlen(test_md2));
tt_mem_op(md3->body, ==, test_md3_noannotation,
strlen(test_md3_noannotation));
tor_asprintf(&fn, "%s"PATH_SEPARATOR"cached-microdescs.new",
options->DataDirectory);
s = read_file_to_str(fn, RFTS_BIN, NULL);
tt_assert(s);
test_mem_op(md1->body, ==, s + md1->off, md1->bodylen);
test_mem_op(md2->body, ==, s + md2->off, md2->bodylen);
test_mem_op(md3->body, ==, s + md3->off, md3->bodylen);
tt_mem_op(md1->body, ==, s + md1->off, md1->bodylen);
tt_mem_op(md2->body, ==, s + md2->off, md2->bodylen);
tt_mem_op(md3->body, ==, s + md3->off, md3->bodylen);
tt_ptr_op(md1->family, ==, NULL);
tt_ptr_op(md3->family, !=, NULL);
......@@ -180,9 +180,9 @@ test_md_cache(void *data)
tor_asprintf(&fn, "%s"PATH_SEPARATOR"cached-microdescs",
options->DataDirectory);
s = read_file_to_str(fn, RFTS_BIN, NULL);
test_mem_op(md1->body, ==, s + md1->off, strlen(test_md1));
test_mem_op(md2->body, ==, s + md2->off, strlen(test_md2));
test_mem_op(md3->body, ==, s + md3->off, strlen(test_md3_noannotation));
tt_mem_op(md1->body, ==, s + md1->off, strlen(test_md1));
tt_mem_op(md2->body, ==, s + md2->off, strlen(test_md2));
tt_mem_op(md3->body, ==, s + md3->off, strlen(test_md3_noannotation));
/* Okay, now we are going to forget about the cache entirely, and reload it
* from the disk. */
......@@ -191,12 +191,12 @@ test_md_cache(void *data)
md1 = microdesc_cache_lookup_by_digest256(mc, d1);
md2 = microdesc_cache_lookup_by_digest256(mc, d2);
md3 = microdesc_cache_lookup_by_digest256(mc, d3);
test_assert(md1);
test_assert(md2);
test_assert(md3);
test_mem_op(md1->body, ==, s + md1->off, strlen(test_md1));
test_mem_op(md2->body, ==, s + md2->off, strlen(test_md2));
test_mem_op(md3->body, ==, s + md3->off, strlen(test_md3_noannotation));
tt_assert(md1);
tt_assert(md2);
tt_assert(md3);
tt_mem_op(md1->body, ==, s + md1->off, strlen(test_md1));
tt_mem_op(md2->body, ==, s + md2->off, strlen(test_md2));
tt_mem_op(md3->body, ==, s + md3->off, strlen(test_md3_noannotation));
tt_int_op(md1->last_listed, ==, time1);
tt_int_op(md2->last_listed, ==, time2);
......
......@@ -23,9 +23,9 @@ test_nodelist_node_get_verbose_nickname_by_id_null_node(void *arg)
(void) arg;
/* make sure node_get_by_id returns NULL */
test_assert(!node_get_by_id(ID));
tt_assert(!node_get_by_id(ID));
node_get_verbose_nickname_by_id(ID, vname);
test_streq(vname, "$AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
tt_str_op(vname,==, "$AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
done:
return;
}
......@@ -54,7 +54,7 @@ test_nodelist_node_get_verbose_nickname_not_named(void *arg)
"\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA",
DIGEST_LEN);
node_get_verbose_nickname(&mock_node, vname);
test_streq(vname, "$AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA~TestOR");
tt_str_op(vname,==, "$AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA~TestOR");
done:
return;
......
......@@ -48,16 +48,16 @@ test_policy_summary_helper(const char *policy_str,
line.next = NULL;
r = policies_parse_exit_policy(&line, &policy, 1, 0, 0, 1);
test_eq(r, 0);
tt_int_op(r,==, 0);
summary = policy_summarize(policy, AF_INET);
test_assert(summary != NULL);
test_streq(summary, expected_summary);
tt_assert(summary != NULL);
tt_str_op(summary,==, expected_summary);
short_policy = parse_short_policy(summary);
tt_assert(short_policy);
summary_after = write_short_policy(short_policy);
test_streq(summary, summary_after);
tt_str_op(summary,==, summary_after);
done:
tor_free(summary_after);
......@@ -86,104 +86,104 @@ test_policies_general(void *arg)
policy = smartlist_new();
p = router_parse_addr_policy_item_from_string("reject 192.168.0.0/16:*",-1);
test_assert(p != NULL);
test_eq(ADDR_POLICY_REJECT, p->policy_type);
tt_assert(p != NULL);
tt_int_op(ADDR_POLICY_REJECT,==, p->policy_type);
tor_addr_from_ipv4h(&tar, 0xc0a80000u);
test_eq(0, tor_addr_compare(&p->addr, &tar, CMP_EXACT));
test_eq(16, p->maskbits);
test_eq(1, p->prt_min);
test_eq(65535, p->prt_max);
tt_int_op(0,==, tor_addr_compare(&p->addr, &tar, CMP_EXACT));
tt_int_op(16,==, p->maskbits);
tt_int_op(1,==, p->prt_min);
tt_int_op(65535,==, p->prt_max);
smartlist_add(policy, p);
tor_addr_from_ipv4h(&tar, 0x01020304u);
test_assert(ADDR_POLICY_ACCEPTED ==
tt_assert(ADDR_POLICY_ACCEPTED ==
compare_tor_addr_to_addr_policy(&tar, 2, policy));
tor_addr_make_unspec(&tar);
test_assert(ADDR_POLICY_PROBABLY_ACCEPTED ==
tt_assert(ADDR_POLICY_PROBABLY_ACCEPTED ==
compare_tor_addr_to_addr_policy(&tar, 2, policy));
tor_addr_from_ipv4h(&tar, 0xc0a80102);
test_assert(ADDR_POLICY_REJECTED ==
tt_assert(ADDR_POLICY_REJECTED ==
compare_tor_addr_to_addr_policy(&tar, 2, policy));
test_assert(0 == policies_parse_exit_policy(NULL, &policy2, 1, 1, 0, 1));
test_assert(policy2);
tt_assert(0 == policies_parse_exit_policy(NULL, &policy2, 1, 1, 0, 1));
tt_assert(policy2);
policy3 = smartlist_new();
p = router_parse_addr_policy_item_from_string("reject *:*",-1);
test_assert(p != NULL);
tt_assert(p != NULL);
smartlist_add(policy3, p);
p = router_parse_addr_policy_item_from_string("accept *:*",-1);
test_assert(p != NULL);
tt_assert(p != NULL);
smartlist_add(policy3, p);
policy4 = smartlist_new();
p = router_parse_addr_policy_item_from_string("accept *:443",-1);
test_assert(p != NULL);
tt_assert(p != NULL);
smartlist_add(policy4, p);
p = router_parse_addr_policy_item_from_string("accept *:443",-1);
test_assert(p != NULL);
tt_assert(p != NULL);
smartlist_add(policy4, p);
policy5 = smartlist_new();
p = router_parse_addr_policy_item_from_string("reject 0.0.0.0/8:*",-1);
test_assert(p != NULL);
tt_assert(p != NULL);
smartlist_add(policy5, p);
p = router_parse_addr_policy_item_from_string("reject 169.254.0.0/16:*",-1);
test_assert(p != NULL);
tt_assert(p != NULL);
smartlist_add(policy5, p);
p = router_parse_addr_policy_item_from_string("reject 127.0.0.0/8:*",-1);
test_assert(p != NULL);
tt_assert(p != NULL);
smartlist_add(policy5, p);
p = router_parse_addr_policy_item_from_string("reject 192.168.0.0/16:*",-1);
test_assert(p != NULL);
tt_assert(p != NULL);
smartlist_add(policy5, p);
p = router_parse_addr_policy_item_from_string("reject 10.0.0.0/8:*",-1);
test_assert(p != NULL);
tt_assert(p != NULL);
smartlist_add(policy5, p);
p = router_parse_addr_policy_item_from_string("reject 172.16.0.0/12:*",-1);
test_assert(p != NULL);
tt_assert(p != NULL);
smartlist_add(policy5, p);
p = router_parse_addr_policy_item_from_string("reject 80.190.250.90:*",-1);
test_assert(p != NULL);
tt_assert(p != NULL);
smartlist_add(policy5, p);
p = router_parse_addr_policy_item_from_string("reject *:1-65534",-1);
test_assert(p != NULL);
tt_assert(p != NULL);
smartlist_add(policy5, p);
p = router_parse_addr_policy_item_from_string("reject *:65535",-1);
test_assert(p != NULL);
tt_assert(p != NULL);
smartlist_add(policy5, p);
p = router_parse_addr_policy_item_from_string("accept *:1-65535",-1);
test_assert(p != NULL);
tt_assert(p != NULL);
smartlist_add(policy5, p);
policy6 = smartlist_new();
p = router_parse_addr_policy_item_from_string("accept 43.3.0.0/9:*",-1);
test_assert(p != NULL);
tt_assert(p != NULL);
smartlist_add(policy6, p);
policy7 = smartlist_new();
p = router_parse_addr_policy_item_from_string("accept 0.0.0.0/8:*",-1);
test_assert(p != NULL);
tt_assert(p != NULL);
smartlist_add(policy7, p);
test_assert(!exit_policy_is_general_exit(policy));
test_assert(exit_policy_is_general_exit(policy2));
test_assert(!exit_policy_is_general_exit(NULL));
test_assert(!exit_policy_is_general_exit(policy3));
test_assert(!exit_policy_is_general_exit(policy4));
test_assert(!exit_policy_is_general_exit(policy5));
test_assert(!exit_policy_is_general_exit(policy6));
test_assert(!exit_policy_is_general_exit(policy7));
tt_assert(!exit_policy_is_general_exit(policy));
tt_assert(exit_policy_is_general_exit(policy2));
tt_assert(!exit_policy_is_general_exit(NULL));
tt_assert(!exit_policy_is_general_exit(policy3));
tt_assert(!exit_policy_is_general_exit(policy4));
tt_assert(!exit_policy_is_general_exit(policy5));
tt_assert(!exit_policy_is_general_exit(policy6));
tt_assert(!exit_policy_is_general_exit(policy7));
test_assert(cmp_addr_policies(policy, policy2));
test_assert(cmp_addr_policies(policy, NULL));
test_assert(!cmp_addr_policies(policy2, policy2));
test_assert(!cmp_addr_policies(NULL, NULL));
tt_assert(cmp_addr_policies(policy, policy2));
tt_assert(cmp_addr_policies(policy, NULL));
tt_assert(!cmp_addr_policies(policy2, policy2));
tt_assert(!cmp_addr_policies(NULL, NULL));
test_assert(!policy_is_reject_star(policy2, AF_INET));
test_assert(policy_is_reject_star(policy, AF_INET));
test_assert(policy_is_reject_star(NULL, AF_INET));
tt_assert(!policy_is_reject_star(policy2, AF_INET));
tt_assert(policy_is_reject_star(policy, AF_INET));
tt_assert(policy_is_reject_star(NULL, AF_INET));
addr_policy_list_free(policy);
policy = NULL;
......@@ -193,11 +193,11 @@ test_policies_general(void *arg)
line.key = (char*)"foo";
line.value = (char*)"accept *:80,reject private:*,reject *:*";
line.next = NULL;
test_assert(0 == policies_parse_exit_policy(&line, &policy, 1, 0, 0, 1));
test_assert(policy);
tt_assert(0 == policies_parse_exit_policy(&line, &policy, 1, 0, 0, 1));
tt_assert(policy);
//test_streq(policy->string, "accept *:80");
//test_streq(policy->next->string, "reject *:*");
test_eq(smartlist_len(policy), 4);
tt_int_op(smartlist_len(policy),==, 4);
/* test policy summaries */
/* check if we properly ignore private IP addresses */
......@@ -359,7 +359,7 @@ test_dump_exit_policy_to_string(void *arg)
ri->exit_policy = NULL; // expecting "reject *:*"
ep = router_dump_exit_policy_to_string(ri,1,1);
test_streq("reject *:*",ep);
tt_str_op("reject *:*",==, ep);
tor_free(ep);
......@@ -372,7 +372,7 @@ test_dump_exit_policy_to_string(void *arg)
ep = router_dump_exit_policy_to_string(ri,1,1);
test_streq("accept *:*",ep);
tt_str_op("accept *:*",==, ep);
tor_free(ep);
......@@ -382,7 +382,7 @@ test_dump_exit_policy_to_string(void *arg)
ep = router_dump_exit_policy_to_string(ri,1,1);
test_streq("accept *:*\nreject *:25",ep);
tt_str_op("accept *:*\nreject *:25",==, ep);
tor_free(ep);
......@@ -393,7 +393,7 @@ test_dump_exit_policy_to_string(void *arg)
ep = router_dump_exit_policy_to_string(ri,1,1);
test_streq("accept *:*\nreject *:25\nreject 8.8.8.8:*",ep);
tt_str_op("accept *:*\nreject *:25\nreject 8.8.8.8:*",==, ep);
tor_free(ep);
policy_entry =
......@@ -403,8 +403,8 @@ test_dump_exit_policy_to_string(void *arg)
ep = router_dump_exit_policy_to_string(ri,1,1);
test_streq("accept *:*\nreject *:25\nreject 8.8.8.8:*\n"
"reject6 [fc00::]/7:*",ep);
tt_str_op("accept *:*\nreject *:25\nreject 8.8.8.8:*\n"
"reject6 [fc00::]/7:*",==, ep);
tor_free(ep);
policy_entry =
......@@ -414,8 +414,8 @@ test_dump_exit_policy_to_string(void *arg)
ep = router_dump_exit_policy_to_string(ri,1,1);
test_streq("accept *:*\nreject *:25\nreject 8.8.8.8:*\n"
"reject6 [fc00::]/7:*\naccept6 [c000::]/3:*",ep);
tt_str_op("accept *:*\nreject *:25\nreject 8.8.8.8:*\n"
"reject6 [fc00::]/7:*\naccept6 [c000::]/3:*",==, ep);
done:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment