Exemplo n.º 1
0
        private void Test_WriteEvent_ByteArray(bool useSelfDescribingEvents, Listener listener)
        {
            EventSourceSettings settings = EventSourceSettings.EtwManifestEventFormat;

            if (useSelfDescribingEvents)
            {
                settings = EventSourceSettings.EtwSelfDescribingEventFormat;
            }

            using (var logger = new EventSourceTestByteArray(settings))
            {
                var tests = new List <SubTest>();
                /*************************************************************************/
                /**************************** byte[] TESTING *****************************/
                /*************************************************************************/
                // We only support arrays of any type with the SelfDescribing case.
                /*************************************************************************/
                byte[] blob = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
                tests.Add(new SubTest("Write/Array/EventWithByteArrayArg",
                                      delegate()
                {
                    logger.EventWithByteArrayArg(blob, 1000);
                },
                                      delegate(Event evt)
                {
                    Assert.Equal(logger.Name, evt.ProviderName);
                    Assert.Equal("EventWithByteArrayArg", evt.EventName);

                    if (evt.IsEventListener)
                    {
                        byte[] retBlob = (byte[])evt.PayloadValue(0, "blob");
                        Assert.NotNull(retBlob);
                        Assert.True(Equal(blob, retBlob));
                        Assert.Equal(1000, (int)evt.PayloadValue(1, "n"));
                    }
                }));

                if (!useSelfDescribingEvents)
                {
                    /*************************************************************************/
                    tests.Add(new SubTest("Write/Array/NonEventCallingEventWithBytePtrArg",
                                          delegate()
                    {
                        logger.NonEventCallingEventWithBytePtrArg(blob, 2, 4, 1001);
                    },
                                          delegate(Event evt)
                    {
                        Assert.Equal(logger.Name, evt.ProviderName);
                        Assert.Equal("EventWithBytePtrArg", evt.EventName);

                        if (evt.IsEtw)
                        {
                            Assert.Equal(2, evt.PayloadCount);
                            byte[] retBlob = (byte[])evt.PayloadValue(0, "blob");
                            Assert.Equal(4, retBlob.Length);
                            Assert.Equal(retBlob[0], blob[2]);
                            Assert.Equal(retBlob[3], blob[2 + 3]);
                            Assert.Equal(1001, (int)evt.PayloadValue(1, "n"));
                        }
                        else
                        {
                            Assert.Equal(3, evt.PayloadCount);
                            byte[] retBlob = (byte[])evt.PayloadValue(1, "blob");
                            Assert.Equal(1001, (int)evt.PayloadValue(2, "n"));
                        }
                    }));
                }

                tests.Add(new SubTest("Write/Array/EventWithLongByteArray",
                                      delegate()
                {
                    logger.EventWithLongByteArray(blob, 1000);
                },
                                      delegate(Event evt)
                {
                    Assert.Equal(logger.Name, evt.ProviderName);
                    Assert.Equal("EventWithLongByteArray", evt.EventName);

                    Assert.Equal(2, evt.PayloadCount);
                    byte[] retBlob = (byte[])evt.PayloadValue(0, "blob");
                    Assert.True(Equal(blob, retBlob));

                    Assert.Equal(1000, (long)evt.PayloadValue(1, "lng"));
                }));

                // If you only wish to run one or several of the tests you can filter them here by
                // Uncommenting the following line.
                // tests = tests.FindAll(test => Regex.IsMatch(test.Name, "ventWithByteArray"));

                // Next run the same tests with the TraceLogging path.
                EventTestHarness.RunTests(tests, listener, logger);
            }
        }
Exemplo n.º 2
0
        private void Test_WriteEvent_ByteArray(bool useSelfDescribingEvents, Listener listener)
        {
            EventSourceSettings settings = EventSourceSettings.EtwManifestEventFormat;
            if (useSelfDescribingEvents)
                settings = EventSourceSettings.EtwSelfDescribingEventFormat;

            using (var logger = new EventSourceTestByteArray(settings))
            {
                var tests = new List<SubTest>();
                /*************************************************************************/
                /**************************** byte[] TESTING *****************************/
                /*************************************************************************/
                // We only support arrays of any type with the SelfDescribing case.  
                /*************************************************************************/
                byte[] blob = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
                tests.Add(new SubTest("Write/Array/EventWithByteArrayArg",
                    delegate ()
                    {
                        logger.EventWithByteArrayArg(blob, 1000);
                    },
                    delegate (Event evt)
                    {
                        Assert.Equal(logger.Name, evt.ProviderName);
                        Assert.Equal("EventWithByteArrayArg", evt.EventName);

                        if (evt.IsEventListener)
                        {
                            byte[] retBlob = (byte[])evt.PayloadValue(0, "blob");
                            Assert.NotNull(retBlob);
                            Assert.True(Equal(blob, retBlob));
                            Assert.Equal(1000, (int)evt.PayloadValue(1, "n"));
                        }
                    }));
 
                if (!useSelfDescribingEvents)
                {
                    /*************************************************************************/
                    tests.Add(new SubTest("Write/Array/NonEventCallingEventWithBytePtrArg",
                        delegate ()
                        {
                            logger.NonEventCallingEventWithBytePtrArg(blob, 2, 4, 1001);
                        },
                        delegate (Event evt)
                        {
                            Assert.Equal(logger.Name, evt.ProviderName);
                            Assert.Equal("EventWithBytePtrArg", evt.EventName);
                            
                            if (evt.IsEtw)
                            {
                                Assert.Equal(2, evt.PayloadCount);
                                byte[] retBlob = (byte[])evt.PayloadValue(0, "blob");
                                Assert.Equal(4, retBlob.Length);
                                Assert.Equal(retBlob[0], blob[2]);
                                Assert.Equal(retBlob[3], blob[2 + 3]);
                                Assert.Equal(1001, (int)evt.PayloadValue(1, "n"));
                            }
                            else
                            {
                                Assert.Equal(3, evt.PayloadCount);
                                byte[] retBlob = (byte[])evt.PayloadValue(1, "blob");
                                Assert.Equal(1001, (int)evt.PayloadValue(2, "n"));
                            }
                        }));
                }

                tests.Add(new SubTest("Write/Array/EventWithLongByteArray",
                    delegate ()
                    {
                        logger.EventWithLongByteArray(blob, 1000);
                    },
                    delegate (Event evt)
                    {
                        Assert.Equal(logger.Name, evt.ProviderName);
                        Assert.Equal("EventWithLongByteArray", evt.EventName);

                        Assert.Equal(2, evt.PayloadCount);
                        byte[] retBlob = (byte[])evt.PayloadValue(0, "blob");
                        Assert.True(Equal(blob, retBlob));

                        Assert.Equal(1000, (long)evt.PayloadValue(1, "lng"));
                    }));

                // If you only wish to run one or several of the tests you can filter them here by 
                // Uncommenting the following line.  
                // tests = tests.FindAll(test => Regex.IsMatch(test.Name, "ventWithByteArray"));

                // Next run the same tests with the TraceLogging path.  
                EventTestHarness.RunTests(tests, listener, logger);
            }
        }