Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | package org.mozilla.gecko.background.common; |
michael@0 | 5 | |
michael@0 | 6 | import org.mozilla.gecko.background.common.log.Logger; |
michael@0 | 7 | import org.mozilla.gecko.background.common.log.writers.AndroidLevelCachingLogWriter; |
michael@0 | 8 | import org.mozilla.gecko.background.common.log.writers.AndroidLogWriter; |
michael@0 | 9 | import org.mozilla.gecko.background.common.log.writers.LogWriter; |
michael@0 | 10 | import org.mozilla.gecko.background.helpers.AndroidSyncTestCase; |
michael@0 | 11 | |
michael@0 | 12 | public class TestAndroidLogWriters extends AndroidSyncTestCase { |
michael@0 | 13 | public static final String TEST_LOG_TAG = "TestAndroidLogWriters"; |
michael@0 | 14 | |
michael@0 | 15 | public static final String TEST_MESSAGE_1 = "LOG TEST MESSAGE one"; |
michael@0 | 16 | public static final String TEST_MESSAGE_2 = "LOG TEST MESSAGE two"; |
michael@0 | 17 | public static final String TEST_MESSAGE_3 = "LOG TEST MESSAGE three"; |
michael@0 | 18 | |
michael@0 | 19 | public void setUp() { |
michael@0 | 20 | Logger.stopLoggingToAll(); |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | public void tearDown() { |
michael@0 | 24 | Logger.resetLogging(); |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | /** |
michael@0 | 28 | * Verify these *all* appear in the Android log by using |
michael@0 | 29 | * <code>adb logcat | grep TestAndroidLogWriters</code> after executing |
michael@0 | 30 | * <code>adb shell setprop log.tag.TestAndroidLogWriters ERROR</code>. |
michael@0 | 31 | * <p> |
michael@0 | 32 | * This writer does not use the Android log levels! |
michael@0 | 33 | */ |
michael@0 | 34 | public void testAndroidLogWriter() { |
michael@0 | 35 | LogWriter lw = new AndroidLogWriter(); |
michael@0 | 36 | |
michael@0 | 37 | Logger.error(TEST_LOG_TAG, TEST_MESSAGE_1, new RuntimeException()); |
michael@0 | 38 | Logger.startLoggingTo(lw); |
michael@0 | 39 | Logger.error(TEST_LOG_TAG, TEST_MESSAGE_2); |
michael@0 | 40 | Logger.warn(TEST_LOG_TAG, TEST_MESSAGE_2); |
michael@0 | 41 | Logger.info(TEST_LOG_TAG, TEST_MESSAGE_2); |
michael@0 | 42 | Logger.debug(TEST_LOG_TAG, TEST_MESSAGE_2); |
michael@0 | 43 | Logger.trace(TEST_LOG_TAG, TEST_MESSAGE_2); |
michael@0 | 44 | Logger.stopLoggingTo(lw); |
michael@0 | 45 | Logger.error(TEST_LOG_TAG, TEST_MESSAGE_3, new RuntimeException()); |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | /** |
michael@0 | 49 | * Verify only *some* of these appear in the Android log by using |
michael@0 | 50 | * <code>adb logcat | grep TestAndroidLogWriters</code> after executing |
michael@0 | 51 | * <code>adb shell setprop log.tag.TestAndroidLogWriters INFO</code>. |
michael@0 | 52 | * <p> |
michael@0 | 53 | * This writer should use the Android log levels! |
michael@0 | 54 | */ |
michael@0 | 55 | public void testAndroidLevelCachingLogWriter() throws Exception { |
michael@0 | 56 | LogWriter lw = new AndroidLevelCachingLogWriter(new AndroidLogWriter()); |
michael@0 | 57 | |
michael@0 | 58 | Logger.error(TEST_LOG_TAG, TEST_MESSAGE_1, new RuntimeException()); |
michael@0 | 59 | Logger.startLoggingTo(lw); |
michael@0 | 60 | Logger.error(TEST_LOG_TAG, TEST_MESSAGE_2); |
michael@0 | 61 | Logger.warn(TEST_LOG_TAG, TEST_MESSAGE_2); |
michael@0 | 62 | Logger.info(TEST_LOG_TAG, TEST_MESSAGE_2); |
michael@0 | 63 | Logger.debug(TEST_LOG_TAG, TEST_MESSAGE_2); |
michael@0 | 64 | Logger.trace(TEST_LOG_TAG, TEST_MESSAGE_2); |
michael@0 | 65 | Logger.stopLoggingTo(lw); |
michael@0 | 66 | Logger.error(TEST_LOG_TAG, TEST_MESSAGE_3, new RuntimeException()); |
michael@0 | 67 | } |
michael@0 | 68 | } |