|
| 1 | +#region Apache License |
| 2 | +// |
| 3 | +// Licensed to the Apache Software Foundation (ASF) under one or more |
| 4 | +// contributor license agreements. See the NOTICE file distributed with |
| 5 | +// this work for additional information regarding copyright ownership. |
| 6 | +// The ASF licenses this file to you under the Apache License, Version 2.0 |
| 7 | +// (the "License"); you may not use this file except in compliance with |
| 8 | +// the License. You may obtain a copy of the License at |
| 9 | +// |
| 10 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +// |
| 12 | +// Unless required by applicable law or agreed to in writing, software |
| 13 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +// See the License for the specific language governing permissions and |
| 16 | +// limitations under the License. |
| 17 | +// |
| 18 | +#endregion |
| 19 | + |
| 20 | + |
| 21 | +using System; |
| 22 | +using System.Diagnostics; |
| 23 | + |
| 24 | +using log4net.Appender; |
| 25 | +using log4net.Config; |
| 26 | +using log4net.Core; |
| 27 | +using log4net.Layout; |
| 28 | +using log4net.Repository; |
| 29 | +using NUnit.Framework; |
| 30 | + |
| 31 | +namespace log4net.Tests.Appender; |
| 32 | + |
| 33 | +/// <summary> |
| 34 | +/// Used for internal unit testing the <see cref="OutputDebugStringAppender"/> class. |
| 35 | +/// </summary> |
| 36 | +/// <remarks> |
| 37 | +/// Used for internal unit testing the <see cref="OutputDebugStringAppender"/> class. |
| 38 | +/// </remarks> |
| 39 | +[TestFixture] |
| 40 | +[Platform(Include = "Win")] |
| 41 | +public sealed class OutputDebugStringAppenderTest |
| 42 | +{ |
| 43 | + /// <summary> |
| 44 | + /// Verifies that the OutputDebugString api is called by the appender without issues |
| 45 | + /// </summary> |
| 46 | + [Test] |
| 47 | + public void AppendShouldNotCauseAnyErrors() |
| 48 | + { |
| 49 | + ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString()); |
| 50 | + |
| 51 | + OutputDebugStringAppender outputDebugStringAppender = new() |
| 52 | + { |
| 53 | + Layout = new SimpleLayout(), |
| 54 | + ErrorHandler = new FailOnError() |
| 55 | + }; |
| 56 | + outputDebugStringAppender.ActivateOptions(); |
| 57 | + |
| 58 | + BasicConfigurator.Configure(rep, outputDebugStringAppender); |
| 59 | + |
| 60 | + ILog log = LogManager.GetLogger(rep.Name, GetType()); |
| 61 | + log.Debug("Message - Сообщение - הודעה"); |
| 62 | + |
| 63 | + // need a way to check that the api is actually called and the string is properly marshalled. |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | +class FailOnError : IErrorHandler |
| 68 | +{ |
| 69 | + public void Error(string message, Exception? e, ErrorCode errorCode) => Assert.Fail($"Unexpected error: {message} exception: {e}, errorCode: {errorCode}"); |
| 70 | + public void Error(string message, Exception e) => Assert.Fail($"Unexpected error: {message} exception: {e}"); |
| 71 | + public void Error(string message) => Assert.Fail($"Unexpected error: {message}"); |
| 72 | +} |
0 commit comments