📄 rms_logdisabledtest.java
字号:
/*
* Copyright (C) 2006-2007 Funambol
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package com.funambol.util;
import com.funambol.util.LogViewer;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;
import javax.microedition.rms.RecordStoreNotFoundException;
import jmunit.framework.cldc10.AssertionFailedException;
import jmunit.framework.cldc10.TestCase;
public class RMS_LogDisabledTest extends TestCase {
/** Creates a new instance of RMS_LogDisabledTest */
public RMS_LogDisabledTest() {
super(5, "RMS_LogDisabledTest");
}
public void setUp() {
}
public void tearDown() {
try {
RecordStore dbStore = RecordStore.openRecordStore(RMSAppender.LOGDBNAME, false);
dbStore.closeRecordStore();
RecordStore.deleteRecordStore(RMSAppender.LOGDBNAME);
} catch (RecordStoreException ex) {
System.out.println("tearDown: ex=" + ex.getMessage());
}
}
public void test(int i) throws Throwable {
switch(i) {
case 0:
testInitLogDISABLED();
break;
case 1:
testNoLoggingConstructor();
break;
case 2:
testNoLoggingSetLevel();
break;
case 3:
testNoLoggingSetLevel();
break;
case 4:
testNoLoggingSetLevel();
break;
default:
break;
}
}
private void testInitLogDISABLED() throws AssertionFailedException {
System.out.println("testInitLogDISABLED");
Log.initLog(new RMSAppender(RMSAppender.LOGDBNAME), Log.DISABLED);
assertTrue(Log.getLogLevel()==Log.DISABLED);
System.out.println("Log.getLogLevel(): " + Log.getLogLevel());
}
private void testNoLoggingConstructor() throws AssertionFailedException {
System.out.println("testNoLoggingConstructor");
Log.initLog(new RMSAppender(RMSAppender.LOGDBNAME), Log.DISABLED);
Log.error("Error");
Log.info("Info");
Log.debug("Debug");
Log.trace("Trace");
try {
RecordStore rs = RecordStore.openRecordStore(RMSAppender.LOGDBNAME, false);
assertTrue(false);
} catch (RecordStoreNotFoundException n) {
assertTrue(true);
} catch (RecordStoreException ex) {
ex.printStackTrace();
assertTrue(false);
}
}
private void testNoLoggingSetLevel() throws AssertionFailedException {
System.out.println("testNoLoggingSetLevel");
Log.initLog(new RMSAppender(RMSAppender.LOGDBNAME));
Log.setLogLevel(Log.DISABLED);
Log.error("Error");
Log.info("Info");
Log.debug("Debug");
Log.trace("Trace");
LogViewer lv = new LogViewer();
String[] actualLog = lv.getLogEntries(lv.RMSLOG);;
assertTrue(actualLog[0].equals("No Log entries found."));
}
private void testLoggingConstructor() throws AssertionFailedException {
System.out.println("testLoggingConstructor");
Log.initLog(new RMSAppender(RMSAppender.LOGDBNAME), Log.DEBUG);
Log.error("Error");
Log.info("Info");
Log.debug("Debug");
Log.trace("Trace");
LogViewer lv = new LogViewer();
String[] actualLog = lv.getLogEntries(lv.RMSLOG);
String[] expectedLog = new String[]{"Error", "Info", "Debug"};
assertEquals(expectedLog, actualLog);
}
private void testLoggingSetLevel() throws AssertionFailedException {
System.out.println("testLoggingSetLevel");
Log.initLog(new RMSAppender(RMSAppender.LOGDBNAME));
Log.setLogLevel(Log.DEBUG);
Log.error("Error");
Log.info("Info");
Log.debug("Debug");
Log.trace("Trace");
LogViewer lv = new LogViewer();
String[] actualLog = lv.getLogEntries(lv.RMSLOG);
String[] expectedLog = new String[]{"Error", "Info", "Debug"};
assertEquals(expectedLog, actualLog);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -