char* temp; PRInt32 port; pURL->GetScheme(&temp); cout << "Got " << temp << ','; pURL->GetPreHost(&temp); cout << temp << ','; pURL->GetHost(&temp); cout << temp << ','; pURL->GetPort(&port); cout << port << ','; pURL->GetPath(&temp); cout << temp << endl;
"http,username:password,hostname.com,80,/pathname/more/path", ",username,host,8080,/path", "http,,gagan,-1,/", ",,host,0,/netlib", ",,,-1,", "mailbox,,,-1,/foo", ",username:pass,hostname.edu,80,/pathname", "http,username:password,hostname,80,/pathname" };  for (int i = 0; i< tests; ++i) { writeout(url[i]); cout << "Expect " << resultset[i] << endl << endl;
nsresult testURL(const char* i_pURL){    const char* temp;	nsresult result = NS_OK;    const int tests = 8;	/* 		If you add a test case then make sure you also add the expected	   	result in the resultset as well. 	*/    const char* url[tests] =     {        "http://username:password@hostname.com:80/pathname/./more/stuff/../path",        "username@host:8080/path",        "http://gagan/",        "host:port/netlib", //port should now be 0        "", //empty string        "mailbox:///foo", // No host specified path should be /foo        "user:pass@hostname.edu:80/pathname", //this is always user:pass and not http:user        "http://username:password@hostname:80/pathname"    };	const char* resultset[tests];	{		"http,username:password,hostname.com,80,/pathname/more/path",		",username,host,8080,/path",		"http,,gagan,-1,/",		",,host,0,/netlib",		",,,-1,",		"mailbox,,,-1,/foo",		",username:pass,hostname.edu,80,/pathname",		"http,username:password,hostname,80,/pathname"	}    for (int i = 0; i< tests; ++i)    {        nsCOMPtr<nsIURL> pURL;				cout << "Analyzing " << url[i] << endl;		NS_NewURL(url[i], do_QueryInterface(pURL));		if (pURL)		{			char* temp;			PRInt32 port;			pURL->GetScheme(&temp);			cout << "Got " << temp << ',';			pURL->GetPreHost(&temp);			cout << temp << ',';			pURL->GetHost(&temp);			cout << temp << ',';			pURL->GetPort(&port);			cout << port << ',';			pURL->GetPath(&temp);			cout << temp << endl;		}		cout << "Expect " << resultset[i] << endl;    }      return 0;}