Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / embedding / qa / testembed / nsICmdParams.cpp
blobb1916224d3ddf7e590ad603153464d20c9998b3a
1 // nsICmdParams.cpp : implementation file
2 //
4 #include "stdafx.h"
5 #include "testembed.h"
6 #include "nsICmdParams.h"
7 #include "QaUtils.h"
8 #include "BrowserFrm.h"
9 #include "BrowserImpl.h"
10 #include "BrowserView.h"
11 #include "Tests.h"
12 #include "nsICommandMgr.h"
14 #ifdef _DEBUG
15 #define new DEBUG_NEW
16 #undef THIS_FILE
17 static char THIS_FILE[] = __FILE__;
18 #endif
20 /////////////////////////////////////////////////////////////////////////////
21 // nsICmdParams
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);
40 if (!cmdParamsObj) {
41 QAOutput("Didn't get nsICommandParams object.");
42 return nsnull;
44 nsICommandParams *retVal = cmdParamsObj;
45 NS_ADDREF(retVal);
46 return retVal;
49 void CnsICmdParams::GetValueTypeTest(const char *aCommand, const char *stateType, int displayMode)
51 PRInt16 retval;
53 cmdParamObj = GetCommandParamObject();
54 if (cmdParamObj) {
55 FormatAndPrintOutput("The input command name = ", aCommand, displayMode);
56 FormatAndPrintOutput("The input state type = ", stateType, displayMode);
57 cmdMgrObj = CnsICommandMgr::GetCommandMgrObject(qaWebBrowser, displayMode);
58 if (!cmdMgrObj) {
59 QAOutput("We didn't get nsICommandMgr object. Test fails.", displayMode);
60 return;
62 else {
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);
70 else
71 QAOutput("GetValueTypeTest(): We didn't get nsICommandParams object.", 1);
74 void CnsICmdParams::GetBooleanValueTest(const char *aCommand, const char *stateType, int displayMode)
76 PRBool retval;
78 cmdParamObj = GetCommandParamObject();
79 if (cmdParamObj) {
80 FormatAndPrintOutput("The input command name = ", aCommand, displayMode);
81 FormatAndPrintOutput("The input state type = ", stateType, displayMode);
82 cmdMgrObj = CnsICommandMgr::GetCommandMgrObject(qaWebBrowser, displayMode);
83 if (!cmdMgrObj) {
84 QAOutput("We didn't get nsICommandMgr object. Test fails.", displayMode);
85 return;
87 else
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);
94 else
95 QAOutput("GetBooleanValueTest(): We didn't get nsICommandParams object.", 1);
98 void CnsICmdParams::GetLongValueTest(PRInt32 value, const char *stateType, int displayMode)
100 PRInt32 retval;
102 cmdParamObj = GetCommandParamObject();
103 if (cmdParamObj)
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);
112 else
113 QAOutput("GetLongValueTest: We didn't get nsICommandParams object.", 1);
116 void CnsICmdParams::GetDoubleValueTest(double value, const char *stateType, int displayMode)
118 double retval;
120 cmdParamObj = GetCommandParamObject();
121 if (cmdParamObj) {
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);
129 else
130 QAOutput("GetDoubleValueTest: We didn't get nsICommandParams object.", 1);
133 void CnsICmdParams::GetStringValueTest(char *stringVal, const char *stateType, int displayMode)
135 nsAutoString retval;
136 cmdParamObj = GetCommandParamObject();
137 if (cmdParamObj) {
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);
146 else
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();
153 if (cmdParamObj) {
154 FormatAndPrintOutput("The input command name = ", aCommand, displayMode);
155 FormatAndPrintOutput("The input state type = ", stateType, displayMode);
156 cmdMgrObj = CnsICommandMgr::GetCommandMgrObject(qaWebBrowser, displayMode);
157 if (!cmdMgrObj) {
158 QAOutput("We didn't get nsICommandMgr object. Test fails.", displayMode);
159 return;
161 else
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);
167 if (tCstringValue)
168 nsCRT::free(tCstringValue);
170 else
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();
179 if (cmdParamObj) {
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);
185 else
186 QAOutput("SetBooleanValueTest(): We didn't get nsICommandParams object.", 1);
189 void CnsICmdParams::SetLongValueTest(PRInt32 value, const char *stateType, int displayMode)
191 cmdParamObj = GetCommandParamObject();
192 if (cmdParamObj) {
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);
198 else
199 QAOutput("SetLongValueTest(): We didn't get nsICommandParams object.", 1);
202 void CnsICmdParams::SetDoubleValueTest(double value, const char *stateType, int displayMode)
204 cmdParamObj = GetCommandParamObject();
205 if (cmdParamObj) {
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);
211 else
212 QAOutput("SetDoubleValueTest(): We didn't get nsICommandParams object.", 1);
215 void CnsICmdParams::SetStringValueTest(char *value, const char *stateType, int displayMode)
217 cmdParamObj = GetCommandParamObject();
218 if (cmdParamObj) {
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);
224 else
225 QAOutput("SetStringValueTest(): We didn't get nsICommandParams object.", 1);
228 void CnsICmdParams::SetCStringValueTest(char *value, const char *stateType, int displayMode)
230 cmdParamObj = GetCommandParamObject();
231 if (cmdParamObj) {
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);
237 else
238 QAOutput("SetCStringValueTest(): We didn't get nsICommandParams object.", 1);
241 void CnsICmdParams::OnStartTests(UINT nMenuID)
243 switch(nMenuID)
245 case ID_INTERFACES_NSICOMMANDPARAMS_RUNALLTESTS :
246 RunAllTests();
247 break;
248 case ID_INTERFACES_NSICOMMANDPARAMS_GETVALUETYPE :
249 GetValueTypeTest( "cmd_bold", "state_all", 2);
250 break;
251 case ID_INTERFACES_NSICOMMANDPARAMS_GETBOOLEANVALUE :
252 GetBooleanValueTest("cmd_bold", "state_mixed", 2);
253 break;
254 case ID_INTERFACES_NSICOMMANDPARAMS_GETLONGVALUE :
255 GetLongValueTest(57000000, "state_attribute", 2);
256 break;
257 case ID_INTERFACES_NSICOMMANDPARAMS_GETDOUBLEVALUE :
258 GetDoubleValueTest(5.25, "state_attribute", 2);
259 break;
260 case ID_INTERFACES_NSICOMMANDPARAMS_GETSTRINGVALUE :
261 GetStringValueTest("MyString!!", "state_attribute", 2);
262 break;
263 case ID_INTERFACES_NSICOMMANDPARAMS_GETCSTRINGVALUE:
264 GetCStringValueTest("cmd_fontColor", "state_attribute", 2);
265 break;
266 case ID_INTERFACES_NSICOMMANDPARAMS_GETISUPPORTSVALUE :
267 QAOutput("Not implemented yet.", 2);
268 break;
269 case ID_INTERFACES_NSICOMMANDPARAMS_SETBOOLEANVALUE :
270 SetBooleanValueTest(PR_TRUE, "state_attribute", 2);
271 break;
272 case ID_INTERFACES_NSICOMMANDPARAMS_SETLONGVALUE :
273 SetLongValueTest(25000000, "state_attribute", 2);
274 break;
275 case ID_INTERFACES_NSICOMMANDPARAMS_SETDOUBLEVALUE :
276 SetDoubleValueTest(-3.05, "state_attribute", 2);
277 break;
278 case ID_INTERFACES_NSICOMMANDPARAMS_SETSTRINGVALUE :
279 SetStringValueTest("HELLO!", "state_attribute", 2);
280 break;
281 case ID_INTERFACES_NSICOMMANDPARAMS_SETCSTRINGVALUE:
282 SetCStringValueTest("#FF0000", "state_attribute", 2);
283 break;
284 case ID_INTERFACES_NSICOMMANDPARAMS_SETISUPPORTSVALUE :
285 QAOutput("Not implemented yet.", 2);
286 break;
287 case ID_INTERFACES_NSICOMMANDPARAMS_REMOVEVALUE :
288 QAOutput("Not implemented yet.", 2);
289 break;
290 case ID_INTERFACES_NSICOMMANDPARAMS_HASMOREELEMENTS :
291 QAOutput("Not implemented yet.", 2);
292 break;
293 case ID_INTERFACES_NSICOMMANDPARAMS_FIRST :
294 QAOutput("Not implemented yet.", 2);
295 break;
296 case ID_INTERFACES_NSICOMMANDPARAMS_GETNEXT :
297 QAOutput("Not implemented yet.", 2);
298 break;
302 void CnsICmdParams::RunAllTests()
304 cmdParamObj = GetCommandParamObject();
305 if (cmdParamObj)
306 QAOutput("We got nsICommandParams object.", 1);
307 else
308 QAOutput("We didn't get nsICommandParams object.", 1);
310 PRInt16 i;
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