michael@0: /* Any copyright is dedicated to the Public Domain.
michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0:
michael@0: package org.mozilla.gecko.background.common;
michael@0:
michael@0: import org.mozilla.gecko.background.common.log.Logger;
michael@0: import org.mozilla.gecko.background.common.log.writers.AndroidLevelCachingLogWriter;
michael@0: import org.mozilla.gecko.background.common.log.writers.AndroidLogWriter;
michael@0: import org.mozilla.gecko.background.common.log.writers.LogWriter;
michael@0: import org.mozilla.gecko.background.helpers.AndroidSyncTestCase;
michael@0:
michael@0: public class TestAndroidLogWriters extends AndroidSyncTestCase {
michael@0: public static final String TEST_LOG_TAG = "TestAndroidLogWriters";
michael@0:
michael@0: public static final String TEST_MESSAGE_1 = "LOG TEST MESSAGE one";
michael@0: public static final String TEST_MESSAGE_2 = "LOG TEST MESSAGE two";
michael@0: public static final String TEST_MESSAGE_3 = "LOG TEST MESSAGE three";
michael@0:
michael@0: public void setUp() {
michael@0: Logger.stopLoggingToAll();
michael@0: }
michael@0:
michael@0: public void tearDown() {
michael@0: Logger.resetLogging();
michael@0: }
michael@0:
michael@0: /**
michael@0: * Verify these *all* appear in the Android log by using
michael@0: * adb logcat | grep TestAndroidLogWriters
after executing
michael@0: * adb shell setprop log.tag.TestAndroidLogWriters ERROR
.
michael@0: *
michael@0: * This writer does not use the Android log levels!
michael@0: */
michael@0: public void testAndroidLogWriter() {
michael@0: LogWriter lw = new AndroidLogWriter();
michael@0:
michael@0: Logger.error(TEST_LOG_TAG, TEST_MESSAGE_1, new RuntimeException());
michael@0: Logger.startLoggingTo(lw);
michael@0: Logger.error(TEST_LOG_TAG, TEST_MESSAGE_2);
michael@0: Logger.warn(TEST_LOG_TAG, TEST_MESSAGE_2);
michael@0: Logger.info(TEST_LOG_TAG, TEST_MESSAGE_2);
michael@0: Logger.debug(TEST_LOG_TAG, TEST_MESSAGE_2);
michael@0: Logger.trace(TEST_LOG_TAG, TEST_MESSAGE_2);
michael@0: Logger.stopLoggingTo(lw);
michael@0: Logger.error(TEST_LOG_TAG, TEST_MESSAGE_3, new RuntimeException());
michael@0: }
michael@0:
michael@0: /**
michael@0: * Verify only *some* of these appear in the Android log by using
michael@0: * adb logcat | grep TestAndroidLogWriters
after executing
michael@0: * adb shell setprop log.tag.TestAndroidLogWriters INFO
.
michael@0: *
michael@0: * This writer should use the Android log levels! michael@0: */ michael@0: public void testAndroidLevelCachingLogWriter() throws Exception { michael@0: LogWriter lw = new AndroidLevelCachingLogWriter(new AndroidLogWriter()); michael@0: michael@0: Logger.error(TEST_LOG_TAG, TEST_MESSAGE_1, new RuntimeException()); michael@0: Logger.startLoggingTo(lw); michael@0: Logger.error(TEST_LOG_TAG, TEST_MESSAGE_2); michael@0: Logger.warn(TEST_LOG_TAG, TEST_MESSAGE_2); michael@0: Logger.info(TEST_LOG_TAG, TEST_MESSAGE_2); michael@0: Logger.debug(TEST_LOG_TAG, TEST_MESSAGE_2); michael@0: Logger.trace(TEST_LOG_TAG, TEST_MESSAGE_2); michael@0: Logger.stopLoggingTo(lw); michael@0: Logger.error(TEST_LOG_TAG, TEST_MESSAGE_3, new RuntimeException()); michael@0: } michael@0: }