Exemple #1
0
int uri_test ( void ) {
	unsigned int i;
	struct uri_test *uri_test;
	int rc;
	int overall_rc = 0;

	for ( i = 0 ; i < ( sizeof ( uri_tests ) /
			    sizeof ( uri_tests[0] ) ) ; i++ ) {
		uri_test = &uri_tests[i];
		rc = test_parse_unparse ( uri_test->base_uri_string );
		if ( rc != 0 )
			overall_rc = rc;
		rc = test_parse_unparse ( uri_test->relative_uri_string );
		if ( rc != 0 )
			overall_rc = rc;
		rc = test_parse_unparse ( uri_test->resolved_uri_string );
		if ( rc != 0 )
			overall_rc = rc;
		rc = test_resolve ( uri_test->base_uri_string,
				    uri_test->relative_uri_string,
				    uri_test->resolved_uri_string );
		if ( rc != 0 )
			overall_rc = rc;
	}

	if ( overall_rc )
		printf ( "URI tests failed: %s\n", strerror ( overall_rc ) );
	return overall_rc;
}
int main (int argc, char ** argv)
{
	printf ("  RESOLVER  TESTS\n");
	printf ("====================\n\n");

	init (argc, argv);

	test_resolve ();
	test_name ();
	test_lockname ();
	test_tempname ();
	test_checkfile ();


	printf ("\ntest_backendhelpers RESULTS: %d test(s) done. %d error(s).\n", nbTest, nbError);

	return nbError;
}
Exemple #3
0
int init(void)
{
    ne_uri u = {0}, proxy = {0};
    int optc, n;
    char *proxy_url = NULL;
    char str[64], *src;
    int i;


    if ((times1=malloc(sizeof(float)*pget_option.requests)) == NULL){
	perror("malloc(times1) :");
	exit(-1);
    }	
    if ((times2=malloc(sizeof(float)*pget_option.requests)) == NULL){
	perror("malloc(times2) :");
	exit(-1);
    }	
	
    while ((optc = getopt_long(test_argc, test_argv, 
			       "d:hp", longopts, NULL)) != -1) {
	switch (optc) {
	case 'd':
	    htdocs_root = optarg;
	    break;
	case 'p':
	    proxy_url = optarg;
	    break;
	default:
	    exit(1);
	}
    }

    n = test_argc - optind;

    if (n == 0 || n > 3 || n == 2) {
	exit(1);
    }

    if (htdocs_root == NULL)
	htdocs_root = "htdocs";

    if (ne_uri_parse(test_argv[optind], &u)) {
	t_context("couldn't parse server URL `%s'",
		  test_argv[optind]);
	return FAILHARD;
    }       

    if (proxy_url) {
	if (ne_uri_parse(proxy_url, &proxy)) {
	    t_context("couldn't parse proxy URL `%s'", proxy_url);
	    return FAILHARD;
	}
	if (proxy.scheme && strcmp(proxy.scheme, "http") != 0) {
	    t_context("cannot use scheme `%s' for proxy", proxy.scheme);
	    return FAILHARD;
	}
	if (proxy.port > 0) {
	    proxy_port = proxy.port;
	} else {
	    proxy_port = 8080;
	}
	proxy_hostname = proxy.host;
    }		      

    if (u.scheme && strcmp(u.scheme, "https") == 0)
	use_secure = 1;

    i_hostname = u.host;
    if (u.port > 0) {
	i_port = u.port;
    } else {
	if (use_secure) {
	    i_port = 443;
	} else {
	    i_port = 80;
	}
    }
    if (ne_path_has_trailing_slash(u.path)) {
	i_path = u.path;
    } else {
	i_path = ne_concat(u.path, "/", NULL);
    }

    i_path = ne_path_escape(i_path);
    
    if (n > 2) {
	i_username = test_argv[optind+1];
	i_password = test_argv[optind+2];
	
	if (strlen(i_username) >= NE_ABUFSIZ) {
	    t_context("username must be <%d chars", NE_ABUFSIZ);
	    return FAILHARD;
	}

	if (strlen(i_password) >= NE_ABUFSIZ) {
	    t_context("password must be <%d chars", NE_ABUFSIZ);
	    return FAILHARD;
	}
    }
    
    if (proxy_hostname)
	CALL(test_resolve(proxy_hostname, "proxy server"));
    else
	CALL(test_resolve(i_hostname, "server"));

    CALL(open_foo());

    CALL(test_connect());

    printf("Done\n");
    return OK;
}
Exemple #4
0
/*----------------------------------------------------------------------------*/
int 
main_switch_test (int num_var, char **ptr_var) 
{
  int mode;

/*   if (num_var == 0) mode = -1; */
/*   else              mode = atoi (ptr_var[0]); */
  if (num_var == 0) mode = 0; // печатаем меню
  else              mode = atoi (ptr_var[0]);

  //my_stderr_set (stdout);

  switch (mode) {
  case  0:
    printf ("MENU : \n\n");

  case  1: //--------------------------------------------------------
    if (mode==0)  printf ("1 - ALL TESTS [@ == debug] \n");
    else {
      printf ("test_eval_all \n");
      printf ("\n");
      test_eval_all (test_eval_one, TEST_1x2_0); 
      test_eval_all (test_eval_one, TEST_1x3_0); 
      test_eval_all (test_eval_one, TEST_1x2_1); 
      printf ("\n"); 

      printf ("test_prob_all [aigo1] \n");  
      test_prob_all ("aigo1"); 
      printf ("\n"); 

      printf ("test_play_all [aigo aigo] \n"); 
      test_play_all ("aigo", "aigo"); 
      printf ("\n"); 

      //printf ("minmax tests \n"); // перенесено в СOMMON
      //minmax_tests (); 
      break;
    }

  case  91: //--------------------------------------------------------
    if (mode==0)  ;
    else {
      debug = TRUE;
      printf ("\n");
      test_eval_all (test_eval_one, TEST_1x2_0); 
      printf ("\n");
      test_eval_all (test_eval_one, TEST_1x3_0); 
      printf ("\n");
      test_eval_all (test_eval_one, TEST_1x2_1); 
      printf ("\n"); 
      break;
    }

  case 2: //--------------------------------------------------------
    if (mode==0)  printf ("2 - test_prob_all [prog] \n");
    else {
      char *prog = ptr_var[1];
      test_prob_all (prog); 
      break;
    }

  case 3: //--------------------------------------------------------
    if (mode==0)  {
      printf ("3 - auto_play [prog1 prog2  ii jj] \n");
    } else {
      char *prog1 = ptr_var[1];
      char *prog2 = ptr_var[2];
      int   ii    = atoi (ptr_var[3]);
      int   jj    = atoi (ptr_var[4]);

      srand (0); // установим одинаковые условия для теста
                 // после  work_begin->YRAND_S ..

      YT_GOBAN *goban = goban_create (ii, jj);

      game_autoplay_ (goban, prog1, prog2, /* is_print */TRUE);
      break;
    }

  case 5: //--------------------------------------------------------
    if (mode==0)  printf ("5 - resolve [pname ii jj megabytes mlevel] \n");
    else {
      char *pname = ptr_var[1];        // aigo  migo
      int  ii  = atoi (ptr_var[2]);
      int  jj  = atoi (ptr_var[3]);
      int  mb  = atoi (ptr_var[4]);
      int  mlevel = atoi (ptr_var[5]); // 14  1  2 

      test_resolve (pname, ii, jj, mb, mlevel); 
      //test_resolve ("migo", ii, jj, mb, mlevel); //mini-max
      //test_resolve ("aigo", ii, jj, mb, mlevel); //alfa-beta
      break;
    }

  case 7: //--------------------------------------------------------
    if (mode==0)  printf ("7 - make Baza [ii jj megabytes] \n");
    else {
      int  ii  = atoi (ptr_var[1]);
      int  jj  = atoi (ptr_var[2]);
      int  mb  = atoi (ptr_var[3]);
      test_moves_map (0, "migo50", ii, jj, /* 600 */mb, /* is_moved_map = */ 1); 
      break;
    } //-------------------------------------------------------------

  case 8: //--------------------------------------------------------
    if (mode==0)  printf ("8 - read Baza [ii jj]  \n");
    else {
      int  ii  = atoi (ptr_var[1]);
      int  jj  = atoi (ptr_var[2]);
      solver_check (ii, jj, TRUE);
      break;
    } //-------------------------------------------------------------

  case 9: //--------------------------------------------------------
    if (mode==0)  printf ("9 - read Baza [ii jj] (NOT PRINT ERR) \n");
    else {
      int  ii  = atoi (ptr_var[1]);
      int  jj  = atoi (ptr_var[2]);
      solver_check (ii, jj, FALSE);
      break;
    } //-------------------------------------------------------------

  case 10: //--------------------------------------------------------
    if (mode==0)  printf ("10 - LEVELING \n");
    else {
      main_leveling (--num_var, ++ptr_var); 
      break;
    } //-------------------------------------------------------------

  case 11: //--------------------------------------------------------
    if (mode==0)  printf ("11 - myhash_test \n");
    else {
      myhash_test () ; 
      break;
    } //-------------------------------------------------------------

  case 12: //--------------------------------------------------------
    if (mode==0)  printf ("12 - myeuler_test \n");
    else {
      //win_test ();
      myeuler_test (); 
      break;
    } //-------------------------------------------------------------

  default: //--------------------------------------------------------
    if (mode!=0) 
    printf ("Sorry, what you want ??\n");
  }

  //fprintf (SERR, "\n");
  printf ("\n");
  return 1;
} 
Exemple #5
0
/*
 * Main test entry.
 */
