diff --git a/mozilla/xpcom/tests/nsIFileEnumerator.cpp b/mozilla/xpcom/tests/nsIFileEnumerator.cpp new file mode 100644 index 00000000000..9d0f46156ee --- /dev/null +++ b/mozilla/xpcom/tests/nsIFileEnumerator.cpp @@ -0,0 +1,81 @@ +#include "nsILocalFile.h" + +#include "stdio.h" +#include "nsIComponentManager.h" +#include "nsIServiceManager.h" +#include "nsMemory.h" +#include "nsXPIDLString.h" + + +PRBool LoopInDir(nsILocalFile* file) +{ + nsresult rv; + nsCOMPtr entries; + rv = file->GetDirectoryEntries(getter_AddRefs(entries)); + if(NS_FAILED(rv) || !entries) + return PR_FALSE; + + PRUint32 count = 0; + PRBool hasMore; + while(NS_SUCCEEDED(entries->HasMoreElements(&hasMore)) && hasMore) + { + nsCOMPtr sup; + entries->GetNext(getter_AddRefs(sup)); + if(!sup) + return PR_FALSE; + + nsCOMPtr file = do_QueryInterface(sup); + if(!file) + return PR_FALSE; + + char* name; + if(NS_FAILED(file->GetLeafName(&name))) + return PR_FALSE; + + //printf("%s\t", name); + PRBool isDir; + + rv = file->IsDirectory(&isDir); + if (isDir == PR_TRUE) + { + nsCOMPtr lfile = do_QueryInterface(file); + LoopInDir(lfile); + } + nsMemory::Free(name); + } + return PR_TRUE; +} + + +int +main(int argc, char* argv[]) +{ + nsresult rv; + nsCOMPtr topDir; + + rv = NS_InitXPCOM(nsnull, nsnull); + if (NS_FAILED(rv)) return -1; + + nsComponentManager::AutoRegister(nsIComponentManager::NS_Startup, NULL); + + if (argc > 1 && argv[1] != nsnull) + { + char* pathStr = argv[1]; + NS_NewLocalFile(pathStr, PR_FALSE, getter_AddRefs(topDir)); + } + + if (!topDir) + { + printf("No Top Dir\n"); + return -1; + } + PRInt32 startTime = PR_IntervalNow(); + + LoopInDir(topDir); + + PRInt32 endTime = PR_IntervalNow(); + + printf("\nTime: %d\n", PR_IntervalToMilliseconds(endTime - startTime)); + + return 0; +}