167 { |
165 { |
168 ((SysUtilTest)tc).testIsDiskSpaceBelowCriticalLevel(); |
166 ((SysUtilTest)tc).testIsDiskSpaceBelowCriticalLevel(); |
169 } |
167 } |
170 })); |
168 })); |
171 |
169 |
172 if (Platform.isS60()) |
|
173 { |
|
174 suite.addTest(new SysUtilTest("testPropertyListener", new TestMethod() |
|
175 { |
|
176 public void run(TestCase tc) |
|
177 { |
|
178 ((SysUtilTest)tc).testPropertyListener(); |
|
179 } |
|
180 })); |
|
181 |
|
182 suite.addTest(new SysUtilTest("testGetProcessState", new TestMethod() |
|
183 { |
|
184 public void run(TestCase tc) |
|
185 { |
|
186 ((SysUtilTest)tc).testGetProcessState(); |
|
187 } |
|
188 })); |
|
189 |
|
190 suite.addTest(new SysUtilTest("testDriveGetters", new TestMethod() |
|
191 { |
|
192 public void run(TestCase tc) |
|
193 { |
|
194 ((SysUtilTest)tc).testDriveGetters(); |
|
195 } |
|
196 })); |
|
197 |
|
198 suite.addTest(new SysUtilTest("testGetScreenSize", new TestMethod() |
|
199 { |
|
200 public void run(TestCase tc) |
|
201 { |
|
202 ((SysUtilTest)tc).testGetScreenSize(); |
|
203 } |
|
204 })); |
|
205 |
|
206 suite.addTest(new SysUtilTest("testIsoToLang", new TestMethod() |
|
207 { |
|
208 public void run(TestCase tc) |
|
209 { |
|
210 ((SysUtilTest)tc).testIsoToLang(); |
|
211 } |
|
212 })); |
|
213 } |
|
214 |
|
215 com.nokia.mj.impl.utils.OmjTestRunner.run(suite); |
170 com.nokia.mj.impl.utils.OmjTestRunner.run(suite); |
216 } |
171 } |
217 |
172 |
218 public SysUtilTest() |
173 public SysUtilTest() |
219 { |
174 { |
241 |
196 |
242 public void testGetPropertyValue() |
197 public void testGetPropertyValue() |
243 { |
198 { |
244 try |
199 try |
245 { |
200 { |
246 // Test PS keys defined in hwrmpowerstatesdkpskey.h |
201 // Test PS keys defined in ScreensaverInternalPSKeys.h |
247 Uid uid = PlatformUid.createUid("0x10205041"); // KPSUidHWRMPowerState |
202 Uid uid = PlatformUid.createUid("0x101F8771"); // KPSUidScreenSaver |
248 int key = 0x00000003; // KHWRMChargingStatus |
203 int key = 0x00000001; // KScreenSaverPreviewMode |
249 int value = SysUtil.getPropertyValue(uid, key); |
204 int value = SysUtil.getPropertyValue(uid, key); |
250 assertTrue("KHWRMChargingStatus(!=0): " + value, value == 0); |
205 assertTrue("KScreenSaverPreviewMode(!=0): " + value, value == 0); |
251 } |
206 } |
252 catch (InstallerException ie) |
207 catch (InstallerException ie) |
253 { |
208 { |
254 ie.printStackTrace(); |
209 ie.printStackTrace(); |
255 assertTrue("Unexpected exception: " + ie, false); |
210 assertTrue("Unexpected exception: " + ie, false); |
274 |
229 |
275 public void testSetPropertyValue() |
230 public void testSetPropertyValue() |
276 { |
231 { |
277 try |
232 try |
278 { |
233 { |
279 Uid uid = SysUtil.PROP_CATEGORY_SYSTEM; |
234 // Test PS keys defined in ScreensaverInternalPSKeys.h |
280 long key = SysUtil.PROP_KEY_JAVA_LATEST_INSTALLATION_PROGRESS; |
235 Uid uid = PlatformUid.createUid("0x101F8771"); // KPSUidScreenSaver |
|
236 int key = 0x00000001; // KScreenSaverPreviewMode |
|
237 // Set screensaver preview mode on (stays on for 10 secs). |
281 SysUtil.setPropertyValue(uid, key, 1); |
238 SysUtil.setPropertyValue(uid, key, 1); |
282 int value = SysUtil.getPropertyValue(uid, key); |
239 int value = SysUtil.getPropertyValue(uid, key); |
283 assertTrue("PROP_KEY_JAVA_LATEST_INSTALLATION_PROGRESS(!=1): " + |
240 assertTrue("KScreenSaverPreviewMode(!=1): " + value, value == 1); |
284 value, value == 1); |
|
285 } |
241 } |
286 catch (InstallerException ie) |
242 catch (InstallerException ie) |
287 { |
243 { |
288 ie.printStackTrace(); |
244 ie.printStackTrace(); |
289 assertTrue("Unexpected exception: " + ie, false); |
245 assertTrue("Unexpected exception: " + ie, false); |
380 |
337 |
381 public void testGetRepositoryValue() |
338 public void testGetRepositoryValue() |
382 { |
339 { |
383 try |
340 try |
384 { |
341 { |
385 // Test CenRep keys defined in Java security. |
342 // Test CenRep keys defined in ScreensaverInternalCRKeys.h |
386 Uid uid = PlatformUid.createUid("0x2001B289"); // KJavaSecurity |
343 Uid uid = PlatformUid.createUid("0x101F8770"); // KCRUidScreenSaver |
387 long key = 0x00000004; // KJavaSecurity/KWarningsMode |
344 long key = 0x00000004; // KScreenSaverInvertedColors |
388 int value = SysUtil.getRepositoryValue(uid, key); |
345 int value = SysUtil.getRepositoryValue(uid, key); |
389 assertTrue("KJavaSecurity/KWarningsMode(!=2): " + value, |
346 assertTrue("KScreenSaverInvertedColors(!=0): " + value, value == 0); |
390 value == 2); |
|
391 } |
347 } |
392 catch (InstallerException ie) |
348 catch (InstallerException ie) |
393 { |
349 { |
394 ie.printStackTrace(); |
350 ie.printStackTrace(); |
395 assertTrue("Unexpected exception: " + ie, false); |
351 assertTrue("Unexpected exception: " + ie, false); |
417 try |
373 try |
418 { |
374 { |
419 Uid uid = SysUtil.REPO_ID_JAVA_INST_VARIATION; |
375 Uid uid = SysUtil.REPO_ID_JAVA_INST_VARIATION; |
420 long key = SysUtil.REPO_KEY_JAVA_INST_SHELL_FOLDER_VALUE; |
376 long key = SysUtil.REPO_KEY_JAVA_INST_SHELL_FOLDER_VALUE; |
421 String value = SysUtil.getRepositoryStringValue(uid, key); |
377 String value = SysUtil.getRepositoryStringValue(uid, key); |
422 assertTrue("Unexpected value: " + value, "Games,Applications".equals(value)); |
378 //assertTrue("Unexpected value: " + value, "Games,Applications".equals(value)); |
423 //assertTrue("Unexpected value: " + value, "".equals(value)); |
379 assertTrue("Unexpected value: " + value, "".equals(value)); |
424 } |
380 } |
425 catch (InstallerException ie) |
381 catch (InstallerException ie) |
426 { |
382 { |
427 ie.printStackTrace(); |
383 ie.printStackTrace(); |
428 assertTrue("Unexpected exception: " + ie, false); |
384 assertTrue("Unexpected exception: " + ie, false); |
615 catch (InstallerException ie) |
571 catch (InstallerException ie) |
616 { |
572 { |
617 // OK, expected exception. |
573 // OK, expected exception. |
618 } |
574 } |
619 } |
575 } |
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 |
|
696 public void testGetProcessState() |
|
697 { |
|
698 int state = SysUtil.getProcessState(PlatformUid.createUid("[102033e6]")); |
|
699 assertTrue("installer process state is " + state + |
|
700 ", not " + SysUtil.PROC_STATE_ALIVE, |
|
701 SysUtil.PROC_STATE_ALIVE == state); |
|
702 state = SysUtil.getProcessState(PlatformUid.createUid("[e0001001]")); |
|
703 assertTrue("nonexisting process state is " + state + ", not 0", |
|
704 0 == state); |
|
705 } |
|
706 |
|
707 public void testDriveGetters() |
|
708 { |
|
709 int defMem = SysUtil.getDefaultPhoneMemory(); |
|
710 int defMassStorage = SysUtil.getDefaultMassStorage(); |
|
711 Log.log("testDriveGetter: defaultPhoneMemory = " + defMem); |
|
712 Log.log("testDriveGetter: defaultMassStorage = " + defMassStorage); |
|
713 } |
|
714 |
|
715 public void testGetScreenSize() |
|
716 { |
|
717 int screenWidth = SysUtil.getScreenWidth(); |
|
718 int screenHeight = SysUtil.getScreenHeight(); |
|
719 Log.log("testGetScreenSize: screenWidth = " + screenWidth); |
|
720 Log.log("testGetScreenSize: screenHeight = " + screenHeight); |
|
721 assertTrue("screenWidth <= 0", screenWidth > 0); |
|
722 assertTrue("screenHeight <= 0", screenHeight > 0); |
|
723 } |
|
724 |
|
725 public void testIsoToLang() |
|
726 { |
|
727 testIsoToLang("unknown", -1); // unknown locale is indicated with -1 |
|
728 testIsoToLang("fi", 9); // ELangFinnish, Finnish |
|
729 testIsoToLang("fi_FI", 9); // ELangFinnish, Finnish |
|
730 testIsoToLang("sv", 6); // ELangSwedish, Swedish |
|
731 testIsoToLang("sv_FI", 85); // ELangFinlandSwedish, Finland Swedish |
|
732 testIsoToLang("en", 1); // ELangEnglish, UK English |
|
733 testIsoToLang("en_US", 10); // ELangAmerican, American |
|
734 testIsoToLang("en_AU", 20); // ELangAustralian, Australian English |
|
735 } |
|
736 |
|
737 private void testIsoToLang(String aLocale, int aLang) |
|
738 { |
|
739 assertTrue("SysUtil.isoToLang " + aLocale + " != " + aLang, |
|
740 SysUtil.isoToLang(aLocale) == aLang); |
|
741 } |
|
742 } |
576 } |