|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 package com.nokia.mj.impl.utils; |
|
20 |
|
21 import com.nokia.mj.impl.utils.Logger; |
|
22 |
|
23 import com.nokia.mj.impl.rt.test.UnitTestSuiteCreator; |
|
24 import j2meunit.framework.Test; |
|
25 import j2meunit.framework.TestCase; |
|
26 import j2meunit.framework.TestMethod; |
|
27 import j2meunit.framework.TestSuite; |
|
28 |
|
29 /** |
|
30 * DebugUtils unit tests. |
|
31 */ |
|
32 public class LoggerTests extends TestCase implements UnitTestSuiteCreator |
|
33 { |
|
34 // Create the test suite. |
|
35 public TestSuite createTestSuite(String[] args) |
|
36 { |
|
37 TestSuite suite = new TestSuite(this.getClass().getName()); |
|
38 |
|
39 suite.addTest(new LoggerTests("Test Log writings", new TestMethod() |
|
40 { |
|
41 public void run(TestCase tc) |
|
42 { |
|
43 ((LoggerTests)tc).testLogWritings(); |
|
44 } |
|
45 })); |
|
46 |
|
47 return suite; |
|
48 } |
|
49 |
|
50 public LoggerTests() |
|
51 { |
|
52 } |
|
53 |
|
54 public LoggerTests(String aTestName, TestMethod aTestMethod) |
|
55 { |
|
56 super(aTestName, aTestMethod); |
|
57 } |
|
58 |
|
59 // End j2meunit test framework setup |
|
60 |
|
61 protected void setUp() |
|
62 { |
|
63 } |
|
64 |
|
65 protected void tearDown() |
|
66 { |
|
67 } |
|
68 |
|
69 public void testLogWritings() |
|
70 { |
|
71 // Check the log writings manually from JavaLocation.log file. |
|
72 try |
|
73 { |
|
74 Logger.ELOG(Logger.EJavaLocation, "This is Logger.ELOG without exception"); |
|
75 Logger.ELOG(Logger.EJavaLocation, "This is Logger.ELOG with exception", new Exception("Logger.ELOG")); |
|
76 Logger.ELOG(Logger.EJavaLocation, "This is Logger.ELOG with null exception", null); |
|
77 Logger.ELOG(Logger.EJavaLocation, null); |
|
78 |
|
79 Logger.WLOG(Logger.EJavaLocation, "This is Logger.WLOG without exception"); |
|
80 Logger.WLOG(Logger.EJavaLocation, "This is Logger.WLOG with exception", new Exception("Logger.WLOG")); |
|
81 Logger.WLOG(Logger.EJavaLocation, "This is Logger.WLOG with null exception", null); |
|
82 Logger.WLOG(Logger.EJavaLocation, null); |
|
83 |
|
84 Logger.PLOG(Logger.EJavaLocation, "This is Logger.PLOG without exception"); |
|
85 Logger.PLOG(Logger.EJavaLocation, "This is Logger.PLOG with exception", new Exception("Logger.PLOG")); |
|
86 Logger.PLOG(Logger.EJavaLocation, "This is Logger.PLOG with null exception", null); |
|
87 Logger.PLOG(Logger.EJavaLocation, null); |
|
88 |
|
89 Logger.ILOG(Logger.EJavaLocation, "This is Logger.ILOG without exception"); |
|
90 Logger.ILOG(Logger.EJavaLocation, "This is Logger.ILOG with exception", new Exception("Logger.PLOG")); |
|
91 Logger.ILOG(Logger.EJavaLocation, "This is Logger.ILOG with null exception", null); |
|
92 Logger.ILOG(Logger.EJavaLocation, null); |
|
93 |
|
94 Logger.JELOG(Logger.EJavaLocation, "This is Logger.JELOG"); |
|
95 Logger.JELOG(Logger.EJavaLocation, null); |
|
96 |
|
97 Logger.HLOG(Logger.EJavaLocation, "This is Logger.HLOG"); |
|
98 Logger.HLOG(Logger.EJavaLocation, null); |
|
99 |
|
100 testLOG(Logger.EError, "Logger.EError"); |
|
101 testLOG(Logger.EWarning, "Logger.EWarning"); |
|
102 testLOG(Logger.EInfoPrd, "Logger.EInfoPrd"); |
|
103 testLOG(Logger.EInfo, "Logger.EInfo"); |
|
104 } |
|
105 catch (Throwable t) |
|
106 { |
|
107 t.printStackTrace(); |
|
108 assertTrue(t.toString(), false); |
|
109 } |
|
110 } |
|
111 |
|
112 private void testLOG(int level, String str) |
|
113 { |
|
114 Logger.LOG(Logger.EJavaLocation, level, "This is Logger.LOG (" + str + ") without exception"); |
|
115 Logger.LOG(Logger.EJavaLocation, level, "This is Logger.LOG (" + str + ") with exception", new Exception(str)); |
|
116 Logger.LOG(Logger.EJavaLocation, level, "This is Logger.LOG (" + str + ") with null exception", null); |
|
117 Logger.LOG(Logger.EJavaLocation, level, null); |
|
118 } |
|
119 } |