rv = NS_AutoregisterComponents(); NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't register XPCOM components");
nsCOMPtr<nsIServiceManager> servMan; NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan); NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); registrar->AutoRegister(nsnull);
main(int argc, char* argv[]){    nsresult rv;    if(argc <2) {      printf(" %s -f to test filecache\n", argv[0]) ;      printf(" %s -m to test memcache\n", argv[0]) ;      return -1 ;    }    nsCOMPtr<nsINetDataCache> cache;    rv = NS_AutoregisterComponents();    NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't register XPCOM components");    if (PL_strcasecmp(argv[1], "-m") == 0) {        rv = nsComponentManager::CreateInstance(kMemCacheCID, nsnull,                                            NS_GET_IID(nsINetDataCache),                                            getter_AddRefs(cache));        NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't create memory cache factory");    } else if (PL_strcasecmp(argv[1], "-f") == 0) {        // initialize pref        initPref() ;        rv = nsComponentManager::CreateInstance(kDiskCacheCID, nsnull,                                            NS_GET_IID(nsINetDataCache),                                             getter_AddRefs(cache));        NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't create disk cache factory") ;    } else {      printf("  %s -f to test filecache\n", argv[0]) ;      printf(" %s -m to test memcache\n", argv[0]) ;      return -1 ;    }    InitQueue();    PRUnichar* description;    rv = cache->GetDescription(&description);    NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't get cache description");    nsCAutoString descStr; descStr.AssignWithConversion(description);    printf("Testing: %s\n", descStr.get());    rv = cache->RemoveAll();    NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't clear cache");    PRUint32 startOccupancy;    rv = cache->GetStorageInUse(&startOccupancy);    NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't get cache occupancy");    PRUint32 numEntries = (PRUint32)-1;    rv = cache->GetNumEntries(&numEntries);    NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't get number of cache entries");    NS_ASSERTION(numEntries == 0, "Couldn't clear cache");    rv = FillCache(cache);    NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't fill cache with random test data");    rv = TestRead(cache);    NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't read random test data from cache");    rv = TestRecordID(cache);    NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't index records using record ID");    rv = TestEnumeration(cache);    NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't successfully enumerate records");    rv = TestTruncation(cache);    NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't successfully truncate records");    rv = TestOffsetWrites(cache);    NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't successfully write to records using non-zero offsets");    rv = cache->RemoveAll();    NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't clear cache");    rv = cache->GetNumEntries(&numEntries);    NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't get number of cache entries");    NS_ASSERTION(numEntries == 0, "Couldn't clear cache");    PRUint32 endOccupancy;    rv = cache->GetStorageInUse(&endOccupancy);    NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't get cache occupancy");    NS_ASSERTION(startOccupancy == endOccupancy, "Cache occupancy not correctly computed ?");    return 0;}