1 /* 2 * Copyright (C) 2013 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 package android.os.cts; 17 18 import static org.junit.Assert.assertFalse; 19 import static org.junit.Assert.assertTrue; 20 import static org.junit.Assert.fail; 21 22 import android.os.WorkSource; 23 import android.platform.test.annotations.AppModeSdkSandbox; 24 25 import androidx.test.ext.junit.runners.AndroidJUnit4; 26 27 import com.android.compatibility.common.util.ApiTest; 28 29 import org.junit.Test; 30 import org.junit.runner.RunWith; 31 32 import java.util.Arrays; 33 34 @RunWith(AndroidJUnit4.class) 35 @AppModeSdkSandbox(reason = "Allow test in the SDK sandbox (does not prevent other modes).") 36 public class WorkSourceTest { wsNew(int uid)37 private WorkSource wsNew(int uid) { 38 return new WorkSource(uid); 39 } 40 wsNew(int[] uids)41 private WorkSource wsNew(int[] uids) { 42 WorkSource ws = new WorkSource(); 43 for (int i=0; i<uids.length; i++) { 44 ws.add(uids[i]); 45 } 46 checkWorkSource("Constructed", ws, uids); 47 return ws; 48 } 49 wsNew(int[] uids, String[] names)50 private WorkSource wsNew(int[] uids, String[] names) { 51 WorkSource ws = new WorkSource(); 52 for (int i=0; i<uids.length; i++) { 53 ws.add(uids[i], names[i]); 54 } 55 checkWorkSource("Constructed", ws, uids, names); 56 return ws; 57 } 58 wsAddReturningNewbs(WorkSource ws, WorkSource other)59 private WorkSource wsAddReturningNewbs(WorkSource ws, WorkSource other) { 60 return ws.addReturningNewbs(other); 61 } 62 wsSetReturningDiffs(WorkSource ws, WorkSource other)63 private WorkSource[] wsSetReturningDiffs(WorkSource ws, WorkSource other) { 64 return ws.setReturningDiffs(other); 65 } 66 printArrays(StringBuilder sb, int[] uids, String[] names)67 private void printArrays(StringBuilder sb, int[] uids, String[] names) { 68 sb.append("{ "); 69 for (int i=0; i<uids.length; i++) { 70 if (i > 0) sb.append(", "); 71 sb.append(uids[i]); 72 if (names != null) { 73 sb.append(" "); 74 sb.append(names[i]); 75 } 76 } 77 sb.append(" }"); 78 } 79 failWorkSource(String op, WorkSource ws, int[] uids)80 private void failWorkSource(String op, WorkSource ws, int[] uids) { 81 StringBuilder sb = new StringBuilder(); 82 sb.append(op); 83 sb.append(": Expected: "); 84 printArrays(sb, uids, null); 85 sb.append(", got: "); 86 sb.append(ws); 87 fail(sb.toString()); 88 } 89 failWorkSource(String op, WorkSource ws, int[] uids, String[] names)90 private void failWorkSource(String op, WorkSource ws, int[] uids, String[] names) { 91 StringBuilder sb = new StringBuilder(); 92 sb.append(op); 93 sb.append(": Expected: "); 94 printArrays(sb, uids, names); 95 sb.append(", got: "); 96 sb.append(ws); 97 fail(sb.toString()); 98 } 99 checkWorkSource(String op, WorkSource ws, int[] uids)100 private void checkWorkSource(String op, WorkSource ws, int[] uids) { 101 if (ws == null || uids == null) { 102 if (ws != null) { 103 fail(op + ": WorkSource is not null " + ws +", but expected null"); 104 } 105 if (uids != null) { 106 fail(op + "WorkSource is null, but expected non-null: " + Arrays.toString(uids)); 107 } 108 return; 109 } 110 if (ws.size() != uids.length) { 111 failWorkSource(op, ws, uids); 112 } 113 for (int i=0; i<uids.length; i++) { 114 if (uids[i] != ws.getUid(i)) { 115 failWorkSource(op, ws, uids); 116 } 117 } 118 } 119 checkWorkSource(String op, WorkSource ws, int[] uids, String[] names)120 private void checkWorkSource(String op, WorkSource ws, int[] uids, String[] names) { 121 if (ws == null || uids == null) { 122 if (ws != null) { 123 fail(op + ": WorkSource is not null " + ws +", but expected null"); 124 } 125 if (uids != null) { 126 fail(op + "WorkSource is null, but expected non-null: " + Arrays.toString(uids)); 127 } 128 return; 129 } 130 if (ws.size() != uids.length) { 131 failWorkSource(op, ws, uids, names); 132 } 133 for (int i=0; i<uids.length; i++) { 134 if (uids[i] != ws.getUid(i) || !names[i].equals(ws.getPackageName(i))) { 135 failWorkSource(op, ws, uids, names); 136 } 137 } 138 } 139 140 @Test testConstructEmpty()141 public void testConstructEmpty() { 142 checkWorkSource("Empty", new WorkSource(), new int[] { }); 143 } 144 145 @Test testConstructSingle()146 public void testConstructSingle() throws Exception { 147 checkWorkSource("Single 1", wsNew(1), new int[] { 1 }); 148 } 149 150 @ApiTest(apis = {"android.os.WorkSource#add"}) 151 @Test testAddRawOrdered()152 public void testAddRawOrdered() throws Exception { 153 WorkSource ws = wsNew(1); 154 ws.add(2); 155 checkWorkSource("First", ws, new int[] { 1 , 2 }); 156 ws.add(20); 157 checkWorkSource("Second", ws, new int[] { 1 , 2, 20 }); 158 ws.add(100); 159 checkWorkSource("Third", ws, new int[] { 1, 2, 20, 100 }); 160 } 161 162 @ApiTest(apis = {"android.os.WorkSource#add"}) 163 @Test testAddRawRevOrdered()164 public void testAddRawRevOrdered() throws Exception { 165 WorkSource ws = wsNew(100); 166 ws.add(20); 167 checkWorkSource("First", ws, new int[] { 20, 100 }); 168 ws.add(2); 169 checkWorkSource("Second", ws, new int[] { 2, 20, 100 }); 170 ws.add(1); 171 checkWorkSource("Third", ws, new int[] { 1, 2, 20, 100 }); 172 } 173 174 @ApiTest(apis = {"android.os.WorkSource#add"}) 175 @Test testAddRawUnordered()176 public void testAddRawUnordered() throws Exception { 177 WorkSource ws = wsNew(10); 178 ws.add(2); 179 checkWorkSource("First", ws, new int[] { 2, 10 }); 180 ws.add(5); 181 checkWorkSource("Second", ws, new int[] { 2, 5, 10 }); 182 ws.add(1); 183 checkWorkSource("Third", ws, new int[] { 1, 2, 5, 10 }); 184 ws.add(100); 185 checkWorkSource("Fourth", ws, new int[] { 1, 2, 5, 10, 100 }); 186 } 187 188 @ApiTest(apis = {"android.os.WorkSource#add"}) 189 @Test testAddWsOrdered()190 public void testAddWsOrdered() throws Exception { 191 WorkSource ws = wsNew(1); 192 ws.add(wsNew(2)); 193 checkWorkSource("First", ws, new int[] { 1 , 2 }); 194 ws.add(wsNew(20)); 195 checkWorkSource("Second", ws, new int[] { 1 , 2, 20 }); 196 ws.add(wsNew(100)); 197 checkWorkSource("Third", ws, new int[] { 1 , 2, 20, 100 }); 198 } 199 200 @ApiTest(apis = {"android.os.WorkSource#add"}) 201 @Test testAddWsRevOrdered()202 public void testAddWsRevOrdered() throws Exception { 203 WorkSource ws = wsNew(100); 204 ws.add(wsNew(20)); 205 checkWorkSource("First", ws, new int[] { 20, 100 }); 206 ws.add(wsNew(2)); 207 checkWorkSource("Second", ws, new int[] { 2, 20, 100 }); 208 ws.add(wsNew(1)); 209 checkWorkSource("Third", ws, new int[] { 1, 2, 20, 100 }); 210 } 211 212 @ApiTest(apis = {"android.os.WorkSource#add"}) 213 @Test testAddWsUnordered()214 public void testAddWsUnordered() throws Exception { 215 WorkSource ws = wsNew(10); 216 ws.add(wsNew(2)); 217 checkWorkSource("First", ws, new int[] { 2, 10 }); 218 ws.add(wsNew(5)); 219 checkWorkSource("Second", ws, new int[] { 2, 5, 10 }); 220 ws.add(wsNew(1)); 221 checkWorkSource("Third", ws, new int[] { 1, 2, 5, 10 }); 222 ws.add(wsNew(100)); 223 checkWorkSource("Fourth", ws, new int[] { 1, 2, 5, 10, 100 }); 224 } 225 doTestCombineTwoUids(int[] lhs, int[] rhs, int[] expected, int[] newbs, int[] gones)226 private void doTestCombineTwoUids(int[] lhs, int[] rhs, int[] expected, int[] newbs, 227 int[] gones) throws Exception { 228 WorkSource ws1 = wsNew(lhs); 229 WorkSource ws2 = wsNew(rhs); 230 ws1.add(ws2); 231 checkWorkSource("Add result", ws1, expected); 232 ws1 = wsNew(lhs); 233 WorkSource wsNewbs = wsAddReturningNewbs(ws1, ws2); 234 checkWorkSource("AddReturning result", ws1, expected); 235 checkWorkSource("Newbs", wsNewbs, newbs); 236 ws1 = wsNew(lhs); 237 WorkSource[] res = wsSetReturningDiffs(ws1, ws2); 238 checkWorkSource("SetReturning result", ws1, rhs); 239 checkWorkSource("Newbs", res[0], newbs); 240 checkWorkSource("Gones", res[1], gones); 241 } 242 makeRepeatingIntArray(String[] stringarray, int value)243 private int[] makeRepeatingIntArray(String[] stringarray, int value) { 244 if (stringarray == null) { 245 return null; 246 } 247 int[] res = new int[stringarray.length]; 248 for (int i=0; i<stringarray.length; i++) { 249 res[i] = value; 250 } 251 return res; 252 } 253 doTestCombineTwoNames(String[] lhsnames, String[] rhsnames, String[] expectednames, String[] newbnames, String[] gonenames)254 private void doTestCombineTwoNames(String[] lhsnames, String[] rhsnames, 255 String[] expectednames, String[] newbnames, 256 String[] gonenames) throws Exception { 257 int[] lhs = makeRepeatingIntArray(lhsnames, 0); 258 int[] rhs = makeRepeatingIntArray(rhsnames, 0); 259 int[] expected = makeRepeatingIntArray(expectednames, 0); 260 int[] newbs = makeRepeatingIntArray(newbnames, 0); 261 int[] gones = makeRepeatingIntArray(gonenames, 0); 262 doTestCombineTwoUidsNames(lhs, lhsnames, rhs, rhsnames, expected, expectednames, 263 newbs, newbnames, gones, gonenames); 264 } 265 doTestCombineTwoUidsNames(int[] lhs, String[] lhsnames, int[] rhs, String[] rhsnames, int[] expected, String[] expectednames, int[] newbs, String[] newbnames, int[] gones, String[] gonenames)266 private void doTestCombineTwoUidsNames(int[] lhs, String[] lhsnames, int[] rhs, String[] rhsnames, 267 int[] expected, String[] expectednames, int[] newbs, String[] newbnames, 268 int[] gones, String[] gonenames) throws Exception { 269 WorkSource ws1 = wsNew(lhs, lhsnames); 270 WorkSource ws2 = wsNew(rhs, rhsnames); 271 ws1.add(ws2); 272 checkWorkSource("Add result", ws1, expected, expectednames); 273 ws1 = wsNew(lhs, lhsnames); 274 WorkSource wsNewbs = wsAddReturningNewbs(ws1, ws2); 275 checkWorkSource("AddReturning result", ws1, expected, expectednames); 276 checkWorkSource("Newbs", wsNewbs, newbs, newbnames); 277 ws1 = wsNew(lhs, lhsnames); 278 WorkSource[] res = wsSetReturningDiffs(ws1, ws2); 279 checkWorkSource("SetReturning result", ws1, rhs, rhsnames); 280 checkWorkSource("Newbs", res[0], newbs, newbnames); 281 checkWorkSource("Gones", res[1], gones, gonenames); 282 } 283 makeRepeatingStringArray(int[] intarray, String value)284 private String[] makeRepeatingStringArray(int[] intarray, String value) { 285 if (intarray == null) { 286 return null; 287 } 288 String[] res = new String[intarray.length]; 289 for (int i=0; i<intarray.length; i++) { 290 res[i] = value; 291 } 292 return res; 293 } 294 makeStringArray(int[] intarray)295 private String[] makeStringArray(int[] intarray) { 296 if (intarray == null) { 297 return null; 298 } 299 String[] res = new String[intarray.length]; 300 for (int i=0; i<intarray.length; i++) { 301 res[i] = Character.toString((char)('A' + intarray[i])); 302 } 303 return res; 304 } 305 doTestCombineTwo(int[] lhs, int[] rhs, int[] expected, int[] newbs, int[] gones)306 private void doTestCombineTwo(int[] lhs, int[] rhs, int[] expected, int[] newbs, 307 int[] gones) throws Exception { 308 doTestCombineTwoUids(lhs, rhs, expected, newbs, gones); 309 doTestCombineTwoUidsNames(lhs, makeRepeatingStringArray(lhs, "A"), 310 rhs, makeRepeatingStringArray(rhs, "A"), 311 expected, makeRepeatingStringArray(expected, "A"), 312 newbs, makeRepeatingStringArray(newbs, "A"), 313 gones, makeRepeatingStringArray(gones, "A")); 314 doTestCombineTwoNames(makeStringArray(lhs), makeStringArray(rhs), 315 makeStringArray(expected), makeStringArray(newbs), makeStringArray(gones)); 316 } 317 318 @ApiTest(apis = {"android.os.WorkSource#add"}) 319 @Test testCombineMultiFront()320 public void testCombineMultiFront() throws Exception { 321 doTestCombineTwo( 322 new int[] { 10, 20, 30, 40 }, 323 new int[] { 1, 2, 15, 16 }, 324 new int[] { 1, 2, 10, 15, 16, 20, 30, 40 }, 325 new int[] { 1, 2, 15, 16 }, 326 new int[] { 10, 20, 30, 40 }); 327 } 328 329 @ApiTest(apis = {"android.os.WorkSource#add"}) 330 @Test testCombineMultiMiddle()331 public void testCombineMultiMiddle() throws Exception { 332 doTestCombineTwo( 333 new int[] { 10, 20, 30, 40 }, 334 new int[] { 12, 14, 22 }, 335 new int[] { 10, 12, 14, 20, 22, 30, 40 }, 336 new int[] { 12, 14, 22 }, 337 new int[] { 10, 20, 30, 40 }); 338 } 339 340 @ApiTest(apis = {"android.os.WorkSource#add"}) 341 @Test testCombineMultiEnd()342 public void testCombineMultiEnd() throws Exception { 343 doTestCombineTwo( 344 new int[] { 10, 20, 30, 40 }, 345 new int[] { 35, 45, 50 }, 346 new int[] { 10, 20, 30, 35, 40, 45, 50 }, 347 new int[] { 35, 45, 50 }, 348 new int[] { 10, 20, 30, 40 }); 349 } 350 351 @ApiTest(apis = {"android.os.WorkSource#add"}) 352 @Test testCombineMultiFull()353 public void testCombineMultiFull() throws Exception { 354 doTestCombineTwo( 355 new int[] { 10, 20, 30, 40 }, 356 new int[] { 1, 2, 15, 35, 50 }, 357 new int[] { 1, 2, 10, 15, 20, 30, 35, 40, 50 }, 358 new int[] { 1, 2, 15, 35, 50 }, 359 new int[] { 10, 20, 30, 40 }); 360 } 361 362 @ApiTest(apis = {"android.os.WorkSource#add"}) 363 @Test testCombineMultiSame()364 public void testCombineMultiSame() throws Exception { 365 doTestCombineTwo( 366 new int[] { 10, 20, 30, 40 }, 367 new int[] { 10, 20, 30 }, 368 new int[] { 10, 20, 30, 40 }, 369 null, 370 new int[] { 40 }); 371 } 372 373 @ApiTest(apis = {"android.os.WorkSource#add"}) 374 @Test testCombineMultiSomeSame()375 public void testCombineMultiSomeSame() throws Exception { 376 doTestCombineTwo( 377 new int[] { 10, 20, 30, 40 }, 378 new int[] { 1, 30, 40 }, 379 new int[] { 1, 10, 20, 30, 40 }, 380 new int[] { 1 }, 381 new int[] { 10, 20 }); 382 } 383 384 @ApiTest(apis = {"android.os.WorkSource#add"}) 385 @Test testCombineMultiSomeSameUidsNames()386 public void testCombineMultiSomeSameUidsNames() throws Exception { 387 doTestCombineTwoUidsNames( 388 new int[] { 10, 10, 20, 30, 30, 30, 40 }, 389 new String[] { "A", "B", "A", "A", "B", "C", "A" }, 390 new int[] { 1, 30, 40, 50 }, 391 new String[] { "A", "A", "B", "A" }, 392 new int[] { 1, 10, 10, 20, 30, 30, 30, 40, 40, 50 }, 393 new String[] { "A", "A", "B", "A", "A", "B", "C", "A", "B", "A" }, 394 new int[] { 1, 40, 50 }, 395 new String[] { "A", "B", "A" }, 396 new int[] { 10, 10, 20, 30, 30, 40 }, 397 new String[] { "A", "B", "A", "B", "C", "A" }); 398 } 399 doTestRemoveUids(int[] lhs, int[] rhs, int[] result, boolean diff)400 private void doTestRemoveUids(int[] lhs, int[] rhs, int[] result, boolean diff) throws Exception { 401 WorkSource ws1 = wsNew(lhs); 402 WorkSource ws2 = wsNew(rhs); 403 boolean diffres = ws1.remove(ws2); 404 if (diffres != diff) { 405 StringBuilder sb = new StringBuilder(); 406 sb.append("Expected diff "); 407 sb.append(diff); 408 sb.append(" but got "); 409 sb.append(diffres); 410 sb.append(" when removing "); 411 sb.append(ws2); 412 sb.append(" from "); 413 sb.append(ws1); 414 fail(sb.toString()); 415 } 416 checkWorkSource("Remove", ws1, result); 417 } 418 doTestRemoveNames(String[] lhsnames, String[] rhsnames, String[] resultnames, boolean diff)419 private void doTestRemoveNames(String[] lhsnames, String[] rhsnames, 420 String[] resultnames, boolean diff) throws Exception { 421 int[] lhs = makeRepeatingIntArray(lhsnames, 0); 422 int[] rhs = makeRepeatingIntArray(rhsnames, 0); 423 int[] result = makeRepeatingIntArray(resultnames, 0); 424 WorkSource ws1 = wsNew(lhs, lhsnames); 425 WorkSource ws2 = wsNew(rhs, rhsnames); 426 boolean diffres = ws1.remove(ws2); 427 if (diffres != diff) { 428 StringBuilder sb = new StringBuilder(); 429 sb.append("Expected diff "); 430 sb.append(diff); 431 sb.append(" but got "); 432 sb.append(diffres); 433 sb.append(" when removing "); 434 sb.append(ws2); 435 sb.append(" from "); 436 sb.append(ws1); 437 fail(sb.toString()); 438 } 439 checkWorkSource("Remove", ws1, result, resultnames); 440 } 441 doTestRemoveUidsNames(int[] lhs, String[] lhsnames, int[] rhs, String[] rhsnames, int[] result, String[] resultnames, boolean diff)442 private void doTestRemoveUidsNames(int[] lhs, String[] lhsnames, int[] rhs, String[] rhsnames, 443 int[] result, String[] resultnames, boolean diff) throws Exception { 444 WorkSource ws1 = wsNew(lhs, lhsnames); 445 WorkSource ws2 = wsNew(rhs, rhsnames); 446 boolean diffres = ws1.remove(ws2); 447 if (diffres != diff) { 448 StringBuilder sb = new StringBuilder(); 449 sb.append("Expected diff "); 450 sb.append(diff); 451 sb.append(" but got "); 452 sb.append(diffres); 453 sb.append(" when removing "); 454 sb.append(ws2); 455 sb.append(" from "); 456 sb.append(ws1); 457 fail(sb.toString()); 458 } 459 checkWorkSource("Remove", ws1, result, resultnames); 460 } 461 doTestRemove(int[] lhs, int[] rhs, int[] result, boolean diff)462 private void doTestRemove(int[] lhs, int[] rhs, int[] result, boolean diff) throws Exception { 463 doTestRemoveUids(lhs, rhs, result, diff); 464 doTestRemoveUidsNames(lhs, makeRepeatingStringArray(lhs, "A"), 465 rhs, makeRepeatingStringArray(rhs, "A"), 466 result, makeRepeatingStringArray(result, "A"), 467 diff); 468 doTestRemoveNames(makeStringArray(lhs), makeStringArray(rhs), 469 makeStringArray(result), diff); 470 } 471 472 @ApiTest(apis = {"android.os.WorkSource#remove"}) 473 @Test testRemoveNone()474 public void testRemoveNone() throws Exception { 475 doTestRemove( 476 new int[] { 10, 20, 30, 40 }, 477 new int[] { 1, 2, 35, 50 }, 478 new int[] { 10, 20, 30, 40 }, 479 false); 480 } 481 482 @ApiTest(apis = {"android.os.WorkSource#remove"}) 483 @Test testRemoveMultiFront()484 public void testRemoveMultiFront() throws Exception { 485 doTestRemove( 486 new int[] { 10, 20, 30, 40 }, 487 new int[] { 1, 2, 10, 30 }, 488 new int[] { 20, 40 }, 489 true); 490 } 491 492 @ApiTest(apis = {"android.os.WorkSource#remove"}) 493 @Test testRemoveMultiMiddle()494 public void testRemoveMultiMiddle() throws Exception { 495 doTestRemove( 496 new int[] { 10, 20, 30, 40 }, 497 new int[] { 20, 30 }, 498 new int[] { 10, 40 }, 499 true); 500 } 501 502 @ApiTest(apis = {"android.os.WorkSource#remove"}) 503 @Test testRemoveMultiEnd()504 public void testRemoveMultiEnd() throws Exception { 505 doTestRemove( 506 new int[] { 10, 20, 30, 40 }, 507 new int[] { 30, 40, 50 }, 508 new int[] { 10, 20 }, 509 true); 510 } 511 512 @ApiTest(apis = {"android.os.WorkSource#remove"}) 513 @Test testRemoveMultiFull()514 public void testRemoveMultiFull() throws Exception { 515 doTestRemove( 516 new int[] { 10, 20, 30, 40 }, 517 new int[] { 1, 2, 20, 25, 35, 40 }, 518 new int[] { 10, 30 }, 519 true); 520 } 521 522 @ApiTest(apis = {"android.os.WorkSource#remove"}) 523 @Test testRemoveMultiAll()524 public void testRemoveMultiAll() throws Exception { 525 doTestRemove( 526 new int[] { 10, 20, 30, 40 }, 527 new int[] { 10, 20, 30, 40 }, 528 new int[] { }, 529 true); 530 } 531 532 @ApiTest(apis = {"android.os.WorkSource#isEmpty"}) 533 @Test testIsEmptyByDefault()534 public void testIsEmptyByDefault() { 535 WorkSource ws = new WorkSource(); 536 assertTrue("isEmpty false for empty WorkSource", ws.isEmpty()); 537 } 538 539 @ApiTest(apis = {"android.os.WorkSource#clear"}) 540 @Test testIsEmptyOnClear()541 public void testIsEmptyOnClear() { 542 WorkSource ws = wsNew(new int[] {1, 2, 3}, new String[] {"a", "aa", "aaa"}); 543 assertFalse(ws.isEmpty()); 544 ws.clear(); 545 assertTrue(ws.isEmpty()); 546 } 547 548 @ApiTest(apis = {"android.os.WorkSource#withoutNames"}) 549 @Test testWithoutNames()550 public void testWithoutNames() { 551 WorkSource ws = wsNew( 552 new int[] {10, 12, 12, 15, 15, 17}, 553 new String[] {"a", "b", "c", "d", "e", "f"}); 554 WorkSource wsWithoutNames = ws.withoutNames(); 555 556 int[] expectedUids = new int[] {10, 12, 15, 17}; 557 if (expectedUids.length != wsWithoutNames.size()) { 558 failWorkSource("withoutNames", wsWithoutNames, expectedUids); 559 } 560 for (int i = 0; i < expectedUids.length; i++) { 561 if (wsWithoutNames.getUid(i) != expectedUids[i]) { 562 failWorkSource("withoutNames", wsWithoutNames, expectedUids); 563 } 564 if (wsWithoutNames.getPackageName(i) != null) { 565 fail("Name " + wsWithoutNames.getPackageName(i) + " found at i = " + i); 566 } 567 } 568 try { 569 wsWithoutNames.add(50, "name"); 570 fail("Added name to unnamed worksource"); 571 } catch (IllegalArgumentException e) { 572 // Expected 573 } 574 } 575 } 576