示例#1
0
        public void TestListner()
        {
            // add the listener
            TestListener testListnerOne = new TestListener(1234);
            TestListener testListnerTwo = new TestListener(12345);

            // remove previous listeners
            Debug.RemoveAllListeners();
            Assert.AreEqual(Debug.ListenerCount, 0, "Failed to remove all listeners");

            // add listeners
            Debug.AddListner(testListnerOne);
            Debug.AddListner(testListnerTwo);
            Assert.AreEqual(Debug.ListenerCount,2, "Failed to add listeners");

            // add duplicate listener
            Assert.IsFalse(Debug.AddListner(testListnerOne), "Added duplicate test listener");

            // get listener by id
            Assert.IsNotNull(Debug.GetListnerById(1234), "Failed to get listener by ID");

            // get listener by index
            Assert.IsNotNull(Debug.GetListnerByIndex(1), "Failed to get listener by index");

            // get invalid listener by id
            Assert.IsNull(Debug.GetListnerById(567), "Returned invalid listener by ID");

            // get invalid listener by index
            Assert.IsNull(Debug.GetListnerByIndex(2), "Returned invalid listener by index");

            testListnerOne.dumpCount = 0;
            testListnerOne.dumpCount = 0;

            testListnerTwo.Enabled = false;

            // dump some messages
            Debug.RemoveAllFilters();

            Debug.Report("Test string");
            Debug.Report("Test string");
            Debug.Report("Test string");

            Assert.AreEqual(3,testListnerOne.dumpCount, "Failed to send messages to listener");
            Assert.AreEqual(testListnerTwo.dumpCount, 0, "Messages sent to disabled listener");

            // remove the listeners
            Debug.RemoveAllListeners();
            Assert.IsTrue(Debug.ListenerCount == 0, "Failed to remove all listeners");
        }
示例#2
0
        public void TestFilter()
        {
            TestFilter filter = new TestFilter(1234);
            TestListener listener = new TestListener(12345);

            // remove previous filters
            Debug.RemoveAllFilters();
            Assert.AreEqual(Debug.FilterCount, 0, "Failed to remove all filters");

            // add the filter
            Debug.AddFilter(filter);
            Assert.AreEqual(Debug.FilterCount, 1, "Failed to add filter");

            // add duplicate filter
            Assert.IsFalse(Debug.AddFilter(filter), "Added duplicate filter");

            // get filter by ID
            Assert.IsNotNull(Debug.GetFilterById(1234), "Failed to get filter by ID");

            // get filter by index
            Assert.IsNotNull(Debug.GetFilterByIndex(0), "Failed to get filter by index");

            // get invalid listener by id
            Assert.IsNull(Debug.GetFilterById(567), "Returned invalid listener by ID");

            // get invalid listener by index
            Assert.IsNull(Debug.GetFilterByIndex(1), "Returned invalid listener by index");

            // add the listener
            Debug.AddListner(listener);
            listener.dumpCount = 0;

            // dump some messages
            Debug.Report("test");
            Debug.Report("block test");

            Assert.AreNotEqual(0,listener.dumpCount, "All messages blocked");
            Assert.LessOrEqual(1,listener.dumpCount, "Some messages not blocked");

            // test with the filter disabled
            filter.Enabled = false;

            listener.dumpCount = 0;
            Debug.Report("test");
            Debug.Report("block test");

            Assert.AreNotEqual(0,listener.dumpCount, "All messages blocked");
            Assert.AreEqual(2,listener.dumpCount, "Some messages not blocked");

            // remove all filters
            Debug.RemoveAllFilters();
            Assert.AreEqual(0,Debug.FilterCount, "Failed to remove all listeners");
        }