зеркало из https://github.com/mozilla/pjs.git
Added code to check return values. Cleaned up a bit.
This commit is contained in:
Родитель
1b400664e7
Коммит
f788c85180
|
@ -58,21 +58,30 @@ extern "C" void NS_SetupRegistry();
|
|||
#endif
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
nsComponentManager::RegisterComponent(kNetServiceCID, NULL, NULL, NETLIB_DLL,
|
||||
PR_FALSE, PR_FALSE);
|
||||
nsComponentManager::RegisterComponent(kEventQueueServiceCID, NULL, NULL, XPCOM_DLL,
|
||||
PR_FALSE, PR_FALSE);
|
||||
nsresult ret;
|
||||
|
||||
ret = nsComponentManager::RegisterComponent(kNetServiceCID, NULL,
|
||||
NULL, NETLIB_DLL, PR_FALSE, PR_FALSE);
|
||||
if (NS_FAILED(ret)) {
|
||||
printf("cannot register net service\n");
|
||||
return 1;
|
||||
}
|
||||
ret = nsComponentManager::RegisterComponent(kEventQueueServiceCID, NULL,
|
||||
NULL, XPCOM_DLL, PR_FALSE, PR_FALSE);
|
||||
if (NS_FAILED(ret)) {
|
||||
printf("cannot register event queue service\n");
|
||||
return 1;
|
||||
}
|
||||
#ifdef XP_MAC // have not build this on PC and UNIX yet so make it #ifdef XP_MAC
|
||||
NS_SetupRegistry();
|
||||
#endif
|
||||
|
||||
nsresult ret;
|
||||
|
||||
nsIEventQueueService* pEventQueueService = nsnull;
|
||||
ret = nsServiceManager::GetService(kEventQueueServiceCID,
|
||||
kIEventQueueServiceIID, (nsISupports**) &pEventQueueService);
|
||||
if (NS_FAILED(ret)) {
|
||||
if (NS_FAILED(ret) || (!pEventQueueService)) {
|
||||
printf("cannot get event queue service\n");
|
||||
return 1;
|
||||
}
|
||||
|
@ -84,43 +93,53 @@ main(int argc, char *argv[])
|
|||
nsINetService* pNetService = nsnull;
|
||||
ret = nsServiceManager::GetService(kNetServiceCID, kINetServiceIID,
|
||||
(nsISupports**) &pNetService);
|
||||
if (NS_FAILED(ret)) {
|
||||
if (NS_FAILED(ret) || (!pNetService)) {
|
||||
printf("cannot get net service\n");
|
||||
return 1;
|
||||
}
|
||||
nsIURL *url = nsnull;
|
||||
nsIURL* url = nsnull;
|
||||
ret = pNetService->CreateURL(&url, nsString(TEST_URL), nsnull, nsnull,
|
||||
nsnull);
|
||||
if (NS_FAILED(ret)) {
|
||||
if (NS_FAILED(ret) || (!url)) {
|
||||
printf("cannot create URL\n");
|
||||
return 1;
|
||||
}
|
||||
nsIInputStream *in = nsnull;
|
||||
nsIInputStream* in = nsnull;
|
||||
ret = pNetService->OpenBlockingStream(url, nsnull, &in);
|
||||
if (NS_FAILED(ret)) {
|
||||
if (NS_FAILED(ret) || (!in)) {
|
||||
printf("cannot open stream\n");
|
||||
return 1;
|
||||
}
|
||||
nsIPersistentProperties *props = nsnull;
|
||||
nsIPersistentProperties* props = nsnull;
|
||||
ret = nsComponentManager::CreateInstance(kPersistentPropertiesCID, NULL,
|
||||
kIPersistentPropertiesIID, (void**) &props);
|
||||
if (NS_FAILED(ret)) {
|
||||
if (NS_FAILED(ret) || (!props)) {
|
||||
printf("create nsIPersistentProperties failed\n");
|
||||
return 1;
|
||||
}
|
||||
props->Load(in);
|
||||
ret = props->Load(in);
|
||||
if (NS_FAILED(ret)) {
|
||||
printf("cannot load properties\n");
|
||||
return 1;
|
||||
}
|
||||
int i = 1;
|
||||
while (1) {
|
||||
char name[16];
|
||||
name[0] = 0;
|
||||
sprintf(name, "%d", i);
|
||||
nsAutoString v("");
|
||||
props->GetProperty(name, v);
|
||||
if (!v.Length()) {
|
||||
ret = props->GetProperty(name, v);
|
||||
if (NS_FAILED(ret) || (!v.Length())) {
|
||||
break;
|
||||
}
|
||||
char *value = v.ToNewCString();
|
||||
cout << "\"" << i << "\"=\"" << value << "\"" << endl;
|
||||
delete[] value;
|
||||
char* value = v.ToNewCString();
|
||||
if (value) {
|
||||
cout << "\"" << i << "\"=\"" << value << "\"" << endl;
|
||||
delete[] value;
|
||||
}
|
||||
else {
|
||||
printf("%d: ToNewCString failed\n", i);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
|
|
|
@ -58,21 +58,30 @@ extern "C" void NS_SetupRegistry();
|
|||
#endif
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
nsComponentManager::RegisterComponent(kNetServiceCID, NULL, NULL, NETLIB_DLL,
|
||||
PR_FALSE, PR_FALSE);
|
||||
nsComponentManager::RegisterComponent(kEventQueueServiceCID, NULL, NULL, XPCOM_DLL,
|
||||
PR_FALSE, PR_FALSE);
|
||||
nsresult ret;
|
||||
|
||||
ret = nsComponentManager::RegisterComponent(kNetServiceCID, NULL,
|
||||
NULL, NETLIB_DLL, PR_FALSE, PR_FALSE);
|
||||
if (NS_FAILED(ret)) {
|
||||
printf("cannot register net service\n");
|
||||
return 1;
|
||||
}
|
||||
ret = nsComponentManager::RegisterComponent(kEventQueueServiceCID, NULL,
|
||||
NULL, XPCOM_DLL, PR_FALSE, PR_FALSE);
|
||||
if (NS_FAILED(ret)) {
|
||||
printf("cannot register event queue service\n");
|
||||
return 1;
|
||||
}
|
||||
#ifdef XP_MAC // have not build this on PC and UNIX yet so make it #ifdef XP_MAC
|
||||
NS_SetupRegistry();
|
||||
#endif
|
||||
|
||||
nsresult ret;
|
||||
|
||||
nsIEventQueueService* pEventQueueService = nsnull;
|
||||
ret = nsServiceManager::GetService(kEventQueueServiceCID,
|
||||
kIEventQueueServiceIID, (nsISupports**) &pEventQueueService);
|
||||
if (NS_FAILED(ret)) {
|
||||
if (NS_FAILED(ret) || (!pEventQueueService)) {
|
||||
printf("cannot get event queue service\n");
|
||||
return 1;
|
||||
}
|
||||
|
@ -84,43 +93,53 @@ main(int argc, char *argv[])
|
|||
nsINetService* pNetService = nsnull;
|
||||
ret = nsServiceManager::GetService(kNetServiceCID, kINetServiceIID,
|
||||
(nsISupports**) &pNetService);
|
||||
if (NS_FAILED(ret)) {
|
||||
if (NS_FAILED(ret) || (!pNetService)) {
|
||||
printf("cannot get net service\n");
|
||||
return 1;
|
||||
}
|
||||
nsIURL *url = nsnull;
|
||||
nsIURL* url = nsnull;
|
||||
ret = pNetService->CreateURL(&url, nsString(TEST_URL), nsnull, nsnull,
|
||||
nsnull);
|
||||
if (NS_FAILED(ret)) {
|
||||
if (NS_FAILED(ret) || (!url)) {
|
||||
printf("cannot create URL\n");
|
||||
return 1;
|
||||
}
|
||||
nsIInputStream *in = nsnull;
|
||||
nsIInputStream* in = nsnull;
|
||||
ret = pNetService->OpenBlockingStream(url, nsnull, &in);
|
||||
if (NS_FAILED(ret)) {
|
||||
if (NS_FAILED(ret) || (!in)) {
|
||||
printf("cannot open stream\n");
|
||||
return 1;
|
||||
}
|
||||
nsIPersistentProperties *props = nsnull;
|
||||
nsIPersistentProperties* props = nsnull;
|
||||
ret = nsComponentManager::CreateInstance(kPersistentPropertiesCID, NULL,
|
||||
kIPersistentPropertiesIID, (void**) &props);
|
||||
if (NS_FAILED(ret)) {
|
||||
if (NS_FAILED(ret) || (!props)) {
|
||||
printf("create nsIPersistentProperties failed\n");
|
||||
return 1;
|
||||
}
|
||||
props->Load(in);
|
||||
ret = props->Load(in);
|
||||
if (NS_FAILED(ret)) {
|
||||
printf("cannot load properties\n");
|
||||
return 1;
|
||||
}
|
||||
int i = 1;
|
||||
while (1) {
|
||||
char name[16];
|
||||
name[0] = 0;
|
||||
sprintf(name, "%d", i);
|
||||
nsAutoString v("");
|
||||
props->GetProperty(name, v);
|
||||
if (!v.Length()) {
|
||||
ret = props->GetProperty(name, v);
|
||||
if (NS_FAILED(ret) || (!v.Length())) {
|
||||
break;
|
||||
}
|
||||
char *value = v.ToNewCString();
|
||||
cout << "\"" << i << "\"=\"" << value << "\"" << endl;
|
||||
delete[] value;
|
||||
char* value = v.ToNewCString();
|
||||
if (value) {
|
||||
cout << "\"" << i << "\"=\"" << value << "\"" << endl;
|
||||
delete[] value;
|
||||
}
|
||||
else {
|
||||
printf("%d: ToNewCString failed\n", i);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче