167 } |
169 } |
168 })); |
170 })); |
169 |
171 |
170 if (Platform.isS60()) |
172 if (Platform.isS60()) |
171 { |
173 { |
|
174 suite.addTest(new SysUtilTest("testPropertyListener", new TestMethod() |
|
175 { |
|
176 public void run(TestCase tc) |
|
177 { |
|
178 ((SysUtilTest)tc).testPropertyListener(); |
|
179 } |
|
180 })); |
|
181 |
172 suite.addTest(new SysUtilTest("testGetProcessState", new TestMethod() |
182 suite.addTest(new SysUtilTest("testGetProcessState", new TestMethod() |
173 { |
183 { |
174 public void run(TestCase tc) |
184 public void run(TestCase tc) |
175 { |
185 { |
176 ((SysUtilTest)tc).testGetProcessState(); |
186 ((SysUtilTest)tc).testGetProcessState(); |
264 |
274 |
265 public void testSetPropertyValue() |
275 public void testSetPropertyValue() |
266 { |
276 { |
267 try |
277 try |
268 { |
278 { |
269 // Test PS keys defined in ScreensaverInternalPSKeys.h |
279 Uid uid = SysUtil.PROP_CATEGORY_SYSTEM; |
270 Uid uid = PlatformUid.createUid("0x101F8771"); // KPSUidScreenSaver |
280 long key = SysUtil.PROP_KEY_JAVA_LATEST_INSTALLATION_PROGRESS; |
271 int key = 0x00000001; // KScreenSaverPreviewMode |
|
272 // Set screensaver preview mode on (stays on for 10 secs). |
|
273 SysUtil.setPropertyValue(uid, key, 1); |
281 SysUtil.setPropertyValue(uid, key, 1); |
274 int value = SysUtil.getPropertyValue(uid, key); |
282 int value = SysUtil.getPropertyValue(uid, key); |
275 assertTrue("KScreenSaverPreviewMode(!=1): " + value, value == 1); |
283 assertTrue("PROP_KEY_JAVA_LATEST_INSTALLATION_PROGRESS(!=1): " + |
|
284 value, value == 1); |
276 } |
285 } |
277 catch (InstallerException ie) |
286 catch (InstallerException ie) |
278 { |
287 { |
279 ie.printStackTrace(); |
288 ie.printStackTrace(); |
280 assertTrue("Unexpected exception: " + ie, false); |
289 assertTrue("Unexpected exception: " + ie, false); |
283 |
292 |
284 public void testSetUndefinedPropertyValue() |
293 public void testSetUndefinedPropertyValue() |
285 { |
294 { |
286 try |
295 try |
287 { |
296 { |
288 // Test PS keys defined in ScreensaverInternalPSKeys.h |
297 Uid uid = SysUtil.PROP_CATEGORY_SYSTEM; |
289 Uid uid = PlatformUid.createUid("0x101F8771"); // KPSUidScreenSaver |
298 int key = 0x00000100; // Undefined key |
290 int key = 0x00000010; // Undefined key |
|
291 SysUtil.setPropertyValue(uid, key, 1); |
299 SysUtil.setPropertyValue(uid, key, 1); |
292 assertTrue("Setting undefined property value did not fail", false); |
300 assertTrue("Setting undefined property value did not fail", false); |
293 } |
301 } |
294 catch (InstallerException ie) |
302 catch (InstallerException ie) |
295 { |
303 { |
372 |
380 |
373 public void testGetRepositoryValue() |
381 public void testGetRepositoryValue() |
374 { |
382 { |
375 try |
383 try |
376 { |
384 { |
377 // Test CenRep keys defined in ScreensaverInternalCRKeys.h |
385 // Test CenRep keys defined in Java security. |
378 Uid uid = PlatformUid.createUid("0x101F8770"); // KCRUidScreenSaver |
386 Uid uid = PlatformUid.createUid("0x2001B289"); // KJavaSecurity |
379 long key = 0x00000004; // KScreenSaverInvertedColors |
387 long key = 0x00000004; // KJavaSecurity/KWarningsMode |
380 int value = SysUtil.getRepositoryValue(uid, key); |
388 int value = SysUtil.getRepositoryValue(uid, key); |
381 assertTrue("KScreenSaverInvertedColors(!=0): " + value, value == 0); |
389 assertTrue("KJavaSecurity/KWarningsMode(!=2): " + value, |
|
390 value == 2); |
382 } |
391 } |
383 catch (InstallerException ie) |
392 catch (InstallerException ie) |
384 { |
393 { |
385 ie.printStackTrace(); |
394 ie.printStackTrace(); |
386 assertTrue("Unexpected exception: " + ie, false); |
395 assertTrue("Unexpected exception: " + ie, false); |
607 { |
616 { |
608 // OK, expected exception. |
617 // OK, expected exception. |
609 } |
618 } |
610 } |
619 } |
611 |
620 |
|
621 public void testPropertyListener() |
|
622 { |
|
623 final int category = 0x101f75b6; |
|
624 final int key = 0x20019546; |
|
625 final int value = 15; |
|
626 final Object synchObject = this; |
|
627 PropertyListener listener = new PropertyListener() |
|
628 { |
|
629 public void valueChanged(int aCategory, int aKey, int aValue) |
|
630 { |
|
631 try |
|
632 { |
|
633 if (aValue == 0) |
|
634 { |
|
635 // Ignore the first event which is sent when |
|
636 // subscription is made. |
|
637 return; |
|
638 } |
|
639 synchronized (synchObject) |
|
640 { |
|
641 iPropertyValue = aValue; |
|
642 Log.log("PropertyListener.valueChanged: " + aValue + |
|
643 " (" + aCategory + ", " + aKey + ")"); |
|
644 if (aCategory != category) |
|
645 { |
|
646 Log.logError("PropertyListener.valueChanged: " + |
|
647 "invalid category " + aCategory); |
|
648 } |
|
649 if (aKey != key) |
|
650 { |
|
651 Log.logError("PropertyListener.valueChanged: " + |
|
652 "invalid key " + aKey); |
|
653 } |
|
654 synchObject.notify(); |
|
655 } |
|
656 } |
|
657 catch (Throwable t) |
|
658 { |
|
659 Log.logError("PropertyListener.valueChanged exception", t); |
|
660 } |
|
661 } |
|
662 }; |
|
663 try |
|
664 { |
|
665 iPropertyValue = 0; |
|
666 SysUtil.setPropertyValue( |
|
667 PlatformUid.createUid(category), key, iPropertyValue); |
|
668 PropertyProvider provider = new PropertyProvider(); |
|
669 provider.subscribe(category, key, listener); |
|
670 SysUtil.setPropertyValue( |
|
671 PlatformUid.createUid(category), key, value); |
|
672 try |
|
673 { |
|
674 synchronized (synchObject) |
|
675 { |
|
676 if (iPropertyValue == 0) |
|
677 { |
|
678 synchObject.wait(2000); |
|
679 } |
|
680 } |
|
681 } |
|
682 catch (InterruptedException ie) |
|
683 { |
|
684 } |
|
685 provider.unsubscribe(); |
|
686 assertTrue("Unexpected property value after test: " + |
|
687 iPropertyValue, iPropertyValue == value); |
|
688 } |
|
689 catch (Throwable t) |
|
690 { |
|
691 Log.logError("testPropertyListener exception", t); |
|
692 assertTrue("Unexpected exception " + t, false); |
|
693 } |
|
694 } |
|
695 |
612 public void testGetProcessState() |
696 public void testGetProcessState() |
613 { |
697 { |
614 int state = SysUtil.getProcessState(PlatformUid.createUid("[102033e6]")); |
698 int state = SysUtil.getProcessState(PlatformUid.createUid("[102033e6]")); |
615 assertTrue("installer process state is " + state + |
699 assertTrue("installer process state is " + state + |
616 ", not " + SysUtil.PROC_STATE_ALIVE, |
700 ", not " + SysUtil.PROC_STATE_ALIVE, |