int resolve_test(void)
{
    pj_pool_t *pool;
    pj_dns_resolver *resv;
    pj_str_t nameserver;
    pj_uint16_t port = 5353;
    pj_status_t status;

    pool = pjsip_endpt_create_pool(endpt, NULL, 4000, 4000);

    status = pjsip_endpt_create_resolver(endpt, &resv);

    nameserver = pj_str("192.168.0.106");
    pj_dns_resolver_set_ns(resv, 1, &nameserver, &port);
    pjsip_endpt_set_resolver(endpt, resv);

    add_dns_entries(resv);

    /* These all should be resolved as IP addresses (DNS A query) */
    {
	pjsip_server_addresses ref;
	create_ref(&ref, PJSIP_TRANSPORT_UDP, "1.1.1.1", 5060);
	status = test_resolve("IP address without transport and port", pool, PJSIP_TRANSPORT_UNSPECIFIED, "1.1.1.1", 0, &ref);
	if (status != PJ_SUCCESS)
	    return -100;
    }
    {
	pjsip_server_addresses ref;
	create_ref(&ref, PJSIP_TRANSPORT_UDP, "1.1.1.1", 5060);
	status = test_resolve("IP address with explicit port", pool, PJSIP_TRANSPORT_UNSPECIFIED, "1.1.1.1", 5060, &ref);
	if (status != PJ_SUCCESS)
	    return -110;
    }
    {
	pjsip_server_addresses ref;
	create_ref(&ref, PJSIP_TRANSPORT_TCP, "1.1.1.1", 5060);
	status = test_resolve("IP address without port (TCP)", pool, PJSIP_TRANSPORT_TCP,"1.1.1.1", 0, &ref);
	if (status != PJ_SUCCESS)
	    return -120;
    }
    {
	pjsip_server_addresses ref;
	create_ref(&ref, PJSIP_TRANSPORT_TLS, "1.1.1.1", 5061);
	status = test_resolve("IP address without port (TLS)", pool, PJSIP_TRANSPORT_TLS, "1.1.1.1", 0, &ref);
	if (status != PJ_SUCCESS)
	    return -130;
    }

    /* This should be resolved as DNS A record (because port is present) */
    {
	pjsip_server_addresses ref;
	create_ref(&ref, PJSIP_TRANSPORT_UDP, "5.5.5.5", 5060);
	status = test_resolve("domain name with port should resolve to A record", pool, PJSIP_TRANSPORT_UNSPECIFIED, "example.com", 5060, &ref);
	if (status != PJ_SUCCESS)
	    return -140;
    }

    /* This will fail to be resolved as SRV, resolver should fallback to 
     * resolving to A record.
     */
    {
	pjsip_server_addresses ref;
	create_ref(&ref, PJSIP_TRANSPORT_UDP, "2.2.2.2", 5060);
	status = test_resolve("failure with SRV fallback to A record", pool, PJSIP_TRANSPORT_UNSPECIFIED, "sip02.example.com", 0, &ref);
	if (status != PJ_SUCCESS)
	    return -150;
    }

    /* Same as above, but explicitly for TLS. */
    {
	pjsip_server_addresses ref;
	create_ref(&ref, PJSIP_TRANSPORT_TLS, "2.2.2.2", 5061);
	status = test_resolve("failure with SRV fallback to A record (for TLS)", pool, PJSIP_TRANSPORT_TLS, "sip02.example.com", 0, &ref);
	if (status != PJ_SUCCESS)
	    return -150;
    }

    /* Standard DNS SRV followed by A recolution */
    {
	pjsip_server_addresses ref;
	create_ref(&ref, PJSIP_TRANSPORT_UDP, "6.6.6.6", 50060);
	status = test_resolve("standard SRV resolution", pool, PJSIP_TRANSPORT_UNSPECIFIED, "domain.com", 0, &ref);
	if (status != PJ_SUCCESS)
	    return -155;
    }

    /* Standard DNS SRV followed by A recolution (explicit transport) */
    {
	pjsip_server_addresses ref;
	create_ref(&ref, PJSIP_TRANSPORT_TCP, "6.6.6.6", 50060);
	add_ref(&ref, PJSIP_TRANSPORT_TCP, "7.7.7.7", 50060);
	status = test_resolve("standard SRV resolution with explicit transport (TCP)", pool, PJSIP_TRANSPORT_TCP, "domain.com", 0, &ref);
	if (status != PJ_SUCCESS)
	    return -160;
    }


    /* Round robin/load balance test */
    if (round_robin_test(pool) != 0)
	return -170;

    /* Timeout test */
    {
	status = test_resolve("timeout test", pool, PJSIP_TRANSPORT_UNSPECIFIED, "an.invalid.address", 0, NULL);
	if (status == PJ_SUCCESS)
	    return -150;
    }

    return 0;
}
static void path_test() {
	
	test_path(".", ".");
	test_path("./", ".");
	test_path(".////./././//././/", ".");
	test_path("./a", "a");
	test_path(".////./././//././/a", "a");
	test_path("./..", "..");
	test_path(".////./././//././/..", "..");
	test_path("./a/..", ".");
	
	test_path("/a", "/a");
	test_path("/a/b", "/a/b");
	test_path("/a/b/c", "/a/b/c");
	test_path("/a/", "/a");
	test_path("/a/b", "/a/b");
	test_path("/a/b/c/./", "/a/b/c");
	
	test_path("/", "/");
	test_path("/..", "/..");
	test_path("/../", "/..");
	test_path("/..//", "/..");
	test_path("/../..", "/../..");
	test_path("/..//..", "/../..");
	test_path("/../../", "/../..");
	test_path("/..//../", "/../..");
	test_path("/../..//", "/../..");
	test_path("/..//..//", "/../..");
	
	test_path("/a", "/a");
	test_path("/a/..", "/");
	test_path("/a/../", "/");
	test_path("/a/..//", "/");
	test_path("/a/../..", "/..");
	test_path("/a/..//..", "/..");
	test_path("/a/../../", "/..");
	test_path("/a/..//../", "/..");
	test_path("/a/../..//", "/..");
	test_path("/a/..//..//", "/..");
	
	test_path("/abcd", "/abcd");
	test_path("/abcd/..", "/");
	test_path("/abcd/../", "/");
	test_path("/abcd/..//", "/");
	test_path("/abcd/../..", "/..");
	test_path("/abcd/..//..", "/..");
	test_path("/abcd/../../", "/..");
	test_path("/abcd/..//../", "/..");
	test_path("/abcd/../..//", "/..");
	test_path("/abcd/..//..//", "/..");
	
	test_path("/../a", "/../a");
	test_path("/../a/", "/../a");
	test_path("/../a//", "/../a");
	test_path("/../a/..", "/..");
	test_path("/../a//..", "/..");
	test_path("/../a/../", "/..");
	test_path("/../a//../", "/..");
	test_path("/../a/..//", "/..");
	test_path("/../a//..//", "/..");
	
	// -------
	
	test_path("a", "a");
	test_path("a/b", "a/b");
	test_path("a/", "a");
	test_path("a/b/", "a/b");
	
	test_path("", "");
	test_path("..", "..");
	test_path("../", "..");
	test_path("..//", "..");
	test_path("../..", "../..");
	test_path("..//..", "../..");
	test_path("../../", "../..");
	test_path("..//../", "../..");
	test_path("../..//", "../..");
	test_path("..//..//", "../..");
	
	test_path("a", "a");
	test_path("a/..", ".");
	test_path("a/../", ".");
	test_path("a/..//", ".");
	test_path("a/../..", "..");
	test_path("a/..//..", "..");
	test_path("a/../../", "..");
	test_path("a/..//../", "..");
	test_path("a/../..//", "..");
	test_path("a/..//..//", "..");
	
	test_path("abcd", "abcd");
	test_path("abcd/..", ".");
	test_path("abcd/../", ".");
	test_path("abcd/..//", ".");
	test_path("abcd/../..", "..");
	test_path("abcd/..//..", "..");
	test_path("abcd/../../", "..");
	test_path("abcd/..//../", "..");
	test_path("abcd/../..//", "..");
	test_path("abcd/..//..//", "..");
	
	test_path("../a", "../a");
	test_path("../a/", "../a");
	test_path("../a//", "../a");
	test_path("../a/..", "..");
	test_path("../a//..", "..");
	test_path("../a/../", "..");
	test_path("../a//../", "..");
	test_path("../a/..//", "..");
	test_path("../a//..//", "..");
	
	test_path("/.", "/");
	
	// --- 
	
	test_resolve(".", "a", "a");
	test_resolve(".", "a/b", "a/b");
	test_resolve(".", "..", "..");
	test_resolve(".", "a", "a");
	test_resolve("a", "..", ".");
	test_resolve("a/b", "..", "a");
	test_resolve("a/b", "../..", ".");
	test_resolve("a", "..", ".");
	
	test_resolve(".", "", ".");
	test_resolve(".", "a/..", ".");
	
	test_resolve("/a", "b", "/a/b");
	test_resolve("/a", "b/c", "/a/b/c");
	test_resolve("/a/b", "c", "/a/b/c");
	
	test_resolve("/..", "..", "/../..");
	
	test_resolve("/a", "..", "/");
	test_resolve("/a", "../..", "/..");
	test_resolve("/a/..", "..", "/..");
	
	test_resolve("/abcd", "..", "/");
	test_resolve("/abcd", "../..", "/..");
	test_resolve("/abcd/..", "..", "/..");
	
	test_resolve("/" , "../a", "/../a");
	test_resolve("/..", "a", "/../a");
	test_resolve("/", "../a/..", "/..");
	test_resolve("/..", "a/..", "/..");
	test_resolve("/../a", "..", "/..");
	
	// ---
	
	test_parent("", "..");
	test_parent(".", "..");
	test_parent("a", ".");
	test_parent("a/b", "a");
	test_parent("/", "/..");
	test_parent("/a", "/");
	test_parent("/a/b", "/a");
	test_parent("..", "../..");
	test_parent("../..", "../../..");
	
}