Ejemplo n.º 1
0
END_TEST

START_TEST(test_network_nodes)
{
    Edge *e1 = NULL, *e2 = NULL, *e3 = NULL;
    SList *nodes = NULL;
    Node ntmp = 0;

    e1 = edge_create(1, 2, 1, 0);
    e2 = edge_create(3, 4, 1, 0);
    e3 = edge_create(5, 6, 1, 0);

    net = network_create();
    network_add_edge(net, e1);
    network_add_edge(net, e2);
    network_add_edge(net, e3);

    nodes = network_nodes(net);
    fail_unless(nodes != NULL);
    fail_unless(slist_length(nodes) == 6);
    
    while(nodes != NULL){
        ntmp = *((Node *) slist_head_data(nodes));
        fail_unless((1 <= ntmp) && (ntmp <= 6));
        nodes = slist_next(nodes);
    }

    network_destroy(net);
}
Ejemplo n.º 2
0
END_TEST

START_TEST(test_network_get_neightbours)
{
    Edge *e1 = NULL, *e2 = NULL, *e3 = NULL;
    Node *ntmp = NULL;
    SList *el = NULL, *tmp = NULL;

    e1 = edge_create(2, 3, 1, 0);
    e2 = edge_create(1, 4, 1, 0);
    e3 = edge_create(2, 1, 1, 0);

    net = network_create();
    network_add_edge(net, e1);
    network_add_edge(net, e2);
    network_add_edge(net, e3);

    el = network_neighbours(net, 2);
    fail_unless(!slist_is_empty(el));

    tmp = el;
    while(tmp != NULL){
        ntmp = (Node *) slist_nth_data(tmp, 0);

        fail_unless(*ntmp == 3 || *ntmp == 1);

        tmp = slist_next(tmp);
    }

    slist_free(el);
    network_destroy(net);
}
Ejemplo n.º 3
0
END_TEST

/* Testeo de funcionalidad */
START_TEST(test_network_get_edges)
{
    Edge *e1 = NULL, *e2 = NULL, *e3 = NULL, *etmp = NULL;
    SList *el = NULL, *tmp = NULL;
    Node ntmp = 0;

    e1 = edge_create(0, 1, 1, 0);
    e2 = edge_create(0, 2, 1, 0);
    e3 = edge_create(2, 3, 1, 0);

    net = network_create();
    network_add_edge(net, e1);
    network_add_edge(net, e2);
    network_add_edge(net, e3);

    el = network_get_edges(net, 0);
    fail_unless(!slist_is_empty(el));

    tmp = el;
    while(tmp != NULL){
        etmp = (Edge *) slist_nth_data(tmp, 0);
        ntmp = *edge_get_second(etmp);
        fail_unless(ntmp == 1 || ntmp == 2);

        tmp = slist_next(tmp);
    }

    network_destroy(net);
}
Ejemplo n.º 4
0
int main(int argc, char* argv[]) {
  int listenfd, connfd;
  struct sockaddr_in addr;
  char buf[256];
  time_t tick;

  network_init();

  listenfd = common_socket(AF_INET, SOCK_STREAM, 0);
  addr.sin_addr.s_addr = htonl(INADDR_ANY);
  addr.sin_family      = AF_INET;
  addr.sin_port        = htons(5555);
  common_bind(listenfd, (struct sockaddr*)&addr, sizeof(addr));
  common_listen(listenfd, 5);

  for (;;) {
    connfd = common_accept(listenfd, NULL, NULL);

    tick = time(NULL);
    snprintf(buf, sizeof(buf), "%.24s\r\n", ctime(&tick));
    common_write(connfd, buf, strlen(buf));

    common_close(connfd);
  }
  common_close(listenfd);

  network_destroy();

  return 0;
}
Ejemplo n.º 5
0
int main(int argc, char* argv[]) {
  int listenfd;
  int clientfd;
  struct sockaddr_in addr;
  socklen_t addrlen;

  network_init();

  listenfd = common_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  addr.sin_addr.s_addr = htonl(INADDR_ANY);
  addr.sin_family      = AF_INET;
  addr.sin_port        = htons(5555);
  common_bind(listenfd, (struct sockaddr*)&addr, sizeof(addr));
  common_listen(listenfd, SOMAXCONN);

  printf("echo server start sucess !!!\n");
  for (;;) {
    addrlen = sizeof(addr);
    clientfd = common_accept(listenfd, (struct sockaddr*)&addr, &addrlen);

    CreateThread(NULL, 0, echo_process, &clientfd, 0, NULL);
  }
  common_close(listenfd);

  network_destroy();

  return 0;
}
Ejemplo n.º 6
0
END_TEST

/* Crear y destruir */
START_TEST(test_network_new_destroy)
{
    net = network_create();
    network_destroy(net);
}
Ejemplo n.º 7
0
void client_manager_destroy()
{
  if (!g_client_manager)
    return;
  logger_message("[CLIENT] Manager destroy");
  list_foreach(&g_client_manager->clients, (feach) &client_destroy);
  list_clear(&g_client_manager->clients);
  list_free(&g_client_manager->commands);
  network_destroy();
  free(g_client_manager);
  g_client_manager = NULL;
}
Ejemplo n.º 8
0
// -----[ ez_topo_destroy ]------------------------------------------
void ez_topo_destroy(ez_topo_t ** eztopo_ref)
{
  ez_topo_t * eztopo;

  if (*eztopo_ref != NULL) {
    eztopo= *eztopo_ref;
    if (eztopo->network != NULL)
      network_destroy(&eztopo->network);
    FREE(eztopo->nodes);
    FREE(eztopo->edges);
    FREE(*eztopo_ref);
  }
}
Ejemplo n.º 9
0
int main(int argc, char* argv[]) {
  int sockfd;
  struct sockaddr_in addr;
  socklen_t addrlen = sizeof(addr);

  network_init();

  sockfd = common_socket(AF_INET, SOCK_STREAM, 0);
  addr.sin_addr.s_addr = inet_addr("127.0.0.1");
  addr.sin_family      = AF_INET;
  addr.sin_port        = htons(5555);
  common_connect(sockfd, (struct sockaddr*)&addr, addrlen);

  logical_cli(stdin, sockfd);

  common_close(sockfd);
  network_destroy();

  return 0;
}
Ejemplo n.º 10
0
/* Para testing de memoria */
void network_memory_test(void){
    /* Codigo que deberia correr sin memory leaks */

    Edge *e1 = NULL, *e2 = NULL, *e3 = NULL, *e4 = NULL, *etmp = NULL;
    Node *ntmp = NULL;
    SList *el = NULL, *nl = NULL, *tmp = NULL;

    e1 = edge_create(0, 1, 1, 0);
    e2 = edge_create(0, 2, 4, 0);
    e3 = edge_create(2, 3, 6, 0);
    e4 = edge_create(2, 0, 0, 0);

    net = network_create();
    network_add_edge(net, e1);
    network_add_edge(net, e2);
    network_add_edge(net, e3);
    network_add_edge(net, e4);

    el = network_get_edges(net, 0);

    tmp = el;
    while(tmp != NULL){
        etmp = (Edge *) slist_nth_data(tmp, 0);
        edge_pprint(etmp);
        tmp = slist_next(tmp);
    }

    nl = network_neighbours(net, 2);
    printf("Vecinos del nodo: 2\n");

    tmp = nl;
    while(tmp != NULL){
        ntmp = (Node *) slist_nth_data(tmp, 0);
        tmp = slist_next(tmp);

        printf("  %d\n", *ntmp);
    }

    slist_free(nl);
    network_destroy(net);
}