1 // nsICmdParams.cpp : implementation file
6 #include "nsICmdParams.h"
8 #include "BrowserFrm.h"
9 #include "BrowserImpl.h"
10 #include "BrowserView.h"
12 #include "nsICommandMgr.h"
17 static char THIS_FILE
[] = __FILE__
;
20 /////////////////////////////////////////////////////////////////////////////
23 // note: this table is temporary. will customize later.
24 // 1st column: command; 2nd column: DoCommand state, 3rd column: CmdParam state;
27 CnsICmdParams::CnsICmdParams(nsIWebBrowser
*mWebBrowser
)
29 qaWebBrowser
= mWebBrowser
;
32 CnsICmdParams::~CnsICmdParams()
36 nsICommandParams
* CnsICmdParams::GetCommandParamObject()
38 nsCOMPtr
<nsICommandParams
> cmdParamsObj
= do_CreateInstance(NS_COMMAND_PARAMS_CONTRACTID
,&rv
);
39 RvTestResult(rv
, "GetCommandParamsObject() test", 1);
41 QAOutput("Didn't get nsICommandParams object.");
44 nsICommandParams
*retVal
= cmdParamsObj
;
49 void CnsICmdParams::GetValueTypeTest(const char *aCommand
, const char *stateType
, int displayMode
)
53 cmdParamObj
= GetCommandParamObject();
55 FormatAndPrintOutput("The input command name = ", aCommand
, displayMode
);
56 FormatAndPrintOutput("The input state type = ", stateType
, displayMode
);
57 cmdMgrObj
= CnsICommandMgr::GetCommandMgrObject(qaWebBrowser
, displayMode
);
59 QAOutput("We didn't get nsICommandMgr object. Test fails.", displayMode
);
63 rv
= cmdMgrObj
->GetCommandState(aCommand
, nsnull
, cmdParamObj
);
64 RvTestResult(rv
, "cmdMgrObj->GetCommandState test", displayMode
);
66 rv
= cmdParamObj
->GetValueType(stateType
, &retval
);
67 RvTestResult(rv
, "GetValueType test", displayMode
);
68 FormatAndPrintOutput("GetValueType return int = ", retval
, displayMode
);
71 QAOutput("GetValueTypeTest(): We didn't get nsICommandParams object.", 1);
74 void CnsICmdParams::GetBooleanValueTest(const char *aCommand
, const char *stateType
, int displayMode
)
78 cmdParamObj
= GetCommandParamObject();
80 FormatAndPrintOutput("The input command name = ", aCommand
, displayMode
);
81 FormatAndPrintOutput("The input state type = ", stateType
, displayMode
);
82 cmdMgrObj
= CnsICommandMgr::GetCommandMgrObject(qaWebBrowser
, displayMode
);
84 QAOutput("We didn't get nsICommandMgr object. Test fails.", displayMode
);
88 cmdMgrObj
->GetCommandState(aCommand
, nsnull
, cmdParamObj
);
90 rv
= cmdParamObj
->GetBooleanValue(stateType
, &retval
);
91 RvTestResult(rv
, "GetBooleanValue test", displayMode
);
92 FormatAndPrintOutput("GetBooleanValue() return boolean = ", retval
, displayMode
);
95 QAOutput("GetBooleanValueTest(): We didn't get nsICommandParams object.", 1);
98 void CnsICmdParams::GetLongValueTest(PRInt32 value
, const char *stateType
, int displayMode
)
102 cmdParamObj
= GetCommandParamObject();
105 FormatAndPrintOutput("The input Set value = ", value
, displayMode
);
106 FormatAndPrintOutput("The input state type = ", stateType
, displayMode
);
107 cmdParamObj
->SetLongValue(stateType
, value
);
108 rv
= cmdParamObj
->GetLongValue(stateType
, &retval
);
109 RvTestResult(rv
, "GetLongValue test", displayMode
);
110 FormatAndPrintOutput("GetLongValue() return long = ", retval
, displayMode
);
113 QAOutput("GetLongValueTest: We didn't get nsICommandParams object.", 1);
116 void CnsICmdParams::GetDoubleValueTest(double value
, const char *stateType
, int displayMode
)
120 cmdParamObj
= GetCommandParamObject();
122 FormatAndPrintOutput("The input Set value = ", value
, displayMode
);
123 FormatAndPrintOutput("The input state type = ", stateType
, displayMode
);
124 cmdParamObj
->SetDoubleValue(stateType
, value
);
125 rv
= cmdParamObj
->GetDoubleValue(stateType
, &retval
);
126 RvTestResult(rv
, "GetDoubleValue test", displayMode
);
127 FormatAndPrintOutput("GetDoubleValue() return double = ", retval
, displayMode
);
130 QAOutput("GetDoubleValueTest: We didn't get nsICommandParams object.", 1);
133 void CnsICmdParams::GetStringValueTest(char *stringVal
, const char *stateType
, int displayMode
)
136 cmdParamObj
= GetCommandParamObject();
138 FormatAndPrintOutput("The input string = ", stringVal
, displayMode
);
139 FormatAndPrintOutput("The input state type = ", stateType
, displayMode
);
141 rv
= cmdParamObj
->SetStringValue(stateType
, NS_ConvertASCIItoUTF16(stringVal
));
142 rv
= cmdParamObj
->GetStringValue(stateType
, retval
);
143 RvTestResult(rv
, "GetStringValue test", displayMode
);
144 // FormatAndPrintOutput("GetStringValue() return string = ", retval, displayMode);
147 QAOutput("GetStringValueTest: We didn't get nsICommandParams object.", 1);
150 void CnsICmdParams::GetCStringValueTest(const char *aCommand
, const char *stateType
, int displayMode
)
152 cmdParamObj
= GetCommandParamObject();
154 FormatAndPrintOutput("The input command name = ", aCommand
, displayMode
);
155 FormatAndPrintOutput("The input state type = ", stateType
, displayMode
);
156 cmdMgrObj
= CnsICommandMgr::GetCommandMgrObject(qaWebBrowser
, displayMode
);
158 QAOutput("We didn't get nsICommandMgr object. Test fails.", displayMode
);
162 cmdMgrObj
->GetCommandState(aCommand
, nsnull
, cmdParamObj
);
163 char *tCstringValue
= nsnull
;
164 rv
= cmdParamObj
->GetCStringValue(stateType
, &tCstringValue
);
165 RvTestResult(rv
, "GetCStringValue test", displayMode
);
166 FormatAndPrintOutput("the CString value = ", tCstringValue
, displayMode
);
168 nsCRT::free(tCstringValue
);
171 QAOutput("GetCStringValueTest: We didn't get nsICommandParams object.", 1);
174 // NS_ConvertASCIItoUTF16
176 void CnsICmdParams::SetBooleanValueTest(PRBool value
, const char *stateType
, int displayMode
)
178 cmdParamObj
= GetCommandParamObject();
180 FormatAndPrintOutput("The input state type = ", stateType
, displayMode
);
181 FormatAndPrintOutput("The input value = ", value
, displayMode
);
182 rv
= cmdParamObj
->SetBooleanValue(stateType
, value
);
183 RvTestResult(rv
, "SetBooleanValue() test", displayMode
);
186 QAOutput("SetBooleanValueTest(): We didn't get nsICommandParams object.", 1);
189 void CnsICmdParams::SetLongValueTest(PRInt32 value
, const char *stateType
, int displayMode
)
191 cmdParamObj
= GetCommandParamObject();
193 FormatAndPrintOutput("The input state type = ", stateType
, displayMode
);
194 FormatAndPrintOutput("The input value = ", value
, displayMode
);
195 rv
= cmdParamObj
->SetLongValue(stateType
, value
);
196 RvTestResult(rv
, "SetLongValue() test", displayMode
);
199 QAOutput("SetLongValueTest(): We didn't get nsICommandParams object.", 1);
202 void CnsICmdParams::SetDoubleValueTest(double value
, const char *stateType
, int displayMode
)
204 cmdParamObj
= GetCommandParamObject();
206 FormatAndPrintOutput("The input state type = ", stateType
, displayMode
);
207 FormatAndPrintOutput("The input value = ", value
, displayMode
);
208 rv
= cmdParamObj
->SetDoubleValue(stateType
, value
);
209 RvTestResult(rv
, "SetDoubleValue() test", displayMode
);
212 QAOutput("SetDoubleValueTest(): We didn't get nsICommandParams object.", 1);
215 void CnsICmdParams::SetStringValueTest(char *value
, const char *stateType
, int displayMode
)
217 cmdParamObj
= GetCommandParamObject();
219 FormatAndPrintOutput("The input state type = ", stateType
, displayMode
);
220 FormatAndPrintOutput("The input value = ", value
, displayMode
);
221 rv
= cmdParamObj
->SetStringValue(stateType
, NS_ConvertASCIItoUTF16(value
));
222 RvTestResult(rv
, "SetStringValue() test", displayMode
);
225 QAOutput("SetStringValueTest(): We didn't get nsICommandParams object.", 1);
228 void CnsICmdParams::SetCStringValueTest(char *value
, const char *stateType
, int displayMode
)
230 cmdParamObj
= GetCommandParamObject();
232 FormatAndPrintOutput("The input state type = ", stateType
, displayMode
);
233 FormatAndPrintOutput("The input value = ", value
, displayMode
);
234 rv
= cmdParamObj
->SetCStringValue(stateType
, value
);
235 RvTestResult(rv
, "SetCStringValue() test", displayMode
);
238 QAOutput("SetCStringValueTest(): We didn't get nsICommandParams object.", 1);
241 void CnsICmdParams::OnStartTests(UINT nMenuID
)
245 case ID_INTERFACES_NSICOMMANDPARAMS_RUNALLTESTS
:
248 case ID_INTERFACES_NSICOMMANDPARAMS_GETVALUETYPE
:
249 GetValueTypeTest( "cmd_bold", "state_all", 2);
251 case ID_INTERFACES_NSICOMMANDPARAMS_GETBOOLEANVALUE
:
252 GetBooleanValueTest("cmd_bold", "state_mixed", 2);
254 case ID_INTERFACES_NSICOMMANDPARAMS_GETLONGVALUE
:
255 GetLongValueTest(57000000, "state_attribute", 2);
257 case ID_INTERFACES_NSICOMMANDPARAMS_GETDOUBLEVALUE
:
258 GetDoubleValueTest(5.25, "state_attribute", 2);
260 case ID_INTERFACES_NSICOMMANDPARAMS_GETSTRINGVALUE
:
261 GetStringValueTest("MyString!!", "state_attribute", 2);
263 case ID_INTERFACES_NSICOMMANDPARAMS_GETCSTRINGVALUE
:
264 GetCStringValueTest("cmd_fontColor", "state_attribute", 2);
266 case ID_INTERFACES_NSICOMMANDPARAMS_GETISUPPORTSVALUE
:
267 QAOutput("Not implemented yet.", 2);
269 case ID_INTERFACES_NSICOMMANDPARAMS_SETBOOLEANVALUE
:
270 SetBooleanValueTest(PR_TRUE
, "state_attribute", 2);
272 case ID_INTERFACES_NSICOMMANDPARAMS_SETLONGVALUE
:
273 SetLongValueTest(25000000, "state_attribute", 2);
275 case ID_INTERFACES_NSICOMMANDPARAMS_SETDOUBLEVALUE
:
276 SetDoubleValueTest(-3.05, "state_attribute", 2);
278 case ID_INTERFACES_NSICOMMANDPARAMS_SETSTRINGVALUE
:
279 SetStringValueTest("HELLO!", "state_attribute", 2);
281 case ID_INTERFACES_NSICOMMANDPARAMS_SETCSTRINGVALUE
:
282 SetCStringValueTest("#FF0000", "state_attribute", 2);
284 case ID_INTERFACES_NSICOMMANDPARAMS_SETISUPPORTSVALUE
:
285 QAOutput("Not implemented yet.", 2);
287 case ID_INTERFACES_NSICOMMANDPARAMS_REMOVEVALUE
:
288 QAOutput("Not implemented yet.", 2);
290 case ID_INTERFACES_NSICOMMANDPARAMS_HASMOREELEMENTS
:
291 QAOutput("Not implemented yet.", 2);
293 case ID_INTERFACES_NSICOMMANDPARAMS_FIRST
:
294 QAOutput("Not implemented yet.", 2);
296 case ID_INTERFACES_NSICOMMANDPARAMS_GETNEXT
:
297 QAOutput("Not implemented yet.", 2);
302 void CnsICmdParams::RunAllTests()
304 cmdParamObj
= GetCommandParamObject();
306 QAOutput("We got nsICommandParams object.", 1);
308 QAOutput("We didn't get nsICommandParams object.", 1);
312 QAOutput("Run All nsICommandParam Set and Get tests. Check C:/Temp/TestOutput.txt for test results.", 2);
313 for (i
=0; i
< 50; i
++)
315 FormatAndPrintOutput("loop cnt = ", i
, 1);
316 SetBooleanValueTest(CommandTable
[i
].mBooleanValue
, CommandTable
[i
].mCmdParamState
, 1);
317 SetLongValueTest(CommandTable
[i
].mLongValue
, CommandTable
[i
].mCmdParamState
, 1);
318 SetDoubleValueTest(CommandTable
[i
].mDoubleValue
, CommandTable
[i
].mCmdParamState
, 1);
319 SetStringValueTest(CommandTable
[i
].mStringValue
, CommandTable
[i
].mCmdParamState
, 1);
320 SetCStringValueTest(CommandTable
[i
].mCStringValue
, CommandTable
[i
].mCmdParamState
, 1);
322 GetValueTypeTest(CommandTable
[i
].mCmdName
, CommandTable
[i
].mCmdParamState
, 1);
323 GetBooleanValueTest(CommandTable
[i
].mCmdName
, CommandTable
[i
].mCmdParamState
, 1);
324 GetLongValueTest(CommandTable
[i
].mLongValue
, CommandTable
[i
].mCmdParamState
, 1);
325 GetDoubleValueTest(CommandTable
[i
].mDoubleValue
, CommandTable
[i
].mCmdParamState
, 1);
326 GetStringValueTest(CommandTable
[i
].mStringValue
, CommandTable
[i
].mCmdParamState
, 1);
327 GetCStringValueTest(CommandTable
[i
].mCmdName
, CommandTable
[i
].mCmdParamState
, 1);
329 QAOutput("Other tests Not implemented yet.", 2);
332 /////////////////////////////////////////////////////////////////////////////
333 // nsICmdParams message handlers