2 #include "TestCommon.h"
4 #include "nsThreadUtils.h"
7 #if defined(PR_LOGGING)
9 // set NSPR_LOG_MODULES=Test:5
11 static PRLogModuleInfo
*gTestLog
= nsnull
;
13 #define LOG(args) PR_LOG(gTestLog, PR_LOG_DEBUG, args)
15 class MyStreamLoaderObserver
: public nsIStreamLoaderObserver
19 NS_DECL_NSISTREAMLOADEROBSERVER
22 NS_IMPL_ISUPPORTS1(MyStreamLoaderObserver
, nsIStreamLoaderObserver
)
25 MyStreamLoaderObserver::OnStreamComplete(nsIStreamLoader
*loader
,
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()));
41 int main(int argc
, char **argv
)
43 if (test_common_init(&argc
, &argv
) != 0)
47 printf("usage: %s <url>\n", argv
[0]);
51 #if defined(PR_LOGGING)
52 gTestLog
= PR_NewLogModule("Test");
55 nsresult rv
= NS_InitXPCOM2(nsnull
, nsnull
, nsnull
);
61 rv
= NS_NewURI(getter_AddRefs(uri
), nsDependentCString(argv
[1]));
65 nsCOMPtr
<nsIChannel
> chan
;
66 rv
= NS_NewChannel(getter_AddRefs(chan
), uri
);
70 nsCOMPtr
<nsIStreamLoaderObserver
> observer
= new MyStreamLoaderObserver();
74 nsCOMPtr
<nsIStreamLoader
> loader
;
75 rv
= NS_NewStreamLoader(getter_AddRefs(loader
), observer
);
79 rv
= chan
->AsyncOpen(loader
, nsnull
);
84 } // this scopes the nsCOMPtrs
85 // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM
86 NS_ShutdownXPCOM(nsnull
);