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; }
static bool test_trim_none() { emit_test("Test trim() on a std::string with no white space."); std::string a("Indurain"); trim(a); emit_output_expected_header(); emit_retval("%s", "Indurain"); emit_output_actual_header(); emit_retval("%s", a.c_str()); if(strcmp(a.c_str(), "Indurain") != MATCH) { FAIL; } PASS; }
static bool test_trim_beginning() { emit_test("Test trim() on a std::string with white space at the beginning."); std::string a(" Merckx"); trim(a); emit_output_expected_header(); emit_retval("%s", "Merckx"); emit_output_actual_header(); emit_retval("%s", a.c_str()); if(strcmp(a.c_str(), "Merckx") != MATCH) { FAIL; } PASS; }
static bool test_trim_empty() { emit_test("Test trim() on an empty std::string."); std::string a; trim(a); emit_output_expected_header(); emit_retval("%s", ""); emit_output_actual_header(); emit_retval("%s", a.c_str()); if(strcmp(a.c_str(), "") != MATCH) { FAIL; } PASS; }
static bool test_upper_case_non_empty() { emit_test("Test upper_case() on a non-empty std::string."); std::string a("lower UPPER"); upper_case(a); emit_output_expected_header(); emit_retval("%s", "LOWER UPPER"); emit_output_actual_header(); emit_retval("%s", a.c_str()); if(strcmp(a.c_str(), "LOWER UPPER") != MATCH) { FAIL; } PASS; }
static bool test_chomp_new_line_end() { emit_test("Does chomp() remove the newLine if its the last character in " "the std::string?"); std::string a("stuff\n"); chomp(a); emit_output_expected_header(); emit_retval("%s", "stuff"); emit_output_actual_header(); emit_retval("%s", a.c_str()); if(strcmp(a.c_str(), "stuff") != MATCH) { FAIL; } PASS; }
static bool test_chomp_new_line_beginning() { emit_test("Does chomp() do nothing if the newLine if it's not the last " "character in the std::string?"); std::string a("stuff\nmore stuff"); chomp(a); emit_output_expected_header(); emit_retval("%s", "stuff\nmore stuff"); emit_output_actual_header(); emit_retval("%s", a.c_str()); if(strcmp(a.c_str(), "stuff\nmore stuff") != MATCH) { FAIL; } PASS; }
static bool test_chomp_return_true() { emit_test("Does chomp() return true if the std::string has a newLine at the " "end?"); std::string a("stuff\n"); bool result = chomp(a); emit_output_expected_header(); emit_retval("%d", 1); emit_output_actual_header(); emit_retval("%d", result); if(!result) { FAIL; } PASS; }
static bool test_chomp_crlf_end() { emit_test("Does chomp() remove CR and LF if they are the last characters" " in the std::string?"); std::string a("stuff\r\n"); chomp(a); emit_output_expected_header(); emit_retval("%s", "stuff"); emit_output_actual_header(); emit_retval("%s", a.c_str()); if(strcmp(a.c_str(), "stuff") != MATCH) { FAIL; } PASS; }
static bool test_chomp_return_false() { emit_test("Does chomp() return false if the std::string doesn't have a " "newLine?"); std::string a("stuff"); bool result = chomp(a); emit_output_expected_header(); emit_retval("%d", 0); emit_output_actual_header(); emit_retval("%d", result); if(result) { FAIL; } PASS; }
static bool test_name() { emit_test("Does a path starting with a name return false?"); const char *param = "tmp/foo"; int expected = 0; emit_input_header(); emit_param("STRING", param); int result = fullpath(param); emit_output_expected_header(); emit_retval("%d", expected); emit_output_actual_header(); emit_retval("%d", result); if(expected != result) { FAIL; } PASS; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
static bool test_drive_path_backslash() { emit_test("Does a path with a drive letter followed by a colon and backslash return true?"); const char *param = "c:\\"; int expected = 1; emit_input_header(); emit_param("STRING", param); int result = fullpath(param); emit_output_expected_header(); emit_retval("%d", expected); emit_output_actual_header(); emit_retval("%d", result); if(expected != result) { FAIL; } PASS; }
static bool test_backslash() { emit_test("Does a path with only a backslash return true?"); const char *param = "\\"; int expected = 1; emit_input_header(); emit_param("STRING", param); int result = fullpath(param); emit_output_expected_header(); emit_retval("%d", expected); emit_output_actual_header(); emit_retval("%d", result); if(expected != result) { FAIL; } PASS; }
static bool test_colon_forward_slash() { emit_test("Does a path with a colon followed by a forward slash return false?"); const char *param = ":/"; int expected = 0; emit_input_header(); emit_param("STRING", param); int result = fullpath(param); emit_output_expected_header(); emit_retval("%d", expected); emit_output_actual_header(); emit_retval("%d", result); if(expected != result) { FAIL; } PASS; }
static bool test_forward_slash() { emit_test("Does a path starting with a forward slash return true?"); const char *param = "/tmp/foo"; int expected = 1; emit_input_header(); emit_param("STRING", param); int result = fullpath(param); emit_output_expected_header(); emit_retval("%d", expected); emit_output_actual_header(); emit_retval("%d", result); if(expected != result) { FAIL; } PASS; }
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; }
static bool tokenize_skip() { emit_test("Test GetNextToken() when skipping blank tokens."); const char *a = " Ottavio Bottechia_"; Tokenize(a); const char* tok = GetNextToken(" ", true); emit_input_header(); emit_param("delim", "%s", " "); emit_param("skipBlankTokens", "%d", true); emit_output_expected_header(); emit_retval("%s", "Ottavio"); emit_output_actual_header(); emit_retval("%s", tok); if(strcmp(tok, "Ottavio") != MATCH) { FAIL; } PASS; }
static bool test_normal_case() { char *up = NULL; emit_test("Does a uppercase string get converted to lower in place?"); char input[1024]; sprintf(input, "%s", "UPPER"); emit_input_header(); emit_param("STRING", input); up = strlwr(input); emit_output_expected_header(); emit_retval("upper"); emit_output_actual_header(); emit_retval("%s", up); if(strcmp(input, "upper") != 0) { FAIL; } PASS; }
static bool test_null() { emit_test("Does a NULL path return a period?"); const char *param = "NULL"; const char *expect = "."; emit_input_header(); emit_param("STRING", param); emit_output_expected_header(); emit_retval("%s", expect); char *path = condor_dirname(param); emit_output_actual_header(); emit_retval("%s", path); if(strcmp(path, expect) != MATCH) { free(path); FAIL; } free(path); PASS; }
static bool test_double_backslash() { emit_test("Does a path with one directory using a double backslash and the other using a single backslash return the full parent directory?"); const char *param = "\\\\foo\\bar\\zap.txt"; const char *expect = "\\\\foo\\bar"; emit_input_header(); emit_param("STRING", param); emit_output_expected_header(); emit_retval("%s", expect); char *path = condor_dirname(param); emit_output_actual_header(); emit_retval("%s", path); if(strcmp(path, expect) != MATCH) { free(path); FAIL; } free(path); PASS; }
static bool test_period_and_backslash_with_special_file() { emit_test("Does a path using a period and a backslash return the parent directory?"); const char *param = ".foo\\.bar.txt"; const char *expect = ".foo"; emit_input_header(); emit_param("STRING", param); emit_output_expected_header(); emit_retval("%s", expect); char *path = condor_dirname(param); emit_output_actual_header(); emit_retval("%s", path); if(strcmp(path, expect) != MATCH) { free(path); FAIL; } free(path); PASS; }
static bool test_period_and_forward_slash() { emit_test("Does a path using both a period and a forward slash return the parent directory"); const char *param = ".foo/bar"; const char *expect = ".foo"; emit_input_header(); emit_param("STRING", param); emit_output_expected_header(); emit_retval("%s", expect); char *path = condor_dirname(param); emit_output_actual_header(); emit_retval("%s", path); if(strcmp(path, expect) != MATCH) { free(path); FAIL; } free(path); PASS; }
static bool test_backslash_and_file_extension() { emit_test("Does a path with two directories and a file extension using backslashes return the full parent directory?"); const char *param = "foo\\bar\\zap.txt"; const char *expect = "foo\\bar"; emit_input_header(); emit_param("STRING", param); emit_output_expected_header(); emit_retval("%s", expect); char *path = condor_dirname(param); emit_output_actual_header(); emit_retval("%s", path); if(strcmp(path, expect) != MATCH) { free(path); FAIL; } free(path); PASS; }