Ejemplo n.º 1
0
static bool test_slash_notation() {
	emit_test("Is normal input parsed correctly with slash notation for the mask?");
	char* inputstring = strdup("192.168.3.4/8");
	emit_input_header();
	emit_param("STRING", inputstring);
	struct in_addr ip;
	unsigned char* ipbyte = (unsigned char*) &ip;
	struct in_addr mask;
	unsigned char* maskbyte = (unsigned char*) &mask;
	int result = is_valid_network(inputstring, &ip, &mask);
	free(inputstring);
	emit_output_expected_header();
	int expected_return = TRUE;
	emit_retval("%s", tfstr(expected_return));
	emit_param("IP", "192.168.3.4");
	emit_param("MASK", "255.0.0.0");
	emit_output_actual_header();
	emit_retval("%s", tfstr(result));
	emit_param("IP", "%d.%d.%d.%d", *ipbyte, *(ipbyte + 1), *(ipbyte + 2), *(ipbyte + 3));
	emit_param("MASK", "%d.%d.%d.%d", *maskbyte, *(maskbyte + 1), *(maskbyte + 2), *(maskbyte + 3));
	if( expected_return != result ||
		192 != *ipbyte || 168 != *(ipbyte + 1) || 3 != *(ipbyte + 2) || 4 != *(ipbyte + 3) ||
		255 != *maskbyte || 0 != *(maskbyte + 1) || 0 != *(maskbyte + 2) || 0 != *(maskbyte + 3)) {
		FAIL;
	}
	PASS;
}
Ejemplo n.º 2
0
static bool test_one_octet_wildcard() {
	emit_test("Is it identified as an IP address with one octet and a wildcard?");
	char* input = strdup( "66.*" );
	emit_input_header();
	emit_param("IP", input);
	int result = is_ipaddr( input, NULL );
	free( input );
	emit_output_expected_header();
	emit_retval("%s", tfstr(TRUE));
	emit_output_actual_header();
	emit_retval("%s", tfstr(result));
	if(result != TRUE) {
		FAIL;
	}
	PASS;
}
Ejemplo n.º 3
0
static bool test_start_wildcard() {
	emit_test("Does it fail correctly with a wildcard and then some octets?");
	char* input = strdup( "*.0.42.1" );
	emit_input_header();
	emit_param("IP", input);
	int result = is_ipaddr( input, NULL );
	free( input );
	emit_output_expected_header();
	emit_retval("%s", tfstr(FALSE));
	emit_output_actual_header();
	emit_retval("%s", tfstr(result));
	if(result != FALSE) {
		FAIL;
	}
	PASS;
}
Ejemplo n.º 4
0
static bool test_only_wildcard() {
	emit_test("Does it work with nothing but a single wildcard?"); 
	char* input = strdup( "*" );
	emit_input_header();
	emit_param("IP", input);
	int result = is_ipaddr( input, NULL );
	free( input );
	emit_output_expected_header();
	emit_retval("%s", tfstr(TRUE));
	emit_output_actual_header();
	emit_retval("%s", tfstr(result));
	if(result != TRUE) {
		FAIL;
	}
	PASS;
}
Ejemplo n.º 5
0
static bool test_lower_bound() {
	emit_test("Does it work with one octet <0?");
	char* input = strdup( "-2.71.82.81" );
	emit_input_header();
	emit_param("IP", input);
	int result = is_ipaddr( input, NULL );
	free( input );
	emit_output_expected_header();
	emit_retval("%s", tfstr(FALSE));
	emit_output_actual_header();
	emit_retval("%s", tfstr(result));
	if(result != FALSE) {
		FAIL;
	}
	PASS;
}
Ejemplo n.º 6
0
static bool test_no_angle_brackets() {
	emit_test("Is the string correctly rejected if there are no angle brackets?");
	char* input = strdup( "209.172.63.167:8080" );
	emit_input_header();
	emit_param("SINFUL", input);
	int result = is_valid_sinful( input );
	free( input );
	emit_output_expected_header();
	emit_retval("%s", tfstr(FALSE));
	emit_output_actual_header();
	emit_retval("%s", tfstr(result));
	if(result != FALSE) {
		FAIL;
	}
	PASS;
}
Ejemplo n.º 7
0
static bool test_hostname() {
	emit_test("Are hostnames instead of IP addresses rejected like they should be?");
	char* input = strdup( "<balthazar.cs.wisc.edu:47>" );
	emit_input_header();
	emit_param("SINFUL", input);
	int result = is_valid_sinful( input );
	free( input );
	emit_output_expected_header();
	emit_retval("%s", tfstr(FALSE));
	emit_output_actual_header();
	emit_retval("%s", tfstr(result));
	if(result != FALSE) {
		FAIL;
	}
	PASS;
}
Ejemplo n.º 8
0
static bool test_normal_case() {
	emit_test("Is normal input identified correctly?");
	char* input = strdup( "<208.122.19.56:47>" );
	emit_input_header();
	emit_param("SINFUL", input);
	int result = is_valid_sinful( input );
	free( input );
	emit_output_expected_header();
	emit_retval("%s", tfstr(TRUE));
	emit_output_actual_header();
	emit_retval("%s", tfstr(result));
	if(result != TRUE) {
		FAIL;
	}
	PASS;
}
Ejemplo n.º 9
0
static bool test_alpha_input() {
	emit_test("Does an error occur on alpha-only input?");
	struct sockaddr_in sa_in;
	char* input = strdup("Iamafish");
	int result = string_to_sin(input, &sa_in);
	emit_input_header();
	emit_param("STRING", input);
	free(input);
	emit_output_expected_header();
	emit_retval("%s", tfstr(FALSE));
	emit_output_actual_header();
	emit_retval("%s", tfstr(result));
	if(result != 0) {
		FAIL;
	}
	PASS;
}
Ejemplo n.º 10
0
static bool test_normal_case() {
	emit_test("Is normal input identified correctly?");
	char* input = strdup( "66.184.142.51" );
	emit_input_header();
	emit_param("IP", input);
	struct in_addr ip;
	unsigned char* byte = (unsigned char*) &ip;
	int result = is_ipaddr( input, &ip );
	free( input );
	emit_output_expected_header();
	emit_param("IP", "%d.%d.%d.%d", 66, 184, 142, 51);
	emit_retval("%s", tfstr(TRUE));
	emit_output_actual_header();
	emit_param("IP", "%d.%d.%d.%d", *byte, *(byte+1), *(byte+2), *(byte+3));
	emit_retval("%s", tfstr(result));
	if(result != TRUE || *byte != 66 || *(byte+1) != 184 || *(byte+2) != 142 || *(byte+3) != 51) {
		FAIL;
	}
	PASS;
}
Ejemplo n.º 11
0
static bool test_normal_case() {
	emit_test("Is normal input converted correctly?");
	struct sockaddr_in sa_in;
	char* input = strdup("<192.168.0.2:80?param1=value1&param2=value2>");
	int result = string_to_sin(input, &sa_in);
	emit_input_header();
	emit_param("STRING", input);
	free(input);
	emit_output_expected_header();
	emit_retval("%s", tfstr(TRUE));
	emit_param("sockaddr_in.in_addr", "192.168.0.2");
	emit_param("sockaddr_in.port", "80");
	emit_output_actual_header();
	emit_retval("%s", tfstr(result));
	unsigned char* byte = (unsigned char*) &sa_in.sin_addr;
	int port = ntohs(sa_in.sin_port);
	emit_param("sockaddr_in.in_addr", "%d.%d.%d.%d", *byte, *(byte+1), *(byte+2), *(byte+3));
	emit_param("sockaddr_in.port", "%d", port);
	if(result != 1 || port != 80 || !utest_sock_eq_octet(&(sa_in.sin_addr), 192, 168, 0, 2) ) {
		FAIL;
	}
	PASS;
}
Ejemplo n.º 12
0
bool cut_assert_false_impl(bool value, const char *expr, const char *file, int line)
{
	int tmp_errno = errno;

	if (value) {
		dprintf(D_ALWAYS, "Failed cut_assert_false(%s) with value %s at %d in "
			"%s.\n", expr, tfstr(value), line, file);
		dprintf(D_ALWAYS, "A possibly useful errno is %d(%s).\n",
			tmp_errno, strerror(tmp_errno));
		exit(EXIT_FAILURE);
	}

	return value;
}
Ejemplo n.º 13
0
int
N(        const N_in * in
	, N_out *
	, N_atoms * atoms)
{
	int a = in->a;
	Aob * & ga = atoms->ga();
	bool ga_new = false;
	bool gb_new = false;
	if(ga == NULL) {
		ga = new Aob(a%10);
		ga_new = true;
	}
	if(atoms->have_gb()) {
		Bob * & gb = atoms->gb();
		if(gb == NULL) {
			gb = new Bob(a);
			gb_new = true;
		} else {
			gb->add(a);
		}
#define tfstr(B) (B ? "true" : "false")
		printf("N %d %d %d %s %s\n"
			, in->a
			, ga->id()
			, gb->a()
			, tfstr(ga_new)
			, tfstr(gb_new));
	} else {
		printf("N %d %d   have no gb %s\n"
			, in->a
			, ga->id()
			, tfstr(ga_new));
	}
	return 0;
}