Adding Checker test program to Loki.
git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@843 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
parent
a7e94f86a5
commit
42daab3664
2 changed files with 387 additions and 0 deletions
187
test/Checker/Checker_MSVC_9.vcproj
Normal file
187
test/Checker/Checker_MSVC_9.vcproj
Normal file
|
@ -0,0 +1,187 @@
|
||||||
|
<?xml version="1.0" encoding="Windows-1252"?>
|
||||||
|
<VisualStudioProject
|
||||||
|
ProjectType="Visual C++"
|
||||||
|
Version="9.00"
|
||||||
|
Name="Checker"
|
||||||
|
ProjectGUID="{2148AAC5-5CE3-493E-8D82-439ABC2E8053}"
|
||||||
|
RootNamespace="Checker"
|
||||||
|
TargetFrameworkVersion="196613"
|
||||||
|
>
|
||||||
|
<Platforms>
|
||||||
|
<Platform
|
||||||
|
Name="Win32"
|
||||||
|
/>
|
||||||
|
</Platforms>
|
||||||
|
<ToolFiles>
|
||||||
|
</ToolFiles>
|
||||||
|
<Configurations>
|
||||||
|
<Configuration
|
||||||
|
Name="Debug|Win32"
|
||||||
|
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||||
|
IntermediateDirectory="$(ConfigurationName)"
|
||||||
|
ConfigurationType="1"
|
||||||
|
CharacterSet="0"
|
||||||
|
>
|
||||||
|
<Tool
|
||||||
|
Name="VCPreBuildEventTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCCustomBuildTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCXMLDataGeneratorTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCWebServiceProxyGeneratorTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCMIDLTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="0"
|
||||||
|
StringPooling="true"
|
||||||
|
MinimalRebuild="true"
|
||||||
|
BasicRuntimeChecks="3"
|
||||||
|
RuntimeLibrary="3"
|
||||||
|
FloatingPointExceptions="false"
|
||||||
|
WarningLevel="4"
|
||||||
|
DebugInformationFormat="3"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCManagedResourceCompilerTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCResourceCompilerTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPreLinkEventTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCLinkerTool"
|
||||||
|
OutputFile="$(ProjectDir)$(ConfigurationName)\$(ProjectName).exe"
|
||||||
|
GenerateDebugInformation="true"
|
||||||
|
TargetMachine="1"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCALinkTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCManifestTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCXDCMakeTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCBscMakeTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCFxCopTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCAppVerifierTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPostBuildEventTool"
|
||||||
|
/>
|
||||||
|
</Configuration>
|
||||||
|
<Configuration
|
||||||
|
Name="Release|Win32"
|
||||||
|
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||||
|
IntermediateDirectory="$(ConfigurationName)"
|
||||||
|
ConfigurationType="1"
|
||||||
|
CharacterSet="2"
|
||||||
|
WholeProgramOptimization="1"
|
||||||
|
>
|
||||||
|
<Tool
|
||||||
|
Name="VCPreBuildEventTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCCustomBuildTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCXMLDataGeneratorTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCWebServiceProxyGeneratorTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCMIDLTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="2"
|
||||||
|
EnableIntrinsicFunctions="true"
|
||||||
|
RuntimeLibrary="2"
|
||||||
|
EnableFunctionLevelLinking="true"
|
||||||
|
WarningLevel="3"
|
||||||
|
DebugInformationFormat="3"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCManagedResourceCompilerTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCResourceCompilerTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPreLinkEventTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCLinkerTool"
|
||||||
|
UseUnicodeResponseFiles="false"
|
||||||
|
OutputFile="$(ProjectDir)$(ConfigurationName)\$(ProjectName).exe"
|
||||||
|
GenerateDebugInformation="false"
|
||||||
|
OptimizeReferences="2"
|
||||||
|
EnableCOMDATFolding="2"
|
||||||
|
TargetMachine="1"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCALinkTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCManifestTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCXDCMakeTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCBscMakeTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCFxCopTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCAppVerifierTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPostBuildEventTool"
|
||||||
|
/>
|
||||||
|
</Configuration>
|
||||||
|
</Configurations>
|
||||||
|
<References>
|
||||||
|
</References>
|
||||||
|
<Files>
|
||||||
|
<Filter
|
||||||
|
Name="Source Files"
|
||||||
|
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||||
|
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
||||||
|
>
|
||||||
|
<File
|
||||||
|
RelativePath=".\main.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
</Filter>
|
||||||
|
<Filter
|
||||||
|
Name="Header Files"
|
||||||
|
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||||
|
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
|
||||||
|
>
|
||||||
|
<File
|
||||||
|
RelativePath="..\..\include\loki\Checker.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
</Filter>
|
||||||
|
</Files>
|
||||||
|
<Globals>
|
||||||
|
</Globals>
|
||||||
|
</VisualStudioProject>
|
200
test/Checker/main.cpp
Normal file
200
test/Checker/main.cpp
Normal file
|
@ -0,0 +1,200 @@
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Test program for The Loki Library
|
||||||
|
// Copyright (c) 2008 Richard Sposato
|
||||||
|
// The copyright on this file is protected under the terms of the MIT license.
|
||||||
|
//
|
||||||
|
// Permission to use, copy, modify, distribute and sell this software for any
|
||||||
|
// purpose is hereby granted without fee, provided that the above copyright
|
||||||
|
// notice appear in all copies and that both that copyright notice and this
|
||||||
|
// permission notice appear in supporting documentation.
|
||||||
|
//
|
||||||
|
// The author makes no representations about the suitability of this software
|
||||||
|
// for any purpose. It is provided "as is" without express or implied warranty.
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// $Id$
|
||||||
|
|
||||||
|
/// @file main.cpp This provides examples on how to use Loki's Checker facility.
|
||||||
|
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include "../../include/loki/Checker.h"
|
||||||
|
|
||||||
|
|
||||||
|
#if !defined( nullptr )
|
||||||
|
#define nullptr NULL
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined( NULL )
|
||||||
|
#define NULL 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/* This class has 2 invariants. The this pointer may never equal NULL, and the
|
||||||
|
value may not equal zero.
|
||||||
|
*/
|
||||||
|
class Thingy
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
// This example shows how static functions can use a no-throw checkers.
|
||||||
|
static void ChangeThat( void )
|
||||||
|
{
|
||||||
|
CheckStaticForNoThrow checker( &Thingy::StaticIsValid );
|
||||||
|
(void)checker;
|
||||||
|
s_value--;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This example shows how static functions can use an invariant checkers.
|
||||||
|
static unsigned int GetThat( void )
|
||||||
|
{
|
||||||
|
CheckStaticInvariants checker( &Thingy::StaticIsValid );
|
||||||
|
(void)checker;
|
||||||
|
return s_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This example shows how ctors can use an invariant checker.
|
||||||
|
explicit Thingy( unsigned int value ) : m_value( value )
|
||||||
|
{
|
||||||
|
CheckInvariants checker( this, &Thingy::IsValid );
|
||||||
|
(void)checker;
|
||||||
|
checker.Check();
|
||||||
|
}
|
||||||
|
|
||||||
|
// A destructor really doesn't need a checker, but does need to confirm
|
||||||
|
// the object is valid at the start of the destructor.
|
||||||
|
~Thingy( void )
|
||||||
|
{
|
||||||
|
assert( IsValid() );
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator == ( const Thingy & that ) const
|
||||||
|
{
|
||||||
|
return ( m_value == that.m_value );
|
||||||
|
}
|
||||||
|
|
||||||
|
void DoSomethingEvil( void )
|
||||||
|
{
|
||||||
|
m_value = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This example shows how to use the no-throw checker.
|
||||||
|
unsigned int GetValue( void ) const
|
||||||
|
{
|
||||||
|
CheckForNoThrow checker( this, &Thingy::IsValid );
|
||||||
|
(void)checker;
|
||||||
|
return m_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This example shows how to use the equality checker.
|
||||||
|
unsigned int DoSomething( bool doThrow ) const
|
||||||
|
{
|
||||||
|
CheckForEquality checker( this, &Thingy::IsValid );
|
||||||
|
(void)checker;
|
||||||
|
if ( doThrow )
|
||||||
|
throw ::std::exception( "Test Exception." );
|
||||||
|
return m_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This example shows how to use the no-change checker.
|
||||||
|
void DoSomethingElse( void ) const
|
||||||
|
{
|
||||||
|
CheckForNoChange checker( this, &Thingy::IsValid );
|
||||||
|
(void)checker;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
// This is a static validator.
|
||||||
|
static bool StaticIsValid( void )
|
||||||
|
{
|
||||||
|
assert( s_value != 0 );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is a per-instance validator.
|
||||||
|
bool IsValid( void ) const
|
||||||
|
{
|
||||||
|
assert( nullptr != this );
|
||||||
|
assert( m_value != 0 );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// These lines show how to declare checkers for non-static functions in a host class.
|
||||||
|
typedef ::Loki::Checker< Thingy, ::Loki::CheckForNoThrow > CheckForNoThrow;
|
||||||
|
typedef ::Loki::Checker< Thingy, ::Loki::CheckForNoChangeOrThrow > CheckForNoChangeOrThrow;
|
||||||
|
typedef ::Loki::Checker< Thingy, ::Loki::CheckForNoChange > CheckForNoChange;
|
||||||
|
typedef ::Loki::Checker< Thingy, ::Loki::CheckForEquality > CheckForEquality;
|
||||||
|
typedef ::Loki::Checker< Thingy, ::Loki::CheckForNothing > CheckInvariants;
|
||||||
|
|
||||||
|
// These lines show how to declare checkers for static functions of a host class.
|
||||||
|
typedef ::Loki::StaticChecker< ::Loki::CheckStaticForNoThrow > CheckStaticForNoThrow;
|
||||||
|
typedef ::Loki::StaticChecker< ::Loki::CheckStaticForNothing > CheckStaticInvariants;
|
||||||
|
|
||||||
|
static unsigned int s_value;
|
||||||
|
|
||||||
|
unsigned int m_value;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
unsigned int Thingy::s_value = 10;
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// This is a validator function called by checkers inside standalone functions.
|
||||||
|
bool AllIsValid( void )
|
||||||
|
{
|
||||||
|
assert( Thingy::GetThat() != 0 );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// These lines show how to declare checkers for standalone functions.
|
||||||
|
typedef ::Loki::StaticChecker< ::Loki::CheckStaticForNoThrow > CheckStaticForNoThrow;
|
||||||
|
typedef ::Loki::StaticChecker< ::Loki::CheckStaticForNothing > CheckStaticInvariants;
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void DoSomething( void )
|
||||||
|
{
|
||||||
|
// This example shows how to use a checker in a stand-alone function.
|
||||||
|
CheckStaticForNoThrow checker( &AllIsValid );
|
||||||
|
(void)checker;
|
||||||
|
Thingy::ChangeThat();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
int main( unsigned int argc, const char * const argv[] )
|
||||||
|
{
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// First do some tests on class member functions.
|
||||||
|
Thingy t1( 1 );
|
||||||
|
t1.DoSomething( false );
|
||||||
|
Thingy t2( 2 );
|
||||||
|
t2.DoSomething( true );
|
||||||
|
|
||||||
|
// Next do some tests with static member functions.
|
||||||
|
Thingy::ChangeThat();
|
||||||
|
const unsigned int value = Thingy::GetThat();
|
||||||
|
assert( value != 0 );
|
||||||
|
|
||||||
|
// Then do a test with a standalone function.
|
||||||
|
DoSomething();
|
||||||
|
}
|
||||||
|
catch ( ... )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
Loading…
Add table
Add a link
Reference in a new issue