当前位置: 首页>>代码示例>>C++>>正文


C++ MOCK函数代码示例

本文整理汇总了C++中MOCK函数的典型用法代码示例。如果您正苦于以下问题:C++ MOCK函数的具体用法?C++ MOCK怎么用?C++ MOCK使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了MOCK函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的MOCK函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。