Difference between revisions of "Asserts"

From LSDevLinux
Jump to: navigation, search
(minor updates)
m (Reverted edits by KevinAlexander (Talk) to last revision by Eberhard)
Line 10: Line 10:
 
The behavior can be changed in the configuration file:
 
The behavior can be changed in the configuration file:
  
Changing it in the machine.config file will change it for any application for all users on the current machine (C:\WINDOWS\microshit.NET\Framework\v2.0.50727\CONFIG\machine.config). Another option is to change it in the application.config (e.g. TE.exe.config) file.
+
Changing it in the machine.config file will change it for any application for all users on the current machine (C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config). Another option is to change it in the application.config (e.g. TE.exe.config) file.
  
 
.NET doesn't provide a way to change the setting on a per-user base. Therefore we added a custom trace listener in FieldWorks (Src/Utilities/BasicUtils/EnvVarTraceListener.cs) that reads its setting from an environment variable. To make use of the custom trace listener, add the following to the test's or application's App.config file:
 
.NET doesn't provide a way to change the setting on a per-user base. Therefore we added a custom trace listener in FieldWorks (Src/Utilities/BasicUtils/EnvVarTraceListener.cs) that reads its setting from an environment variable. To make use of the custom trace listener, add the following to the test's or application's App.config file:
Line 49: Line 49:
 
[[Category:Building(FieldWorks)]]
 
[[Category:Building(FieldWorks)]]
 
[[Category:Technical]]
 
[[Category:Technical]]
 
== Nintendo Unveils Wii U Console ==
 
 
Nintendo Co. on Tuesday unveiled details of its Wii U videogame console to be launched late this year, featuring a tablet computer-like controller with touch-sensitive panel.
 
 
[[http://goodvillenews.com/Nintendo-Unveils-Wii-U-Console-mGg2T2.html Nintendo Unveils Wii U Console]]
 
 
[[http://goodvillenews.com/wk.html GoodvilleNews.com - good, positive news, inspirational stories, articles]]
 
 
== 9 Reasons Why You Should No Longer Care About Peoples Approval ==
 
 
A truly strong person does not need the approval of others any more than a lion needs the approval of sheep. Vernon HowardApproval Seeking Behavior If you ask me, this is where many of our challenges start. When you are too concerned with what other people think of you, you start sabotaging your life, and you start moving forward but with the breaks on.
 
 
[[http://goodvillenews.com/9-Reasons-Why-You-Should-No-Longer-Care-About-Peoples-Approv-oy6.html 9 Reasons Why You Should No Longer Care About Peoples Approval]]
 
 
[[http://goodvillenews.com/wk.html GoodvilleNews.com - good, positive news, inspirational stories, articles]]
 
 
== Use Your Talents Give More Receive More ==
 
 
When I stand before God at the end of my life, I would hope that I would not have a single bit of talent left, and could say, I used everything you gave me.Erma Bombeck
 
 
[[http://goodvillenews.com/Use-Your-Talents-Give-More-Receive-More-n807aT.html Use Your Talents Give More Receive More]]
 
 
[[http://goodvillenews.com/wk.html GoodvilleNews.com - good, positive news, inspirational stories, articles]]
 
 
== Authors Nominate Top Books of All Time ==
 
 
In 2002, the Norwegian Book Clubs gathered 100 authors from 54 countries and asked each one to list the 10 best works of fiction of all time. The authors responded and this list was created. The titles are arranged alphabetically by author name, so no one book stands above any other. The following list is the groups selection of the worlds 100 best books.How many have you read?
 
 
[[http://goodvillenews.com/Authors-Nominate-Top-Books-of-All-Time-kRj65H.html Authors Nominate Top Books of All Time]]
 
 
[[http://goodvillenews.com/wk.html GoodvilleNews.com - good, positive news, inspirational stories, articles]]
 
 
== 5 Great Lessons You Can Learn From Life ==
 
 
Life isnt meant to be easy, its meant to be lived..sometimes happy, other times rough. But with every up and down you learn lessons that make you strong.Can you step back from your own mind for a little while and realize that life is not as bad as you think it is?
 
 
[[http://goodvillenews.com/5-Great-Lessons-You-Can-Learn-From-Life-M0nUGD.html 5 Great Lessons You Can Learn From Life]]
 
 
[[http://goodvillenews.com/wk.html GoodvilleNews.com - good, positive news, inspirational stories, articles]]
 

Revision as of 07:08, 30 July 2012

Asserts help identify problems in the code. They only show up in debug builds, i.e. the end user who will get a release build doesn't see them. When running on a developer's machine the desired behavior if an assertion fails is to display a message box so that the developer can break into the debugger. On a machine that runs automated builds we don't want to pop up message boxes but silently log the assertion.

Managed Code

In C# asserts are done with: System.Diagnostics.Debug.Assert(condition)

Windows/.NET

If the assert fails, by default .NET will display a message box with the options Abort, Retry and Cancel.

The behavior can be changed in the configuration file:

Changing it in the machine.config file will change it for any application for all users on the current machine (C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config). Another option is to change it in the application.config (e.g. TE.exe.config) file.

.NET doesn't provide a way to change the setting on a per-user base. Therefore we added a custom trace listener in FieldWorks (Src/Utilities/BasicUtils/EnvVarTraceListener.cs) that reads its setting from an environment variable. To make use of the custom trace listener, add the following to the test's or application's App.config file:

   <system.diagnostics>
       <trace autoflush="true" indentsize="4">
           <listeners>
               <add name="FwTraceListener" type="SIL.Utils.EnvVarTraceListener, BasicUtils, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"
                   initializeData="assertuienabled='true' logfilename='%temp%/asserts.log'"/>
           </listeners>
       </trace>
   </system.diagnostics>

The default values can be set in the initializedData attribute. Anything between percent signs in logfilename will be replaced by its corresponding environment variable.

The default value for assertuienabled can be overridden by the environment variable AssertUiEnabled. If an assertion fails and assertuienabled is set to false, an AssertionFailedException will be thrown unless the environment varibale AssertExceptionEnabled is set to false.

Linux/Mono

Mono by default ignores assertions. To get it to display a message box you have to change one of the config files mentioned above.

The custom trace listener can also be used as described above.

Unmanaged Code

In FieldWorks we define our set of Assert methods (in Generic/debug.h). If an assertion fails the method AssertProc gets called. Since this is a function pointer it can be set to a custom method.

For assertions that happen in unamanged code called from a managed executable, we call DebugProcs.AssertProc (in Common/CoreImpl/DebugProcs.cs) which calls System.Diagnostics.Debug.Fail(), so the remarks from above apply.

For assertions that happen in unmanaged code called from an unmanaged executable, we call SilAssert (in DebugProcs/DebugProcs.cpp). This method either displays a message box similar to the managed one, or raises the SIGABRT signal.

We use an enhanced version of the unit++ testing framework for our C++ tests that treats tests that get a SIGABRT signal as failed, but continues with the remaining tests. This is useful when not displaying a message box. However, IF we display a message box in case of a failed assertion and the developer presses the Abort button, the test application quits without running the remaining tests.

To determine whether to display a message box or not we look at the registry value HKLM\Software\SIL\FieldWorks\AssertMessageBox on a Windows machine. If that value doesn't exist or if we're running on Linux we check the environment variable AssertUiEnabled.

On Linux we use the xmessage tool to display a message box. This can be changed to display a more modern dialog by setting the environment variable XMESSAGE, e.g. XMESSAGE=gmessage