1 // 2 // Copyright (c) 2010-2018 Antmicro 3 // Copyright (c) 2011-2015 Realtime Embedded 4 // 5 // This file is licensed under the MIT License. 6 // Full license text is available in 'licenses/MIT.txt'. 7 // 8 using System; 9 10 namespace Antmicro.Renode.Utilities 11 { 12 class AssertException : Exception 13 { AssertException()14 public AssertException() 15 { 16 } 17 AssertException(string message)18 public AssertException(string message) : base(message) 19 { 20 } 21 AssertException(string message, Exception inner)22 public AssertException(string message, Exception inner) : base(message, inner) 23 { 24 } 25 } 26 27 /// <summary> 28 /// Simple class that throws exception when the assertion fails. 29 /// This class' methods should be only in "debug mode", so they are defined only when 30 /// DEBUG symbol is defined, to avoid accidental condition or message parameter 31 /// evaluations in release builds. 32 /// </summary> 33 static class DebugAssert 34 { 35 #if DEBUG Assert(bool condition, string message)36 static public void Assert(bool condition, string message) 37 { 38 if(!condition) 39 { 40 throw new AssertException(String.Concat("Assert failed: ",message)); 41 } 42 } 43 AssertFalse(bool condition, string message)44 static public void AssertFalse(bool condition, string message) 45 { 46 Assert(!condition, message); 47 } 48 #endif 49 } 50 } 51 52