Added cairoFontface destroy
[mozilla-central.git] / xpcom / tests / nsIFileEnumerator.cpp
blob3eeb0d4b024ebb7e3ce078f426b81ec527d86ccf
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 == PR_TRUE)
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;
65 nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan);
66 NS_ASSERTION(registrar, "Null nsIComponentRegistrar");
67 if (registrar)
68 registrar->AutoRegister(nsnull);
70 if (argc > 1 && argv[1] != nsnull)
72 char* pathStr = argv[1];
73 NS_NewNativeLocalFile(nsDependentCString(pathStr), PR_FALSE, getter_AddRefs(topDir));
76 if (!topDir)
78 printf("No Top Dir\n");
79 return -1;
81 PRInt32 startTime = PR_IntervalNow();
83 LoopInDir(topDir);
85 PRInt32 endTime = PR_IntervalNow();
87 printf("\nTime: %d\n", PR_IntervalToMilliseconds(endTime - startTime));
88 } // this scopes the nsCOMPtrs
89 // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM
90 rv = NS_ShutdownXPCOM(nsnull);
91 NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed");
92 return 0;