Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / netwerk / test / TestStreamLoader.cpp
blob80aeb3e895226b668ba5e85c1a7e3c77ab62ff56
1 #include <stdio.h>
2 #include "TestCommon.h"
3 #include "nsNetUtil.h"
4 #include "nsThreadUtils.h"
5 #include "prlog.h"
7 #if defined(PR_LOGGING)
8 //
9 // set NSPR_LOG_MODULES=Test:5
11 static PRLogModuleInfo *gTestLog = nsnull;
12 #endif
13 #define LOG(args) PR_LOG(gTestLog, PR_LOG_DEBUG, args)
15 class MyStreamLoaderObserver : public nsIStreamLoaderObserver
17 public:
18 NS_DECL_ISUPPORTS
19 NS_DECL_NSISTREAMLOADEROBSERVER
22 NS_IMPL_ISUPPORTS1(MyStreamLoaderObserver, nsIStreamLoaderObserver)
24 NS_IMETHODIMP
25 MyStreamLoaderObserver::OnStreamComplete(nsIStreamLoader *loader,
26 nsISupports *ctxt,
27 nsresult status,
28 PRUint32 resultLen,
29 const PRUint8 *result)
31 LOG(("OnStreamComplete [status=%x resultLen=%u]\n", status, resultLen));
33 nsCOMPtr<nsIRequest> request;
34 loader->GetRequest(getter_AddRefs(request));
35 LOG((" request=%p\n", request.get()));
37 QuitPumpingEvents();
38 return NS_OK;
41 int main(int argc, char **argv)
43 if (test_common_init(&argc, &argv) != 0)
44 return -1;
46 if (argc < 2) {
47 printf("usage: %s <url>\n", argv[0]);
48 return -1;
51 #if defined(PR_LOGGING)
52 gTestLog = PR_NewLogModule("Test");
53 #endif
55 nsresult rv = NS_InitXPCOM2(nsnull, nsnull, nsnull);
56 if (NS_FAILED(rv))
57 return -1;
60 nsCOMPtr<nsIURI> uri;
61 rv = NS_NewURI(getter_AddRefs(uri), nsDependentCString(argv[1]));
62 if (NS_FAILED(rv))
63 return -1;
65 nsCOMPtr<nsIChannel> chan;
66 rv = NS_NewChannel(getter_AddRefs(chan), uri);
67 if (NS_FAILED(rv))
68 return -1;
70 nsCOMPtr<nsIStreamLoaderObserver> observer = new MyStreamLoaderObserver();
71 if (!observer)
72 return -1;
74 nsCOMPtr<nsIStreamLoader> loader;
75 rv = NS_NewStreamLoader(getter_AddRefs(loader), observer);
76 if (NS_FAILED(rv))
77 return -1;
79 rv = chan->AsyncOpen(loader, nsnull);
80 if (NS_FAILED(rv))
81 return -1;
83 PumpEvents();
84 } // this scopes the nsCOMPtrs
85 // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM
86 NS_ShutdownXPCOM(nsnull);
87 return rv;