/* Checks if the given uri defines a file * (as opposed to a network service) */ gboolean gnc_uri_is_file_uri (const gchar *uri) { gchar *protocol = gnc_uri_get_protocol ( uri ); gboolean result = gnc_uri_is_file_protocol ( protocol ); g_free ( protocol ); return result; }
int main(int argc, char **argv) { int i; qof_init(); /* TEST: gnc_uri_get_components */ for (i = 0; strs[i].uri != NULL; i++) { gchar *tprotocol = NULL; gchar *thostname = NULL; gchar *tusername = NULL; gchar *tpassword = NULL; gchar *tpath = NULL; gint32 tport = 0; gboolean testresult; gnc_uri_get_components( strs[i].uri, &tprotocol, &thostname, &tport, &tusername, &tpassword, &tpath ); testresult = ( safe_strcmp ( tprotocol, strs[i].protocol ) == 0 ) & ( safe_strcmp ( thostname, strs[i].hostname ) == 0 ) & ( safe_strcmp ( tusername, strs[i].username ) == 0 ) & ( safe_strcmp ( tpassword, strs[i].password ) == 0 ) & ( safe_strcmp ( tpath, strs[i].path ) == 0 ) & ( tport == strs[i].port ); do_test_args(testresult, "gnc_uri_get_components", __FILE__, __LINE__, "\n %s:\n" " Expected: %s, %s, %s, %s, %s, %d\n" " Got : %s, %s, %s, %s, %s, %d\n", strs[i].uri, strs[i].protocol, strs[i].hostname, strs[i].username, strs[i].password, strs[i].path, strs[i].port, tprotocol, thostname, tusername, tpassword, tpath, tport); g_free(tprotocol); g_free(thostname); g_free(tusername); g_free(tpassword); g_free(tpath); } /* TEST: gnc_uri_get_protocol */ for (i = 0; strs[i].uri != NULL; i++) { gchar *tprotocol = NULL; gboolean testresult; tprotocol = gnc_uri_get_protocol( strs[i].uri ); testresult = ( safe_strcmp ( tprotocol, strs[i].protocol ) == 0 ); do_test_args(testresult, "gnc_uri_get_protocol", __FILE__, __LINE__, "\n %s:\n" " Expected: %s\n" " Got : %s\n", strs[i].uri, strs[i].protocol, tprotocol ); g_free(tprotocol); } /* TEST: gnc_uri_get_path */ for (i = 0; strs[i].uri != NULL; i++) { gchar *tpath = NULL; gboolean testresult; tpath = gnc_uri_get_path( strs[i].uri ); testresult = ( safe_strcmp ( tpath, strs[i].path ) == 0 ); do_test_args(testresult, "gnc_uri_get_path", __FILE__, __LINE__, "\n %s:\n" " Expected: %s\n" " Got : %s\n", strs[i].uri, strs[i].path, tpath ); g_free(tpath); } /* TEST: gnc_uri_create_uri */ for (i = 0; strs[i].uri != NULL; i++) { gchar *turi = NULL; gboolean testresult; turi = gnc_uri_create_uri( strs[i].protocol, strs[i].hostname, strs[i].port, strs[i].username, strs[i].password, strs[i].path ); testresult = ( safe_strcmp ( turi, strs[i].created_uri ) == 0 ); do_test_args(testresult, "gnc_uri_create_uri", __FILE__, __LINE__, "\n %s, %s, %s, %s, %s, %d:\n" " Expected: %s\n" " Got : %s\n", strs[i].protocol, strs[i].hostname, strs[i].username, strs[i].password, strs[i].path, strs[i].port, strs[i].created_uri, turi); g_free(turi); } /* TEST: gnc_uri_normalize_uri */ for (i = 0; strs[i].uri != NULL; i++) { gchar *turi = NULL; gboolean testresult; turi = gnc_uri_normalize_uri( strs[i].uri, strs[i].want_password ); testresult = ( safe_strcmp ( turi, strs[i].normalized_uri ) == 0 ); do_test_args(testresult, "gnc_uri_normalize_uri", __FILE__, __LINE__, "\n %s:\n" " Expected: %s\n" " Got : %s\n", strs[i].uri, strs[i].normalized_uri, turi ); g_free(turi); } /* TEST: gnc_uri_is_file_protocol */ for (i = 0; strs[i].uri != NULL; i++) { gboolean tis_file_protocol; gboolean testresult; tis_file_protocol = gnc_uri_is_file_protocol( strs[i].protocol ); testresult = ( tis_file_protocol == strs[i].is_file_protocol ); do_test_args(testresult, "gnc_uri_is_file_protocol", __FILE__, __LINE__, "\n %s:\n" " Expected: %s\n" " Got : %s\n", strs[i].uri, strs[i].is_file_protocol, tis_file_protocol ); } /* TEST: gnc_uri_is_file_uri */ for (i = 0; strs[i].uri != NULL; i++) { gboolean tis_file_uri; gboolean testresult; tis_file_uri = gnc_uri_is_file_uri( strs[i].uri ); testresult = ( tis_file_uri == strs[i].is_file_protocol ); do_test_args(testresult, "gnc_uri_is_file_uri", __FILE__, __LINE__, "\n %s:\n" " Expected: %s\n" " Got : %s\n", strs[i].uri, strs[i].is_file_protocol, tis_file_uri ); } print_test_results(); return get_rv(); }