Back to index

lightning-sunbird  0.9+nobinonly
nsICmdParams.cpp
Go to the documentation of this file.
00001 // nsICmdParams.cpp : implementation file
00002 //
00003 
00004 #include "stdafx.h"
00005 #include "testembed.h"
00006 #include "nsICmdParams.h"
00007 #include "QaUtils.h"
00008 #include "BrowserFrm.h"
00009 #include "BrowserImpl.h"
00010 #include "BrowserView.h"
00011 #include "Tests.h"
00012 #include "nsICommandMgr.h"
00013 
00014 #ifdef _DEBUG
00015 #define new DEBUG_NEW
00016 #undef THIS_FILE
00017 static char THIS_FILE[] = __FILE__;
00018 #endif
00019 
00021 // nsICmdParams
00022 
00023 // note: this table is temporary. will customize later.
00024 // 1st column: command; 2nd column: DoCommand state, 3rd column: CmdParam state; 
00025 
00026 
00027 CnsICmdParams::CnsICmdParams(nsIWebBrowser *mWebBrowser)
00028 {
00029        qaWebBrowser = mWebBrowser;
00030 }
00031 
00032 CnsICmdParams::~CnsICmdParams()
00033 {
00034 }
00035 
00036 nsICommandParams * CnsICmdParams::GetCommandParamObject()
00037 {
00038     nsCOMPtr<nsICommandParams> cmdParamsObj = do_CreateInstance(NS_COMMAND_PARAMS_CONTRACTID,&rv);
00039        RvTestResult(rv, "GetCommandParamsObject() test", 1); 
00040     if (!cmdParamsObj) {
00041         QAOutput("Didn't get nsICommandParams object.");
00042               return nsnull;
00043        }
00044        nsICommandParams *retVal = cmdParamsObj;
00045        NS_ADDREF(retVal);
00046        return retVal;
00047 }
00048 
00049 void CnsICmdParams::GetValueTypeTest(const char *aCommand, const char *stateType, int displayMode)
00050 {
00051        PRInt16 retval;
00052 
00053        cmdParamObj = GetCommandParamObject();
00054        if (cmdParamObj) {
00055               FormatAndPrintOutput("The input command name = ", aCommand, displayMode);
00056               FormatAndPrintOutput("The input state type = ", stateType, displayMode);
00057               cmdMgrObj = CnsICommandMgr::GetCommandMgrObject(qaWebBrowser, displayMode);
00058               if (!cmdMgrObj) {
00059                      QAOutput("We didn't get nsICommandMgr object. Test fails.", displayMode);
00060                      return;
00061               }
00062               else {
00063                      rv = cmdMgrObj->GetCommandState(aCommand, nsnull, cmdParamObj);
00064                      RvTestResult(rv, "cmdMgrObj->GetCommandState test", displayMode);
00065               }
00066               rv = cmdParamObj->GetValueType(stateType, &retval);
00067               RvTestResult(rv, "GetValueType test", displayMode);
00068               FormatAndPrintOutput("GetValueType return int = ", retval, displayMode);
00069        }      
00070        else
00071            QAOutput("GetValueTypeTest(): We didn't get nsICommandParams object.", 1);
00072 }
00073 
00074 void CnsICmdParams::GetBooleanValueTest(const char *aCommand, const char *stateType, int displayMode)
00075 {
00076        PRBool retval;
00077 
00078        cmdParamObj = GetCommandParamObject();
00079        if (cmdParamObj) {
00080               FormatAndPrintOutput("The input command name = ", aCommand, displayMode);
00081               FormatAndPrintOutput("The input state type = ", stateType, displayMode);
00082               cmdMgrObj = CnsICommandMgr::GetCommandMgrObject(qaWebBrowser, displayMode);
00083               if (!cmdMgrObj) {
00084                      QAOutput("We didn't get nsICommandMgr object. Test fails.", displayMode);
00085                      return;
00086               }
00087               else
00088                      cmdMgrObj->GetCommandState(aCommand, nsnull, cmdParamObj);
00089 
00090               rv = cmdParamObj->GetBooleanValue(stateType, &retval);
00091               RvTestResult(rv, "GetBooleanValue test", displayMode);
00092               FormatAndPrintOutput("GetBooleanValue() return boolean = ", retval, displayMode);
00093        }
00094        else
00095            QAOutput("GetBooleanValueTest(): We didn't get nsICommandParams object.", 1);
00096 }
00097 
00098 void CnsICmdParams::GetLongValueTest(PRInt32 value, const char *stateType, int displayMode)
00099 {
00100        PRInt32       retval;
00101 
00102        cmdParamObj = GetCommandParamObject();
00103        if (cmdParamObj)
00104        {
00105               FormatAndPrintOutput("The input Set value = ", value, displayMode);
00106               FormatAndPrintOutput("The input state type = ", stateType, displayMode);
00107               cmdParamObj->SetLongValue(stateType, value);
00108               rv = cmdParamObj->GetLongValue(stateType, &retval);
00109               RvTestResult(rv, "GetLongValue test", displayMode);
00110               FormatAndPrintOutput("GetLongValue() return long = ", retval, displayMode);
00111        }
00112        else
00113            QAOutput("GetLongValueTest: We didn't get nsICommandParams object.", 1);
00114 }
00115 
00116 void CnsICmdParams::GetDoubleValueTest(double value, const char *stateType, int displayMode)
00117 {
00118        double retval;
00119 
00120        cmdParamObj = GetCommandParamObject();
00121        if (cmdParamObj) {
00122               FormatAndPrintOutput("The input Set value = ", value, displayMode);
00123               FormatAndPrintOutput("The input state type = ", stateType, displayMode);
00124               cmdParamObj->SetDoubleValue(stateType, value);
00125               rv = cmdParamObj->GetDoubleValue(stateType, &retval);
00126               RvTestResult(rv, "GetDoubleValue test", displayMode);
00127               FormatAndPrintOutput("GetDoubleValue() return double = ", retval, displayMode);
00128        }
00129        else
00130            QAOutput("GetDoubleValueTest: We didn't get nsICommandParams object.", 1);
00131 }
00132 
00133 void CnsICmdParams::GetStringValueTest(char *stringVal, const char *stateType, int displayMode)
00134 {
00135        nsAutoString retval;
00136        cmdParamObj = GetCommandParamObject();
00137        if (cmdParamObj) {
00138               FormatAndPrintOutput("The input string = ", stringVal, displayMode);
00139               FormatAndPrintOutput("The input state type = ", stateType, displayMode);
00140 
00141               rv = cmdParamObj->SetStringValue(stateType, NS_ConvertASCIItoUCS2(stringVal));             
00142               rv = cmdParamObj->GetStringValue(stateType, retval);
00143               RvTestResult(rv, "GetStringValue test", displayMode);
00144 //            FormatAndPrintOutput("GetStringValue() return string = ", retval, displayMode);
00145        }
00146        else
00147            QAOutput("GetStringValueTest: We didn't get nsICommandParams object.", 1);
00148 }
00149 
00150 void CnsICmdParams::GetCStringValueTest(const char *aCommand, const char *stateType, int displayMode)
00151 {
00152        cmdParamObj = GetCommandParamObject();
00153        if (cmdParamObj) {
00154               FormatAndPrintOutput("The input command name = ", aCommand, displayMode);
00155               FormatAndPrintOutput("The input state type = ", stateType, displayMode);
00156               cmdMgrObj = CnsICommandMgr::GetCommandMgrObject(qaWebBrowser, displayMode);
00157               if (!cmdMgrObj) {
00158                      QAOutput("We didn't get nsICommandMgr object. Test fails.", displayMode);
00159                      return;
00160               }
00161               else
00162                      cmdMgrObj->GetCommandState(aCommand, nsnull, cmdParamObj);
00163               char *tCstringValue = nsnull;
00164               rv = cmdParamObj->GetCStringValue(stateType, &tCstringValue);
00165               RvTestResult(rv, "GetCStringValue test", displayMode);
00166               FormatAndPrintOutput("the CString value = ", tCstringValue, displayMode);
00167               if (tCstringValue)
00168                      nsCRT::free(tCstringValue);        
00169        }
00170        else
00171            QAOutput("GetCStringValueTest: We didn't get nsICommandParams object.", 1);
00172 }
00173 
00174 // NS_ConvertASCIItoUCS2
00175 
00176 void CnsICmdParams::SetBooleanValueTest(PRBool value, const char *stateType, int displayMode)
00177 {
00178        cmdParamObj = GetCommandParamObject();
00179        if (cmdParamObj) {
00180               FormatAndPrintOutput("The input state type = ", stateType, displayMode);
00181               FormatAndPrintOutput("The input value = ", value, displayMode);
00182               rv = cmdParamObj->SetBooleanValue(stateType, value);
00183               RvTestResult(rv, "SetBooleanValue() test", displayMode);
00184        }
00185        else
00186            QAOutput("SetBooleanValueTest(): We didn't get nsICommandParams object.", 1);
00187 }
00188 
00189 void CnsICmdParams::SetLongValueTest(PRInt32 value, const char *stateType, int displayMode)
00190 {
00191        cmdParamObj = GetCommandParamObject();
00192        if (cmdParamObj) {
00193               FormatAndPrintOutput("The input state type = ", stateType, displayMode);
00194               FormatAndPrintOutput("The input value = ", value, displayMode);
00195               rv = cmdParamObj->SetLongValue(stateType, value);
00196               RvTestResult(rv, "SetLongValue() test", displayMode);
00197        }
00198        else
00199            QAOutput("SetLongValueTest(): We didn't get nsICommandParams object.", 1);
00200 }
00201 
00202 void CnsICmdParams::SetDoubleValueTest(double value, const char *stateType, int displayMode)
00203 {
00204        cmdParamObj = GetCommandParamObject();
00205        if (cmdParamObj) {
00206               FormatAndPrintOutput("The input state type = ", stateType, displayMode);
00207               FormatAndPrintOutput("The input value = ", value, displayMode);
00208               rv = cmdParamObj->SetDoubleValue(stateType, value);
00209               RvTestResult(rv, "SetDoubleValue() test", displayMode);
00210        }
00211        else
00212            QAOutput("SetDoubleValueTest(): We didn't get nsICommandParams object.", 1);
00213 }
00214 
00215 void CnsICmdParams::SetStringValueTest(char *value, const char *stateType, int displayMode)
00216 {
00217        cmdParamObj = GetCommandParamObject();
00218        if (cmdParamObj) {
00219               FormatAndPrintOutput("The input state type = ", stateType, displayMode);
00220               FormatAndPrintOutput("The input value = ", value, displayMode);
00221               rv = cmdParamObj->SetStringValue(stateType, NS_ConvertASCIItoUCS2(value));
00222               RvTestResult(rv, "SetStringValue() test", displayMode);
00223        }
00224        else
00225            QAOutput("SetStringValueTest(): We didn't get nsICommandParams object.", 1);
00226 }
00227 
00228 void CnsICmdParams::SetCStringValueTest(char *value, const char *stateType, int displayMode)
00229 {
00230        cmdParamObj = GetCommandParamObject();
00231        if (cmdParamObj) {
00232               FormatAndPrintOutput("The input state type = ", stateType, displayMode);
00233               FormatAndPrintOutput("The input value = ", value, displayMode);
00234               rv = cmdParamObj->SetCStringValue(stateType, value);
00235               RvTestResult(rv, "SetCStringValue() test", displayMode);
00236        }
00237        else
00238            QAOutput("SetCStringValueTest(): We didn't get nsICommandParams object.", 1);
00239 }
00240 
00241 void CnsICmdParams::OnStartTests(UINT nMenuID)
00242 {
00243        switch(nMenuID)
00244        {
00245               case ID_INTERFACES_NSICOMMANDPARAMS_RUNALLTESTS :
00246                      RunAllTests();
00247                      break;
00248               case ID_INTERFACES_NSICOMMANDPARAMS_GETVALUETYPE :
00249                      GetValueTypeTest( "cmd_bold", "state_all", 2);
00250                      break;
00251               case ID_INTERFACES_NSICOMMANDPARAMS_GETBOOLEANVALUE :
00252                      GetBooleanValueTest("cmd_bold", "state_mixed", 2);
00253                      break;
00254               case ID_INTERFACES_NSICOMMANDPARAMS_GETLONGVALUE  :
00255                      GetLongValueTest(57000000, "state_attribute", 2);
00256                      break;
00257               case ID_INTERFACES_NSICOMMANDPARAMS_GETDOUBLEVALUE :
00258                      GetDoubleValueTest(5.25, "state_attribute", 2);
00259                      break;
00260               case ID_INTERFACES_NSICOMMANDPARAMS_GETSTRINGVALUE :
00261                      GetStringValueTest("MyString!!", "state_attribute", 2);
00262                      break;
00263               case ID_INTERFACES_NSICOMMANDPARAMS_GETCSTRINGVALUE:
00264                      GetCStringValueTest("cmd_fontColor", "state_attribute", 2);
00265                      break;
00266               case ID_INTERFACES_NSICOMMANDPARAMS_GETISUPPORTSVALUE :
00267                      QAOutput("Not implemented yet.", 2);
00268                      break;
00269               case ID_INTERFACES_NSICOMMANDPARAMS_SETBOOLEANVALUE :
00270                      SetBooleanValueTest(PR_TRUE, "state_attribute", 2);
00271                      break;
00272               case ID_INTERFACES_NSICOMMANDPARAMS_SETLONGVALUE :
00273                      SetLongValueTest(25000000, "state_attribute", 2);
00274                      break;
00275               case ID_INTERFACES_NSICOMMANDPARAMS_SETDOUBLEVALUE :
00276                      SetDoubleValueTest(-3.05, "state_attribute", 2);
00277                      break;
00278               case ID_INTERFACES_NSICOMMANDPARAMS_SETSTRINGVALUE :
00279                      SetStringValueTest("HELLO!", "state_attribute", 2);
00280                      break;
00281               case ID_INTERFACES_NSICOMMANDPARAMS_SETCSTRINGVALUE:
00282                      SetCStringValueTest("#FF0000", "state_attribute", 2);
00283                      break;
00284               case ID_INTERFACES_NSICOMMANDPARAMS_SETISUPPORTSVALUE :
00285                      QAOutput("Not implemented yet.", 2);
00286                      break;
00287               case ID_INTERFACES_NSICOMMANDPARAMS_REMOVEVALUE :
00288                      QAOutput("Not implemented yet.", 2);
00289                      break;
00290               case ID_INTERFACES_NSICOMMANDPARAMS_HASMOREELEMENTS :
00291                      QAOutput("Not implemented yet.", 2);
00292                      break;
00293               case ID_INTERFACES_NSICOMMANDPARAMS_FIRST :
00294                      QAOutput("Not implemented yet.", 2);
00295                      break;
00296               case ID_INTERFACES_NSICOMMANDPARAMS_GETNEXT :
00297                      QAOutput("Not implemented yet.", 2);
00298                      break;
00299        }
00300 }
00301 
00302 void CnsICmdParams::RunAllTests()
00303 {
00304        cmdParamObj = GetCommandParamObject();
00305        if (cmdParamObj)
00306         QAOutput("We got nsICommandParams object.", 1);
00307        else
00308            QAOutput("We didn't get nsICommandParams object.", 1);
00309 
00310        PRInt16 i;
00311 
00312        QAOutput("Run All nsICommandParam Set and Get tests. Check C:/Temp/TestOutput.txt for test results.", 2);
00313        for (i=0; i < 50; i++)
00314        {
00315               FormatAndPrintOutput("loop cnt = ", i, 1);
00316               SetBooleanValueTest(CommandTable[i].mBooleanValue, CommandTable[i].mCmdParamState, 1);
00317               SetLongValueTest(CommandTable[i].mLongValue, CommandTable[i].mCmdParamState, 1);
00318               SetDoubleValueTest(CommandTable[i].mDoubleValue, CommandTable[i].mCmdParamState, 1);
00319               SetStringValueTest(CommandTable[i].mStringValue, CommandTable[i].mCmdParamState, 1);
00320               SetCStringValueTest(CommandTable[i].mCStringValue, CommandTable[i].mCmdParamState, 1);
00321 
00322               GetValueTypeTest(CommandTable[i].mCmdName, CommandTable[i].mCmdParamState, 1);
00323               GetBooleanValueTest(CommandTable[i].mCmdName, CommandTable[i].mCmdParamState, 1);
00324               GetLongValueTest(CommandTable[i].mLongValue, CommandTable[i].mCmdParamState, 1);
00325               GetDoubleValueTest(CommandTable[i].mDoubleValue, CommandTable[i].mCmdParamState, 1);
00326               GetStringValueTest(CommandTable[i].mStringValue, CommandTable[i].mCmdParamState, 1);
00327               GetCStringValueTest(CommandTable[i].mCmdName, CommandTable[i].mCmdParamState, 1);
00328        }
00329        QAOutput("Other tests Not implemented yet.", 2);
00330 }
00331 
00333 // nsICmdParams message handlers