本文整理汇总了C++中MOCK函数的典型用法代码示例。如果您正苦于以下问题:C++ MOCK函数的具体用法?C++ MOCK怎么用?C++ MOCK使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MOCK函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: fuzz_init
int
fuzz_init(void)
{
MOCK(consensus_compute_digest, mock_consensus_compute_digest_);
MOCK(consensus_digest_eq, mock_consensus_digest_eq_);
return 0;
}
开发者ID:Samdney,项目名称:tor,代码行数:7,代码来源:fuzz_diff_apply.c
示例2: test_skew_common
/** Do common setup for test_timely_consensus() and
* test_early_consensus(). Call networkstatus_set_current_consensus()
* on a constructed consensus and with an appropriately-modified
* approx_time. Callers expect presence or absence of appropriate log
* messages and control events. */
static int
test_skew_common(void *arg, time_t now, unsigned long *offset)
{
char *consensus = NULL;
int retval = 0;
*offset = strtoul(arg, NULL, 10);
/* Initialize the SRV subsystem */
MOCK(get_my_v3_authority_cert, get_my_v3_authority_cert_m);
mock_cert = authority_cert_parse_from_string(AUTHORITY_CERT_1,
strlen(AUTHORITY_CERT_1),
NULL);
sr_init(0);
UNMOCK(get_my_v3_authority_cert);
construct_consensus(&consensus, now);
tt_assert(consensus);
update_approx_time(now + *offset);
mock_apparent_skew = 0;
/* Caller will call UNMOCK() */
MOCK(clock_skew_warning, mock_clock_skew_warning);
/* Caller will call teardown_capture_of_logs() */
setup_capture_of_logs(LOG_WARN);
retval = networkstatus_set_current_consensus(consensus, strlen(consensus),
"microdesc", 0,
NULL);
done:
tor_free(consensus);
return retval;
}
开发者ID:jfrazelle,项目名称:tor,代码行数:39,代码来源:test_routerlist.c
示例3: test_address_get_if_addrs_no_internal_fail
static void
test_address_get_if_addrs_no_internal_fail(void *arg)
{
smartlist_t *results1 = NULL, *results2 = NULL;
(void)arg;
MOCK(get_interface_addresses_raw,
mock_get_interface_addresses_raw_fail);
MOCK(get_interface_address6_via_udp_socket_hack,
mock_get_interface_address6_via_udp_socket_hack_fail);
results1 = get_interface_address6_list(LOG_ERR, AF_INET6, 0);
tt_ptr_op(results1, OP_NE, NULL);
tt_int_op(smartlist_len(results1),OP_EQ,0);
results2 = get_interface_address_list(LOG_ERR, 0);
tt_ptr_op(results2, OP_NE, NULL);
tt_int_op(smartlist_len(results2),OP_EQ,0);
done:
UNMOCK(get_interface_addresses_raw);
UNMOCK(get_interface_address6_via_udp_socket_hack);
interface_address6_list_free(results1);
interface_address6_list_free(results2);
return;
}
开发者ID:Samdney,项目名称:tor,代码行数:27,代码来源:test_address.c
示例4: test_conn_edge_ap_handshake_rewrite_and_attach_closes_conn_with_error
static void
test_conn_edge_ap_handshake_rewrite_and_attach_closes_conn_with_error(void *data)
{
entry_connection_t *conn = entry_connection_new(CONN_TYPE_AP, AF_INET);
addressmap_init();
origin_circuit_t *circuit = NULL;
crypt_path_t *path = NULL;
(void) data;
MOCK(connection_ap_handshake_rewrite, connection_ap_handshake_rewrite_mock);
MOCK(connection_mark_unattached_ap_, connection_mark_unattached_ap_mock);
init_rewrite_mock();
rewrite_mock->should_close = 1;
rewrite_mock->end_reason = END_STREAM_REASON_MISC;
int res = connection_ap_handshake_rewrite_and_attach(conn, circuit, path);
tt_int_op(res, OP_EQ, -1);
done:
UNMOCK(connection_ap_handshake_rewrite);
UNMOCK(connection_mark_unattached_ap_);
destroy_rewrite_mock();
tor_free(circuit);
tor_free(path);
}
开发者ID:twstrike,项目名称:tor,代码行数:28,代码来源:test_connection_edge_ap_handshake.c
示例5: setup_desc_mocks
static void
setup_desc_mocks(void)
{
MOCK(router_get_descriptor_digests,
descbr_get_digests_mock);
MOCK(router_get_dl_status_by_descriptor_digest,
descbr_get_dl_by_digest_mock);
reset_mocked_dl_statuses();
}
开发者ID:francois-wellenreiter,项目名称:tor,代码行数:9,代码来源:test_controller.c
示例6: test_address_udp_socket_trick_whitebox
static void
test_address_udp_socket_trick_whitebox(void *arg)
{
int hack_retval;
tor_addr_t *addr_from_hack = tor_malloc_zero(sizeof(tor_addr_t));
struct sockaddr_in6 *mock_addr6;
struct sockaddr_in6 *ipv6_to_check =
tor_malloc_zero(sizeof(struct sockaddr_in6));
(void)arg;
MOCK(tor_open_socket,fake_open_socket);
MOCK(tor_connect_socket,pretend_to_connect);
MOCK(tor_getsockname,fake_getsockname);
MOCK(tor_close_socket,fake_close_socket);
mock_addr = tor_malloc_zero(sizeof(struct sockaddr_storage));
sockaddr_in_from_string("23.32.246.118",(struct sockaddr_in *)mock_addr);
hack_retval =
get_interface_address6_via_udp_socket_hack(LOG_DEBUG,
AF_INET, addr_from_hack);
tt_int_op(hack_retval,OP_EQ,0);
tt_assert(tor_addr_eq_ipv4h(addr_from_hack, 0x1720f676));
/* Now, lets do an IPv6 case. */
memset(mock_addr,0,sizeof(struct sockaddr_storage));
mock_addr6 = (struct sockaddr_in6 *)mock_addr;
mock_addr6->sin6_family = AF_INET6;
mock_addr6->sin6_port = 0;
tor_inet_pton(AF_INET6,"2001:cdba::3257:9652",&(mock_addr6->sin6_addr));
hack_retval =
get_interface_address6_via_udp_socket_hack(LOG_DEBUG,
AF_INET6, addr_from_hack);
tt_int_op(hack_retval,OP_EQ,0);
tor_addr_to_sockaddr(addr_from_hack,0,(struct sockaddr *)ipv6_to_check,
sizeof(struct sockaddr_in6));
tt_assert(sockaddr_in6_are_equal(mock_addr6,ipv6_to_check));
done:
UNMOCK(tor_open_socket);
UNMOCK(tor_connect_socket);
UNMOCK(tor_getsockname);
UNMOCK(tor_close_socket);
tor_free(ipv6_to_check);
tor_free(mock_addr);
tor_free(addr_from_hack);
return;
}
开发者ID:Samdney,项目名称:tor,代码行数:56,代码来源:test_address.c
示例7: fuzz_init
int
fuzz_init(void)
{
disable_signature_checking();
MOCK(dump_desc, mock_dump_desc__nodump);
MOCK(router_compute_hash_final, mock_router_produce_hash_final__nohash);
MOCK(signed_digest_equals, mock_signed_digest_equals__yes);
ed25519_init();
return 0;
}
开发者ID:Samdney,项目名称:tor,代码行数:10,代码来源:fuzz_consensus.c
示例8: setup_ns_mocks
static void
setup_ns_mocks(void)
{
MOCK(networkstatus_get_dl_status_by_flavor, ns_dl_status_mock);
MOCK(networkstatus_get_dl_status_by_flavor_bootstrap,
ns_dl_status_bootstrap_mock);
MOCK(networkstatus_get_dl_status_by_flavor_running,
ns_dl_status_running_mock);
reset_mocked_dl_statuses();
}
开发者ID:francois-wellenreiter,项目名称:tor,代码行数:10,代码来源:test_controller.c
示例9: fuzz_init
int
fuzz_init(void)
{
disable_signature_checking();
MOCK(dump_desc, mock_dump_desc__nodump);
MOCK(rsa_ed25519_crosscert_check, mock_rsa_ed25519_crosscert_check);
MOCK(decrypt_desc_layer, mock_decrypt_desc_layer);
ed25519_init();
return 0;
}
开发者ID:Samdney,项目名称:tor,代码行数:10,代码来源:fuzz_hsdescv3.c
示例10: test_conn_edge_ap_handshake_rewrite_and_attach_closes_conn_for_excluded_exit
static void
test_conn_edge_ap_handshake_rewrite_and_attach_closes_conn_for_excluded_exit(void *data)
{
entry_connection_t *conn = entry_connection_new(CONN_TYPE_AP, AF_INET);
addressmap_init();
origin_circuit_t *circuit = NULL;
crypt_path_t *path = NULL;
(void) data;
MOCK(get_options, get_options_mock);
MOCK(connection_ap_handshake_rewrite, connection_ap_handshake_rewrite_mock);
MOCK(connection_mark_unattached_ap_, connection_mark_unattached_ap_mock);
MOCK(node_get_by_nickname, node_get_by_nickname_mock);
init_rewrite_mock();
init_exit_node_mock();
init_mock_options();
rewrite_mock->should_close = 0;
rewrite_mock->exit_source = ADDRMAPSRC_NONE;
SET_SOCKS_ADDRESS(conn->socks_request, "http://www.wellformed.exit");
conn->socks_request->command = SOCKS_COMMAND_CONNECT;
strlcpy(exit_node_mock->rs->nickname, "wellformed", MAX_NICKNAME_LEN+1);
options_mock->AllowDotExit = 1;
options_mock->StrictNodes = 0;
options_mock->SafeLogging_ = SAFELOG_SCRUB_NONE;
excluded_nodes = routerset_new();
smartlist_add(excluded_nodes->list, tor_strdup("wellformed"));
strmap_set(excluded_nodes->names, tor_strdup("wellformed"), exit_node_mock);
options_mock->ExcludeExitNodes = excluded_nodes;
int prev_log = setup_capture_of_logs(LOG_INFO);
int res = connection_ap_handshake_rewrite_and_attach(conn, circuit, path);
tt_int_op(unattachment_reason_spy, OP_EQ, END_STREAM_REASON_TORPROTOCOL);
tt_int_op(res, OP_EQ, -1);
tt_str_op(mock_saved_log_at(-1), OP_EQ, "Excluded relay in exit address 'http://www.exit'. Refusing.\n");
done:
UNMOCK(get_options);
UNMOCK(connection_ap_handshake_rewrite);
UNMOCK(connection_mark_unattached_ap_);
UNMOCK(node_get_by_nickname);
destroy_rewrite_mock();
destroy_mock_options();
destroy_exit_node_mock();
tor_free(excluded_nodes);
tor_free(circuit);
tor_free(path);
teardown_capture_of_logs(prev_log);
}
开发者ID:twstrike,项目名称:tor,代码行数:54,代码来源:test_connection_edge_ap_handshake.c
示例11: fuzz_init
int
fuzz_init(void)
{
disable_signature_checking();
MOCK(check_tap_onion_key_crosscert,
mock_check_tap_onion_key_crosscert__nocheck);
MOCK(dump_desc, mock_dump_desc__nodump);
MOCK(router_compute_hash_final, mock_router_produce_hash_final__nohash);
ed25519_init();
return 0;
}
开发者ID:Samdney,项目名称:tor,代码行数:11,代码来源:fuzz_descriptor.c
示例12: setup_bridge_mocks
static void
setup_bridge_mocks(void)
{
disable_descbr = 0;
MOCK(list_bridge_identities,
descbr_get_digests_mock);
MOCK(get_bridge_dl_status_by_id,
descbr_get_dl_by_digest_mock);
reset_mocked_dl_statuses();
}
开发者ID:francois-wellenreiter,项目名称:tor,代码行数:11,代码来源:test_controller.c
示例13: disable_signature_checking
void
disable_signature_checking(void)
{
MOCK(crypto_pk_public_checksig,
mock_crypto_pk_public_checksig__nocheck);
MOCK(crypto_pk_public_checksig_digest,
mock_crypto_pk_public_checksig_digest__nocheck);
MOCK(ed25519_checksig, mock_ed25519_checksig__nocheck);
MOCK(ed25519_checksig_batch, mock_ed25519_checksig_batch__nocheck);
MOCK(ed25519_impl_spot_check, mock_ed25519_impl_spot_check__nocheck);
}
开发者ID:jfrazelle,项目名称:tor,代码行数:11,代码来源:fuzzing_common.c
示例14: setup_cert_mocks
static void
setup_cert_mocks(void)
{
MOCK(list_authority_ids_with_downloads, cert_dl_status_auth_ids_mock);
MOCK(id_only_download_status_for_authority_id,
cert_dl_status_def_for_auth_mock);
MOCK(list_sk_digests_for_authority_id,
cert_dl_status_sks_for_auth_id_mock);
MOCK(download_status_for_authority_id_and_sk,
cert_dl_status_fp_sk_mock);
reset_mocked_dl_statuses();
}
开发者ID:francois-wellenreiter,项目名称:tor,代码行数:12,代码来源:test_controller.c
示例15: fuzz_init
int
fuzz_init(void)
{
/* Set up fake response handler */
MOCK(connection_write_to_buf_impl_, mock_connection_write_to_buf_impl_);
/* Set up the fake handler functions */
MOCK(connection_mark_unattached_ap_, mock_connection_mark_unattached_ap_);
MOCK(connection_ap_rewrite_and_attach_if_allowed,
mock_connection_ap_rewrite_and_attach_if_allowed);
return 0;
}
开发者ID:Samdney,项目名称:tor,代码行数:12,代码来源:fuzz_http_connect.c
示例16: test_oos_kill_conn_list
static void
test_oos_kill_conn_list(void *arg)
{
connection_t *c1, *c2;
or_connection_t *or_c1 = NULL;
dir_connection_t *dir_c2 = NULL;
smartlist_t *l = NULL;
(void)arg;
/* Set up mocks */
mark_calls = 0;
MOCK(connection_mark_for_close_internal_, mark_for_close_oos_mock);
cfe_calls = 0;
MOCK(connection_or_close_for_error, close_for_error_mock);
/* Make fake conns */
or_c1 = tor_malloc_zero(sizeof(*or_c1));
or_c1->base_.magic = OR_CONNECTION_MAGIC;
or_c1->base_.type = CONN_TYPE_OR;
c1 = TO_CONN(or_c1);
dir_c2 = tor_malloc_zero(sizeof(*dir_c2));
dir_c2->base_.magic = DIR_CONNECTION_MAGIC;
dir_c2->base_.type = CONN_TYPE_DIR;
dir_c2->base_.state = DIR_CONN_STATE_MIN_;
dir_c2->base_.purpose = DIR_PURPOSE_MIN_;
c2 = TO_CONN(dir_c2);
tt_assert(c1 != NULL);
tt_assert(c2 != NULL);
/* Make list */
l = smartlist_new();
smartlist_add(l, c1);
smartlist_add(l, c2);
/* Run kill_conn_list_for_oos() */
kill_conn_list_for_oos(l);
/* Check call counters */
tt_int_op(mark_calls, OP_EQ, 1);
tt_int_op(cfe_calls, OP_EQ, 1);
done:
UNMOCK(connection_or_close_for_error);
UNMOCK(connection_mark_for_close_internal_);
if (l) smartlist_free(l);
tor_free(or_c1);
tor_free(dir_c2);
return;
}
开发者ID:francois-wellenreiter,项目名称:tor,代码行数:53,代码来源:test_oos.c
示例17: test_cntev_orconn_state_proxy
static void
test_cntev_orconn_state_proxy(void *arg)
{
orconn_event_msg_t conn;
(void)arg;
MOCK(queue_control_event_string, mock_queue_control_event_string);
control_testing_set_global_event_mask(EVENT_MASK_(EVENT_STATUS_CLIENT));
setup_orconn_state(&conn, 1, 1, PROXY_CONNECT);
send_ocirc_chan(1, 1, true);
send_orconn_state(&conn, OR_CONN_STATE_CONNECTING);
assert_bootmsg("3 TAG=conn_proxy");
send_orconn_state(&conn, OR_CONN_STATE_PROXY_HANDSHAKING);
assert_bootmsg("4 TAG=conn_done_proxy");
send_orconn_state(&conn, OR_CONN_STATE_TLS_HANDSHAKING);
assert_bootmsg("10 TAG=conn_done");
send_orconn_state(&conn, OR_CONN_STATE_OR_HANDSHAKING_V3);
assert_bootmsg("14 TAG=handshake");
send_orconn_state(&conn, OR_CONN_STATE_OPEN);
assert_bootmsg("15 TAG=handshake_done");
send_ocirc_chan(2, 2, false);
conn.u.state.gid = 2;
conn.u.state.chan = 2;
send_orconn_state(&conn, OR_CONN_STATE_CONNECTING);
assert_bootmsg("78 TAG=ap_conn_proxy");
send_orconn_state(&conn, OR_CONN_STATE_PROXY_HANDSHAKING);
assert_bootmsg("79 TAG=ap_conn_done_proxy");
done:
tor_free(saved_event_str);
UNMOCK(queue_control_event_string);
}
开发者ID:jfrazelle,项目名称:tor,代码行数:34,代码来源:test_controller_events.c
示例18: do_ext_or_handshake
/* Helper: Do a successful Extended ORPort authentication handshake. */
static void
do_ext_or_handshake(or_connection_t *conn)
{
char b[256];
tt_int_op(0, OP_EQ, connection_ext_or_start_auth(conn));
CONTAINS("\x01\x00", 2);
WRITE("\x01", 1);
WRITE("But when I look ahead up the whi", 32);
MOCK(crypto_rand, crypto_rand_return_tse_str);
tt_int_op(0, OP_EQ, connection_ext_or_process_inbuf(conn));
UNMOCK(crypto_rand);
tt_int_op(TO_CONN(conn)->state, OP_EQ,
EXT_OR_CONN_STATE_AUTH_WAIT_CLIENT_HASH);
CONTAINS("\xec\x80\xed\x6e\x54\x6d\x3b\x36\xfd\xfc\x22\xfe\x13\x15\x41\x6b"
"\x02\x9f\x1a\xde\x76\x10\xd9\x10\x87\x8b\x62\xee\xb7\x40\x38\x21"
"te road There is always another ", 64);
/* Send the right response this time. */
WRITE("\xab\x39\x17\x32\xdd\x2e\xd9\x68\xcd\x40\xc0\x87\xd1\xb1\xf2\x5b"
"\x33\xb3\xcd\x77\xff\x79\xbd\x80\xc2\x07\x4b\xbf\x43\x81\x19\xa2",
32);
tt_int_op(0, OP_EQ, connection_ext_or_process_inbuf(conn));
CONTAINS("\x01", 1);
tt_assert(! TO_CONN(conn)->marked_for_close);
tt_int_op(TO_CONN(conn)->state, OP_EQ, EXT_OR_CONN_STATE_OPEN);
done: ;
}
开发者ID:1234max,项目名称:tor,代码行数:29,代码来源:test_extorport.c
示例19: test_bridges_get_transport_by_bridge_addrport
/**
* Calling get_transport_by_bridge_addrport() with the address and port of a
* configured bridge which uses a pluggable transport should return 0 and set
* appropriate transport_t.
*/
static void
test_bridges_get_transport_by_bridge_addrport(void *arg)
{
transport_t *transport = NULL;
tor_addr_t *addr = tor_malloc(sizeof(tor_addr_t));
uint16_t port = 1234;
int ret;
helper_add_bridges_to_bridgelist(arg);
mark_transport_list(); // Also initialise our transport_list
ret = tor_addr_parse(addr, "1.2.3.4");
tt_int_op(ret, OP_EQ, 2); // it returns the address family on success?
/* After we mock transport_get_by_name() to return a bogus transport_t with
* the name it was asked for, the call should succeed.
*/
MOCK(transport_get_by_name, mock_transport_get_by_name);
ret = get_transport_by_bridge_addrport((const tor_addr_t*)addr, port,
(const transport_t**)&transport);
tt_int_op(ret, OP_EQ, 0); // returns 0 on success
tt_ptr_op(transport, OP_NE, NULL);
tt_str_op(transport->name, OP_EQ, "obfs4");
done:
UNMOCK(transport_get_by_name);
tor_free(addr);
transport_free(transport);
mark_bridge_list();
sweep_bridge_list();
}
开发者ID:Samdney,项目名称:tor,代码行数:38,代码来源:test_bridges.c
示例20: global_init
static void
global_init(void)
{
subsystems_init_upto(SUBSYS_LEVEL_LIBS);
flush_log_messages_from_startup();
tor_compress_init();
if (crypto_global_init(0, NULL, NULL) < 0)
abort();
{
struct sipkey sipkey = { 1337, 7331 };
siphash_unset_global_key();
siphash_set_global_key(&sipkey);
}
/* set up the options. */
mock_options = tor_malloc_zero(sizeof(or_options_t));
MOCK(get_options, mock_get_options);
/* Make BUG() and nonfatal asserts crash */
tor_set_failed_assertion_callback(abort);
/* Make protocol warnings handled correctly. */
init_protocol_warning_severity_level();
}
开发者ID:jfrazelle,项目名称:tor,代码行数:27,代码来源:fuzzing_common.c
注:本文中的MOCK函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论