Bug 545892 - Always pass WM_NCPAINT events to the default event procedure. r=bent...
[mozilla-central.git] / xpcom / tests / nsIFileEnumerator.cpp
blob9c01010ee422086055d4e9f614e1225b2c541621
1 #include "nsILocalFile.h"
2 #include "nsStringGlue.h"
4 #include <stdio.h>
5 #include "nsIComponentRegistrar.h"
6 #include "nsIComponentManager.h"
7 #include "nsIServiceManager.h"
8 #include "nsMemory.h"
9 #include "nsISimpleEnumerator.h"
10 #include "nsCOMPtr.h"
12 PRBool LoopInDir(nsILocalFile* file)
14 nsresult rv;
15 nsCOMPtr<nsISimpleEnumerator> entries;
16 rv = file->GetDirectoryEntries(getter_AddRefs(entries));
17 if(NS_FAILED(rv) || !entries)
18 return PR_FALSE;
20 PRBool hasMore;
21 while(NS_SUCCEEDED(entries->HasMoreElements(&hasMore)) && hasMore)
23 nsCOMPtr<nsISupports> sup;
24 entries->GetNext(getter_AddRefs(sup));
25 if(!sup)
26 return PR_FALSE;
28 nsCOMPtr<nsILocalFile> file = do_QueryInterface(sup);
29 if(!file)
30 return PR_FALSE;
32 nsCAutoString name;
33 if(NS_FAILED(file->GetNativeLeafName(name)))
34 return PR_FALSE;
36 PRBool isDir;
37 printf("%s\n", name.get());
38 rv = file->IsDirectory(&isDir);
39 if (NS_FAILED(rv))
41 printf("IsDirectory Failed!!!\n");
42 return PR_FALSE;
45 if (isDir)
47 nsCOMPtr<nsILocalFile> lfile = do_QueryInterface(file);
48 LoopInDir(lfile);
51 return PR_TRUE;
55 int
56 main(int argc, char* argv[])
58 nsresult rv;
60 nsCOMPtr<nsILocalFile> topDir;
62 nsCOMPtr<nsIServiceManager> servMan;
63 rv = NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull);
64 if (NS_FAILED(rv)) return -1;
66 if (argc > 1 && argv[1] != nsnull)
68 char* pathStr = argv[1];
69 NS_NewNativeLocalFile(nsDependentCString(pathStr), PR_FALSE, getter_AddRefs(topDir));
72 if (!topDir)
74 printf("No Top Dir\n");
75 return -1;
77 PRInt32 startTime = PR_IntervalNow();
79 LoopInDir(topDir);
81 PRInt32 endTime = PR_IntervalNow();
83 printf("\nTime: %d\n", PR_IntervalToMilliseconds(endTime - startTime));
84 } // this scopes the nsCOMPtrs
85 // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM
86 rv = NS_ShutdownXPCOM(nsnull);
87 NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed");
88 return 0;