Back to index

lightning-sunbird  0.9+nobinonly
nsProfile.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Ashish Bhatt <ashishbhatt@netscape.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 // File Overview....
00040 //
00041 // Test cases for the nsISelection Interface
00042 
00043 #include "stdafx.h"
00044 #include "QaUtils.h"
00045 #include <stdio.h>
00046 #include "nsProfile.h"
00047 
00048 CProfile::CProfile(nsIWebBrowser* mWebBrowser)
00049 {
00050        qaWebBrowser = mWebBrowser;
00051 }
00052 
00053 
00054 CProfile::~CProfile()
00055 {
00056 }
00057 
00058 
00059 void CProfile::OnStartTests(UINT nMenuID)
00060 {
00061        // Calls  all or indivdual test cases on the basis of the 
00062        // option selected from menu.
00063 
00064        switch(nMenuID)
00065        {
00066               case ID_INTERFACES_NSIPROFILE_RUNALLTESTS :
00067                      RunAllTests();
00068                      break ;
00069               case ID_INTERFACES_NSIPROFILE_GETPROFILECOUNT :
00070                      GetProfileCount();
00071                      break ;
00072               case ID_INTERFACES_NSIPROFILE_GETCURRENTPROFILE :
00073                      GetCurrentProfile();
00074                      break ;
00075               case ID_INTERFACES_NSIPROFILE_SETCURRENTPROFILE :
00076                      SetCurrentProfile();
00077                      break ;
00078               case ID_INTERFACES_NSIPROFILE_GETPROFILELIST :
00079                      GetProfileList();
00080                      break ;
00081               case ID_INTERFACES_NSIPROFILE_PROFILEEXISTS :
00082                      ProfileExists();
00083                      break ;
00084               case ID_INTERFACES_NSIPROFILE_CREATENEWPROFILE :
00085                      CreateNewProfile();
00086                      break ;
00087               case ID_INTERFACES_NSIPROFILE_RENAMEPROFILE :
00088                      RenameProfile();
00089                      break ;
00090               case ID_INTERFACES_NSIPROFILE_DELETEPROFILE :
00091                      DeleteProfile();
00092                      break ;
00093               case ID_INTERFACES_NSIPROFILE_CLONEPROFILE :
00094                      CloneProfile();
00095                      break ;
00096               case ID_INTERFACES_NSIPROFILE_SHUTDOWNCURRENTPROFILE :
00097                      ShutDownCurrentProfile();
00098                      break ;
00099        }
00100 
00101 }
00102 
00103 void CProfile::RunAllTests()
00104 {
00105     
00106        nsCOMPtr<nsIProfile> oNsProfile (do_GetService(NS_PROFILE_CONTRACTID,&rv));
00107 
00108     RvTestResultDlg(rv, "do_GetService",true);
00109 
00110        if (!oNsProfile)
00111        {
00112            RvTestResultDlg(rv, "Cannot get the nsIprofile object");
00113            return ;
00114        }
00115 
00116        PRInt32 profileCount;
00117     rv = oNsProfile->GetProfileCount(&profileCount);
00118     RvTestResultDlg(rv, "nsIProfile::GetProfileCount() ");
00119 
00120     nsXPIDLString   currProfileName;
00121     rv = oNsProfile->GetCurrentProfile(getter_Copies(currProfileName));
00122     RvTestResultDlg(rv, "nsIProfile::GetCurrentProfile() ");
00123 
00124     rv = oNsProfile->SetCurrentProfile(currProfileName);
00125     RvTestResultDlg(rv, "nsIProfile::SetCurrentProfile() ");
00126 
00127 
00128     PRUint32    listLen;
00129     PRUnichar   **profileList;
00130 
00131     rv = oNsProfile->GetProfileList(&listLen, &profileList);
00132     RvTestResultDlg(rv, "oNsProfile->GetProfileList");
00133 
00134     for (PRUint32 index = 0; index < listLen; index++)
00135     {
00136         CString tmpStr(profileList[index]);
00137            RvTestResultDlg(rv, tmpStr);
00138        }
00139 
00140     PRBool exists = FALSE;
00141     rv = oNsProfile->ProfileExists(currProfileName, &exists);
00142     RvTestResultDlg(rv, "oNsProfile->ProfileExists");
00143 
00144        USES_CONVERSION ;
00145 
00146        NS_NAMED_LITERAL_STRING(newProfileName, "nsIProfileTest");
00147 
00148     rv = oNsProfile->CreateNewProfile(newProfileName.get(), nsnull, nsnull, PR_TRUE);
00149     RvTestResultDlg(rv, "oNsProfile->CreateNewProfile");
00150 
00151     rv = oNsProfile->CloneProfile(currProfileName);
00152     RvTestResultDlg(rv, "oNsProfile->CloneProfile");
00153 
00154     rv = oNsProfile->RenameProfile(currProfileName, T2W("nsIProfileTestNew"));
00155     RvTestResultDlg(rv, "oNsProfile->RenameProfile");
00156 
00157     rv = oNsProfile->DeleteProfile(T2W("nsIProfileTestNew"), PR_TRUE);
00158     RvTestResultDlg(rv, "oNsProfile->DeleteProfile");
00159  
00160 }
00161 
00162 void CProfile::GetProfileCount()
00163 {
00164        nsCOMPtr<nsIProfile> oNsProfile (do_GetService(NS_PROFILE_CONTRACTID,&rv));
00165 
00166     RvTestResultDlg(rv, "do_GetService",true);
00167 
00168        if (!oNsProfile)
00169        {
00170            RvTestResultDlg(rv, "Cannot get the nsIprofile object");
00171            return ;
00172        }
00173 
00174        PRInt32 profileCount;
00175     rv = oNsProfile->GetProfileCount(&profileCount);
00176     RvTestResultDlg(rv, "nsIProfile::GetProfileCount() ");
00177 }
00178 
00179 void CProfile::GetCurrentProfile()
00180 {
00181        nsCOMPtr<nsIProfile> oNsProfile (do_GetService(NS_PROFILE_CONTRACTID,&rv));
00182 
00183     RvTestResultDlg(rv, "do_GetService",true);
00184        if (!oNsProfile)
00185        {
00186            RvTestResultDlg(rv, "Cannot get the nsIprofile object");
00187            return ;
00188        }
00189 
00190        nsXPIDLString   currProfileName;
00191     rv = oNsProfile->GetCurrentProfile(getter_Copies(currProfileName));
00192     RvTestResultDlg(rv, "nsIProfile::GetCurrentProfile() ");
00193 }
00194 
00195 void CProfile::SetCurrentProfile()
00196 {
00197        nsCOMPtr<nsIProfile> oNsProfile (do_GetService(NS_PROFILE_CONTRACTID,&rv));
00198 
00199     RvTestResultDlg(rv, "do_GetService",true);
00200        if (!oNsProfile)
00201        {
00202            RvTestResultDlg(rv, "Cannot get the nsIprofile object");
00203            return ;
00204        }
00205 
00206        nsXPIDLString   currProfileName;
00207     rv = oNsProfile->GetCurrentProfile(getter_Copies(currProfileName));
00208     RvTestResultDlg(rv, "nsIProfile::GetCurrentProfile() ");
00209 
00210     rv = oNsProfile->SetCurrentProfile(currProfileName);
00211     RvTestResultDlg(rv, "nsIProfile::SetCurrentProfile() ");
00212 }
00213 
00214 void CProfile::GetProfileList()
00215 {
00216        nsCOMPtr<nsIProfile> oNsProfile (do_GetService(NS_PROFILE_CONTRACTID,&rv));
00217 
00218     RvTestResultDlg(rv, "do_GetService",true);
00219        if (!oNsProfile)
00220        {
00221            RvTestResultDlg(rv, "Cannot get the nsIprofile object");
00222            return ;
00223        }
00224 
00225        PRUint32    listLen;
00226     PRUnichar   **profileList;
00227 
00228     rv = oNsProfile->GetProfileList(&listLen, &profileList);
00229     RvTestResultDlg(rv, "oNsProfile->GetProfileList");
00230 
00231     for (PRUint32 index = 0; index < listLen; index++)
00232     {
00233         CString tmpStr(profileList[index]);
00234            RvTestResultDlg(rv, tmpStr);
00235        }
00236 }
00237 
00238 void CProfile::ProfileExists()
00239 {
00240        nsCOMPtr<nsIProfile> oNsProfile (do_GetService(NS_PROFILE_CONTRACTID,&rv));
00241 
00242     RvTestResultDlg(rv, "do_GetService",true);
00243        if (!oNsProfile)
00244        {
00245            RvTestResultDlg(rv, "Cannot get the nsIprofile object");
00246            return ;
00247        }
00248 
00249        nsXPIDLString   currProfileName;
00250     rv = oNsProfile->GetCurrentProfile(getter_Copies(currProfileName));
00251     RvTestResultDlg(rv, "nsIProfile::GetCurrentProfile() ");
00252 
00253        PRBool exists = FALSE;
00254     rv = oNsProfile->ProfileExists(currProfileName, &exists);
00255     RvTestResultDlg(rv, "oNsProfile->ProfileExists");
00256 }
00257 
00258 void CProfile::CreateNewProfile()
00259 {
00260        nsCOMPtr<nsIProfile> oNsProfile (do_GetService(NS_PROFILE_CONTRACTID,&rv));
00261 
00262     RvTestResultDlg(rv, "do_GetService",true);
00263        if (!oNsProfile)
00264        {
00265            RvTestResultDlg(rv, "Cannot get the nsIprofile object");
00266            return ;
00267        }
00268 
00269        USES_CONVERSION ;
00270 
00271        rv = oNsProfile->CreateNewProfile(T2W("New Test"), nsnull, nsnull, PR_TRUE);
00272     RvTestResultDlg(rv, "oNsProfile->CreateNewProfile");
00273    
00274 }
00275 
00276 void CProfile::RenameProfile()
00277 {
00278        nsCOMPtr<nsIProfile> oNsProfile (do_GetService(NS_PROFILE_CONTRACTID,&rv));
00279 
00280     RvTestResultDlg(rv, "do_GetService",true);
00281        if (!oNsProfile)
00282        {
00283            RvTestResultDlg(rv, "Cannot get the nsIprofile object");
00284            return ;
00285        }
00286 
00287        USES_CONVERSION ;
00288 
00289        nsXPIDLString   currProfileName;
00290     rv = oNsProfile->GetCurrentProfile(getter_Copies(currProfileName));
00291     RvTestResultDlg(rv, "nsIProfile::GetCurrentProfile() ");
00292 
00293        rv = oNsProfile->RenameProfile(currProfileName, T2W("New default"));
00294     RvTestResultDlg(rv, "oNsProfile->RenameProfile");
00295 }
00296 
00297 void CProfile::DeleteProfile()
00298 {
00299        nsCOMPtr<nsIProfile> oNsProfile (do_GetService(NS_PROFILE_CONTRACTID,&rv));
00300 
00301     RvTestResultDlg(rv, "do_GetService",true);
00302        if (!oNsProfile)
00303        {
00304            RvTestResultDlg(rv, "Cannot get the nsIprofile object");
00305            return ;
00306        }
00307 
00308        USES_CONVERSION ;
00309 
00310        nsXPIDLString   currProfileName;
00311     rv = oNsProfile->GetCurrentProfile(getter_Copies(currProfileName));
00312     RvTestResultDlg(rv, "nsIProfile::GetCurrentProfile() ");
00313 
00314     rv = oNsProfile->DeleteProfile(currProfileName, PR_TRUE);
00315     RvTestResultDlg(rv, "oNsProfile->DeleteProfile");
00316 }
00317 
00318 void CProfile::CloneProfile()
00319 {
00320        nsCOMPtr<nsIProfile> oNsProfile (do_GetService(NS_PROFILE_CONTRACTID,&rv));
00321 
00322     RvTestResultDlg(rv, "do_GetService",true);
00323        if (!oNsProfile)
00324        {
00325            RvTestResultDlg(rv, "Cannot get the nsIprofile object");
00326            return ;
00327        }
00328  
00329        USES_CONVERSION ;
00330 
00331        nsXPIDLString   currProfileName;
00332     rv = oNsProfile->GetCurrentProfile(getter_Copies(currProfileName));
00333     RvTestResultDlg(rv, "nsIProfile::GetCurrentProfile() ");
00334 
00335     rv = oNsProfile->CloneProfile(currProfileName);
00336     RvTestResultDlg(rv, "oNsProfile->CloneProfile");
00337 }
00338 
00339 void CProfile::ShutDownCurrentProfile()
00340 {
00341        nsCOMPtr<nsIProfile> oNsProfile (do_GetService(NS_PROFILE_CONTRACTID,&rv));
00342 
00343     RvTestResultDlg(rv, "do_GetService",true);
00344        if (!oNsProfile)
00345        {
00346            RvTestResultDlg(rv, "Cannot get the nsIprofile object");
00347            return ;
00348        }
00349 }
00350