2 using System.Collections.Generic;
7 namespace NUnit.Framework.TUnit
11 private static string XML_ELEMENT_ENVIRONMENT = "environment";
12 private static string XML_ELEMENT_SUITE = "suite";
13 private static string XML_ELEMENT_SET = "set";
14 private static string XML_ELEMENT_TESTCASE = "testcase";
15 private static string XML_ELEMENT_TEST_ONLOAD_DELAY = "onload_delay";
16 private static string XML_ELEMENT_RESULT = "result";
18 private static string XML_ELEMENT_ACTUAL_RESULT = "actual_result";
19 private static string XML_ELEMENT_START = "start";
20 private static string XML_ELEMENT_END = "end";
21 private static string XML_ELEMENT_STDOUT = "stdout";
22 private static string XML_ELEMENT_STDERR = "stderr";
25 private static string XML_ATTR_NAME_COMPONENT = "component";
26 private static string XML_ATTR_NAME_ELEMENT_EXECUTION_TYPE = "execution_type";
27 private static string XML_ATTR_NAME_ELEMENT_ID = "id";
28 private static string XML_ATTR_NAME_ELEMENT_PRIORITY = "priority";
29 private static string XML_ATTR_NAME_ELEMENT_PURPOSE = "purpose";
33 private XmlReader reader;
35 /* Test Environment */
36 private TestcaseEnvironment testcaseEnv;
39 private TestcaseSuite testcaseSuite;
42 //private ArrayList tcList;
49 // Instance Constructor
53 testcaseEnv = new TestcaseEnvironment();
54 testcaseSuite = new TestcaseSuite();
59 private List<TestcaseData> readXML(string path)
61 List<TestcaseData> tcList = new List<TestcaseData>();
64 //reader = new XmlReader.Create(path);
65 reader = XmlReader.Create(path);
71 switch (reader.NodeType)
73 case XmlNodeType.Element:
74 if (reader.Name == XML_ELEMENT_ENVIRONMENT)
76 /* TEST ENVIRONMENT */
77 while (reader.MoveToNextAttribute())
79 if (reader.Name == "build_id")
81 testcaseEnv.build_id = reader.Value;
82 //LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG ,"ENV build_id : " + testcaseEnv.build_id);
84 else if (reader.Name == "device_id")
86 testcaseEnv.device_id = reader.Value;
87 //LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG ,"ENV device_id : " + testcaseEnv.device_id);
89 else if (reader.Name == "device_model")
91 testcaseEnv.device_model = reader.Value;
92 //LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG ,"ENV device_model : " + testcaseEnv.device_model);
94 else if (reader.Name == "device_name")
96 testcaseEnv.device_name = reader.Value;
97 //LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG ,"ENV device_name : " + testcaseEnv.device_name);
99 else if (reader.Name == "lite_version")
101 testcaseEnv.lite_version = reader.Value;
102 //LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG ,"ENV lite_version : " + testcaseEnv.lite_version);
104 else if (reader.Name == "host")
106 testcaseEnv.host = reader.Value;
107 //LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG ,"ENV host : " + testcaseEnv.host);
109 else if (reader.Name == "manufacturer")
111 testcaseEnv.manufacturer = reader.Value;
112 //LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG ,"ENV manufacturer : " + testcaseEnv.manufacturer);
114 else if (reader.Name == "resolution")
116 testcaseEnv.resolution = reader.Value;
117 //LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG ,"ENV resolution : " + testcaseEnv.resolution);
119 else if (reader.Name == "screen_size")
121 testcaseEnv.screen_size = reader.Value;
122 //LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG ,"ENV screen_size : " + testcaseEnv.screen_size);
126 /* TEST CASE SUITE */
127 else if (reader.Name == XML_ELEMENT_SUITE)
129 while (reader.MoveToNextAttribute())
131 if (reader.Name == "category")
133 testcaseSuite.suite_category = reader.Value;
134 //LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG ,"SUITE category : " + testcaseSuite.suite_category);
136 else if (reader.Name == "launcher")
138 testcaseSuite.suite_launcher = reader.Value;
139 //LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG ,"SUITE launcher : " + testcaseSuite.suite_launcher);
141 else if (reader.Name == "name")
143 testcaseSuite.suite_name = reader.Value;
144 //LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG ,"SUITE name : " + testcaseSuite.suite_name);
148 else if (reader.Name == XML_ELEMENT_SET)
150 reader.MoveToNextAttribute();
151 if (reader.Name == "name")
153 testcaseSuite.set_name = reader.Value;
154 //LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG ,"SET name : " + testcaseSuite.set_name);
158 else if (reader.Name == XML_ELEMENT_TESTCASE)
160 TestcaseData tmp = new TestcaseData();
163 //LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG ,"CASE ARY ADD *****************************");
164 while (reader.MoveToNextAttribute())
166 if (reader.Name == XML_ATTR_NAME_COMPONENT)
168 ((TestcaseData)tcList[count]).component = reader.Value;
169 //LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG ," CASE component : " + reader.Value);
171 else if (reader.Name == XML_ATTR_NAME_ELEMENT_EXECUTION_TYPE)
173 ((TestcaseData)tcList[count]).execution_type = reader.Value;
174 //LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG ," CASE execution : " + reader.Value);
176 else if (reader.Name == XML_ATTR_NAME_ELEMENT_ID)
178 ((TestcaseData)tcList[count]).id = reader.Value;
179 //LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG ," CASE ID : " + reader.Value);
182 else if (reader.Name == XML_ATTR_NAME_ELEMENT_PRIORITY)
184 ((TestcaseData)tcList[count]).priority = reader.Value;
185 //LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG ," CASE priority : " + reader.Value);
187 else if (reader.Name == XML_ATTR_NAME_ELEMENT_PURPOSE)
189 ((TestcaseData)tcList[count]).purpose = reader.Value;
190 //LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG ," CASE purpose : " + reader.Value);
192 else if (reader.Name == XML_ELEMENT_RESULT)
194 ((TestcaseData)tcList[count]).result = reader.Value;
195 //LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG ," CASE result : " + reader.Value);
198 else if (reader.Name == XML_ELEMENT_TEST_ONLOAD_DELAY)
200 ((TestcaseData)tcList[count]).onloaddelay = reader.Value;
201 //LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG ," CASE onloaddelay : " + reader.Value);
207 else if (reader.Name == "description")
209 while (reader.NodeType != XmlNodeType.Text && reader.NodeType != XmlNodeType.EndElement)
212 ((TestcaseData)tcList[count]).test_script_entry = reader.Value;
213 //LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG ," CASE test_script_entry : " + reader.Value);
216 else if (reader.Name == "result_info")
222 if (reader.NodeType == XmlNodeType.Element)
224 if (reader.Name == XML_ELEMENT_ACTUAL_RESULT)
226 while (reader.NodeType != XmlNodeType.Text && reader.NodeType != XmlNodeType.EndElement)
229 ((TestcaseData)tcList[count]).actual_result = reader.Value;
230 //LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG ," CASE actual_result : " + reader.Value);
232 else if (reader.Name == XML_ELEMENT_START)
234 while (reader.NodeType != XmlNodeType.Text && reader.NodeType != XmlNodeType.EndElement)
237 ((TestcaseData)tcList[count]).start = reader.Value;
238 //LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG ," CASE start : " + reader.Value);
240 else if (reader.Name == XML_ELEMENT_END)
242 while (reader.NodeType != XmlNodeType.Text && reader.NodeType != XmlNodeType.EndElement)
245 ((TestcaseData)tcList[count]).end = reader.Value;
246 //LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG ," CASE end : " + reader.Value);
248 else if (reader.Name == XML_ELEMENT_STDOUT)
250 while (reader.NodeType != XmlNodeType.Text && reader.NodeType != XmlNodeType.EndElement)
253 ((TestcaseData)tcList[count]).stdout = reader.Value;
254 //LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG ," CASE stdout : " + reader.Value);
256 else if (reader.Name == XML_ELEMENT_STDERR)
258 while (reader.NodeType != XmlNodeType.Text && reader.NodeType != XmlNodeType.EndElement)
261 ((TestcaseData)tcList[count]).stderr = reader.Value;
262 //LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG ," CASE stderr : " + reader.Value);
265 if (reader.NodeType == XmlNodeType.EndElement)
267 if (reader.Name == "result_info")
275 case XmlNodeType.Text:
276 //if (reader.Name == XML_ELEMENT_TEST_SCRIPT_ENTRY)
278 //((TestcaseData)tcList[count]).test_script_expected_result = reader.Value;
279 ////LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG ," CASE test_script_entry : " + reader.Value);
280 ////LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG ,"CASE ARY END ***************************** ");
283 case XmlNodeType.EndElement:
285 if (reader.Name == "testcase")
287 //LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG ," ***************************** END ***************************** ");
296 LogUtils.Write(LogUtils.ERROR, LogUtils.TAG, "ERROR : " + e.Message);
304 public String[] getTestIdList(string path)
306 List<string> res = new List<string>();
307 List<TestcaseData> tcList;
311 tcList = readXML(path);
312 foreach (TestcaseData data in tcList)
319 LogUtils.Write(LogUtils.ERROR, LogUtils.TAG, "ERROR : " + e.Message);
321 return (string[])res.ToArray<string>();
324 public String[] getFailList(string path)
327 List<string> res = new List<string>();
328 List<TestcaseData> tcList;
332 tcList = readXML(path);
333 foreach (TestcaseData data in tcList)
335 if (data.result == "FAIL")
338 //LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG ,data.id);
344 LogUtils.Write(LogUtils.ERROR, LogUtils.TAG, "ERROR : " + e.Message);
347 return (string[])res.ToArray<string>();
350 public void writeResult(String path, String fileName, TestcaseEnvironment testEnv, List<TestcaseData> list)
354 FileStream fs = new FileStream(path + fileName, FileMode.Create);
355 StreamWriter sw = new StreamWriter(fs);
357 XmlWriter xmlWriter = XmlWriter.Create(sw);
358 xmlWriter.WriteStartDocument();
360 xmlWriter.WriteStartElement("test_definition");
362 xmlWriter.WriteStartElement("suite");
363 xmlWriter.WriteAttributeString("category", "");
364 xmlWriter.WriteAttributeString("extension", "");
365 xmlWriter.WriteAttributeString("name", "");
367 xmlWriter.WriteStartElement("set");
368 xmlWriter.WriteAttributeString("name", "C#");
369 xmlWriter.WriteAttributeString("set_debug_msg", "N/A");
370 xmlWriter.WriteAttributeString("type", "js");
373 foreach (TestcaseData data in list)
376 xmlWriter.WriteStartElement("testcase");
377 xmlWriter.WriteAttributeString("component", data.component);
378 xmlWriter.WriteAttributeString("execution_type", data.execution_type);
379 xmlWriter.WriteAttributeString("id", data.id);
380 xmlWriter.WriteAttributeString("priority", data.priority);
381 xmlWriter.WriteAttributeString("purpose", data.purpose);
382 xmlWriter.WriteAttributeString("onload_delay", data.onloaddelay);
383 xmlWriter.WriteAttributeString("result", data.result);
387 <test_script_entry>/opt/tct-messaging-mms-tizen-tests/messaging/MessageBody_mms_extend.html</test_script_entry>
390 xmlWriter.WriteStartElement("description");
391 xmlWriter.WriteStartElement("test_script_entry");
392 xmlWriter.WriteString(data.test_script_entry);
393 xmlWriter.WriteEndElement(); // close test_script_entry
394 xmlWriter.WriteEndElement(); // close description
398 <actual_result>PASS</actual_result>
399 <start>2016-04-01 16:53:06</start>
400 <end>2016-04-01 16:53:07</end>
401 <stdout>[Message]</stdout>
405 xmlWriter.WriteStartElement("result_info");
407 xmlWriter.WriteStartElement("actual_result");
408 xmlWriter.WriteString(data.actual_result);
409 xmlWriter.WriteEndElement(); // end of atcual_result
411 xmlWriter.WriteStartElement("start");
412 xmlWriter.WriteString(data.start);
413 xmlWriter.WriteEndElement(); // end of start
415 xmlWriter.WriteStartElement("end");
416 xmlWriter.WriteString(data.end);
417 xmlWriter.WriteEndElement(); // end of end
419 xmlWriter.WriteStartElement("stdout");
420 xmlWriter.WriteString(data.stdout);
421 xmlWriter.WriteEndElement(); // end of stdout
423 xmlWriter.WriteStartElement("stderr");
424 xmlWriter.WriteString(data.stderr);
425 xmlWriter.WriteEndElement(); // end of stderr
427 xmlWriter.WriteEndElement(); // end of resultinfo
430 xmlWriter.WriteEndElement(); // end of testcase
432 xmlWriter.WriteEndElement(); // end of set
433 xmlWriter.WriteEndElement(); // end of suite
435 xmlWriter.WriteEndDocument();
444 LogUtils.Write(LogUtils.ERROR, LogUtils.TAG, "ERROR :: : " + e.Message);
449 @fileName : fileName of summary XML
450 @path : path of summary XML
451 @list : SummaryData object list
453 public void writeSummary(String path, String fileName, List<SummaryData> list)
455 FileStream fs = new FileStream(path + fileName, FileMode.Create);
456 StreamWriter sw = new StreamWriter(fs);
458 XmlWriter xmlWriter = XmlWriter.Create(sw);
459 xmlWriter.WriteStartDocument();
461 xmlWriter.WriteStartElement("result_summary");
462 xmlWriter.WriteAttributeString("plan_name", "temp");
468 tct_version,"TCT_3.0"
470 device_id,"0000d85b00006200"
472 device_name,"localhost "
473 host,"Linux-3.13.0-83-generic-x86_64-with-Ubuntu-12.04-precise"
479 xmlWriter.WriteStartElement("environment");
480 xmlWriter.WriteAttributeString("build_id", "");
481 xmlWriter.WriteAttributeString("tct_version", "TCT_3.0");
482 xmlWriter.WriteAttributeString("tct_profile", "mobile");
483 xmlWriter.WriteAttributeString("device_id", "0000d85b00006200");
484 xmlWriter.WriteAttributeString("device_model", "");
485 xmlWriter.WriteAttributeString("device_name", "localhost");
486 xmlWriter.WriteAttributeString("host", "Linux -3.13.0-83-generic-x86_64-with-Ubuntu-12.04-precise");
487 xmlWriter.WriteAttributeString("resolution", "");
488 xmlWriter.WriteAttributeString("screen_size", "");
489 xmlWriter.WriteAttributeString("manufacturer", "");
492 //<other xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string" />
493 xmlWriter.WriteStartElement("other");
494 //string attr = "xmlns:xs";
495 //xmlWriter.WriteAttributeString(attr, "http://www.w3.org/2001/XMLSchema");
496 //xmlWriter.WriteAttributeString(attr, "http://www.w3.org/2001/XMLSchema-instance");
497 //xmlWriter.WriteAttributeString("xsi:type", "xs:string");
498 xmlWriter.WriteEndElement(); // close other
500 xmlWriter.WriteEndElement(); // close environment
504 <summary test_plan_name = "Empty test_plan_name" >
505 < start_at > 2016 - 04 - 08_18_37_38 </ start_at >
506 < end_at > 2016 - 04 - 08_18_38_07 </ end_at >
509 xmlWriter.WriteStartElement("summary");
510 xmlWriter.WriteAttributeString("test_plan_name", "Empty test_plan_name");
512 xmlWriter.WriteStartElement("start_at");
513 xmlWriter.WriteString("2016-04-20_18_37_38");
514 xmlWriter.WriteEndElement(); // close start_at
516 xmlWriter.WriteStartElement("end_at");
517 xmlWriter.WriteString("2016 - 04 - 08_18_38_07");
518 xmlWriter.WriteEndElement(); // close end_at
520 xmlWriter.WriteEndElement(); // close summary
524 < suite name = "tct-fullscreen-nonw3c-tests" >
525 < total_case > 13 </ total_case >
526 < pass_case > 13 </ pass_case >
527 < pass_rate > 100.00 </ pass_rate >
528 < fail_case > 0 </ fail_case >
529 < fail_rate > 0.00 </ fail_rate >
530 < block_case > 0 </ block_case >
531 < block_rate > 0.00 </ block_rate >
532 < na_case > 0 </ na_case >
533 < na_rate > 0.00 </ na_rate >
537 foreach (SummaryData data in list)
539 xmlWriter.WriteStartElement("suite");
540 xmlWriter.WriteAttributeString("name", data.suiteName);
543 xmlWriter.WriteStartElement("total_case");
544 xmlWriter.WriteString(data.totalCase+"");
545 xmlWriter.WriteEndElement();// end of total_case
547 xmlWriter.WriteStartElement("pass_case");
548 xmlWriter.WriteString(data.passCase + "");
549 xmlWriter.WriteEndElement();// end of pass_case
551 xmlWriter.WriteStartElement("pass_rate");
552 xmlWriter.WriteString(data.passRate + "");
553 xmlWriter.WriteEndElement();// end of pass_rate
555 xmlWriter.WriteStartElement("fail_case");
556 xmlWriter.WriteString(data.failCase + "");
557 xmlWriter.WriteEndElement();// end of fail_case
559 xmlWriter.WriteStartElement("fail_rate");
560 xmlWriter.WriteString(data.failRate + "");
561 xmlWriter.WriteEndElement();// end of fail_rate
563 xmlWriter.WriteStartElement("block_case");
564 xmlWriter.WriteString(data.blockCase + "");
565 xmlWriter.WriteEndElement();// end of block_case
567 xmlWriter.WriteStartElement("block_rate");
568 xmlWriter.WriteString(data.blockRate + "");
569 xmlWriter.WriteEndElement();// end of block_rate
571 xmlWriter.WriteStartElement("na_case");
572 xmlWriter.WriteString(data.naCase + "");
573 xmlWriter.WriteEndElement(); // end of na_case
575 xmlWriter.WriteStartElement("na_rate");
576 xmlWriter.WriteString(data.naRate + "");
577 xmlWriter.WriteEndElement();// end of na_reate
579 xmlWriter.WriteEndElement(); // end of suite
583 xmlWriter.WriteEndDocument(); // end of document
595 public class TestcaseData
598 public String component { get; set; }
599 public String execution_type { get; set; }
600 public String id { get; set; }
601 public String priority { get; set; }
602 public String onloaddelay { get; set; }
603 public String purpose { get; set; }
604 public String test_script_entry { get; set; }
605 public String result { get; set; }
607 public String actual_result { get; set; }
608 public String start { get; set; }
609 public String end { get; set; }
610 public String stdout { get; set; }
611 public String stderr { get; set; }
613 public TestcaseData()
621 test_script_entry = "";
633 /* TestcaseSuite Data */
634 public class TestcaseSuite
637 <suite category = "W3C/HTML5 APIs"
638 launcher="WRTLauncher" name="tct-3dtransforms-css3-tests">
639 <set name = "3DTransforms" >
641 public String suite_category { get; set; }
642 public String suite_launcher { get; set; }
643 public String suite_name { get; set; }
644 public String set_name { get; set; }
646 public TestcaseSuite()
656 /* TestcaseEnvironment Data */
657 public class TestcaseEnvironment
660 <suite category = "W3C/HTML5 APIs"
661 launcher="WRTLauncher" name="tct-3dtransforms-css3-tests">
662 <set name = "3DTransforms" >
664 public String build_id { get; set; }
665 public String device_id { get; set; }
666 public String device_model { get; set; }
667 public String device_name { get; set; }
669 public String host { get; set; }
670 public String lite_version { get; set; }
671 public String manufacturer { get; set; }
672 public String resolution { get; set; }
673 public String screen_size { get; set; }
675 public TestcaseEnvironment()
692 public class SummaryData
694 public int totalCase { get; set; }
695 public int passCase { get; set; }
696 public int passRate { get; set; }
697 public int failCase { get; set; }
698 public int failRate { get; set; }
699 public int blockCase { get; set; }
700 public int blockRate { get; set; }
701 public int naCase { get; set; }
702 public int naRate { get; set; }
704 public string suiteName { get; set; }