1 /* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.cts; 18 19 import java.io.BufferedReader; 20 import java.io.File; 21 import java.io.FileReader; 22 import java.io.IOException; 23 import java.security.NoSuchAlgorithmException; 24 import java.util.ArrayList; 25 import java.util.Collection; 26 import java.util.HashMap; 27 import java.util.Iterator; 28 29 import javax.xml.parsers.ParserConfigurationException; 30 import javax.xml.transform.TransformerException; 31 import javax.xml.transform.TransformerFactoryConfigurationError; 32 33 import org.w3c.dom.Document; 34 import org.w3c.dom.Node; 35 import org.xml.sax.SAXException; 36 37 import com.android.cts.TestDevice.DeviceParameterCollector; 38 39 /** 40 * Test the session builder. 41 */ 42 public class TestSessionBuilderTests extends CtsTestBase { 43 private static final String mTmpPlanFileName = "plan"; 44 45 private static final String ATTRIBUTE_DEVICE_ID = "deviceID"; 46 private static final String ATTRIBUTE_BUILD_ID = "buildID"; 47 private static final String ATTRIBUTE_BUILD_VERSION = "buildVersion"; 48 private static final String ATTRIBUTE_BUILD_NAME = "buildName"; 49 50 private String mTestPackageBinaryName = "CtsTestPackage"; 51 52 /** {@inheritDoc} */ 53 @Override 54 public void tearDown() { 55 HostConfig.getInstance().removeTestPacakges(); 56 deleteTestPackage(mTestPackageBinaryName); 57 58 super.tearDown(); 59 } 60 61 /** 62 * Test building simple test session. 63 */ 64 public void testBuildSimpleSession() throws IOException, 65 ParserConfigurationException, SAXException, TestPlanNotFoundException, 66 TestNotFoundException, NoSuchAlgorithmException { 67 final String appPackageName = "com.google.android.cts" + ".CtsTest"; 68 final String suiteName = appPackageName; 69 final String caseName = "CtsTestHello"; 70 final String runner = "android.test.InstrumentationTestRunner"; 71 72 final String serialNum = "serialNum"; 73 final String buildID = "buildid"; 74 final String buildName = "buildname"; 75 final String buildVersion = "buildVersion"; 76 final String testPlanConfigStr = "<TestPlan version=\"1.0\">\n" 77 + "\t<Description>Demo test plan</Description>\n" 78 + "\t\t<PlanSettings>\n" 79 + "\t\t\t<RequiredDevice amount=\"" + 1 + "\"" + "/>\n" 80 + "\t\t</PlanSettings>\n" 81 + "\t<Entry uri=\"" 82 + appPackageName 83 + "\"/>\n" 84 + "</TestPlan>"; 85 86 final String descriptionConfigStr = "<TestPackage name=\"" 87 + mTestPackageBinaryName+ "\" " 88 + "appPackageName=\"" + appPackageName 89 + "\" version=\"1.0\" AndroidFramework=\"Android 1.0\"" 90 + " runner=\"" + runner + "\">\n" 91 + " <Description>something extracted from java doc</Description>\n" 92 + " <TestSuite name=\"" + suiteName + "\"" + ">\n" 93 + " <TestCase name=\"" + caseName + "\"" + " priority=\"mandatory\">\n" 94 + " <Description>" + "something extracted from java doc" 95 + " </Description>\n" 96 + " <!-- Test Methods -->\n" 97 + " <Test name=\"testHello\"" + " type=\"automatic\"" + "/>\n" 98 + " </TestCase>\n" 99 + " </TestSuite>\n" 100 + "</TestPackage>\n"; 101 102 HostConfig.getInstance().removeTestPacakges(); 103 String planPath = 104 HostConfig.getInstance().getPlanRepository().getPlanPath(mTmpPlanFileName); 105 createFile(testPlanConfigStr, planPath); 106 107 createTestPackage(descriptionConfigStr, mTestPackageBinaryName); 108 HostConfig.getInstance().loadTestPackages(); 109 110 TestSession ts = TestSessionBuilder.getInstance().build(planPath); 111 assertEquals(1, ts.getNumOfRequiredDevices()); 112 113 TestSessionLog tsl = ts.getSessionLog(); 114 assertEquals(1, tsl.getTestPackages().size()); 115 116 TestPackage testPackage = tsl.getTestPackages().iterator().next(); 117 assertEquals(1, testPackage.getTestSuites().size()); 118 assertEquals(mTestPackageBinaryName, testPackage.getAppBinaryName()); 119 assertEquals(appPackageName, testPackage.getAppPackageName()); 120 assertEquals("1.0", testPackage.getVersion()); 121 assertEquals("Android 1.0", testPackage.getAndroidVersion()); 122 assertEquals(runner, testPackage.getInstrumentationRunner()); 123 124 TestSuite testSuite = testPackage.getTestSuites().iterator().next(); 125 assertEquals(1, testSuite.getTestCases().size()); 126 assertEquals(suiteName, testSuite.getFullName()); 127 128 TestCase testCase = testSuite.getTestCases().iterator().next(); 129 assertEquals(caseName, testCase.getName()); 130 assertEquals("mandatory", testCase.getPriority()); 131 132 Test test = testCase.getTests().iterator().next(); 133 assertEquals("automatic", test.getType()); 134 assertEquals(CtsTestResult.CODE_NOT_EXECUTED, test.getResult().getResultCode()); 135 assertEquals(runner, test.getInstrumentationRunner()); 136 137 // test build information 138 DeviceParameterCollector deviceParam = new DeviceParameterCollector(); 139 deviceParam.setSerialNumber(serialNum); 140 deviceParam.setBuildId(buildID); 141 deviceParam.setBuildVersion(buildVersion); 142 deviceParam.setProductName(buildName); 143 tsl.setDeviceInfo(deviceParam); 144 Document doc = tsl.createResultDoc(); 145 146 Node buildInfoNode = doc.getElementsByTagName("BuildInfo").item(0); 147 assertEquals(serialNum, buildInfoNode.getAttributes().getNamedItem( 148 ATTRIBUTE_DEVICE_ID).getNodeValue().trim()); 149 assertEquals(buildID, buildInfoNode.getAttributes().getNamedItem( 150 ATTRIBUTE_BUILD_ID).getNodeValue().trim()); 151 assertEquals(buildVersion, buildInfoNode.getAttributes().getNamedItem( 152 ATTRIBUTE_BUILD_VERSION).getNodeValue().trim()); 153 assertEquals(buildName, buildInfoNode.getAttributes().getNamedItem( 154 ATTRIBUTE_BUILD_NAME).getNodeValue().trim()); 155 156 deleteTestPackage(mTestPackageBinaryName); 157 } 158 159 /** 160 * Test getting and removing entries from plan file. 161 */ 162 public void testGetAndRemoveEntriesFromPlanFile() throws UnknownCommandException, 163 CommandNotFoundException, Exception { 164 165 final String appPackageName = "com.google.android.cts"; 166 final String suiteName = appPackageName; 167 final String caseName = "CtsTestHello"; 168 final String runner = "android.test.InstrumentationTestRunner"; 169 170 final String testPlanConfigStr = "<TestPlan version=\"1.0\">\n" 171 + "\t<Description>Demo test plan</Description>\n" 172 + "\t\t<PlanSettings>\n" 173 + "\t\t\t<RequiredDevice amount=\"" + 1 + "\"" + "/>\n" 174 + "\t\t</PlanSettings>\n" 175 + "\t<Entry uri=\"" 176 + appPackageName 177 + "\"/>\n" 178 + "</TestPlan>"; 179 180 final String descriptionConfigStr = "<TestPackage name=\"" 181 + mTestPackageBinaryName+ "\" " 182 + "appPackageName=\"" + appPackageName 183 + "\" version=\"1.0\" AndroidFramework=\"Android 1.0\"" 184 + " runner=\"" + runner + "\">\n" 185 + " <Description>something extracted from java doc</Description>\n" 186 + " <TestSuite name=\"" + suiteName + "\"" + ">\n" 187 + " <TestCase name=\"" + caseName + "\"" + " priority=\"mandatory\">\n" 188 + " <Description>" + "something extracted from java doc" 189 + " </Description>\n" 190 + " <!-- Test Methods -->\n" 191 + " <Test name=\"testHello\"" + " type=\"automatic\"" + "/>\n" 192 + " </TestCase>\n" 193 + " </TestSuite>\n" 194 + "</TestPackage>\n"; 195 196 HostConfig.getInstance().removeTestPacakges(); 197 createTestPackage(descriptionConfigStr, mTestPackageBinaryName); 198 HostConfig.getInstance().loadTestPackages(); 199 200 String planPath = HostConfig.getInstance().getPlanRepository() 201 .getPlanPath(mTmpPlanFileName); 202 createFile(testPlanConfigStr, planPath); 203 204 ArrayList<String> removedPkgList = new ArrayList<String>(); 205 Collection<String> entries = TestPlan.getEntries(planPath, removedPkgList); 206 Iterator<String> it = entries.iterator(); 207 208 assertEquals(1, entries.size()); 209 assertEquals(appPackageName, it.next()); 210 ConsoleUi cui = new ConsoleUi(TestHost.getInstance()); 211 String cmdLine = CTSCommand.REMOVE + " " + "-p" + " " 212 + appPackageName; 213 cui.processCommand(CommandParser.parse(cmdLine)); 214 entries = TestPlan.getEntries(planPath, removedPkgList); 215 assertEquals(1, removedPkgList.size()); 216 217 deleteTestPackage(mTestPackageBinaryName); 218 } 219 220 /** 221 * Test validating package name. 222 */ 223 public void testValidatePackageName() throws IOException { 224 final String packageName = "com.google.android.testname"; 225 String testPackageXmlFilePath = 226 HostConfig.getInstance().getCaseRepository().getXmlPath(packageName); 227 String testpackageAPKFilePath = 228 HostConfig.getInstance().getCaseRepository().getApkPath(packageName); 229 230 HostConfig.getInstance().removeTestPacakges(); 231 createTestPackage("", packageName); 232 233 assertEquals(true, TestPlan.isValidPackageName(packageName)); 234 235 deleteFile(testPackageXmlFilePath); 236 assertEquals(false, TestPlan.isValidPackageName(packageName)); 237 238 deleteFile(testpackageAPKFilePath); 239 assertEquals(false, TestPlan.isValidPackageName(packageName)); 240 } 241 242 /** 243 * Test building test session with dependency. 244 */ 245 public void testBuildSessionWithDependency() throws IOException, 246 ParserConfigurationException, SAXException, TestPlanNotFoundException, 247 TestNotFoundException, NoSuchAlgorithmException { 248 249 final String targetNameSpace = "i don't want to be the target!"; 250 final String appPackageName = "com.google.android.cts"; 251 final String suiteName = appPackageName + ".CtsTest"; 252 final String caseName = "CtsTestHello"; 253 final String runner = "android.test.InstrumentationTestRunner"; 254 255 final String testPlanConfigStr = "<TestPlan version=\"1.0\">\n" 256 + "\t<Description>Demo test plan</Description>\n" 257 + "\t\t<PlanSettings>\n" 258 + "\t\t\t<RequiredDevice amount=\"" + 1 + "\"" + "/>\n" 259 + "\t\t</PlanSettings>\n" 260 + "\t<Entry uri=\"" 261 + appPackageName 262 + "\"/>\n" 263 + "</TestPlan>"; 264 265 final String descriptionConfigStr = "<TestPackage name=\"" 266 + mTestPackageBinaryName + "\" " 267 + "appPackageName=\"" + appPackageName 268 + "\" targetNameSpace=\"" + targetNameSpace 269 + "\" version=\"1.0\" AndroidFramework=\"Android 1.0\"" 270 + " runner=\"" +runner + "\">\n" 271 + " <Description>something extracted from java doc</Description>\n" 272 + " <TestSuite name=\"" + suiteName + "\"" + ">\n" 273 + " <TestCase name=\"" + caseName + "\"" + " priority=\"mandatory\">\n" 274 + " <Description>" + "something extracted from java doc" 275 + " </Description>\n" 276 + " <!-- Test Methods -->\n" 277 + " <Test name=\"testHello\"" + " type=\"automatic\"" + "/>\n" 278 + " </TestCase>\n" 279 + " </TestSuite>\n" 280 + "</TestPackage>\n"; 281 282 HostConfig.getInstance().removeTestPacakges(); 283 284 String planPath = 285 HostConfig.getInstance().getPlanRepository().getPlanPath(mTmpPlanFileName); 286 createFile(testPlanConfigStr, planPath); 287 288 createTestPackage(descriptionConfigStr, mTestPackageBinaryName); 289 HostConfig.getInstance().loadTestPackages(); 290 291 TestSession ts = TestSessionBuilder.getInstance().build(planPath); 292 assertEquals(1, ts.getNumOfRequiredDevices()); 293 294 TestSessionLog tsl = ts.getSessionLog(); 295 assertEquals(1, tsl.getTestPackages().size()); 296 297 TestPackage testPackage = tsl.getTestPackages().iterator().next(); 298 assertEquals(1, testPackage.getTestSuites().size()); 299 assertEquals(mTestPackageBinaryName, testPackage.getAppBinaryName()); 300 assertEquals(targetNameSpace, testPackage.getTargetNameSpace()); 301 assertEquals("1.0", testPackage.getVersion()); 302 assertEquals("Android 1.0", testPackage.getAndroidVersion()); 303 assertEquals(runner, testPackage.getInstrumentationRunner()); 304 305 TestSuite testSuite = testPackage.getTestSuites().iterator().next(); 306 assertEquals(1, testSuite.getTestCases().size()); 307 assertEquals(suiteName, testSuite.getFullName()); 308 309 TestCase testCase = testSuite.getTestCases().iterator().next(); 310 assertEquals(caseName, testCase.getName()); 311 assertEquals("mandatory", testCase.getPriority()); 312 313 Test test = testCase.getTests().iterator().next(); 314 assertEquals("automatic", test.getType()); 315 assertEquals(CtsTestResult.CODE_NOT_EXECUTED, test.getResult().getResultCode()); 316 assertEquals(runner, test.getInstrumentationRunner()); 317 318 deleteTestPackage(mTestPackageBinaryName); 319 } 320 321 /** 322 * Test building test session from embedded suites. 323 */ 324 public void testBuildSessionFromEmbeddedSuites() throws IOException, 325 ParserConfigurationException, SAXException, TestPlanNotFoundException, 326 TestNotFoundException, NoSuchAlgorithmException { 327 328 final String appPackageName = "com.google.android.cts"; 329 final String caseName = "CtsTestHello"; 330 final String testName = "testHello"; 331 332 final String testPlanConfigStr = "<TestPlan version=\"1.0\">\n" 333 + "<Description>Demo test plan</Description>\n" 334 + "<PlanSettings>\n" 335 + " <RequiredDevice amount=\"" + 1 + "\"" + "/>\n" 336 + "</PlanSettings>\n" 337 + "<Entry uri=\"" + appPackageName + "\"/>\n" 338 + "</TestPlan>"; 339 340 final String descriptionConfigStr = "<TestPackage name=\"" + mTestPackageBinaryName + "\"" 341 + " appPackageName=\"" + appPackageName + "\"" 342 + " version=\"1.0\" AndroidFramework=\"Android 1.0\"" 343 + " runner=\"android.test.InstrumentationTestRunner\" >\n" 344 + " <Description>something extracted from java doc</Description>\n" 345 + " <TestSuite name=\"com.google\">\n" 346 + " <TestCase name=\"CtsTestHello\" priority=\"mandatory\">\n" 347 + " <Description>" + "something extracted from java doc" 348 + " </Description>\n" 349 + " <!-- Test Methods -->\n" 350 + " <Test name=\"testHello\"" + " type=\"automatic\"" + "/>\n" 351 + " </TestCase>\n" 352 + " <TestSuite name=\"TestSuiteName\">\n" 353 + " <TestCase name=\"TestCaseName\" priority=\"mandatory\">\n" 354 + " <Description>" + "something extracted from java doc" 355 + " </Description>\n" 356 + " <!-- Test Methods -->\n" 357 + " <Test name=\"testName\"" + " type=\"automatic\"" + "/>\n" 358 + " </TestCase>\n" 359 + " </TestSuite>\n" 360 + " </TestSuite>\n" 361 + "</TestPackage>\n"; 362 363 HostConfig.getInstance().removeTestPacakges(); 364 365 String planPath = 366 HostConfig.getInstance().getPlanRepository().getPlanPath(mTmpPlanFileName); 367 createFile(testPlanConfigStr, planPath); 368 369 createTestPackage(descriptionConfigStr, mTestPackageBinaryName); 370 HostConfig.getInstance().loadTestPackages(); 371 372 TestSession ts = TestSessionBuilder.getInstance().build(planPath); 373 assertEquals(1, ts.getNumOfRequiredDevices()); 374 375 TestSessionLog tsl = ts.getSessionLog(); 376 assertEquals(1, tsl.getTestPackages().size()); 377 378 TestPackage testPackage = tsl.getTestPackages().iterator().next(); 379 assertEquals(1, testPackage.getTestSuites().size()); 380 assertEquals(mTestPackageBinaryName, testPackage.getAppBinaryName()); 381 assertEquals("1.0", testPackage.getVersion()); 382 assertEquals("Android 1.0", testPackage.getAndroidVersion()); 383 384 TestSuite testSuite; 385 testSuite = testPackage.getTestSuites().iterator().next(); 386 assertEquals(1, testSuite.getSubSuites().size()); 387 assertEquals(1, testSuite.getTestCases().size()); 388 assertEquals("com.google", testSuite.getFullName()); 389 assertEquals("com.google", testSuite.getName()); 390 391 TestCase testCase = testSuite.getTestCases().iterator().next(); 392 assertEquals(caseName, testCase.getName()); 393 assertEquals("mandatory", testCase.getPriority()); 394 395 Test test = testCase.getTests().iterator().next(); 396 assertEquals("com.google.CtsTestHello#testHello", test.getFullName()); 397 assertEquals("automatic", test.getType()); 398 assertEquals(testName, test.getName()); 399 assertEquals(CtsTestResult.CODE_NOT_EXECUTED, test.getResult().getResultCode()); 400 401 testSuite = testSuite.getSubSuites().iterator().next(); 402 assertEquals(0, testSuite.getSubSuites().size()); 403 assertEquals(1, testSuite.getTestCases().size()); 404 assertEquals("com.google.TestSuiteName", testSuite.getFullName()); 405 assertEquals("TestSuiteName", testSuite.getName()); 406 407 testCase = testSuite.getTestCases().iterator().next(); 408 assertEquals("TestCaseName", testCase.getName()); 409 assertEquals("mandatory", testCase.getPriority()); 410 411 test = testCase.getTests().iterator().next(); 412 assertEquals("com.google.TestSuiteName.TestCaseName#testName", test.getFullName()); 413 assertEquals("automatic", test.getType()); 414 assertEquals("testName", test.getName()); 415 assertEquals(CtsTestResult.CODE_NOT_EXECUTED, test.getResult().getResultCode()); 416 417 deleteTestPackage(mTestPackageBinaryName); 418 } 419 420 /** 421 * Test loading plan with excluded list from the xml file. 422 */ 423 public void testExcludingFromXmlFile() throws IOException, 424 ParserConfigurationException, 425 SAXException, 426 TestPlanNotFoundException, 427 TestNotFoundException, NoSuchAlgorithmException { 428 429 final String appPackageName = "com.google.android.cts"; 430 final String caseName = "CtsTestHello"; 431 final String testName = "testHello"; 432 final String excludedList = "com.google.TestSuiteName"; 433 434 final String testPlanConfigStr = "<TestPlan version=\"1.0\">\n" 435 + "<Description>Demo test plan</Description>\n" 436 + "<PlanSettings>\n" 437 + " <RequiredDevice amount=\"" + 1 + "\"" + "/>\n" 438 + "</PlanSettings>\n" 439 + " <Entry uri=\"" + appPackageName 440 + "\" " + "exclude=\"" + excludedList + "\"/>\n" 441 + "</TestPlan>"; 442 443 final String descriptionConfigStr = "<TestPackage name=\"" + mTestPackageBinaryName + "\"" 444 + " appPackageName=\"" + appPackageName + "\"" 445 + " version=\"1.0\" AndroidFramework=\"Android 1.0\"" 446 + " runner=\"android.test.InstrumentationTestRunner\" >\n" 447 + " <Description>something extracted from java doc</Description>\n" 448 + " <TestSuite name=\"com.google\">\n" 449 + " <TestCase name=\"CtsTestHello\" priority=\"mandatory\">\n" 450 + " <Description>" + "something extracted from java doc" 451 + " </Description>\n" 452 + " <!-- Test Methods -->\n" 453 + " <Test name=\"testHello\"" + " type=\"automatic\"" + "/>\n" 454 + " <Test name=\"testHello2\"" + " type=\"automatic\"" + "/>\n" 455 + " </TestCase>\n" 456 + " <TestSuite name=\"TestSuiteName\">\n" 457 + " <TestCase name=\"TestCaseName\" priority=\"mandatory\">\n" 458 + " <Description>" + "something extracted from java doc" 459 + " </Description>\n" 460 + " <!-- Test Methods -->\n" 461 + " <Test name=\"testName1\"" + " type=\"automatic\"" + "/>\n" 462 + " <Test name=\"testName2\"" + " type=\"automatic\"" + "/>\n" 463 + " </TestCase>\n" 464 + " </TestSuite>\n" 465 + " </TestSuite>\n" 466 + "</TestPackage>\n"; 467 468 HostConfig.getInstance().removeTestPacakges(); 469 470 String planPath = 471 HostConfig.getInstance().getPlanRepository().getPlanPath(mTmpPlanFileName); 472 createFile(testPlanConfigStr, planPath); 473 474 createTestPackage(descriptionConfigStr, mTestPackageBinaryName); 475 HostConfig.getInstance().loadTestPackages(); 476 477 TestSession ts = TestSessionBuilder.getInstance().build(planPath); 478 assertEquals(1, ts.getNumOfRequiredDevices()); 479 480 TestSessionLog tsl = ts.getSessionLog(); 481 assertEquals(1, tsl.getTestPackages().size()); 482 483 TestPackage testPackage = tsl.getTestPackages().iterator().next(); 484 assertEquals(1, testPackage.getTestSuites().size()); 485 assertEquals(mTestPackageBinaryName, testPackage.getAppBinaryName()); 486 assertEquals("1.0", testPackage.getVersion()); 487 assertEquals("Android 1.0", testPackage.getAndroidVersion()); 488 489 TestSuite testSuite; 490 testSuite = testPackage.getTestSuites().iterator().next(); 491 assertEquals(0, testSuite.getSubSuites().size()); 492 assertEquals(1, testSuite.getTestCases().size()); 493 assertEquals("com.google", testSuite.getFullName()); 494 495 TestCase testCase = testSuite.getTestCases().iterator().next(); 496 assertEquals(caseName, testCase.getName()); 497 assertEquals("mandatory", testCase.getPriority()); 498 499 Test test = testCase.getTests().iterator().next(); 500 assertEquals("com.google.CtsTestHello#testHello", test.getFullName()); 501 assertEquals("automatic", test.getType()); 502 assertEquals(testName, test.getName()); 503 assertEquals(CtsTestResult.CODE_NOT_EXECUTED, test.getResult().getResultCode()); 504 505 deleteTestPackage(mTestPackageBinaryName); 506 } 507 508 /** 509 * Test building and loading plan with excluding list of embedded suite. 510 */ 511 public void testExcludingEmbeddedSuite() throws IOException, 512 ParserConfigurationException, SAXException, TestPlanNotFoundException, 513 TestNotFoundException, 514 TransformerFactoryConfigurationError, TransformerException, NoSuchAlgorithmException { 515 516 final String appPackageName = "com.google.android.cts"; 517 final String caseName = "CtsTestHello"; 518 final String testName = "testHello"; 519 final String excludedList = "com.google.TestSuiteName"; 520 521 final String descriptionConfigStr = "<TestPackage name=\"" + mTestPackageBinaryName + "\"" 522 + " appPackageName=\"" + appPackageName + "\"" 523 + " version=\"1.0\" AndroidFramework=\"Android 1.0\"" 524 + " runner=\"android.test.InstrumentationTestRunner\" >\n" 525 + " <Description>something extracted from java doc</Description>\n" 526 + " <TestSuite name=\"com.google\">\n" 527 + " <TestCase name=\"CtsTestHello\" priority=\"mandatory\">\n" 528 + " <Description>" + "something extracted from java doc" 529 + " </Description>\n" 530 + " <!-- Test Methods -->\n" 531 + " <Test name=\"testHello\"" + " type=\"automatic\"" + "/>\n" 532 + " <Test name=\"testHello2\"" + " type=\"automatic\"" + "/>\n" 533 + " </TestCase>\n" 534 + " <TestSuite name=\"TestSuiteName\">\n" 535 + " <TestCase name=\"TestCaseName\" priority=\"mandatory\">\n" 536 + " <Description>" + "something extracted from java doc" 537 + " </Description>\n" 538 + " <!-- Test Methods -->\n" 539 + " <Test name=\"testName1\"" + " type=\"automatic\"" + "/>\n" 540 + " <Test name=\"testName2\"" + " type=\"automatic\"" + "/>\n" 541 + " </TestCase>\n" 542 + " </TestSuite>\n" 543 + " </TestSuite>\n" 544 + "</TestPackage>\n"; 545 546 HostConfig.getInstance().removeTestPacakges(); 547 createTestPackage(descriptionConfigStr, mTestPackageBinaryName); 548 HostConfig.getInstance().loadTestPackages(); 549 550 ArrayList<String> packageNames = new ArrayList<String>(); 551 packageNames.add(appPackageName); 552 553 HashMap<String, ArrayList<String>> results = new HashMap<String, ArrayList<String>>(); 554 ArrayList<String> list = new ArrayList<String>(); 555 list.add(excludedList); 556 results.put(appPackageName, list); 557 String planName = "plan_test_excluding"; 558 String planPath = HostConfig.getInstance().getPlanRepository().getPlanPath(planName); 559 TestSessionBuilder.getInstance().serialize(planName, packageNames, results); 560 561 TestSession ts = TestSessionBuilder.getInstance().build(planPath); 562 assertEquals(1, ts.getNumOfRequiredDevices()); 563 564 TestSessionLog tsl = ts.getSessionLog(); 565 assertEquals(1, tsl.getTestPackages().size()); 566 567 TestPackage testPackage = tsl.getTestPackages().iterator().next(); 568 assertEquals(1, testPackage.getTestSuites().size()); 569 assertEquals(mTestPackageBinaryName, testPackage.getAppBinaryName()); 570 assertEquals("1.0", testPackage.getVersion()); 571 assertEquals("Android 1.0", testPackage.getAndroidVersion()); 572 573 TestSuite testSuite; 574 testSuite = testPackage.getTestSuites().iterator().next(); 575 assertEquals(0, testSuite.getSubSuites().size()); 576 assertEquals(1, testSuite.getTestCases().size()); 577 assertEquals("com.google", testSuite.getFullName()); 578 579 TestCase testCase = testSuite.getTestCases().iterator().next(); 580 assertEquals(caseName, testCase.getName()); 581 assertEquals("mandatory", testCase.getPriority()); 582 583 Test test = testCase.getTests().iterator().next(); 584 assertEquals("com.google.CtsTestHello#testHello", test.getFullName()); 585 assertEquals("automatic", test.getType()); 586 assertEquals(testName, test.getName()); 587 assertEquals(CtsTestResult.CODE_NOT_EXECUTED, test.getResult().getResultCode()); 588 589 deleteTestPackage(mTestPackageBinaryName); 590 } 591 592 /** 593 * Test building and loading plan with excluding list of the top suite. 594 */ 595 public void testExcludingTopSuite() throws IOException, 596 ParserConfigurationException, SAXException, TestPlanNotFoundException, 597 TestNotFoundException, 598 TransformerFactoryConfigurationError, TransformerException, NoSuchAlgorithmException { 599 600 final String appPackageName = "com.google.android.cts"; 601 final String excludedList = "com.google"; 602 603 final String descriptionConfigStr = "<TestPackage name=\"" + mTestPackageBinaryName + "\"" 604 + " appPackageName=\"" + appPackageName + "\"" 605 + " version=\"1.0\" AndroidFramework=\"Android 1.0\"" 606 + " runner=\"android.test.InstrumentationTestRunner\" >\n" 607 + " <Description>something extracted from java doc</Description>\n" 608 + " <TestSuite name=\"com.google\">\n" 609 + " <TestCase name=\"CtsTestHello\" priority=\"mandatory\">\n" 610 + " <Description>" + "something extracted from java doc" 611 + " </Description>\n" 612 + " <!-- Test Methods -->\n" 613 + " <Test name=\"testHello\"" + " type=\"automatic\"" + "/>\n" 614 + " <Test name=\"testHello2\"" + " type=\"automatic\"" + "/>\n" 615 + " </TestCase>\n" 616 + " <TestSuite name=\"TestSuiteName\">\n" 617 + " <TestCase name=\"TestCaseName\" priority=\"mandatory\">\n" 618 + " <Description>" + "something extracted from java doc" 619 + " </Description>\n" 620 + " <!-- Test Methods -->\n" 621 + " <Test name=\"testName1\"" + " type=\"automatic\"" + "/>\n" 622 + " <Test name=\"testName2\"" + " type=\"automatic\"" + "/>\n" 623 + " </TestCase>\n" 624 + " </TestSuite>\n" 625 + " </TestSuite>\n" 626 + "</TestPackage>\n"; 627 628 HostConfig.getInstance().removeTestPacakges(); 629 createTestPackage(descriptionConfigStr, mTestPackageBinaryName); 630 HostConfig.getInstance().loadTestPackages(); 631 632 ArrayList<String> packageNames = new ArrayList<String>(); 633 packageNames.add(appPackageName); 634 635 HashMap<String, ArrayList<String>> results = new HashMap<String, ArrayList<String>>(); 636 ArrayList<String> list = new ArrayList<String>(); 637 list.add(excludedList); 638 results.put(appPackageName, list); 639 String planName = "plan_test_excluding"; 640 String planPath = HostConfig.getInstance().getPlanRepository().getPlanPath(planName); 641 TestSessionBuilder.getInstance().serialize(planName, packageNames, results); 642 643 TestSession ts = TestSessionBuilder.getInstance().build(planPath); 644 assertEquals(1, ts.getNumOfRequiredDevices()); 645 646 TestSessionLog tsl = ts.getSessionLog(); 647 assertEquals(1, tsl.getTestPackages().size()); 648 649 TestPackage testPackage = tsl.getTestPackages().iterator().next(); 650 assertEquals(0, testPackage.getTestSuites().size()); 651 assertEquals(mTestPackageBinaryName, testPackage.getAppBinaryName()); 652 assertEquals("1.0", testPackage.getVersion()); 653 assertEquals("Android 1.0", testPackage.getAndroidVersion()); 654 655 deleteTestPackage(mTestPackageBinaryName); 656 } 657 658 /** 659 * Test building and loading plan with excluded list of test case. 660 */ 661 public void testExcludingTestCase() throws IOException, 662 ParserConfigurationException, SAXException, TestPlanNotFoundException, 663 TestNotFoundException, 664 TransformerFactoryConfigurationError, TransformerException, NoSuchAlgorithmException { 665 666 final String appPackageName = "com.google.android.cts"; 667 final String caseName = "CtsTestHello"; 668 final String testName = "testHello"; 669 final String excludedList = "com.google.TestCaseName"; 670 671 final String descriptionConfigStr = "<TestPackage name=\"" + mTestPackageBinaryName + "\"" 672 + " appPackageName=\"" + appPackageName + "\"" 673 + " version=\"1.0\" AndroidFramework=\"Android 1.0\"" 674 + " runner=\"android.test.InstrumentationTestRunner\" >\n" 675 + " <Description>something extracted from java doc</Description>\n" 676 + " <TestSuite name=\"com.google\">\n" 677 + " <TestCase name=\"CtsTestHello\" priority=\"mandatory\">\n" 678 + " <Description>" + "something extracted from java doc" 679 + " </Description>\n" 680 + " <!-- Test Methods -->\n" 681 + " <Test name=\"testHello\"" + " type=\"automatic\"" + "/>\n" 682 + " <Test name=\"testHello2\"" + " type=\"automatic\"" + "/>\n" 683 + " </TestCase>\n" 684 + " <TestCase name=\"TestCaseName\" priority=\"mandatory\">\n" 685 + " <Description>" + "something extracted from java doc" 686 + " </Description>\n" 687 + " <!-- Test Methods -->\n" 688 + " <Test name=\"testName1\"" + " type=\"automatic\"" + "/>\n" 689 + " <Test name=\"testName2\"" + " type=\"automatic\"" + "/>\n" 690 + " </TestCase>\n" 691 + " </TestSuite>\n" 692 + "</TestPackage>\n"; 693 694 HostConfig.getInstance().removeTestPacakges(); 695 createTestPackage(descriptionConfigStr, mTestPackageBinaryName); 696 HostConfig.getInstance().loadTestPackages(); 697 698 ArrayList<String> packageNames = new ArrayList<String>(); 699 packageNames.add(appPackageName); 700 701 HashMap<String, ArrayList<String>> results = new HashMap<String, ArrayList<String>>(); 702 ArrayList<String> list = new ArrayList<String>(); 703 list.add(excludedList); 704 results.put(appPackageName, list); 705 String planName = "plan_test_excluding"; 706 String planPath = HostConfig.getInstance().getPlanRepository().getPlanPath(planName); 707 TestSessionBuilder.getInstance().serialize(planName, packageNames, results); 708 709 TestSession ts = TestSessionBuilder.getInstance().build(planPath); 710 assertEquals(1, ts.getNumOfRequiredDevices()); 711 712 TestSessionLog tsl = ts.getSessionLog(); 713 assertEquals(1, tsl.getTestPackages().size()); 714 715 TestPackage testPackage = tsl.getTestPackages().iterator().next(); 716 assertEquals(1, testPackage.getTestSuites().size()); 717 assertEquals(mTestPackageBinaryName, testPackage.getAppBinaryName()); 718 assertEquals("1.0", testPackage.getVersion()); 719 assertEquals("Android 1.0", testPackage.getAndroidVersion()); 720 721 TestSuite testSuite; 722 testSuite = testPackage.getTestSuites().iterator().next(); 723 assertEquals(1, testSuite.getTestCases().size()); 724 assertEquals("com.google", testSuite.getFullName()); 725 726 assertEquals(1, testSuite.getTestCases().size()); 727 728 TestCase testCase = testSuite.getTestCases().iterator().next(); 729 assertEquals(caseName, testCase.getName()); 730 assertEquals("mandatory", testCase.getPriority()); 731 732 Test test = testCase.getTests().iterator().next(); 733 assertEquals("com.google.CtsTestHello#testHello", test.getFullName()); 734 assertEquals("automatic", test.getType()); 735 assertEquals(testName, test.getName()); 736 assertEquals(CtsTestResult.CODE_NOT_EXECUTED, test.getResult().getResultCode()); 737 738 deleteTestPackage(mTestPackageBinaryName); 739 } 740 741 /** 742 * Test building and loading plan with excluded list of all of the test cases. 743 */ 744 public void testExcludingAllTestCases() throws IOException, 745 ParserConfigurationException, SAXException, TestPlanNotFoundException, 746 TestNotFoundException, 747 TransformerFactoryConfigurationError, TransformerException, NoSuchAlgorithmException { 748 749 final String appPackageName = "com.google.android.cts"; 750 final String excludedList = "com.google.TestCaseName;com.google.CtsTestHello"; 751 752 final String descriptionConfigStr = "<TestPackage name=\"" + mTestPackageBinaryName + "\"" 753 + " appPackageName=\"" + appPackageName + "\"" 754 + " version=\"1.0\" AndroidFramework=\"Android 1.0\"" 755 + " runner=\"android.test.InstrumentationTestRunner\" >\n" 756 + " <Description>something extracted from java doc</Description>\n" 757 + " <TestSuite name=\"com.google\">\n" 758 + " <TestCase name=\"CtsTestHello\" priority=\"mandatory\">\n" 759 + " <Description>" + "something extracted from java doc" 760 + " </Description>\n" 761 + " <!-- Test Methods -->\n" 762 + " <Test name=\"testHello\"" + " type=\"automatic\"" + "/>\n" 763 + " <Test name=\"testHello2\"" + " type=\"automatic\"" + "/>\n" 764 + " </TestCase>\n" 765 + " <TestCase name=\"TestCaseName\" priority=\"mandatory\">\n" 766 + " <Description>" + "something extracted from java doc" 767 + " </Description>\n" 768 + " <!-- Test Methods -->\n" 769 + " <Test name=\"testName1\"" + " type=\"automatic\"" + "/>\n" 770 + " <Test name=\"testName2\"" + " type=\"automatic\"" + "/>\n" 771 + " </TestCase>\n" 772 + " </TestSuite>\n" 773 + "</TestPackage>\n"; 774 775 HostConfig.getInstance().removeTestPacakges(); 776 createTestPackage(descriptionConfigStr, mTestPackageBinaryName); 777 HostConfig.getInstance().loadTestPackages(); 778 779 ArrayList<String> packageNames = new ArrayList<String>(); 780 packageNames.add(appPackageName); 781 782 HashMap<String, ArrayList<String>> results = new HashMap<String, ArrayList<String>>(); 783 ArrayList<String> list = new ArrayList<String>(); 784 list.add(excludedList); 785 results.put(appPackageName, list); 786 String planName = "plan_test_excluding"; 787 String planPath = HostConfig.getInstance().getPlanRepository().getPlanPath(planName); 788 TestSessionBuilder.getInstance().serialize(planName, packageNames, results); 789 790 TestSession ts = TestSessionBuilder.getInstance().build(planPath); 791 assertEquals(1, ts.getNumOfRequiredDevices()); 792 793 TestSessionLog tsl = ts.getSessionLog(); 794 assertEquals(1, tsl.getTestPackages().size()); 795 796 TestPackage testPackage = tsl.getTestPackages().iterator().next(); 797 assertEquals(0, testPackage.getTestSuites().size()); 798 assertEquals(mTestPackageBinaryName, testPackage.getAppBinaryName()); 799 assertEquals("1.0", testPackage.getVersion()); 800 assertEquals("Android 1.0", testPackage.getAndroidVersion()); 801 802 assertEquals(0, testPackage.getTestSuites().size()); 803 804 deleteTestPackage(mTestPackageBinaryName); 805 } 806 807 /** 808 * Test building and loading plan with excluded list of test. 809 */ 810 public void testExcludingTest() throws IOException, 811 ParserConfigurationException, SAXException, TestPlanNotFoundException, 812 TestNotFoundException, 813 TransformerFactoryConfigurationError, TransformerException, NoSuchAlgorithmException { 814 815 final String appPackageName = "com.google.android.cts"; 816 final String caseName = "CtsTestHello"; 817 final String testName = "testHello"; 818 final String excludedList = "com.google.CtsTestHello#testHello2"; 819 820 final String descriptionConfigStr = "<TestPackage name=\"" + mTestPackageBinaryName + "\"" 821 + " appPackageName=\"" + appPackageName + "\"" 822 + " version=\"1.0\" AndroidFramework=\"Android 1.0\"" 823 + " runner=\"android.test.InstrumentationTestRunner\" >\n" 824 + " <Description>something extracted from java doc</Description>\n" 825 + " <TestSuite name=\"com.google\">\n" 826 + " <TestCase name=\"CtsTestHello\" priority=\"mandatory\">\n" 827 + " <Description>" + "something extracted from java doc" 828 + " </Description>\n" 829 + " <!-- Test Methods -->\n" 830 + " <Test name=\"testHello\"" + " type=\"automatic\"" + "/>\n" 831 + " <Test name=\"testHello2\"" + " type=\"automatic\"" + "/>\n" 832 + " </TestCase>\n" 833 + " </TestSuite>\n" 834 + "</TestPackage>\n"; 835 836 HostConfig.getInstance().removeTestPacakges(); 837 createTestPackage(descriptionConfigStr, mTestPackageBinaryName); 838 HostConfig.getInstance().loadTestPackages(); 839 840 ArrayList<String> packageNames = new ArrayList<String>(); 841 packageNames.add(appPackageName); 842 843 HashMap<String, ArrayList<String>> results = new HashMap<String, ArrayList<String>>(); 844 ArrayList<String> list = new ArrayList<String>(); 845 list.add(excludedList); 846 results.put(appPackageName, list); 847 String planName = "plan_test_excluding"; 848 String planPath = HostConfig.getInstance().getPlanRepository().getPlanPath(planName); 849 TestSessionBuilder.getInstance().serialize(planName, packageNames, results); 850 851 TestSession ts = TestSessionBuilder.getInstance().build(planPath); 852 assertEquals(1, ts.getNumOfRequiredDevices()); 853 854 TestSessionLog tsl = ts.getSessionLog(); 855 assertEquals(1, tsl.getTestPackages().size()); 856 857 TestPackage testPackage = tsl.getTestPackages().iterator().next(); 858 assertEquals(1, testPackage.getTestSuites().size()); 859 assertEquals(mTestPackageBinaryName, testPackage.getAppBinaryName()); 860 assertEquals("1.0", testPackage.getVersion()); 861 assertEquals("Android 1.0", testPackage.getAndroidVersion()); 862 863 TestSuite testSuite; 864 testSuite = testPackage.getTestSuites().iterator().next(); 865 assertEquals(1, testSuite.getTestCases().size()); 866 assertEquals("com.google", testSuite.getFullName()); 867 868 assertEquals(1, testSuite.getTestCases().size()); 869 870 TestCase testCase = testSuite.getTestCases().iterator().next(); 871 assertEquals(caseName, testCase.getName()); 872 assertEquals("mandatory", testCase.getPriority()); 873 874 Test test = testCase.getTests().iterator().next(); 875 assertEquals("com.google.CtsTestHello#testHello", test.getFullName()); 876 assertEquals("automatic", test.getType()); 877 assertEquals(testName, test.getName()); 878 assertEquals(CtsTestResult.CODE_NOT_EXECUTED, test.getResult().getResultCode()); 879 880 deleteTestPackage(mTestPackageBinaryName); 881 } 882 883 /** 884 * Test building and loading plan with excluded list of all of the tests. 885 */ 886 public void testExcludingAllTests() throws IOException, 887 ParserConfigurationException, SAXException, TestPlanNotFoundException, 888 TestNotFoundException, 889 TransformerFactoryConfigurationError, TransformerException, NoSuchAlgorithmException { 890 891 final String appPackageName = "com.google.android.cts"; 892 final String excludedList = 893 "com.google.CtsTestHello#testHello;com.google.CtsTestHello#testHello2;"; 894 895 final String descriptionConfigStr = "<TestPackage name=\"" + mTestPackageBinaryName + "\"" 896 + " appPackageName=\"" + appPackageName + "\"" 897 + " version=\"1.0\" AndroidFramework=\"Android 1.0\"" 898 + " runner=\"android.test.InstrumentationTestRunner\" >\n" 899 + " <Description>something extracted from java doc</Description>\n" 900 + " <TestSuite name=\"com.google\">\n" 901 + " <TestCase name=\"CtsTestHello\" priority=\"mandatory\">\n" 902 + " <Description>" + "something extracted from java doc" 903 + " </Description>\n" 904 + " <!-- Test Methods -->\n" 905 + " <Test name=\"testHello\"" + " type=\"automatic\"" + "/>\n" 906 + " <Test name=\"testHello2\"" + " type=\"automatic\"" + "/>\n" 907 + " </TestCase>\n" 908 + " </TestSuite>\n" 909 + "</TestPackage>\n"; 910 911 HostConfig.getInstance().removeTestPacakges(); 912 createTestPackage(descriptionConfigStr, mTestPackageBinaryName); 913 HostConfig.getInstance().loadTestPackages(); 914 915 ArrayList<String> packageNames = new ArrayList<String>(); 916 packageNames.add(appPackageName); 917 918 HashMap<String, ArrayList<String>> results = new HashMap<String, ArrayList<String>>(); 919 ArrayList<String> list = new ArrayList<String>(); 920 list.add(excludedList); 921 results.put(appPackageName, list); 922 String planName = "plan_test_excluding"; 923 String planPath = HostConfig.getInstance().getPlanRepository().getPlanPath(planName); 924 TestSessionBuilder.getInstance().serialize(planName, packageNames, results); 925 926 TestSession ts = TestSessionBuilder.getInstance().build(planPath); 927 assertEquals(1, ts.getNumOfRequiredDevices()); 928 929 TestSessionLog tsl = ts.getSessionLog(); 930 assertEquals(1, tsl.getTestPackages().size()); 931 932 TestPackage testPackage = tsl.getTestPackages().iterator().next(); 933 assertEquals(0, testPackage.getTestSuites().size()); 934 assertEquals(mTestPackageBinaryName, testPackage.getAppBinaryName()); 935 assertEquals("1.0", testPackage.getVersion()); 936 assertEquals("Android 1.0", testPackage.getAndroidVersion()); 937 938 deleteTestPackage(mTestPackageBinaryName); 939 } 940 941 /** 942 * Test creating plan with excluded list. 943 */ 944 public void testCreatePlanWithExcludedList() throws IOException, 945 ParserConfigurationException, SAXException, 946 TestPlanNotFoundException, TestNotFoundException, 947 TransformerFactoryConfigurationError, TransformerException, NoSuchAlgorithmException{ 948 949 final String appPackageName = "com.google.android.cts"; 950 final String suiteName1 = appPackageName + "." + "SuiteName1"; 951 final String caseName1 = "CtsTestHello"; 952 final String testName1 = "testHello"; 953 954 final String caseName2 = "CtsTestHello2"; 955 final String testName2 = "testHello2"; 956 final String testName3 = "testHello3"; 957 final String suiteName2 = "com.google.android.cts.CtsTest.SuiteName2"; 958 959 final String descriptionConfigStr = "<TestPackage name=\"" 960 + mTestPackageBinaryName + "\"" 961 + " appPackageName=\"" + appPackageName + "\"" 962 + " version=\"1.0\" AndroidFramework=\"Android 1.0\"" 963 + " runner=\"android.test.InstrumentationTestRunner\" >\n" 964 + " <Description>something extracted from java doc</Description>\n" 965 + " <TestSuite name=\"" + suiteName1 + "\"" + ">\n" 966 + " <TestCase name=\"" + caseName1 + "\"" + " category=\"mandatory\">\n" 967 + " <Description>" + "something extracted from java doc" 968 + " </Description>\n" 969 + " <!-- Test Methods -->\n" 970 + " <Test name=\"" + testName1 + "\" type=\"automatic\"" + "/>\n" 971 + " </TestCase>\n" 972 + " </TestSuite>\n" 973 + " <TestSuite name=\"" + suiteName2 + "\"" + ">\n" 974 + " <TestCase name=\"" + caseName2 + "\"" + " priority=\"mandatory\">\n" 975 + " <Test name=\"" + testName2 +"\" type=\"automatic\" />\n" 976 + " <Test name=\"" + testName3 +"\" type=\"automatic\" />\n" 977 + " </TestCase>\n" 978 + " </TestSuite>\n" 979 + "</TestPackage>\n"; 980 981 HostConfig.getInstance().removeTestPacakges(); 982 createTestPackage(descriptionConfigStr, mTestPackageBinaryName); 983 HostConfig.getInstance().loadTestPackages(); 984 985 ArrayList<String> packageNames = new ArrayList<String>(); 986 packageNames.add(appPackageName); 987 988 HashMap<String, ArrayList<String>> results = new HashMap<String, ArrayList<String>>(); 989 ArrayList<String> list = new ArrayList<String>(); 990 String excludedList = suiteName1 + "." + caseName1 + TestPlan.EXCLUDE_SEPARATOR; 991 excludedList += suiteName2 + "." + caseName2 + Test.METHOD_SEPARATOR + testName2; 992 list.add(excludedList); 993 results.put(appPackageName, list); 994 995 String planName = "plan_test_excluding"; 996 String planPath = HostConfig.getInstance().getPlanRepository().getPlanPath(planName); 997 TestSessionBuilder.getInstance().serialize(planName, packageNames, results); 998 999 TestSession ts = TestSessionBuilder.getInstance().build(planPath); 1000 assertEquals(1, ts.getNumOfRequiredDevices()); 1001 1002 TestSessionLog tsl = ts.getSessionLog(); 1003 assertEquals(1, tsl.getTestPackages().size()); 1004 1005 TestPackage testPackage = tsl.getTestPackages().iterator().next(); 1006 assertEquals(1, testPackage.getTestSuites().size()); 1007 assertEquals(mTestPackageBinaryName, testPackage.getAppBinaryName()); 1008 assertEquals("1.0", testPackage.getVersion()); 1009 assertEquals("Android 1.0", testPackage.getAndroidVersion()); 1010 1011 TestSuite testSuite; 1012 testSuite = testPackage.getTestSuites().iterator().next(); 1013 assertEquals(1, testSuite.getTestCases().size()); 1014 assertEquals(suiteName2, testSuite.getFullName()); 1015 1016 assertEquals(1, testSuite.getTestCases().size()); 1017 1018 TestCase testCase = testSuite.getTestCases().iterator().next(); 1019 assertEquals(caseName2, testCase.getName()); 1020 assertEquals("mandatory", testCase.getPriority()); 1021 assertEquals(1, testCase.getTests().size()); 1022 1023 Test test = testCase.getTests().iterator().next(); 1024 String testName = suiteName2 + "." + caseName2 + Test.METHOD_SEPARATOR + testName3; 1025 assertEquals(testName, test.getFullName()); 1026 assertEquals("automatic", test.getType()); 1027 assertEquals(CtsTestResult.CODE_NOT_EXECUTED, test.getResult().getResultCode()); 1028 1029 deleteTestPackage(mTestPackageBinaryName); 1030 } 1031 1032 /** 1033 * Test creating plan with excluded list of nested suites. 1034 */ 1035 public void testCreatePlanWithExcludedListForNestedSuite() throws IOException, 1036 ParserConfigurationException, SAXException, 1037 TestPlanNotFoundException, TestNotFoundException, 1038 TransformerFactoryConfigurationError, TransformerException, NoSuchAlgorithmException{ 1039 1040 final String appPackageName = "com.google.android.cts"; 1041 final String fullName = mTestPackageBinaryName + ".CtsTest"; 1042 final String suiteName1 = fullName + "." + "SuiteName1"; 1043 final String caseName1 = "CtsTestHello"; 1044 final String testName1 = "testHello"; 1045 1046 final String caseName2 = "CtsTestHello2"; 1047 final String testName2 = "testHello2"; 1048 final String testName3 = "testHello3"; 1049 final String nestedSuiteName1 = "com.google"; 1050 final String nestedSuiteName2 = "android.cts.CtsTest.SuiteName2"; 1051 1052 final String descriptionConfigStr = "<TestPackage name=\"" 1053 + mTestPackageBinaryName + "\"" 1054 + " appPackageName=\"" + appPackageName + "\"" 1055 + " version=\"1.0\" AndroidFramework=\"Android 1.0\"" 1056 + " runner=\"android.test.InstrumentationTestRunner\" >\n" 1057 + " <Description>something extracted from java doc</Description>\n" 1058 + " <TestSuite name=\"" + suiteName1 + "\"" + ">\n" 1059 + " <TestCase name=\"" + caseName1 + "\"" + " category=\"mandatory\">\n" 1060 + " <Description>" + "something extracted from java doc" + "</Description>\n" 1061 + " <!-- Test Methods -->\n" 1062 + " <Test name=\"" + testName1 + "\" type=\"automatic\"" + "/>\n" 1063 + " </TestCase>\n" 1064 + " </TestSuite>\n" 1065 + " <TestSuite name=\"" + nestedSuiteName1 + "\"" + ">\n" 1066 + " <TestSuite name=\"" + nestedSuiteName2 + "\"" + ">\n" 1067 + " <TestCase name=\"" + caseName2 + "\"" + " priority=\"mandatory\">\n" 1068 + " <Test name=\"" + testName2 +"\" type=\"automatic\" />\n" 1069 + " <Test name=\"" + testName3 +"\" type=\"automatic\" />\n" 1070 + " </TestCase>\n" 1071 + " </TestSuite>\n" 1072 + " </TestSuite>\n" 1073 + "</TestPackage>\n"; 1074 1075 HostConfig.getInstance().removeTestPacakges(); 1076 createTestPackage(descriptionConfigStr, mTestPackageBinaryName); 1077 HostConfig.getInstance().loadTestPackages(); 1078 1079 ArrayList<String> packageNames = new ArrayList<String>(); 1080 packageNames.add(appPackageName); 1081 1082 HashMap<String, ArrayList<String>> results = new HashMap<String, ArrayList<String>>(); 1083 ArrayList<String> list = new ArrayList<String>(); 1084 String excludedList = suiteName1 + "." + caseName1 + TestPlan.EXCLUDE_SEPARATOR; 1085 excludedList += nestedSuiteName1 + "." + nestedSuiteName2 1086 + "." + caseName2 + Test.METHOD_SEPARATOR + testName2; 1087 list.add(excludedList); 1088 results.put(appPackageName, list); 1089 1090 String planName = "plan_test_excluding"; 1091 String planPath = HostConfig.getInstance().getPlanRepository().getPlanPath(planName); 1092 TestSessionBuilder.getInstance().serialize(planName, packageNames, results); 1093 1094 TestSession ts = TestSessionBuilder.getInstance().build(planPath); 1095 assertEquals(1, ts.getNumOfRequiredDevices()); 1096 1097 TestSessionLog tsl = ts.getSessionLog(); 1098 assertEquals(1, tsl.getTestPackages().size()); 1099 1100 TestPackage testPackage = tsl.getTestPackages().iterator().next(); 1101 assertEquals(1, testPackage.getTestSuites().size()); 1102 assertEquals(mTestPackageBinaryName, testPackage.getAppBinaryName()); 1103 assertEquals("1.0", testPackage.getVersion()); 1104 assertEquals("Android 1.0", testPackage.getAndroidVersion()); 1105 1106 TestSuite testSuite; 1107 testSuite = testPackage.getTestSuites().iterator().next(); 1108 assertEquals(0, testSuite.getTestCases().size()); 1109 assertEquals(nestedSuiteName1, testSuite.getFullName()); 1110 1111 assertEquals(1, testSuite.getSubSuites().size()); 1112 TestSuite testSubSuite = testSuite.getSubSuites().iterator().next(); 1113 assertEquals(1, testSubSuite.getTestCases().size()); 1114 String suiteName = nestedSuiteName1 + "." + nestedSuiteName2; 1115 assertEquals(suiteName, testSubSuite.getFullName()); 1116 1117 assertEquals(1, testSubSuite.getTestCases().size()); 1118 1119 TestCase testCase = testSubSuite.getTestCases().iterator().next(); 1120 assertEquals(caseName2, testCase.getName()); 1121 assertEquals("mandatory", testCase.getPriority()); 1122 assertEquals(1, testCase.getTests().size()); 1123 1124 Test test = testCase.getTests().iterator().next(); 1125 String testName = nestedSuiteName1 + "." + nestedSuiteName2 + "." +caseName2 1126 + Test.METHOD_SEPARATOR + testName3; 1127 assertEquals(testName, test.getFullName()); 1128 assertEquals("automatic", test.getType()); 1129 assertEquals(CtsTestResult.CODE_NOT_EXECUTED, test.getResult().getResultCode()); 1130 1131 deleteTestPackage(mTestPackageBinaryName); 1132 } 1133 1134 /** 1135 * Test building plan of protocol type. 1136 */ 1137 public void testBuildProtocolPlan() throws IOException, 1138 ParserConfigurationException, SAXException, TestPlanNotFoundException, 1139 TestNotFoundException, NoSuchAlgorithmException { 1140 1141 final String appPackageName = "com.google.android.cts"; 1142 1143 final String testPlanConfigStr = "<TestPlan version=\"1.0\">\n" 1144 + "\t<Description>Demo test plan</Description>\n" 1145 + "\t\t<PlanSettings>\n" 1146 + "\t\t\t<RequiredDevice amount=\"" + 2 + "\"" + "/>\n" 1147 + "\t\t</PlanSettings>\n" 1148 + "\t<Entry uri=\"" 1149 + appPackageName 1150 + "\"/>\n" 1151 + "</TestPlan>"; 1152 1153 final String descriptionConfigStr = "<TestPackage name=\"" + mTestPackageBinaryName +"\" " 1154 + " appPackageName=\"" + appPackageName + "\"" 1155 + " version=\"1.0\" AndroidFramework=\"Android 1.0\"" 1156 + " runner=\"android.test.InstrumentationTestRunner\" >\n" 1157 + " <Description>something extracted from java doc</Description>\n" 1158 + " <TestSuite name=\"com.google.android.cts\"" + ">\n" 1159 + " <TestCase name=\"CtsTestHello\"" + " priority=\"mandatory\">\n" 1160 + " <Description>" + "something extracted from java doc" 1161 + " </Description>\n" 1162 + " <Test name=\"testHello\"" + " type=\"automatic\"" + "/>\n" 1163 + " </TestCase>\n" 1164 + " </TestSuite>\n" 1165 + "</TestPackage>\n"; 1166 1167 HostConfig.getInstance().removeTestPacakges(); 1168 String planPath = HostConfig.getInstance().getPlanRepository() 1169 .getPlanPath(mTmpPlanFileName); 1170 createFile(testPlanConfigStr, planPath); 1171 1172 createTestPackage(descriptionConfigStr, mTestPackageBinaryName); 1173 HostConfig.getInstance().loadTestPackages(); 1174 1175 TestSession ts = TestSessionBuilder.getInstance().build(planPath); 1176 assertEquals(2, ts.getNumOfRequiredDevices()); 1177 1178 TestSessionLog tsl = ts.getSessionLog(); 1179 assertEquals(1, tsl.getTestPackages().size()); 1180 1181 TestPackage testPackage = tsl.getTestPackages().iterator().next(); 1182 assertEquals(1, testPackage.getTestSuites().size()); 1183 assertEquals(mTestPackageBinaryName, testPackage.getAppBinaryName()); 1184 assertEquals("1.0", testPackage.getVersion()); 1185 assertEquals("Android 1.0", testPackage.getAndroidVersion()); 1186 1187 TestSuite testSuite = testPackage.getTestSuites().iterator().next(); 1188 assertEquals(1, testSuite.getTestCases().size()); 1189 assertEquals("com.google.android.cts", testSuite.getFullName()); 1190 1191 TestCase testCase = testSuite.getTestCases().iterator().next(); 1192 Test test = testCase.getTests().iterator().next(); 1193 assertEquals("testHello", test.getName()); 1194 assertEquals("automatic", test.getType()); 1195 assertEquals(CtsTestResult.CODE_NOT_EXECUTED, test.getResult().getResultCode()); 1196 1197 deleteTestPackage(mTestPackageBinaryName); 1198 } 1199 1200 /** 1201 * Test serializing the test plan. 1202 */ 1203 public void testSerialize() throws Exception { 1204 final String srcStr = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" 1205 + "<TestPlan version=\"1.0\">\n" 1206 + "<PlanSettings/>\n" 1207 + "<Entry uri=\"com.google.android.cts.CtsTest\"/>\n" 1208 + "</TestPlan>"; 1209 1210 final String package1 = "com.google.android.cts.CtsTest"; 1211 ArrayList<String> packageNames = new ArrayList<String>(); 1212 packageNames.add(package1); 1213 HashMap<String, ArrayList<String>> selectedResult = 1214 new HashMap<String, ArrayList<String>>(); 1215 selectedResult.put(package1, null); 1216 1217 HostConfig.getInstance().removeTestPacakges(); 1218 String planName = "plan_test"; 1219 String planPath = HostConfig.getInstance().getPlanRepository().getPlanPath(planName); 1220 TestSessionBuilder.getInstance().serialize(planName, packageNames, selectedResult); 1221 1222 File file = new File(planPath); 1223 assertTrue(file.exists()); 1224 assertTrue(file.isFile()); 1225 1226 FileReader dstInput = new FileReader(file); 1227 BufferedReader dstBufReader = new BufferedReader(dstInput); 1228 1229 char[] resChars = new char[1024]; 1230 dstBufReader.read(resChars); 1231 assertEquals(srcStr, new String(resChars).trim()); 1232 1233 dstBufReader.close(); 1234 deleteFile(planPath); 1235 1236 } 1237 1238 /** 1239 * Test loading plan with sub suites. 1240 */ 1241 public void testLoadPlanWithSubSuite() throws IOException, 1242 ParserConfigurationException, SAXException, TestPlanNotFoundException, 1243 TestNotFoundException, 1244 TransformerFactoryConfigurationError, TransformerException, NoSuchAlgorithmException { 1245 1246 final String appPackageName = "com.google.android.cts"; 1247 final String fullName = mTestPackageBinaryName + ".CtsTest"; 1248 final String caseName = "CtsTestHello"; 1249 final String testName = "testHello"; 1250 1251 final String descriptionConfigStr = "<TestPackage name=\"" + mTestPackageBinaryName + "\"" 1252 + " appPackageName=\"" + appPackageName + "\"" 1253 + " version=\"1.0\" AndroidFramework=\"Android 1.0\"" 1254 + " runner=\"android.test.InstrumentationTestRunner\" >\n" 1255 + " <Description>something extracted from java doc</Description>\n" 1256 + " <TestSuite name=\"com.google\">\n" 1257 + " <TestCase name=\"CtsTestHello\" priority=\"mandatory\">\n" 1258 + " <Description>" + "something extracted from java doc" 1259 + " </Description>\n" 1260 + " <!-- Test Methods -->\n" 1261 + " <Test name=\"testHello\"" + " type=\"automatic\"" + "/>\n" 1262 + " </TestCase>\n" 1263 + " <TestSuite name=\"TestSuiteName\">\n" 1264 + " <TestCase name=\"TestCaseName\" priority=\"mandatory\">\n" 1265 + " <Description>" + "something extracted from java doc" 1266 + " </Description>\n" 1267 + " <!-- Test Methods -->\n" 1268 + " <Test name=\"testName1\"" + " type=\"automatic\"" + "/>\n" 1269 + " </TestCase>\n" 1270 + " </TestSuite>\n" 1271 + " </TestSuite>\n" 1272 + "</TestPackage>\n"; 1273 1274 HostConfig.getInstance().removeTestPacakges(); 1275 createTestPackage(descriptionConfigStr, mTestPackageBinaryName); 1276 HostConfig.getInstance().loadTestPackages(); 1277 1278 ArrayList<String> packageNames = new ArrayList<String>(); 1279 packageNames.add(appPackageName); 1280 1281 HashMap<String, ArrayList<String>> results = new HashMap<String, ArrayList<String>>(); 1282 results.put(appPackageName, null); 1283 String planName = "plan_test_excluding"; 1284 String planPath = HostConfig.getInstance().getPlanRepository().getPlanPath(planName); 1285 TestSessionBuilder.getInstance().serialize(planName, packageNames, results); 1286 1287 TestSession ts = TestSessionBuilder.getInstance().build(planPath); 1288 assertEquals(1, ts.getNumOfRequiredDevices()); 1289 1290 ts.getSessionLog().setStartTime(System.currentTimeMillis()); 1291 TestSessionLog tsl = ts.getSessionLog(); 1292 tsl.createResultDoc(); 1293 assertEquals(1, tsl.getTestPackages().size()); 1294 1295 TestPackage testPackage = tsl.getTestPackages().iterator().next(); 1296 assertEquals(1, testPackage.getTestSuites().size()); 1297 assertEquals(mTestPackageBinaryName, testPackage.getAppBinaryName()); 1298 assertEquals("1.0", testPackage.getVersion()); 1299 assertEquals("Android 1.0", testPackage.getAndroidVersion()); 1300 1301 TestSuite testSuite; 1302 testSuite = testPackage.getTestSuites().iterator().next(); 1303 assertEquals(1, testSuite.getSubSuites().size()); 1304 assertEquals(1, testSuite.getTestCases().size()); 1305 assertEquals("com.google", testSuite.getFullName()); 1306 1307 TestCase testCase = testSuite.getTestCases().iterator().next(); 1308 assertEquals(caseName, testCase.getName()); 1309 assertEquals("mandatory", testCase.getPriority()); 1310 1311 Test test = testCase.getTests().iterator().next(); 1312 assertEquals("com.google.CtsTestHello#testHello", test.getFullName()); 1313 assertEquals("automatic", test.getType()); 1314 assertEquals(testName, test.getName()); 1315 assertEquals(CtsTestResult.CODE_NOT_EXECUTED, test.getResult().getResultCode()); 1316 1317 TestSuite subTestSuite; 1318 subTestSuite = testSuite.getSubSuites().iterator().next(); 1319 assertEquals(1, subTestSuite.getTestCases().size()); 1320 assertEquals("com.google.TestSuiteName", subTestSuite.getFullName()); 1321 assertEquals("TestSuiteName", subTestSuite.getName()); 1322 1323 testCase = subTestSuite.getTestCases().iterator().next(); 1324 assertEquals("TestCaseName", testCase.getName()); 1325 assertEquals("mandatory", testCase.getPriority()); 1326 1327 test = testCase.getTests().iterator().next(); 1328 assertEquals("com.google.TestSuiteName.TestCaseName#testName1", test.getFullName()); 1329 assertEquals("automatic", test.getType()); 1330 assertEquals("testName1", test.getName()); 1331 assertEquals(CtsTestResult.CODE_NOT_EXECUTED, test.getResult().getResultCode()); 1332 1333 deleteTestPackage(mTestPackageBinaryName); 1334 } 1335 1336 /** 1337 * Test validating test controller. 1338 */ 1339 public void testValidateTestController() { 1340 String jarPath = "test.jar"; 1341 String packageName = "com.android.tests"; 1342 String className = "ConsoleTests"; 1343 String methodName = "testMethod"; 1344 1345 TestController controller = new TestController(null, null, null, null); 1346 assertFalse(controller.isValid()); 1347 1348 controller = new TestController(jarPath, null, null, null); 1349 assertFalse(controller.isValid()); 1350 1351 controller = new TestController(null, packageName, null, null); 1352 assertFalse(controller.isValid()); 1353 1354 controller = new TestController(null, null, className, null); 1355 assertFalse(controller.isValid()); 1356 1357 controller = new TestController(null, null, null, methodName); 1358 assertFalse(controller.isValid()); 1359 1360 controller = new TestController("", "", "", ""); 1361 assertFalse(controller.isValid()); 1362 1363 controller = new TestController("", packageName, className, methodName); 1364 assertFalse(controller.isValid()); 1365 1366 controller = new TestController(jarPath, "", className, methodName); 1367 assertFalse(controller.isValid()); 1368 1369 controller = new TestController(jarPath, packageName, "", methodName); 1370 assertFalse(controller.isValid()); 1371 1372 controller = new TestController(jarPath, packageName, className, ""); 1373 assertFalse(controller.isValid()); 1374 1375 controller = new TestController(jarPath, packageName, className, methodName); 1376 assertTrue(controller.isValid()); 1377 } 1378 1379 /** 1380 * Test loading plan with test controller. 1381 */ 1382 public void testLoadPlanWithTestController() throws IOException, 1383 ParserConfigurationException, SAXException, 1384 TestPlanNotFoundException, TestNotFoundException, 1385 TransformerFactoryConfigurationError, 1386 TransformerException, NoSuchAlgorithmException { 1387 1388 final String appPackageName = "com.google.android.cts"; 1389 final String jarPath = "test.jar"; 1390 final String controllerPackageName = "com.android.tests"; 1391 final String className = "ConsoleTests"; 1392 final String methodName = "testMethod"; 1393 final String description = controllerPackageName + "." + className 1394 + Test.METHOD_SEPARATOR + methodName; 1395 1396 final String descriptionConfigStr = "<TestPackage name=\"" 1397 + mTestPackageBinaryName + "\" " 1398 + " appPackageName=\"" + appPackageName + "\"" 1399 + " version=\"1.0\" AndroidFramework=\"Android 1.0\"" 1400 + " runner=\"android.test.InstrumentationTestRunner\" jarPath=\"" + jarPath 1401 + "\">\n" 1402 + " <Description>something extracted from java doc</Description>\n" 1403 + " <TestSuite name=\"com.google\">\n" 1404 + " <TestCase name=\"TestCaseName\" priority=\"mandatory\">\n" 1405 + " <Description>" 1406 + "something extracted from java doc" + "</Description>\n" 1407 + " <!-- Test Methods -->\n" 1408 + " <Test name=\"testName1\"" 1409 + " type=\"automatic\"" + " HostController=\"" 1410 + description + "\"" + "/>\n" + " </TestCase>\n" 1411 + " </TestSuite>\n" + "</TestPackage>\n"; 1412 1413 createTestPackage(descriptionConfigStr, mTestPackageBinaryName); 1414 HostConfig.getInstance().loadTestPackages(); 1415 1416 ArrayList<String> packageNames = new ArrayList<String>(); 1417 packageNames.add(appPackageName); 1418 1419 HashMap<String, ArrayList<String>> results = new HashMap<String, ArrayList<String>>(); 1420 results.put(appPackageName, null); 1421 1422 String planName = "plan_test"; 1423 String planPath = HostConfig.getInstance().getPlanRepository().getPlanPath(planName); 1424 TestSessionBuilder.getInstance().serialize(planName, packageNames, results); 1425 1426 TestSession ts = TestSessionBuilder.getInstance().build(planPath); 1427 ts.getSessionLog().setStartTime(System.currentTimeMillis()); 1428 TestSessionLog tsl = ts.getSessionLog(); 1429 TestPackage testPackage = tsl.getTestPackages().iterator().next(); 1430 1431 assertEquals(jarPath, testPackage.getJarPath()); 1432 1433 TestSuite testSuite; 1434 testSuite = testPackage.getTestSuites().iterator().next(); 1435 TestCase testCase = testSuite.getTestCases().iterator().next(); 1436 Test test = testCase.getTests().iterator().next(); 1437 assertEquals(controllerPackageName, test.getTestController().getPackageName()); 1438 assertEquals(className, test.getTestController().getClassName()); 1439 assertEquals(methodName, test.getTestController().getMethodName()); 1440 1441 deleteTestPackage(mTestPackageBinaryName); 1442 } 1443 } 1444