Browse Source

Delete needless unittests again

pull/114/head
nillerusr 2 years ago
parent
commit
08e3444409
  1. 45
      unittests/dmxtest/dmxtest.cpp
  2. 57
      unittests/dmxtest/dmxtest.vpc
  3. 908
      unittests/dmxtest/dmxtest_dmeloglayers.cpp
  4. 110
      unittests/dmxtest/dmxtest_vcdtodme.cpp
  5. 76
      unittests/dmxtest/dmxtestarray.cpp
  6. 393
      unittests/dmxtest/dmxtestdmelog.cpp
  7. 211
      unittests/dmxtest/dmxtestloader.cpp
  8. 111
      unittests/dmxtest/dmxtestnotify.cpp
  9. 760
      unittests/dmxtest/dmxtestserialization.cpp
  10. 1096
      unittests/dmxtest/dmxtestundoredo.cpp
  11. 104
      unittests/dmxtest/dmxtestvalue.cpp
  12. 1508
      unittests/ihvtest1/ihvtest1.cpp
  13. 106
      unittests/ihvtest1/ihvtest1.vpc
  14. 254
      unittests/ihvtest1/sys_clock.cpp
  15. 395
      unittests/networktest/networktest.cpp
  16. 23
      unittests/networktest/networktest.vpc
  17. BIN
      unittests/rt_test/gwolf.tga
  18. 87
      unittests/rt_test/rt_test.cpp
  19. BIN
      unittests/rt_test/rt_test.exe
  20. BIN
      unittests/rt_test/rt_test.pdb
  21. 39
      unittests/rt_test/rt_test.vpc

45
unittests/dmxtest/dmxtest.cpp

@ -1,45 +0,0 @@ @@ -1,45 +0,0 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Unit test program for DMX testing
//
// $NoKeywords: $
//=============================================================================//
#include "unitlib/unitlib.h"
#include "filesystem.h"
#include "datamodel/idatamodel.h"
#include "datamodel/dmelementfactoryhelper.h"
#include "tier3/tier3dm.h"
//-----------------------------------------------------------------------------
// Used to connect/disconnect the DLL
//-----------------------------------------------------------------------------
class CDmxTestAppSystem : public CTier3DmAppSystem< IAppSystem >
{
typedef CTier3DmAppSystem< IAppSystem > BaseClass;
public:
CDmxTestAppSystem()
{
}
virtual bool Connect( CreateInterfaceFn factory )
{
if ( !BaseClass::Connect( factory ) )
return false;
if ( !g_pFullFileSystem || !g_pDataModel || !g_pDmElementFramework )
return false;
return true;
}
virtual InitReturnVal_t Init()
{
MathLib_Init( 2.2f, 2.2f, 0.0f, 2.0f );
return BaseClass::Init();
}
};
USE_UNITTEST_APPSYSTEM( CDmxTestAppSystem )

57
unittests/dmxtest/dmxtest.vpc

@ -1,57 +0,0 @@ @@ -1,57 +0,0 @@
//-----------------------------------------------------------------------------
// DMXTEST.VPC
//
// Project Script
//-----------------------------------------------------------------------------
$Macro SRCDIR "..\.."
$Macro OUTBINDIR "$LIBPUBLIC\unittests"
$Include "$SRCDIR\vpc_scripts\source_dll_base.vpc"
$Configuration
{
$Compiler
{
$AdditionalIncludeDirectories "$BASE,$SRCDIR\game\shared,$SRCDIR\utils\common"
$PreprocessorDefinitions "$BASE;DMXTEST_EXPORTS"
}
}
$Project "Dmxtest"
{
$Folder "Source Files"
{
$File "$SRCDIR\movieobjects\dmx_to_vcd.cpp"
$File "dmxtest.cpp"
$File "dmxtest_dmeloglayers.cpp"
$File "dmxtest_vcdtodme.cpp"
$File "dmxtestarray.cpp"
$File "dmxtestdmelog.cpp"
$File "dmxtestloader.cpp"
$File "dmxtestnotify.cpp"
$File "dmxtestserialization.cpp"
$File "dmxtestundoredo.cpp"
$File "$SRCDIR\public\interpolatortypes.cpp"
$File "$SRCDIR\public\movieobjects\movieobjects.cpp"
}
$Folder "Header Files"
{
$File "$SRCDIR\public\movieobjects\dmx_to_vcd.h"
$File "$SRCDIR\public\interpolatortypes.h"
}
$Folder "Link Libraries"
{
$Lib datamodel
$Lib choreoobjects
$Lib dmserializers
$Lib mathlib
$Lib dmxloader
$Lib movieobjects
$Lib tier2
$Lib tier3
$Lib unitlib
}
}

908
unittests/dmxtest/dmxtest_dmeloglayers.cpp

@ -1,908 +0,0 @@ @@ -1,908 +0,0 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#include "unitlib/unitlib.h"
#include "datamodel/dmelement.h"
#include "movieobjects/movieobjects.h"
#include "datamodel/idatamodel.h"
#include "movieobjects/dmechannel.h"
#include "movieobjects/dmelog.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
#define NUM_CHANNELS 1
#define NUM_LOG_ENTRIES 10
enum
{
SPEW_DIFFS = (1<<0),
SPEW_VALUES= (1<<1),
SPEW_KEYS= (1<<2),
};
static void ValidateDataSets( int spew, char const *testname, CUtlVector< CUtlVector< float > >& values, CUtlVector< CUtlVector< float > >& valuesbaked )
{
int i, j;
// Compare baked, unbaked values
Assert( values.Count() == valuesbaked.Count() );
int c = values.Count();
bool differs = false;
bool spewvalues = ( spew & SPEW_VALUES ) ? true : false;
float tol = 0.0001f;
for ( i = 0; i < c; ++i )
{
CUtlVector< float >& v = values[ i ];
CUtlVector< float >& vb = valuesbaked[ i ];
Assert( v.Count() == vb.Count() );
// Now get the values of the samples in the log
for ( j = 0; j < v.Count(); ++j )
{
Assert( vb.IsValidIndex( j ) );
if ( !vb.IsValidIndex( j ) )
continue;
float v1 = v[ j ];
float v2 = vb[ j ];
if ( fabs( v1 - v2 ) > tol )
{
differs = true;
}
if ( spewvalues )
{
Msg( "%d %f %f\n", j, v[ j ], vb[ j ] );
}
}
}
Msg( " %s\n", differs ? "FAILED" : "OK" );
if ( !(spew & SPEW_DIFFS ) )
return;
for ( i = 0; i < c; ++i )
{
CUtlVector< float >& v = values[ i ];
CUtlVector< float >& vb = valuesbaked[ i ];
Assert( v.Count() == vb.Count() );
// Now get the values of the samples in the log
for ( j = 0; j < v.Count(); ++j )
{
Assert( vb.IsValidIndex( j ) );
if ( !vb.IsValidIndex( j ) )
continue;
if ( v[ j ] == vb[ j ] )
{
if ( differs )
{
Msg( "%d found %f to equal %f\n", j, v[ j ], vb[ j ] );
}
continue;
}
Msg( "%d expected %f to equal %f\n", j, v[ j ], vb[ j ] );
}
}
if ( differs )
{
Msg( "End Test '%s'\n---------------\n", testname );
}
}
static void CreateChannels( int num, CUtlVector< CDmeChannel * >& channels, DmFileId_t fileid )
{
CDisableUndoScopeGuard guard;
for ( int i = 0; i < num; ++i )
{
CDmeChannel *channel = NULL;
channel = CreateElement< CDmeChannel >( "channel1", fileid );
channels.AddToTail( channel );
channel->CreateLog( AT_FLOAT ); // only care about float logs for now
channel->SetMode( CM_PLAY );// Make sure it's in playback mode
}
}
struct TestLayer_t
{
enum
{
TYPE_SIMPLESLOPE = 0, // value == time
TYPE_SINE, // sinusoidal
TYPE_CONSTANT,
};
TestLayer_t() :
startTime( 0 ),
endTime( 0 ),
timeStep( 0 ),
usecurvetype( false ),
curvetype( CURVE_DEFAULT ),
type( TYPE_SIMPLESLOPE ),
constantvalue( 0.0f )
{
}
float ValueForTime( DmeTime_t time ) const
{
float t = (float)time.GetSeconds();
switch ( type )
{
default:
case TYPE_SIMPLESLOPE:
return t;
case TYPE_SINE:
return constantvalue * ( 1.0f + sin( ( t * 0.002f ) * 2 * M_PI ) ) * 0.5f;
case TYPE_CONSTANT:
return constantvalue;
}
return t;
}
int type;
DmeTime_t startTime;
DmeTime_t endTime;
DmeTime_t timeStep;
bool usecurvetype;
int curvetype;
float constantvalue;
};
struct TestParams_t
{
TestParams_t() :
testundo( false ),
usecurves( false ),
purgevalues( true ),
testabort( false ),
spew( 0 ),
spewnontopmostlayers( false ),
defaultcurve( CURVE_DEFAULT ),
mintime( DmeTime_t( 0 ) ),
maxtime( DmeTime_t( 100 ) )
{
}
int spew;
bool usecurves;
bool purgevalues;
bool testundo;
bool testabort;
bool spewnontopmostlayers;
int defaultcurve;
DmeTime_t mintime;
DmeTime_t maxtime;
CUtlVector< TestLayer_t > layers;
void Reset()
{
purgevalues = true;
usecurves = false;
testundo = false;
testabort = false;
spewnontopmostlayers = false;
spew = 0;
mintime = DmeTime_t( 0 );
maxtime = DmeTime_t( 100 );
defaultcurve = CURVE_DEFAULT;
layers.RemoveAll();
}
void AddLayer( DmeTime_t start, DmeTime_t end, DmeTime_t step, int curvetype, int valuetype, float constantvalue = 0.0f )
{
TestLayer_t tl;
tl.startTime = start;
tl.endTime = end;
tl.timeStep = step;
tl.curvetype = curvetype;
tl.type = valuetype;
tl.constantvalue = constantvalue;
layers.AddToTail( tl );
}
};
static void RunLayerTest( char const *testname, CUtlVector< CDmeChannel * >& channels, const TestParams_t& params )
{
if ( params.layers.Count() == 0 )
{
Assert( 0 );
return;
}
Msg( "Test '%s'...\n", testname );
g_pDataModel->StartUndo( testname, testname );
int i;
int c = channels.Count();
{
CDisableUndoScopeGuard guard;
for ( i = 0; i < NUM_CHANNELS; ++i )
{
CDmeChannel *channel = channels[ i ];
CDmeTypedLog< float > *pLog = CastElement< CDmeTypedLog< float > >( channel->GetLog() );
Assert( pLog );
pLog->ClearKeys(); // reset it
CDmeCurveInfo *pCurveInfo = NULL;
if ( params.usecurves )
{
pCurveInfo = pLog->GetOrCreateCurveInfo();
pCurveInfo->SetDefaultCurveType( params.defaultcurve );
pCurveInfo->SetMinValue( 0.0f );
pCurveInfo->SetMaxValue( 1000.0f );
}
else
{
if ( pLog->GetCurveInfo() )
{
g_pDataModel->DestroyElement( pLog->GetCurveInfo()->GetHandle() );
}
pLog->SetCurveInfo( NULL );
}
const TestLayer_t& tl = params.layers[ 0 ];
// Now add entries
DmeTime_t logStep = tl.timeStep;
DmeTime_t logStart = tl.startTime;
for ( DmeTime_t t = logStart; t <= tl.endTime + logStep - DmeTime_t( 1 ); t += logStep )
{
DmeTime_t useTime = t;
if ( useTime > tl.endTime )
{
useTime = tl.endTime;
}
float value = tl.ValueForTime( useTime );
if ( tl.usecurvetype )
{
pLog->SetKey( useTime, value, tl.curvetype );
}
else
{
pLog->SetKey( useTime, value );
}
}
}
}
for ( int layer = 1; layer < params.layers.Count(); ++layer )
{
const TestLayer_t& tl = params.layers[ layer ];
// Test creating a layer and collapsing it back down
g_pChannelRecordingMgr->StartLayerRecording( "layer operations" );
for ( i = 0; i < c; ++i )
{
g_pChannelRecordingMgr->AddChannelToRecordingLayer( channels[ i ] ); // calls log->CreateNewLayer()
}
// Now add values to channel logs
for ( i = 0; i < c; ++i )
{
CDmeChannel *channel = channels[ i ];
CDmeTypedLog< float > *pLog = CastElement< CDmeTypedLog< float > >( channel->GetLog() );
Assert( pLog );
// Now add entries
DmeTime_t logStep = tl.timeStep;
DmeTime_t logStart = tl.startTime;
for ( DmeTime_t t = logStart; t <= tl.endTime + logStep - DmeTime_t( 1 ); t += logStep )
{
DmeTime_t useTime = t;
if ( useTime > tl.endTime )
{
useTime = tl.endTime;
}
float value = tl.ValueForTime( useTime );
if ( tl.usecurvetype )
{
pLog->SetKey( useTime, value, tl.curvetype );
}
else
{
pLog->SetKey( useTime, value );
}
}
}
g_pChannelRecordingMgr->FinishLayerRecording( 0.0f, false ); // don't flatten layers here, we'll do it manually
}
// Now sample values
CUtlVector< CUtlVector< float > > values;
CUtlVector< CUtlVector< float > > valuesbaked;
for ( i = 0; i < c; ++i )
{
CDmeChannel *channel = channels[ i ];
CDmeTypedLog< float > *pLog = CastElement< CDmeTypedLog< float > >( channel->GetLog() );
Assert( pLog );
int idx = values.AddToTail();
CUtlVector< float >& v = values[ idx ];
// Now get the values of the samples in the log
for ( DmeTime_t j = params.mintime; j <= params.maxtime; j += DmeTime_t( 1 ) )
{
float fval = pLog->GetValue( j );
v.AddToTail( fval );
}
}
if ( params.spewnontopmostlayers )
{
for ( i = 0; i < c; ++i )
{
CDmeChannel *channel = channels[ i ];
CDmeTypedLog< float > *pLog = CastElement< CDmeTypedLog< float > >( channel->GetLog() );
Assert( pLog );
// Now get the values of the samples in the log
for ( DmeTime_t j = params.mintime; j <= params.maxtime; j += DmeTime_t( 1 ) )
{
float topValue = pLog->GetValue( j );
float underlyingValue = pLog->GetValueSkippingTopmostLayer( j );
Msg( "t(%d) top [%f] rest [%f]\n",
j.GetTenthsOfMS(), topValue, underlyingValue );
}
}
}
// Now test creating a layer and "undo/redo" of the layer
if ( params.testundo )
{
g_pDataModel->FinishUndo();
g_pDataModel->Undo();
g_pDataModel->Redo();
g_pDataModel->StartUndo( testname, testname );
}
{
CUndoScopeGuard guard( "Bake Layers" );
// Now bake down and resample values
for ( i = 0; i < c; ++i )
{
CDmeChannel *channel = channels[ i ];
CDmeTypedLog< float > *pLog = CastElement< CDmeTypedLog< float > >( channel->GetLog() );
Assert( pLog );
pLog->FlattenLayers( 0.0f, params.spew & SPEW_DIFFS );
int idx = valuesbaked.AddToTail();
CUtlVector< float >& v = valuesbaked[ idx ];
// Now get the values of the samples in the log
for ( DmeTime_t j = params.mintime; j <= params.maxtime; j += DmeTime_t( 1 ) )
{
float fval = pLog->GetValue( j );
v.AddToTail( fval );
}
}
}
ValidateDataSets( params.spew, testname, values, valuesbaked );
// Now test creating a layer and "undo/redo" of the layer
if ( params.testundo )
{
g_pDataModel->FinishUndo();
g_pDataModel->Undo();
g_pDataModel->Redo();
g_pDataModel->StartUndo( testname, testname );
}
if ( params.testabort )
{
g_pDataModel->AbortUndoableOperation();
}
else
{
g_pDataModel->FinishUndo();
}
}
static void RunTimeSelectionTest( char const *testname, CUtlVector< CDmeChannel * >& channels,
const TestParams_t& params, DmeTime_t tHeadPosition, DmeLog_TimeSelection_t& ts, float value )
{
if ( params.layers.Count() == 0 )
{
Assert( 0 );
return;
}
Msg( "Test '%s'...\n", testname );
int i, j;
int c = channels.Count();
if ( params.purgevalues )
{
CDisableUndoScopeGuard guard;
for ( i = 0; i < NUM_CHANNELS; ++i )
{
CDmeChannel *channel = channels[ i ];
CDmeTypedLog< float > *pLog = CastElement< CDmeTypedLog< float > >( channel->GetLog() );
Assert( pLog );
pLog->ClearKeys(); // reset it
CDmeCurveInfo *pCurveInfo = params.usecurves ? pLog->GetOrCreateCurveInfo() : pLog->GetCurveInfo();
if ( params.usecurves )
{
pCurveInfo->SetDefaultCurveType( params.defaultcurve );
pCurveInfo->SetMinValue( 0.0f );
pCurveInfo->SetMaxValue( 1000.0f );
}
else if ( !params.usecurves && pCurveInfo )
{
g_pDataModel->DestroyElement( pCurveInfo->GetHandle() );
pLog->SetCurveInfo( NULL );
}
const TestLayer_t& tl = params.layers[ 0 ];
// Now add entries
DmeTime_t logStep = tl.timeStep;
DmeTime_t logStart = tl.startTime;
for ( DmeTime_t t = logStart; t <= tl.endTime + logStep - DmeTime_t( 1 ); t += logStep )
{
DmeTime_t useTime = t;
if ( useTime > tl.endTime )
useTime = tl.endTime;
float value = tl.ValueForTime( useTime );
if ( tl.usecurvetype )
{
pLog->SetKey( useTime, value, tl.curvetype );
}
else
{
pLog->SetKey( useTime, value );
}
}
}
}
// Test creating a layer and collapsing it back down
g_pChannelRecordingMgr->StartLayerRecording( "layer operations", &ts );
for ( i = 0; i < c; ++i )
{
g_pChannelRecordingMgr->AddChannelToRecordingLayer( channels[ i ] ); // calls log->CreateNewLayer()
}
// Now add values to channel logs
for ( i = 0; i < c; ++i )
{
CDmeChannel *channel = channels[ i ];
CDmeTypedLog< float > *pLog = CastElement< CDmeTypedLog< float > >( channel->GetLog() );
Assert( pLog );
pLog->StampKeyAtHead( tHeadPosition, tHeadPosition, ts, value );
}
// Flattens the layers
g_pChannelRecordingMgr->FinishLayerRecording( 0.0f, true );
if ( params.spew & SPEW_VALUES )
{
for ( i = 0; i < c; ++i )
{
CDmeChannel *channel = channels[ i ];
CDmeTypedLog< float > *pLog = CastElement< CDmeTypedLog< float > >( channel->GetLog() );
Assert( pLog );
Assert( pLog->GetNumLayers() == 1 );
for ( DmeTime_t j = params.mintime; j <= params.maxtime; j += DmeTime_t( 1 ) )
{
float fval = pLog->GetValue( j );
Msg( "%d %f\n", j.GetTenthsOfMS(), fval );
}
}
}
if ( params.spew & SPEW_KEYS )
{
for ( i = 0; i < c; ++i )
{
CDmeChannel *channel = channels[ i ];
CDmeTypedLog< float > *pLog = CastElement< CDmeTypedLog< float > >( channel->GetLog() );
Assert( pLog );
Assert( pLog->GetNumLayers() == 1 );
int kc = pLog->GetKeyCount();
for ( j = 0; j < kc; ++j )
{
DmeTime_t time = pLog->GetKeyTime( j );
float fval = pLog->GetValue( time );
Msg( "%d %f %f\n", j, time.GetSeconds(), fval );
}
}
}
// Now test creating a layer and "undo/redo" of the layer
if ( params.testundo )
{
g_pDataModel->Undo();
g_pDataModel->Redo();
}
}
DEFINE_TESTCASE_NOSUITE( DmxTestDmeLogLayers )
{
Msg( "Running CDmeTypedLog<float> layering tests...\n" );
#ifdef _DEBUG
int nStartingCount = g_pDataModel->GetAllocatedElementCount();
#endif
CUtlVector< CDmeChannel * > channels;
DmFileId_t fileid = g_pDataModel->FindOrCreateFileId( "<DmxTestDmeLogLayers>" );
CreateChannels( NUM_CHANNELS, channels, fileid );
TestParams_t params;
{
params.testundo = false;
params.usecurves = false;
params.defaultcurve = CURVE_DEFAULT;
params.AddLayer( DmeTime_t( 0 ), DmeTime_t( 100 ), DmeTime_t( 10 ), CURVE_DEFAULT, TestLayer_t::TYPE_SIMPLESLOPE );
params.AddLayer( DmeTime_t( 5 ), DmeTime_t( 95 ), DmeTime_t( 10 ), CURVE_DEFAULT, TestLayer_t::TYPE_SIMPLESLOPE );
RunLayerTest( "One-Layer", channels, params );
params.Reset();
}
// Single layer using lerp everywhere
// -----------------------
{
params.testundo = false;
params.usecurves = true;
params.defaultcurve = CURVE_LINEAR_INTERP_TO_LINEAR_INTERP;
params.AddLayer( DmeTime_t( 0 ), DmeTime_t( 100 ), DmeTime_t( 10 ), CURVE_LINEAR_INTERP_TO_LINEAR_INTERP, TestLayer_t::TYPE_SIMPLESLOPE );
RunLayerTest( "One-Layer Lerp", channels, params );
params.Reset();
}
// Two layers using lerp
// ----------------------------
// ------------------------
{
params.testundo = false;
params.usecurves = true;
params.defaultcurve = CURVE_LINEAR_INTERP_TO_LINEAR_INTERP;
params.AddLayer( DmeTime_t( 0 ), DmeTime_t( 100 ), DmeTime_t( 10 ), CURVE_LINEAR_INTERP_TO_LINEAR_INTERP, TestLayer_t::TYPE_SIMPLESLOPE );
params.AddLayer( DmeTime_t( 5 ), DmeTime_t( 95 ), DmeTime_t( 10 ), CURVE_LINEAR_INTERP_TO_LINEAR_INTERP, TestLayer_t::TYPE_SIMPLESLOPE );
RunLayerTest( "Two-Layer Lerp (contained)", channels, params );
params.Reset();
}
// Two layers using CURVE_EASE_IN_TO_EASE_OUT, there should be some disparity
// ----------------------------
// ------------------------
{
params.testundo = false;
params.usecurves = true;
params.defaultcurve = CURVE_EASE_IN_TO_EASE_OUT;
params.AddLayer( DmeTime_t( 0 ), DmeTime_t( 100 ), DmeTime_t( 10 ), CURVE_EASE_IN_TO_EASE_OUT, TestLayer_t::TYPE_SIMPLESLOPE );
params.AddLayer( DmeTime_t( 5 ), DmeTime_t( 95 ), DmeTime_t( 10 ), CURVE_EASE_IN_TO_EASE_OUT, TestLayer_t::TYPE_SIMPLESLOPE );
RunLayerTest( "Two-Layer Ease In/Out (contained)", channels, params );
params.Reset();
}
// Two layers using lerp
// ----------------------------
// ---------
{
params.testundo = false;
params.usecurves = true;
params.mintime = DmeTime_t( -20 );
params.defaultcurve = CURVE_LINEAR_INTERP_TO_LINEAR_INTERP;
params.AddLayer( DmeTime_t( 0 ), DmeTime_t( 100 ), DmeTime_t( 10 ), CURVE_LINEAR_INTERP_TO_LINEAR_INTERP, TestLayer_t::TYPE_SIMPLESLOPE );
params.AddLayer( DmeTime_t( -20 ), DmeTime_t( 20 ), DmeTime_t( 10 ), CURVE_LINEAR_INTERP_TO_LINEAR_INTERP, TestLayer_t::TYPE_SIMPLESLOPE );
RunLayerTest( "Two-Layer Lerp (overhang start)", channels, params );
params.Reset();
}
// Two layers using lerp
// ----------------------------
// ------------
{
params.testundo = false;
params.usecurves = true;
params.maxtime = DmeTime_t( 120 );
params.defaultcurve = CURVE_LINEAR_INTERP_TO_LINEAR_INTERP;
params.AddLayer( DmeTime_t( 0 ), DmeTime_t( 100 ), DmeTime_t( 10 ), CURVE_LINEAR_INTERP_TO_LINEAR_INTERP, TestLayer_t::TYPE_SIMPLESLOPE );
params.AddLayer( DmeTime_t( 80 ), DmeTime_t( 120 ), DmeTime_t( 10 ), CURVE_LINEAR_INTERP_TO_LINEAR_INTERP, TestLayer_t::TYPE_SIMPLESLOPE );
RunLayerTest( "Two-Layer Lerp (overhang end)", channels, params );
params.Reset();
}
// Three layers using lerp
// -------------
// ----- -----
{
params.testundo = false;
params.usecurves = true;
params.defaultcurve = CURVE_LINEAR_INTERP_TO_LINEAR_INTERP;
params.mintime = DmeTime_t( -12 );
params.maxtime = DmeTime_t( 115 );
params.AddLayer( DmeTime_t( 0 ), DmeTime_t( 100 ), DmeTime_t( 10 ), CURVE_LINEAR_INTERP_TO_LINEAR_INTERP, TestLayer_t::TYPE_SIMPLESLOPE );
params.AddLayer( DmeTime_t( -12 ), DmeTime_t( 12 ), DmeTime_t( 4 ), CURVE_LINEAR_INTERP_TO_LINEAR_INTERP, TestLayer_t::TYPE_SIMPLESLOPE );
params.AddLayer( DmeTime_t( 85 ), DmeTime_t( 115 ), DmeTime_t( 5 ), CURVE_LINEAR_INTERP_TO_LINEAR_INTERP, TestLayer_t::TYPE_SIMPLESLOPE );
RunLayerTest( "Three-Layer Lerp (overhang start + end)", channels, params );
params.Reset();
}
// Three layers using lerp
// -------------
// -----
// --
{
params.testundo = false;
params.usecurves = true;
params.defaultcurve = CURVE_LINEAR_INTERP_TO_LINEAR_INTERP;
params.AddLayer( DmeTime_t( 0 ), DmeTime_t( 100 ), DmeTime_t( 10 ), CURVE_LINEAR_INTERP_TO_LINEAR_INTERP, TestLayer_t::TYPE_SIMPLESLOPE );
params.AddLayer( DmeTime_t( 25 ), DmeTime_t( 75 ), DmeTime_t( 10 ), CURVE_LINEAR_INTERP_TO_LINEAR_INTERP, TestLayer_t::TYPE_SIMPLESLOPE );
params.AddLayer( DmeTime_t( 40 ), DmeTime_t( 60 ), DmeTime_t( 5 ), CURVE_LINEAR_INTERP_TO_LINEAR_INTERP, TestLayer_t::TYPE_SIMPLESLOPE );
RunLayerTest( "Three-Layer Lerp (layer inside layer)", channels, params );
params.Reset();
}
// Three layers using lerp
// -------------
// -----
// --
{
params.testundo = false;
params.usecurves = true;
params.defaultcurve = CURVE_LINEAR_INTERP_TO_LINEAR_INTERP;
params.AddLayer( DmeTime_t( 0 ), DmeTime_t( 100 ), DmeTime_t( 10 ), CURVE_LINEAR_INTERP_TO_LINEAR_INTERP, TestLayer_t::TYPE_SIMPLESLOPE );
params.AddLayer( DmeTime_t( 25 ), DmeTime_t( 75 ), DmeTime_t( 10 ), CURVE_LINEAR_INTERP_TO_LINEAR_INTERP, TestLayer_t::TYPE_SIMPLESLOPE );
params.AddLayer( DmeTime_t( 70 ), DmeTime_t( 80 ), DmeTime_t( 2 ), CURVE_LINEAR_INTERP_TO_LINEAR_INTERP, TestLayer_t::TYPE_SIMPLESLOPE );
RunLayerTest( "Three-Layer Lerp (first layer contained, second layer overlapping first at end)", channels, params );
params.Reset();
}
// Three layers using lerp
// -------------
// -----
// --
{
params.testundo = false;
params.usecurves = true;
params.defaultcurve = CURVE_LINEAR_INTERP_TO_LINEAR_INTERP;
params.AddLayer( DmeTime_t( 0 ), DmeTime_t( 100 ), DmeTime_t( 10 ), CURVE_LINEAR_INTERP_TO_LINEAR_INTERP, TestLayer_t::TYPE_SIMPLESLOPE );
params.AddLayer( DmeTime_t( 25 ), DmeTime_t( 75 ), DmeTime_t( 10 ), CURVE_LINEAR_INTERP_TO_LINEAR_INTERP, TestLayer_t::TYPE_SIMPLESLOPE );
params.AddLayer( DmeTime_t( 15 ), DmeTime_t( 35 ), DmeTime_t( 5 ), CURVE_LINEAR_INTERP_TO_LINEAR_INTERP, TestLayer_t::TYPE_SIMPLESLOPE );
RunLayerTest( "Three-Layer Lerp (first layer contained, second layer overlapping first at start)", channels, params );
params.Reset();
}
// Four layers using lerp
// ---------------
// -----
// ----
// -------
{
params.testundo = false;
params.usecurves = true;
// params.spewnontopmostlayers = true;
params.defaultcurve = CURVE_LINEAR_INTERP_TO_LINEAR_INTERP;
params.AddLayer( DmeTime_t( 0 ), DmeTime_t( 100 ), DmeTime_t( 10 ), CURVE_LINEAR_INTERP_TO_LINEAR_INTERP, TestLayer_t::TYPE_CONSTANT, 20.0f );
params.AddLayer( DmeTime_t( 15 ), DmeTime_t( 40 ), DmeTime_t( 10 ), CURVE_LINEAR_INTERP_TO_LINEAR_INTERP, TestLayer_t::TYPE_SIMPLESLOPE );
params.AddLayer( DmeTime_t( 60 ), DmeTime_t( 85 ), DmeTime_t( 5 ), CURVE_LINEAR_INTERP_TO_LINEAR_INTERP, TestLayer_t::TYPE_SIMPLESLOPE );
params.AddLayer( DmeTime_t( 35 ), DmeTime_t( 79 ), DmeTime_t( 5 ), CURVE_LINEAR_INTERP_TO_LINEAR_INTERP, TestLayer_t::TYPE_SIMPLESLOPE );
RunLayerTest( "Four-Layer Lerp (top overlapping end of 1st and start of 2nd layer)", channels, params );
params.Reset();
}
// Single layer using lerp everywhere
// -----------------------
{
params.testundo = false;
params.usecurves = true;
params.spew = 0; //SPEW_VALUES | SPEW_KEYS;
params.mintime = DmeTime_t( 0 );
params.maxtime = DmeTime_t( 10000 );
params.defaultcurve = CURVE_LINEAR_INTERP_TO_LINEAR_INTERP;
params.AddLayer( DmeTime_t( 0 ), DmeTime_t( 10000 ), DmeTime_t( 20 ), CURVE_LINEAR_INTERP_TO_LINEAR_INTERP, TestLayer_t::TYPE_SINE, 100.0f );
DmeTime_t tHeadPosition = DmeTime_t( 5000 );
DmeLog_TimeSelection_t ts;
ts.m_nTimes[ TS_LEFT_FALLOFF ] = tHeadPosition + DmeTime_t( -987 );
ts.m_nTimes[ TS_LEFT_HOLD ] = ts.m_nTimes[ TS_RIGHT_HOLD ] = tHeadPosition;
ts.m_nTimes[ TS_RIGHT_FALLOFF ] = tHeadPosition + DmeTime_t( 1052 );
ts.m_nFalloffInterpolatorTypes[ 0 ] = ts.m_nFalloffInterpolatorTypes[ 1 ] = INTERPOLATE_EASE_INOUT;
// Resample at 50 msec intervals
ts.m_bResampleMode = true;
ts.m_nResampleInterval = DmeTime_t( 50 );
///params.spew |= SPEW_KEYS | SPEW_VALUES;
RunTimeSelectionTest( "One-Layer Time Selection at 50, falloff 25, EASE_INOUT interp", channels, params, tHeadPosition, ts, 250 );
params.purgevalues = false;
// params.spew |= SPEW_VALUES;
// Shift the head and do it all again
tHeadPosition = DmeTime_t( 2000 );
ts.m_nTimes[ TS_LEFT_FALLOFF ] = DmeTime_t( 1487 );
ts.m_nTimes[ TS_LEFT_HOLD ] = ts.m_nTimes[ TS_RIGHT_HOLD ] = tHeadPosition;
ts.m_nTimes[ TS_RIGHT_FALLOFF ] = tHeadPosition + DmeTime_t( 631 );
RunTimeSelectionTest( "2nd layer", channels, params, tHeadPosition, ts, 500 );
params.Reset();
}
// Single layer using lerp everywhere
// -----------------------
{
params.testundo = true;
params.usecurves = true;
params.spew = 0; //SPEW_VALUES | SPEW_KEYS;
params.mintime = DmeTime_t( 0 );
params.maxtime = DmeTime_t( 1000 );
params.defaultcurve = CURVE_LINEAR_INTERP_TO_LINEAR_INTERP;
params.AddLayer( DmeTime_t( 0 ), DmeTime_t( 1000 ), DmeTime_t( 20 ), CURVE_LINEAR_INTERP_TO_LINEAR_INTERP, TestLayer_t::TYPE_CONSTANT, 100.0f );
DmeTime_t tHeadPosition = DmeTime_t( 500 );
DmeLog_TimeSelection_t ts;
ts.m_nTimes[ TS_LEFT_FALLOFF ] = tHeadPosition + DmeTime_t( -100 );
ts.m_nTimes[ TS_LEFT_HOLD ] = ts.m_nTimes[ TS_RIGHT_HOLD ] = tHeadPosition;
ts.m_nTimes[ TS_RIGHT_FALLOFF ] = tHeadPosition + DmeTime_t( 100 );
ts.m_nFalloffInterpolatorTypes[ 0 ] = ts.m_nFalloffInterpolatorTypes[ 1 ] = INTERPOLATE_LINEAR_INTERP;
// Resample at 50 msec intervals
ts.m_bResampleMode = true;
ts.m_nResampleInterval = DmeTime_t( 10 );
// params.spew |= SPEW_VALUES;
RunTimeSelectionTest( "Resetting layer", channels, params, tHeadPosition, ts, 200 );
params.purgevalues = false;
//params.spew |= SPEW_VALUES;
// Shift the head and do it all again
//ts.m_nRelativeFalloffTimes[ 0 ] = 1487 - 2000;
//ts.m_nRelativeHoldTimes[ 0 ] = ts.m_nRelativeHoldTimes[ 1 ] = 0;
//ts.m_nRelativeFalloffTimes[ 1 ] = 631;
//ts.SetHeadPosition( 2000 );
RunTimeSelectionTest( "2nd layer", channels, params, tHeadPosition, ts, 110 );
params.Reset();
}
// g_pDataModel->TraceUndo( true );
// Test abort undo stuff
for ( int i = 0; i < 2; ++i )
// Four layers using lerp
// ---------------
// -----
// ----
// -------
{
params.testundo = false;
params.testabort = i != 1 ? true : false;
params.usecurves = false;
// params.spewnontopmostlayers = true;
params.defaultcurve = CURVE_LINEAR_INTERP_TO_LINEAR_INTERP;
params.AddLayer( DmeTime_t( 0 ), DmeTime_t( 10 ), DmeTime_t( 10 ), CURVE_LINEAR_INTERP_TO_LINEAR_INTERP, TestLayer_t::TYPE_CONSTANT, 20.0f );
params.AddLayer( DmeTime_t( 5 ), DmeTime_t( 6 ), DmeTime_t( 1 ), CURVE_LINEAR_INTERP_TO_LINEAR_INTERP, TestLayer_t::TYPE_SIMPLESLOPE );
RunLayerTest( "Four-Layer Lerp (top overlapping end of 1st and start of 2nd layer)", channels, params );
params.Reset();
}
// g_pDataModel->TraceUndo( false );
//DestroyChannels( channels );
g_pDataModel->ClearUndo();
g_pDataModel->RemoveFileId( fileid );
#ifdef _DEBUG
int nEndingCount = g_pDataModel->GetAllocatedElementCount();
AssertEquals( nEndingCount, nStartingCount );
if ( nEndingCount != nStartingCount )
{
for ( DmElementHandle_t hElement = g_pDataModel->FirstAllocatedElement() ;
hElement != DMELEMENT_HANDLE_INVALID;
hElement = g_pDataModel->NextAllocatedElement( hElement ) )
{
CDmElement *pElement = g_pDataModel->GetElement( hElement );
Assert( pElement );
if ( !pElement )
return;
Msg( "[%s : %s] in memory\n", pElement->GetName(), pElement->GetTypeString() );
}
}
#endif
}
DEFINE_TESTCASE_NOSUITE( DmxTestDmeLogLayersUndo )
{
Msg( "Running CDmeTypedLog<float> layering UNDO tests...\n" );
#ifdef _DEBUG
int nStartingCount = g_pDataModel->GetAllocatedElementCount();
#endif
CUtlVector< CDmeChannel * > channels;
DmFileId_t fileid = g_pDataModel->FindOrCreateFileId( "<DmxTestDmeLogLayersUndo>" );
CreateChannels( NUM_CHANNELS, channels, fileid );
TestParams_t params;
// g_pDataModel->TraceUndo( true );
// Test abort undo stuff
for ( int i = 0; i < 2; ++i )
{
params.testundo = false;
params.testabort = true;
params.usecurves = false;
// params.spewnontopmostlayers = true;
params.defaultcurve = CURVE_LINEAR_INTERP_TO_LINEAR_INTERP;
params.AddLayer( DmeTime_t( 0 ), DmeTime_t( 1000 ), DmeTime_t( 10 ), CURVE_LINEAR_INTERP_TO_LINEAR_INTERP, TestLayer_t::TYPE_CONSTANT, 20.0f );
params.AddLayer( DmeTime_t( 100 ), DmeTime_t( 900 ), DmeTime_t( 5 ), CURVE_LINEAR_INTERP_TO_LINEAR_INTERP, TestLayer_t::TYPE_SIMPLESLOPE );
RunLayerTest( "Abort undo", channels, params );
params.Reset();
}
// g_pDataModel->TraceUndo( false );
g_pDataModel->ClearUndo();
g_pDataModel->RemoveFileId( fileid );
#ifdef _DEBUG
int nEndingCount = g_pDataModel->GetAllocatedElementCount();
AssertEquals( nEndingCount, nStartingCount );
if ( nEndingCount != nStartingCount )
{
for ( DmElementHandle_t hElement = g_pDataModel->FirstAllocatedElement() ;
hElement != DMELEMENT_HANDLE_INVALID;
hElement = g_pDataModel->NextAllocatedElement( hElement ) )
{
CDmElement *pElement = g_pDataModel->GetElement( hElement );
Assert( pElement );
if ( !pElement )
return;
Msg( "[%s : %s] in memory\n", pElement->GetName(), pElement->GetTypeString() );
}
}
#endif
}

110
unittests/dmxtest/dmxtest_vcdtodme.cpp

@ -1,110 +0,0 @@ @@ -1,110 +0,0 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#include "unitlib/unitlib.h"
#include "datamodel/dmelement.h"
#include "movieobjects/movieobjects.h"
#include "datamodel/idatamodel.h"
#include "tier1/utlbuffer.h"
#include "filesystem.h"
#include "movieobjects/dmelog.h"
#include "choreoscene.h"
#include "choreoevent.h"
#include "iscenetokenprocessor.h"
#include "tier1/tokenreader.h"
#include "characterset.h"
#include "movieobjects/dmx_to_vcd.h"
#include "tier3/scenetokenprocessor.h"
#include "tier2/tier2.h"
char const *vcdtestfile = "dmxtest.vcd";
void RunSceneToDmxTests( CChoreoScene *scene )
{
DmFileId_t fileid = g_pDataModel->FindOrCreateFileId( scene->GetFilename() );
CDmeFilmClip *dmx = CreateElement< CDmeFilmClip >( scene->GetFilename(), fileid );
Assert( dmx );
bool success = ConvertSceneToDmx( scene, dmx );
Assert( success );
CChoreoScene *scene2 = new CChoreoScene( NULL );
scene2->SetFileName( scene->GetFilename() );
success = ConvertDmxToScene( dmx, scene2 );
Assert( success );
char sz[ 512 ];
Q_StripExtension( scene->GetFilename(), sz, sizeof( sz ) );
Q_strncat( sz, "_2.vcd", sizeof( sz ), COPY_ALL_CHARACTERS );
scene2->SaveToFile( sz );
delete scene2;
g_pDataModel->RemoveFileId( fileid );
}
DEFINE_TESTCASE_NOSUITE( DmxTestVcdToDme )
{
Msg( "Running .vcd (faceposer) to dmx tests\n" );
#ifdef _DEBUG
int nStartingCount = g_pDataModel->GetAllocatedElementCount();
#endif
CDisableUndoScopeGuard guard;
g_pDmElementFramework->BeginEdit();
const char *pFileName = vcdtestfile;
char pFullPathName[ MAX_PATH ];
char pDir[ MAX_PATH ];
if ( g_pFullFileSystem->GetCurrentDirectory( pDir, sizeof( pDir ) ) )
{
V_ComposeFileName( pDir, vcdtestfile, pFullPathName, sizeof( pFullPathName ) );
V_RemoveDotSlashes( pFullPathName );
pFileName = pFullPathName;
}
CUtlBuffer buf;
if ( g_pFullFileSystem->ReadFile( pFileName, NULL, buf ) )
{
SetTokenProcessorBuffer( (char *)buf.Base() );
CChoreoScene *scene = ChoreoLoadScene( pFileName, NULL, GetTokenProcessor(), NULL );
if ( scene )
{
RunSceneToDmxTests( scene );
delete scene;
}
}
else
{
Msg( "Unable to load test file '%s'\n", pFileName );
}
g_pDataModel->ClearUndo();
#ifdef _DEBUG
int nEndingCount = g_pDataModel->GetAllocatedElementCount();
AssertEquals( nEndingCount, nStartingCount );
if ( nEndingCount != nStartingCount )
{
for ( DmElementHandle_t hElement = g_pDataModel->FirstAllocatedElement() ;
hElement != DMELEMENT_HANDLE_INVALID;
hElement = g_pDataModel->NextAllocatedElement( hElement ) )
{
CDmElement *pElement = g_pDataModel->GetElement( hElement );
Assert( pElement );
if ( !pElement )
return;
Msg( "[%s : %s] in memory\n", pElement->GetName(), pElement->GetTypeString() );
}
}
#endif
}

76
unittests/dmxtest/dmxtestarray.cpp

@ -1,76 +0,0 @@ @@ -1,76 +0,0 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Unit test program for DMX testing (testing the Array operations)
//
// $NoKeywords: $
//=============================================================================//
#include "unitlib/unitlib.h"
#include "datamodel/dmelement.h"
#include "datamodel/idatamodel.h"
#include "tier1/utlbuffer.h"
#include "filesystem.h"
#include "datamodel/dmehandle.h"
#include "tier2/tier2.h"
#include "movieobjects/dmeshape.h"
DEFINE_TESTCASE_NOSUITE( DmxArrayTest )
{
Msg( "Running dmx array tests...\n" );
CDisableUndoScopeGuard sg;
DmFileId_t fileid = g_pDataModel->FindOrCreateFileId( "<RunArrayTests>" );
CDmElement *pElement = CreateElement< CDmElement >( "root", fileid );
CDmElement *pElement2 = CreateElement<CDmElement>( "element1", fileid );
Assert( pElement2 );
CDmElement *pElement3 = CreateElement<CDmElement>( "element2", fileid );
Assert( pElement3 );
CDmeShape *pElement4 = CreateElement<CDmeShape>( "shape", fileid );
Assert( pElement4 );
CDmrStringArray stringVec( pElement, "string_array_test", true );
stringVec.AddToTail( "string1" );
stringVec.AddToTail( "string2" );
stringVec.AddToTail( "string3" );
CDmrArray< float > floatVec( pElement, "float_array_test", true );
floatVec.AddToTail( -1.0f );
floatVec.AddToTail( 0.0f );
floatVec.AddToTail( 1.0f );
CDmrElementArray< > elementVec( pElement, "element_array_test", true );
elementVec.AddToTail( pElement2 );
elementVec.AddToTail( pElement3 );
elementVec.AddToTail( pElement4 );
CDmrStringArray stringVec2( pElement, "string_array_test2", true );
stringVec2 = stringVec;
Shipping_Assert( stringVec2.Count() == 3 );
CDmrArray< float > floatVec2( pElement, "float_array_test2", true );
floatVec2 = floatVec;
Shipping_Assert( floatVec2.Count() == 3 );
CDmrElementArray< > elementVec2( pElement, "element_array_test2", true );
elementVec2 = elementVec;
Shipping_Assert( elementVec2.Count() == 3 );
CDmrElementArray< CDmeShape > elementVec3( pElement, "element_array_test3", true );
elementVec3 = elementVec2;
Shipping_Assert( elementVec3.Count() == 1 );
CUtlVector<DmElementHandle_t> val;
val.AddToTail( pElement2->GetHandle() );
val.AddToTail( pElement4->GetHandle() );
elementVec2 = val;
Shipping_Assert( elementVec2.Count() == 2 );
elementVec3 = val;
Shipping_Assert( elementVec3.Count() == 1 );
g_pDataModel->RemoveFileId( fileid );
}

393
unittests/dmxtest/dmxtestdmelog.cpp

@ -1,393 +0,0 @@ @@ -1,393 +0,0 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#include "unitlib/unitlib.h"
#include "datamodel/dmelement.h"
#include "movieobjects/movieobjects.h"
#include "datamodel/idatamodel.h"
#include "tier1/utlbuffer.h"
#include "filesystem.h"
#include "movieobjects/dmelog.h"
#include "choreoscene.h"
#include "choreoevent.h"
struct data_t
{
int tms; // tenths of a millisecond
float value;
int curvetype;
};
struct tvpair_t
{
int tms;
float expectedvalue;
};
data_t data[] =
{
{ 0, 0.0f, MAKE_CURVE_TYPE( INTERPOLATE_CATMULL_ROM_NORMALIZEX, INTERPOLATE_CATMULL_ROM_NORMALIZEX ) },
{ 10000, 0.5f, MAKE_CURVE_TYPE( INTERPOLATE_CATMULL_ROM_NORMALIZEX, INTERPOLATE_CATMULL_ROM_NORMALIZEX ) },
{ 20000, 0.5f, MAKE_CURVE_TYPE( INTERPOLATE_EASE_IN, INTERPOLATE_EASE_OUT ) },
{ 30000, 0.5f, MAKE_CURVE_TYPE( INTERPOLATE_EASE_OUT, INTERPOLATE_EASE_INOUT ) },
{ 40000, 0.5f, MAKE_CURVE_TYPE( INTERPOLATE_EASE_INOUT, INTERPOLATE_BSPLINE ) },
{ 50000, 0.5f, MAKE_CURVE_TYPE( INTERPOLATE_BSPLINE, INTERPOLATE_LINEAR_INTERP ) },
{ 60000, 1.0f, MAKE_CURVE_TYPE( INTERPOLATE_LINEAR_INTERP, INTERPOLATE_KOCHANEK_BARTELS ) },
{ 70000, 0.0f, MAKE_CURVE_TYPE( INTERPOLATE_KOCHANEK_BARTELS, INTERPOLATE_KOCHANEK_BARTELS_EARLY ) },
{ 80000, 0.5f, MAKE_CURVE_TYPE( INTERPOLATE_KOCHANEK_BARTELS_EARLY, INTERPOLATE_KOCHANEK_BARTELS_LATE ) },
{ 90000, 0.0f, MAKE_CURVE_TYPE( INTERPOLATE_KOCHANEK_BARTELS_LATE, INTERPOLATE_SIMPLE_CUBIC ) },
{ 100000, 0.25f, MAKE_CURVE_TYPE( INTERPOLATE_SIMPLE_CUBIC, INTERPOLATE_CATMULL_ROM ) },
{ 110000, 0.0f, MAKE_CURVE_TYPE( INTERPOLATE_CATMULL_ROM, INTERPOLATE_CATMULL_ROM_NORMALIZE ) },
{ 120000, 0.125f, MAKE_CURVE_TYPE( INTERPOLATE_CATMULL_ROM_NORMALIZE, INTERPOLATE_EXPONENTIAL_DECAY ) },
{ 130000, 0.0f, MAKE_CURVE_TYPE( INTERPOLATE_EXPONENTIAL_DECAY, INTERPOLATE_HOLD ) },
{ 140000, 0.0625f, MAKE_CURVE_TYPE( INTERPOLATE_CATMULL_ROM_NORMALIZEX, INTERPOLATE_EXPONENTIAL_DECAY ) },
{ 150000, 0.0f, MAKE_CURVE_TYPE( INTERPOLATE_CATMULL_ROM_NORMALIZEX, INTERPOLATE_CATMULL_ROM_NORMALIZEX ) },
};
#define NUM_DEF_TESTS 3
static data_t values1[] =
{
{ -1, 0.0f, 0 },
};
static data_t values2[] =
{
{ 5000, 0.5f, CURVE_DEFAULT },
{ -1, 0.0f, 0 },
};
static data_t values3[] =
{
{ 2500, 0.25f, CURVE_DEFAULT },
{ 7500, 0.75f, CURVE_DEFAULT },
{ -1, 0.0f, 0 },
};
static data_t *defaultvaluetest[ NUM_DEF_TESTS ] =
{
values1,
values2,
values3
};
#define NUM_TEST_VALUES 3
static tvpair_t expectedvalues1[NUM_TEST_VALUES] =
{
{ 0, 0.5f },
{ 5000, 0.5f },
{ 10000, 0.5f },
};
static tvpair_t expectedvalues2[NUM_TEST_VALUES] =
{
{ 0, 0.5f },
{ 5000, 0.5f },
{ 10000, 0.5f },
};
static tvpair_t expectedvalues3[NUM_TEST_VALUES] =
{
{ 0, 0.25f },
{ 5000, 0.5f },
{ 10000, 0.75f },
};
static tvpair_t *expectedvalues[ NUM_DEF_TESTS ] =
{
expectedvalues1,
expectedvalues2,
expectedvalues3
};
void ResetLog( CDmeFloatLog *log, bool useCurveTypes, int startIndex = 0, int endIndex = -1 )
{
log->ClearKeys();
CDmeCurveInfo *pCurveInfo = useCurveTypes ? log->GetOrCreateCurveInfo() : log->GetCurveInfo();
if ( useCurveTypes )
{
pCurveInfo->SetDefaultCurveType( MAKE_CURVE_TYPE( INTERPOLATE_CATMULL_ROM_NORMALIZEX, INTERPOLATE_CATMULL_ROM_NORMALIZEX ) );
}
else if ( !useCurveTypes && pCurveInfo )
{
g_pDataModel->DestroyElement( pCurveInfo->GetHandle() );
log->SetCurveInfo( NULL );
}
int i;
int c;
c = ARRAYSIZE( data );
for ( i = startIndex; i < c; ++i )
{
log->SetKey( DmeTime_t( data[ i ].tms ), data[ i ].value, useCurveTypes ? data[ i ].curvetype : CURVE_DEFAULT );
if ( endIndex != -1 && i >= endIndex )
break;
}
}
void CompareFloats( float f1, float f2, float tol, char const *fmt, ... )
{
float diff = fabs( f1 - f2 );
if ( diff < tol )
return;
char buf[ 256 ];
va_list argptr;
va_start( argptr, fmt );
_vsnprintf( buf, sizeof( buf ) - 1, fmt, argptr );
va_end( argptr );
Msg( buf );
}
DEFINE_TESTCASE_NOSUITE( DmxRunDefaultValueLogTest )
{
Msg( "Running CDmeTypedLog<float> default value (stereo channel w/ value 0.5) tests...\n" );
CDisableUndoScopeGuard sg;
DmFileId_t fileid = g_pDataModel->FindOrCreateFileId( "<DmxTestDmeLog>" );
for ( int i = 0; i < NUM_DEF_TESTS; ++i )
{
data_t *pdata = defaultvaluetest[ i ];
tvpair_t *pexpected = expectedvalues[ i ];
// Run each test
CDmeFloatLog *log = CreateElement<CDmeFloatLog>( "curve", fileid );
if ( !log )
{
Msg( "Unable to create CDmeFloatLog object!!!" );
continue;
}
log->SetDefaultValue( 0.5f );
if ( pdata )
{
// Run the test
for ( int j = 0; ; ++j )
{
if ( pdata[ j ].tms == -1 )
break;
log->SetKey( DmeTime_t( pdata[ j ].tms ), pdata[ j ].value );
}
}
// Now compare against expected values
for ( int j = 0; j < NUM_TEST_VALUES; ++j )
{
DmeTime_t t = DmeTime_t( pexpected[ j ].tms );
float v = pexpected[ j ].expectedvalue;
float logv = log->GetValue( t );
Shipping_Assert( v == logv );
}
DestroyElement( log );
}
g_pDataModel->RemoveFileId( fileid );
}
void RunDmeFloatLogTests( CDmeFloatLog *log )
{
Msg( " Testing general log data...\n" );
ResetLog( log, false );
CompareFloats( 0.5f, log->GetValue( DmeTime_t( 2.0f ) ), 0.000001f, "log->GetValue( 2.0 ) expected to be 0.5f\n" );
CompareFloats( 0.5f, log->GetValue( DmeTime_t( 2.5f ) ), 0.000001f, "log->GetValue( 2.5 ) expected to be 0.5f\n" );
CompareFloats( 0.5f, log->GetValue( DmeTime_t( 2.5f ) ), 0.000001f, "log->GetValue( 2.5 ) expected to be 0.5f\n" );
CompareFloats( 0.5f, log->GetValue( DmeTime_t( 6.5f ) ), 0.000001f, "log->GetValue( 6.5 ) expected to be 0.5f\n" );
CDmeCurveInfo *pCurveInfo = log->GetOrCreateCurveInfo();
int idx = log->FindKeyWithinTolerance( DmeTime_t( 6.0f ), DmeTime_t( 0 ) );
Shipping_Assert( log->GetKeyTime( idx ) == DmeTime_t( 6.0f ) );
log->SetKeyCurveType( idx, MAKE_CURVE_TYPE( INTERPOLATE_LINEAR_INTERP, INTERPOLATE_LINEAR_INTERP ) );
log->SetKeyCurveType( idx + 1, MAKE_CURVE_TYPE( INTERPOLATE_LINEAR_INTERP, INTERPOLATE_LINEAR_INTERP ) );
float val = log->GetValue( DmeTime_t( 6.5f ) );
float qval = log->GetValue( DmeTime_t( 6.25f ) );
CompareFloats( 0.5f, val, 0.000001f, "INTERPOLATE_LINEAR_INTERPlog->GetValue( 6500 ) expcted to be 0.5f\n" );
CompareFloats( 0.75f, qval, 0.000001f, "INTERPOLATE_LINEAR_INTERPlog->GetValue( 6250 ) expcted to be 0.75f\n" );
log->SetKeyCurveType( idx, MAKE_CURVE_TYPE( INTERPOLATE_CATMULL_ROM_NORMALIZEX, INTERPOLATE_CATMULL_ROM_NORMALIZEX ) );
log->SetKeyCurveType( idx + 1, MAKE_CURVE_TYPE( INTERPOLATE_CATMULL_ROM_NORMALIZEX, INTERPOLATE_CATMULL_ROM_NORMALIZEX ) );
float val2 = log->GetValue( DmeTime_t( 6.5f ) );
float qval2 = log->GetValue( DmeTime_t( 6.25f ) );
Shipping_Assert( val2 == val );
Shipping_Assert( qval2 != val );
log->SetKeyCurveType( idx, MAKE_CURVE_TYPE( INTERPOLATE_EASE_INOUT, INTERPOLATE_EASE_INOUT ) );
log->SetKeyCurveType( idx + 1, MAKE_CURVE_TYPE( INTERPOLATE_EASE_INOUT, INTERPOLATE_EASE_INOUT ) );
float val3 = log->GetValue( DmeTime_t( 6.5f ) );
float qval3 = log->GetValue( DmeTime_t( 6.25f ) );
Shipping_Assert( val3 == val );
Shipping_Assert( qval3 != val );
log->SetKeyCurveType( idx, MAKE_CURVE_TYPE( INTERPOLATE_EXPONENTIAL_DECAY, INTERPOLATE_EXPONENTIAL_DECAY ) );
log->SetKeyCurveType( idx + 1, MAKE_CURVE_TYPE( INTERPOLATE_EXPONENTIAL_DECAY, INTERPOLATE_EXPONENTIAL_DECAY ) );
float val4 = log->GetValue( DmeTime_t( 6.5f ) );
float qval4 = log->GetValue( DmeTime_t( 6.25f ) );
Shipping_Assert( val4 != val );
Shipping_Assert( qval4 != val );
log->SetKeyCurveType( idx, MAKE_CURVE_TYPE( INTERPOLATE_KOCHANEK_BARTELS, INTERPOLATE_KOCHANEK_BARTELS ) );
log->SetKeyCurveType( idx + 1, MAKE_CURVE_TYPE( INTERPOLATE_KOCHANEK_BARTELS, INTERPOLATE_KOCHANEK_BARTELS ) );
float val5 = log->GetValue( DmeTime_t( 6.5f ) );
float qval5 = log->GetValue( DmeTime_t( 6.25f ) );
Shipping_Assert( val5 == val );
Shipping_Assert( qval5 != val );
pCurveInfo->SetDefaultCurveType( MAKE_CURVE_TYPE( INTERPOLATE_KOCHANEK_BARTELS, INTERPOLATE_KOCHANEK_BARTELS ) );
log->SetKeyCurveType( idx, MAKE_CURVE_TYPE( INTERPOLATE_DEFAULT, INTERPOLATE_DEFAULT ) );
log->SetKeyCurveType( idx + 1, MAKE_CURVE_TYPE( INTERPOLATE_DEFAULT, INTERPOLATE_DEFAULT ) );
float val6 = log->GetValue( DmeTime_t( 6.5f ) );
float qval6 = log->GetValue( DmeTime_t( 6.25f ) );
Shipping_Assert( val5 == val6 );
Shipping_Assert( qval6 == qval5 );
}
void CompareLogToChoreo( CFlexAnimationTrack *track, CDmeFloatLog *log )
{
// Now run tests
for ( DmeTime_t t( 0 ); t < DmeTime_t( 20.0f ); t += DmeTime_t( 0.1f ) )
{
// Compare values
float dmevalue = log->GetValue( t );
float choreovalue = track->GetIntensity( t.GetSeconds() );
CompareFloats( dmevalue, choreovalue, 0.001f, "Time(%f sec) , dme [%f] choreo[%f], diff[%f]\n",
t.GetSeconds(),
dmevalue,
choreovalue,
fabs( dmevalue - choreovalue ) );
}
}
void ResetChoreo( CFlexAnimationTrack *track, bool useCurveTypes, int startIndex = 0, int endIndex = -1 )
{
track->Clear();
int i;
int c;
c = ARRAYSIZE( data );
for ( i = startIndex; i < c; ++i )
{
data_t *e = &data[ i ];
float t = (float)e->tms / 10000.0f;
CExpressionSample *sample = track->AddSample( t, e->value );
Shipping_Assert( sample );
if ( useCurveTypes )
{
sample->SetCurveType( e->curvetype );
}
if ( endIndex != -1 && i >= endIndex )
break;
}
}
void RunDmeChoreoComparisons( CDmeFloatLog *log )
{
Msg( " Testing choreo-style log data...\n" );
ResetLog( log, true );
log->SetRightEdgeTime( DmeTime_t( 15.0f ) );
CChoreoScene *scene = new CChoreoScene( NULL );
CChoreoEvent *event = new CChoreoEvent( scene, CChoreoEvent::FLEXANIMATION, "test" );
event->SetStartTime( 0.0f );
event->SetEndTime( 15.0f );
CFlexAnimationTrack *track = new CFlexAnimationTrack( event );
track->SetFlexControllerName( "flextest" );
track->SetComboType( false );
ResetChoreo( track, true );
Msg( " Comparing default data...\n" );
CompareLogToChoreo( track, log );
ResetLog( log, true, 3, 14 );
ResetChoreo( track, true, 3, 14 );
Msg( " Comparing subset of data...\n" );
CompareLogToChoreo( track, log );
Msg( " Comparing left/right edge settings...\n" );
// Now test right and left edge stuff
// Enable left edge stuff
track->SetEdgeActive( true, true );
track->SetEdgeInfo( true, MAKE_CURVE_TYPE( INTERPOLATE_LINEAR_INTERP, INTERPOLATE_LINEAR_INTERP ), 0.75f );
track->SetEdgeActive( false, true );
track->SetEdgeInfo( false, MAKE_CURVE_TYPE( INTERPOLATE_EASE_OUT, INTERPOLATE_EASE_OUT ), 0.25f );
// Same settings for log
log->SetUseEdgeInfo( true );
log->SetDefaultEdgeZeroValue( 0.0f );
log->SetEdgeInfo( 0, true, 0.75f, MAKE_CURVE_TYPE( INTERPOLATE_LINEAR_INTERP, INTERPOLATE_LINEAR_INTERP ) );
log->SetEdgeInfo( 1, true, 0.25f, MAKE_CURVE_TYPE( INTERPOLATE_EASE_OUT, INTERPOLATE_EASE_OUT ) );
CompareLogToChoreo( track, log );
int i;
for ( i = 1; i < NUM_INTERPOLATE_TYPES; ++i )
{
Msg( " Comparing left/right edge settings[ %s ]...\n", Interpolator_NameForInterpolator( i, true ) );
float val = (float)i / (float)( NUM_INTERPOLATE_TYPES - 1 ) ;
// Now test right and left edge stuff with different data
track->SetEdgeInfo( true, MAKE_CURVE_TYPE( i, i ), val );
track->SetEdgeInfo( false, MAKE_CURVE_TYPE( i, i ), val );
log->SetEdgeInfo( 0, true, val, MAKE_CURVE_TYPE( i, i ) );
log->SetEdgeInfo( 1, true, val, MAKE_CURVE_TYPE( i, i ) );
CompareLogToChoreo( track, log );
}
delete event;
delete scene;
}
DEFINE_TESTCASE_NOSUITE( DmxTestDmeLog )
{
Msg( "Running CDmeTypedLog<float> tests...\n" );
CDisableUndoScopeGuard sg;
DmFileId_t fileid = g_pDataModel->FindOrCreateFileId( "<DmxTestDmeLog>" );
CDmeFloatLog *pElement = CreateElement<CDmeFloatLog>( "curve", fileid );
if ( !pElement )
{
Msg( "Unable to create CDmeFloatLog object!!!" );
return;
}
// Run tests
RunDmeFloatLogTests( pElement );
RunDmeChoreoComparisons( pElement );
g_pDataModel->RemoveFileId( fileid );
}

211
unittests/dmxtest/dmxtestloader.cpp

@ -1,211 +0,0 @@ @@ -1,211 +0,0 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Unit test program for DMX testing
//
// $NoKeywords: $
//=============================================================================//
#include "unitlib/unitlib.h"
#include "dmxloader/dmxloader.h"
#include "dmxloader/dmxelement.h"
struct TestStruct_t
{
DmObjectId_t m_nId;
bool m_bBool;
int m_nInt;
float m_flFloat;
Color m_Color;
Vector2D m_Vector2D;
Vector m_Vector3D;
Vector4D m_Vector4D;
QAngle m_Angles;
Quaternion m_Quaternion;
VMatrix m_Matrix;
char m_pStringBuf[256];
};
BEGIN_DMXELEMENT_UNPACK( TestStruct_t )
DMXELEMENT_UNPACK_FIELD( "id_test", NULL, DmObjectId_t, m_nId )
DMXELEMENT_UNPACK_FIELD( "bool_test", "1", bool, m_bBool )
DMXELEMENT_UNPACK_FIELD( "int_test", "5", int, m_nInt )
DMXELEMENT_UNPACK_FIELD( "float_test", "4.0", float, m_flFloat )
DMXELEMENT_UNPACK_FIELD( "color_test", "200 200 200 200", Color, m_Color )
DMXELEMENT_UNPACK_FIELD( "vector2d_test", "5.0 1.0", Vector2D, m_Vector2D )
DMXELEMENT_UNPACK_FIELD( "vector3d_test", "5.0 1.0 -3.0", Vector, m_Vector3D )
DMXELEMENT_UNPACK_FIELD( "vector4d_test", "5.0 1.0 -4.0 2.0", Vector4D, m_Vector4D )
DMXELEMENT_UNPACK_FIELD( "qangle_test", "5.0 1.0 -3.0", QAngle, m_Angles )
DMXELEMENT_UNPACK_FIELD( "quat_test", "5.0 1.0 -4.0 2.0", Quaternion, m_Quaternion )
DMXELEMENT_UNPACK_FIELD( "vmatrix_test", NULL, VMatrix, m_Matrix )
DMXELEMENT_UNPACK_FIELD_STRING( "string_test", "default", m_pStringBuf )
END_DMXELEMENT_UNPACK( TestStruct_t, s_TestStructUnpack )
void TestReadFile( CDmxElement *pRoot )
{
VMatrix mattest, mat2test;
MatrixBuildRotateZ( mattest, 45 );
MatrixBuildRotateZ( mat2test, 30 );
int i;
unsigned char buftest[256];
unsigned char buf2test[256];
for ( i = 0; i < 256; ++i )
{
buftest[i] = i;
buf2test[i] = 255 - i;
}
// Make sure everything was read in ok.
AssertEquals( pRoot->GetValue<bool>( "bool_test" ), true );
AssertEquals( pRoot->GetValue<int>( "int_test" ), 2 );
AssertFloatEquals( pRoot->GetValue<float>( "float_test" ), 3.0f, 1e-3 );
const Color& color = pRoot->GetValue<Color>( "color_test" );
Shipping_Assert( color.r() == 0 && color.g() == 64 && color.b() == 128 && color.a() == 255 );
const Vector2D& vec2D = pRoot->GetValue<Vector2D>( "vector2d_test" );
Shipping_Assert( vec2D.x == 1.0f && vec2D.y == -1.0f );
const Vector& vec3D = pRoot->GetValue<Vector>( "vector3d_test" );
Shipping_Assert( vec3D.x == 1.0f && vec3D.y == -1.0f && vec3D.z == 0.0f );
const Vector4D& vec4D = pRoot->GetValue<Vector4D>( "vector4d_test" );
Shipping_Assert( vec4D.x == 1.0f && vec4D.y == -1.0f && vec4D.z == 0.0f && vec4D.w == 2.0f );
const QAngle& ang = pRoot->GetValue<QAngle>( "qangle_test" );
Shipping_Assert( ang.x == 0.0f && ang.y == 90.0f && ang.z == -90.0f );
const Quaternion& quat = pRoot->GetValue<Quaternion>( "quat_test" );
Shipping_Assert( quat.x == 1.0f && quat.y == -1.0f && quat.z == 0.0f && quat.w == 2.0f );
const VMatrix& mat = pRoot->GetValue<VMatrix>( "vmatrix_test" );
Shipping_Assert( MatricesAreEqual( mat, mattest, 1e-3 ) );
Shipping_Assert( !Q_stricmp( pRoot->GetValueString( "string_test" ), "test" ) );
const CUtlBinaryBlock& blob = pRoot->GetValue<CUtlBinaryBlock>( "binary_test" );
Shipping_Assert( blob.Length() == 256 );
Shipping_Assert( !memcmp( blob.Get(), buftest, 256 ) );
CDmxElement *pElement7 = pRoot->GetValue<CDmxElement*>( "element_test" );
Shipping_Assert( pElement7 != NULL );
CDmxElement *pElement6 = pRoot->GetValue<CDmxElement*>( "shared_element_test" );
Shipping_Assert( pElement6 != NULL );
const CUtlVector< CDmxElement* >& elementList = pRoot->GetArray<CDmxElement*>( "children" );
Shipping_Assert( elementList.Count() == 2 );
CDmxElement *pElement2 = elementList[0];
CDmxElement *pElement3 = elementList[1];
Shipping_Assert( pElement2 != NULL && pElement3 != NULL );
Shipping_Assert( pElement7->GetValue<CDmxElement*>( "shared_element_test" ) == pElement6 );
const CUtlVector< CDmxElement* >& elementList3 = pElement6->GetArray<CDmxElement*>( "element_array_test" );
CDmxElement *pElement4 = elementList3[0];
CDmxElement *pElement5 = elementList3[1];
const CUtlVector< bool > &boolVec = pElement2->GetArray<bool>( "bool_array_test" );
Shipping_Assert( boolVec.Count() == 2 && boolVec[0] == false && boolVec[1] == true );
const CUtlVector< int > &intVec = pElement2->GetArray<int>( "int_array_test" );
Shipping_Assert( intVec.Count() == 3 && intVec[0] == 0 && intVec[1] == 1 && intVec[2] == 2 );
const CUtlVector< float > &floatVec = pElement2->GetArray<float>( "float_array_test" );
Shipping_Assert( floatVec.Count() == 3 && floatVec[0] == -1.0f && floatVec[1] == 0.0f && floatVec[2] == 1.0f );
const CUtlVector< Color > &colorVec = pElement3->GetArray<Color>( "color_array_test" );
Shipping_Assert( colorVec.Count() == 3 && colorVec[0].r() == 0 && colorVec[1].r() == 64 && colorVec[2].r() == 128 );
const CUtlVector< Vector2D > &vec2DVec = pElement3->GetArray<Vector2D>( "vector2d_array_test" );
Shipping_Assert( vec2DVec.Count() == 2 && vec2DVec[0].x == -1.0f && vec2DVec[1].x == 1.0f );
const CUtlVector< Vector > &vec3DVec = pElement3->GetArray<Vector>( "vector3d_array_test" );
Shipping_Assert( vec3DVec.Count() == 2 && vec3DVec[0].x == 1.0f && vec3DVec[1].x == 2.0f );
const CUtlVector< Vector4D > &vec4DVec = pElement4->GetArray<Vector4D>( "vector4d_array_test" );
Shipping_Assert( vec4DVec.Count() == 2 && vec4DVec[0].x == 1.0f && vec4DVec[1].x == 2.0f );
const CUtlVector< QAngle > &angVec = pElement4->GetArray<QAngle>( "qangle_array_test" );
Shipping_Assert( angVec.Count() == 2 && angVec[0].x == 1.0f && angVec[1].x == 2.0f );
const CUtlVector< Quaternion > &quatVec = pElement4->GetArray<Quaternion>( "quat_array_test" );
Shipping_Assert( quatVec.Count() == 2 && quatVec[0].x == 1.0f && quatVec[1].x == 2.0f );
const CUtlVector< VMatrix > &matVec = pElement5->GetArray<VMatrix>( "vmatrix_array_test" );
Shipping_Assert( matVec.Count() == 2 );
Shipping_Assert( MatricesAreEqual( matVec[0], mattest, 1e-3 ) );
Shipping_Assert( MatricesAreEqual( matVec[1], mat2test, 1e-3 ) );
const CUtlVector< CUtlString > &stringVec = pElement5->GetArray<CUtlString>( "string_array_test" );
Shipping_Assert( stringVec.Count() == 3 && !Q_stricmp( stringVec[2], "string3" ) );
const CUtlVector< CUtlBinaryBlock > &binaryVec = pElement5->GetArray<CUtlBinaryBlock>( "binary_array_test" );
Shipping_Assert( binaryVec.Count() == 2 && !memcmp( binaryVec[1].Get(), buf2test, 256 ) );
const CUtlVector< DmObjectId_t > &idVec = pElement6->GetArray<DmObjectId_t>( "elementid_array_test" );
Shipping_Assert( idVec.Count() == 3 );
TestStruct_t testStruct;
pRoot->UnpackIntoStructure( &testStruct, sizeof( testStruct ), s_TestStructUnpack );
Shipping_Assert( testStruct.m_bBool == true );
Shipping_Assert( testStruct.m_nInt == 2 );
AssertFloatEquals( testStruct.m_flFloat, 3.0f, 1e-3 );
Shipping_Assert( testStruct.m_Color.r() == 0 && testStruct.m_Color.g() == 64 && testStruct.m_Color.b() == 128 && testStruct.m_Color.a() == 255 );
Shipping_Assert( testStruct.m_Vector2D.x == 1.0f && testStruct.m_Vector2D.y == -1.0f );
Shipping_Assert( testStruct.m_Vector3D.x == 1.0f && testStruct.m_Vector3D.y == -1.0f && testStruct.m_Vector3D.z == 0.0f );
Shipping_Assert( testStruct.m_Vector4D.x == 1.0f && testStruct.m_Vector4D.y == -1.0f && testStruct.m_Vector4D.z == 0.0f && testStruct.m_Vector4D.w == 2.0f );
Shipping_Assert( testStruct.m_Angles.x == 0.0f && testStruct.m_Angles.y == 90.0f && testStruct.m_Angles.z == -90.0f );
Shipping_Assert( testStruct.m_Quaternion.x == 1.0f && testStruct.m_Quaternion.y == -1.0f && testStruct.m_Quaternion.z == 0.0f && testStruct.m_Quaternion.w == 2.0f );
Shipping_Assert( MatricesAreEqual( testStruct.m_Matrix, mattest, 1e-3 ) );
Shipping_Assert( !Q_stricmp( testStruct.m_pStringBuf, "test" ) );
pElement6->UnpackIntoStructure( &testStruct, sizeof( testStruct ), s_TestStructUnpack );
Shipping_Assert( testStruct.m_bBool == true );
Shipping_Assert( testStruct.m_nInt == 5 );
AssertFloatEquals( testStruct.m_flFloat, 4.0f, 1e-3 );
Shipping_Assert( testStruct.m_Color.r() == 200 && testStruct.m_Color.g() == 200 && testStruct.m_Color.b() == 200 && testStruct.m_Color.a() == 200 );
Shipping_Assert( testStruct.m_Vector2D.x == 5.0f && testStruct.m_Vector2D.y == 1.0f );
Shipping_Assert( testStruct.m_Vector3D.x == 5.0f && testStruct.m_Vector3D.y == 1.0f && testStruct.m_Vector3D.z == -3.0f );
Shipping_Assert( testStruct.m_Vector4D.x == 5.0f && testStruct.m_Vector4D.y == 1.0f && testStruct.m_Vector4D.z == -4.0f && testStruct.m_Vector4D.w == 2.0f );
Shipping_Assert( testStruct.m_Angles.x == 5.0f && testStruct.m_Angles.y == 1.0f && testStruct.m_Angles.z == -3.0f );
Shipping_Assert( testStruct.m_Quaternion.x == 5.0f && testStruct.m_Quaternion.y == 1.0f && testStruct.m_Quaternion.z == -4.0f && testStruct.m_Quaternion.w == 2.0f );
Shipping_Assert( !Q_stricmp( testStruct.m_pStringBuf, "default" ) );
}
DEFINE_TESTCASE_NOSUITE( DmxLoaderTest )
{
Msg( "Running dmx loader tests...\n" );
CDmxElement *pRoot;
bool bOk = UnserializeDMX( "dmxtestloader.dmx", NULL, false, &pRoot );
Shipping_Assert( bOk );
Shipping_Assert( pRoot );
if ( pRoot )
{
TestReadFile( pRoot );
CleanupDMX( pRoot );
}
bOk = UnserializeDMX( "dmxtestloadertext.dmx", NULL, true, &pRoot );
Shipping_Assert( bOk );
Shipping_Assert( pRoot );
if ( pRoot )
{
TestReadFile( pRoot );
CleanupDMX( pRoot );
}
// Test serialization
bOk = UnserializeDMX( "dmxtestloader.dmx", NULL, false, &pRoot );
Shipping_Assert( bOk );
Shipping_Assert( pRoot );
if ( pRoot )
{
bOk = SerializeDMX( "dmxtestscratch.dmx", NULL, false, pRoot );
Shipping_Assert( bOk );
CleanupDMX( pRoot );
}
CleanupDMX( pRoot );
bOk = UnserializeDMX( "dmxtestscratch.dmx", NULL, false, &pRoot );
Shipping_Assert( bOk );
Shipping_Assert( pRoot );
if ( pRoot )
{
TestReadFile( pRoot );
CleanupDMX( pRoot );
}
}

111
unittests/dmxtest/dmxtestnotify.cpp

@ -1,111 +0,0 @@ @@ -1,111 +0,0 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Unit test program for DMX testing (testing the Notify subsystem)
//
// $NoKeywords: $
//=============================================================================//
#include "unitlib/unitlib.h"
#include "datamodel/dmelement.h"
#include "datamodel/idatamodel.h"
#include "tier1/utlbuffer.h"
#include "filesystem.h"
#include "datamodel/dmehandle.h"
#include "tier2/tier2.h"
class CNotifyTest : public IDmNotify
{
public:
CNotifyTest() : m_nValueCount(0), m_nTopologyCount(0), m_nArrayCount(0) {}
virtual void NotifyDataChanged( const char *pReason, int nNotifySource, int nNotifyFlags )
{
if ( nNotifyFlags & NOTIFY_CHANGE_ATTRIBUTE_VALUE )
{
m_nValueCount++;
}
if ( nNotifyFlags & NOTIFY_CHANGE_ATTRIBUTE_ARRAY_SIZE )
{
m_nArrayCount++;
}
if ( nNotifyFlags & NOTIFY_CHANGE_TOPOLOGICAL )
{
m_nTopologyCount++;
}
}
int m_nTopologyCount;
int m_nArrayCount;
int m_nValueCount;
};
DEFINE_TESTCASE_NOSUITE( DmxNotifyTest )
{
Msg( "Running dmx notify tests...\n" );
CNotifyTest test1, test2;
DmFileId_t fileid = g_pDataModel->FindOrCreateFileId( "<RunNotifyTests>" );
g_pDataModel->InstallNotificationCallback( &test1 );
CDmElement *element = NULL;
{
CUndoScopeGuard guard( NOTIFY_SOURCE_APPLICATION, 0, "create" );
element = CreateElement< CDmElement >( "test", fileid );
}
Shipping_Assert( test1.m_nTopologyCount == 1 );
Shipping_Assert( test1.m_nArrayCount == 0 );
g_pDataModel->Undo();
Shipping_Assert( test1.m_nTopologyCount == 2 );
Shipping_Assert( test1.m_nArrayCount == 0 );
{
CNotifyScopeGuard notify( "test1", NOTIFY_SOURCE_APPLICATION, 0, &test2 );
CDisableUndoScopeGuard guard;
element = CreateElement< CDmElement >( "test", fileid );
}
Shipping_Assert( test1.m_nTopologyCount == 3 );
Shipping_Assert( test1.m_nArrayCount == 0 );
Shipping_Assert( test2.m_nTopologyCount == 1 );
Shipping_Assert( test2.m_nArrayCount == 0 );
{
CDisableUndoScopeGuard guard;
// NOTE: Nested scope guards referring to the same callback shouldn't double call it
CNotifyScopeGuard notify( "test2", NOTIFY_SOURCE_APPLICATION, 0, &test2 );
{
CNotifyScopeGuard notify( "test3", NOTIFY_SOURCE_APPLICATION, 0, &test2 );
DestroyElement( element );
}
}
Shipping_Assert( test1.m_nTopologyCount == 4 );
Shipping_Assert( test1.m_nArrayCount == 0 );
Shipping_Assert( test2.m_nTopologyCount == 2 );
Shipping_Assert( test2.m_nArrayCount == 0 );
{
CUndoScopeGuard guard( NOTIFY_SOURCE_APPLICATION, 0, "create" );
{
element = CreateElement< CDmElement >( "test", fileid );
element->SetValue( "test", 1.0f );
}
guard.Abort();
}
Shipping_Assert( test1.m_nTopologyCount == 4 );
Shipping_Assert( test1.m_nArrayCount == 0 );
Shipping_Assert( test2.m_nTopologyCount == 2 );
Shipping_Assert( test2.m_nArrayCount == 0 );
g_pDataModel->RemoveNotificationCallback( &test1 );
g_pDataModel->RemoveFileId( fileid );
}

760
unittests/dmxtest/dmxtestserialization.cpp

@ -1,760 +0,0 @@ @@ -1,760 +0,0 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Unit test program for DMX testing
//
// $NoKeywords: $
//=============================================================================//
#include "unitlib/unitlib.h"
#include "datamodel/dmelement.h"
#include "datamodel/idatamodel.h"
#include "tier1/utlbuffer.h"
#include "filesystem.h"
#include "datamodel/dmehandle.h"
#include "tier2/tier2.h"
bool AssertEqualElementHierarchies( bool quiet, DmElementHandle_t src1, DmElementHandle_t src2 );
bool AssertUnEqualElementHierarchies( DmElementHandle_t src1, DmElementHandle_t src2 )
{
bool equal = AssertEqualElementHierarchies( true, src1, src2 );
if ( equal )
{
AssertMsg( 0, "Hierarchies equal, expecting mismatch\n" );
}
return !equal;
}
void CreateTestScene( CUtlVector< DmElementHandle_t >& handles, DmFileId_t fileid )
{
DmObjectId_t id;
CreateUniqueId( &id );
VMatrix mat, mat2;
MatrixBuildRotateZ( mat, 45 );
MatrixBuildRotateZ( mat2, 30 );
int i;
unsigned char buf[256];
unsigned char buf2[256];
for ( i = 0; i < 256; ++i )
{
buf[i] = i;
buf2[i] = 255 - i;
}
CDmElement *pElement = CreateElement<CDmElement>( "root", fileid );
Assert( pElement );
CDmElement *pElement2 = CreateElement<CDmElement>( "shared_child", fileid );
Assert( pElement2 );
CDmElement *pElement3 = CreateElement<CDmElement>( "unique_child", fileid );
Assert( pElement3 );
CDmElement *pElement4 = CreateElement<CDmElement>( "shared_array_element", fileid );
Assert( pElement4 );
CDmElement *pElement5 = CreateElement<CDmElement>( "unique_array_element", fileid );
Assert( pElement5 );
CDmElement *pElement6 = CreateElement<CDmElement>( "shared_element", fileid );
Assert( pElement6 );
CDmElement *pElement7 = CreateElement<CDmElement>( "unique_element", fileid );
Assert( pElement7 );
g_pDataModel->SetFileRoot( fileid, pElement->GetHandle() );
handles.AddToTail( pElement->GetHandle() );
handles.AddToTail( pElement2->GetHandle() );
handles.AddToTail( pElement3->GetHandle() );
handles.AddToTail( pElement4->GetHandle() );
handles.AddToTail( pElement5->GetHandle() );
handles.AddToTail( pElement6->GetHandle() );
handles.AddToTail( pElement7->GetHandle() );
pElement->SetValue( "id_test", id );
pElement->SetValue( "bool_test", true );
pElement->SetValue( "int_test", 2 );
pElement->SetValue( "float_test", 3.0f );
pElement->SetValue( "color_test", Color( 0, 64, 128, 255 ) );
pElement->SetValue( "vector2d_test", Vector2D( 1.0f, -1.0f ) );
pElement->SetValue( "vector3d_test", Vector( 1.0f, -1.0f, 0.0f ) );
pElement->SetValue( "vector4d_test", Vector4D( 1.0f, -1.0f, 0.0f, 2.0f ) );
pElement->SetValue( "qangle_test", QAngle( 0.0f, 90.0f, -90.0f ) );
pElement->SetValue( "quat_test", Quaternion( 1.0f, -1.0f, 0.0f, 2.0f ) );
pElement->SetValue( "vmatrix_test", mat );
pElement->SetValue( "string_test", "test" );
pElement->SetValue( "binary_test", buf, 256 );
// Test DONTSAVE
// pElement->SetValue( "dontsave", true );
// CDmAttribute *pAttribute = pElement->GetAttribute( "dontsave" );
// pAttribute->AddFlag( FATTRIB_DONTSAVE );
CDmrArray< bool > boolVec( pElement2, "bool_array_test", true );
boolVec.AddToTail( false );
boolVec.AddToTail( true );
CDmrArray< int > intVec( pElement2, "int_array_test", true );
intVec.AddToTail( 0 );
intVec.AddToTail( 1 );
intVec.AddToTail( 2 );
CDmrArray< float > floatVec( pElement2, "float_array_test", true );
floatVec.AddToTail( -1.0f );
floatVec.AddToTail( 0.0f );
floatVec.AddToTail( 1.0f );
CDmrArray< Color > colorVec( pElement3, "color_array_test", true );
colorVec.AddToTail( Color( 0, 0, 0, 255 ) );
colorVec.AddToTail( Color( 64, 64, 64, 255 ) );
colorVec.AddToTail( Color( 128, 128, 128, 255 ) );
CDmrArray< Vector2D > vector2DVec( pElement3, "vector2d_array_test", true );
vector2DVec.AddToTail( Vector2D( -1.0f, -1.0f ) );
vector2DVec.AddToTail( Vector2D( 1.0f, 1.0f ) );
CDmrArray< Vector > vector3DVec( pElement3, "vector3d_array_test", true );
vector3DVec.AddToTail( Vector( 1.0f, -1.0f, 0.0f ) );
vector3DVec.AddToTail( Vector( 2.0f, -2.0f, 0.0f ) );
CDmrArray< Vector4D > vector4DVec( pElement4, "vector4d_array_test", true );
vector4DVec.AddToTail( Vector4D( 1.0f, -1.0f, 0.0f, 2.0f ) );
vector4DVec.AddToTail( Vector4D( 2.0f, -2.0f, 0.0f, 4.0f ) );
CDmrArray< QAngle > angleVec( pElement4, "qangle_array_test", true );
angleVec.AddToTail( QAngle( 1.0f, -1.0f, 0.0f ) );
angleVec.AddToTail( QAngle( 2.0f, -2.0f, 0.0f ) );
CDmrArray< Quaternion > quatVec( pElement4, "quat_array_test", true );
quatVec.AddToTail( Quaternion( 1.0f, -1.0f, 0.0f, 2.0f ) );
quatVec.AddToTail( Quaternion( 2.0f, -2.0f, 0.0f, 4.0f ) );
CDmrArray< VMatrix > matVec( pElement5, "vmatrix_array_test", true );
matVec.AddToTail( mat );
matVec.AddToTail( mat2 );
CDmrStringArray stringVec( pElement5, "string_array_test", true );
stringVec.AddToTail( "string1" );
stringVec.AddToTail( "string2" );
stringVec.AddToTail( "string3" );
CDmrArray< CUtlBinaryBlock > binaryVec( pElement5, "binary_array_test", true );
CUtlBinaryBlock block( (const void *)buf, 256 );
i = binaryVec.AddToTail( block );
CUtlBinaryBlock block2( (const void *)buf2, 256 );
i = binaryVec.AddToTail( block2);
CDmrArray< DmObjectId_t > idVec( pElement6, "elementid_array_test", true );
i = idVec.AddToTail( pElement6->GetId() );
i = idVec.AddToTail( pElement5->GetId() );
i = idVec.AddToTail( pElement4->GetId() );
CDmrElementArray< > elementVec( pElement6, "element_array_test", true );
elementVec.AddToTail( pElement4 );
elementVec.AddToTail( pElement5 );
CDmrElementArray< > elementVec2( pElement7, "element_array_test", true );
elementVec2.AddToTail( pElement2 );
elementVec2.AddToTail( pElement4 );
pElement->SetValue( "element_test", pElement7 );
pElement->SetValue( "shared_element_test", pElement6 );
CDmrElementArray<> children( pElement, "children", true );
children.InsertBefore( 0, pElement2 );
children.InsertBefore( 1, pElement3 );
pElement7->SetValue( "shared_element_test", pElement6 );
CDmrElementArray<> children2( pElement7, "children", true );
children2.InsertBefore( 0, pElement2 );
}
DmElementHandle_t CreateTestScene( DmFileId_t fileid )
{
CUtlVector< DmElementHandle_t > handles;
CreateTestScene( handles, fileid );
return handles[ 0 ];
}
DmElementHandle_t CreateKeyValuesTestScene( DmFileId_t fileid )
{
CDmElement *pElement = CreateElement<CDmElement>( "root", fileid );
Assert( pElement );
CDmElement *pElement2 = CreateElement<CDmElement>( "shared_child", fileid );
Assert( pElement2 );
CDmElement *pElement3 = CreateElement<CDmElement>( "unique_child", fileid );
Assert( pElement3 );
CDmElement *pElement4 = CreateElement<CDmElement>( "shared_array_element", fileid );
Assert( pElement4 );
CDmElement *pElement5 = CreateElement<CDmElement>( "unique_array_element", fileid );
Assert( pElement5 );
CDmElement *pElement6 = CreateElement<CDmElement>( "shared_element", fileid );
Assert( pElement6 );
CDmElement *pElement7 = CreateElement<CDmElement>( "unique_element", fileid );
Assert( pElement7 );
g_pDataModel->SetFileRoot( fileid, pElement->GetHandle() );
pElement->SetValue( "int_test", 2 );
pElement->SetValue( "float_test", 3.0f );
pElement->SetValue( "string_test", "test" );
CDmrElementArray<> eVec( pElement6, "element_array_test", true );
eVec.AddToTail( pElement4 );
eVec.AddToTail( pElement5 );
CDmrElementArray<> eVec2( pElement7, "element_array_test", true );
eVec2.AddToTail( pElement2 );
eVec2.AddToTail( pElement4 );
pElement->SetValue( "element_test", pElement7 );
pElement->SetValue( "shared_element_test", pElement6 );
CDmrElementArray<> children( pElement, "children", true );
children.InsertBefore( 0, pElement2 );
children.InsertBefore( 1, pElement3 );
pElement7->SetValue( "shared_element_test", pElement6 );
CDmrElementArray<> children2( pElement7, "children", true );
children2.InsertBefore( 0, pElement2 );
return pElement->GetHandle();
}
template< class T >
bool AssertEqualsTest( bool quiet, const T& src1, const T& src2 )
{
if ( !( src1 == src2 ))
{
if ( !quiet )
{
AssertMsg( 0, "Results not equal, expecting equal\n" );
}
return false;
}
return true;
}
template< class T >
bool AssertEqualsUtlVector( bool quiet, const CUtlVector<T> &src1, const CUtlVector<T> &src2 )
{
bool retval = true;
if ( src1.Count() != src2.Count() )
{
if ( !quiet )
{
AssertEqualsTest( quiet, src1.Count(), src2.Count() );
}
retval = false;
}
for ( int i = 0; i < src1.Count(); ++i )
{
if ( !src2.IsValidIndex( i ) )
continue;
if ( !( src1[i] == src2[i] ) )
{
if ( !quiet )
{
AssertEqualsTest( quiet, src1[i], src2[i] );
}
retval = false;
}
}
return retval;
}
template< class T >
bool AssertEqualsUtlVector( bool quiet, CDmAttribute *pAttribute1, CDmAttribute *pAttribute2 )
{
CDmrArray<T> src1( pAttribute1 );
CDmrArray<T> src2( pAttribute2 );
return AssertEqualsUtlVector( quiet, src1.Get(), src2.Get() );
}
bool AssertEqualAttributes( bool quiet, CDmAttribute *pAttribute1, CDmAttribute *pAttribute2 )
{
// Always follow ptrs to elements...
if ( pAttribute1->GetType() != AT_ELEMENT_ARRAY &&
pAttribute1->GetType() != AT_ELEMENT )
{
// Dirty flag checking here is to avoid infinite recursive loops
if ( !pAttribute1->IsFlagSet( FATTRIB_DIRTY ) && !pAttribute2->IsFlagSet( FATTRIB_DIRTY ) )
return true;
}
if ( !pAttribute1 )
{
if ( !quiet )
{
AssertMsg( 0, "AssertEqualAttributes: pAttribute1 is NULL\n" );
}
return false;
}
if ( !pAttribute2 )
{
if ( !quiet )
{
AssertMsg( 0, "AssertEqualAttributes: pAttribute2 is NULL\n" );
}
return false;
}
bool retval = true;
pAttribute1->RemoveFlag( FATTRIB_DIRTY );
pAttribute2->RemoveFlag( FATTRIB_DIRTY );
if ( pAttribute1->GetType() != pAttribute2->GetType() )
{
if ( !quiet )
{
AssertMsg( 0, "pAttribute1->GetType() == pAttribute2->GetType()" );
}
retval = false;
}
switch( pAttribute1->GetType() )
{
case AT_INT:
return AssertEqualsTest( quiet, pAttribute1->GetValue<int>( ), pAttribute2->GetValue<int>( ) );
case AT_FLOAT:
return AssertEqualsTest( quiet, pAttribute1->GetValue<float>( ), pAttribute2->GetValue<float>( ) );
case AT_BOOL:
return AssertEqualsTest( quiet, pAttribute1->GetValue<bool>( ), pAttribute2->GetValue<bool>( ) );
case AT_STRING:
return AssertEqualsTest( quiet, pAttribute1->GetValue<CUtlString>( ), pAttribute2->GetValue<CUtlString>( ) );
case AT_VOID:
return AssertEqualsTest( quiet, pAttribute1->GetValue<CUtlBinaryBlock>( ), pAttribute2->GetValue<CUtlBinaryBlock>( ) );
case AT_OBJECTID:
return true; // skip this for now - two elements can't have the same id, and CreateTestScene currently creates random test_id's each time...
/*
{
if ( !g_pDataModel->IsEqual( pAttribute1->GetValue<DmObjectId_t>( ), pAttribute2->GetValue<DmObjectId_t>( ) ) )
{
if ( !quiet )
{
Assert( g_pDataModel->IsEqual( pAttribute1->GetValue<DmObjectId_t>( ), pAttribute2->GetValue<DmObjectId_t>( ) ) );
}
return false;
}
return true;
}
break;
*/
case AT_COLOR:
return AssertEqualsTest( quiet, pAttribute1->GetValue<Color>( ), pAttribute2->GetValue<Color>( ) );
case AT_VECTOR2:
return AssertEqualsTest( quiet, pAttribute1->GetValue<Vector2D>( ), pAttribute2->GetValue<Vector2D>( ) );
case AT_VECTOR3:
return AssertEqualsTest( quiet, pAttribute1->GetValue<Vector>( ), pAttribute2->GetValue<Vector>( ) );
case AT_VECTOR4:
return AssertEqualsTest( quiet, pAttribute1->GetValue<Vector4D>( ), pAttribute2->GetValue<Vector4D>( ) );
case AT_QANGLE:
return AssertEqualsTest( quiet, pAttribute1->GetValue<QAngle>( ), pAttribute2->GetValue<QAngle>( ) );
case AT_QUATERNION:
return AssertEqualsTest( quiet, pAttribute1->GetValue<Quaternion>( ), pAttribute2->GetValue<Quaternion>( ) );
case AT_VMATRIX:
return AssertEqualsTest( quiet, pAttribute1->GetValue<VMatrix>( ), pAttribute2->GetValue<VMatrix>( ) );
case AT_ELEMENT:
return AssertEqualElementHierarchies( quiet, pAttribute1->GetValue<DmElementHandle_t>( ), pAttribute2->GetValue<DmElementHandle_t>( ) );
case AT_ELEMENT_ARRAY:
{
const CDmrElementArray< CDmElement > src1( pAttribute1 );
const CDmrElementArray< CDmElement > src2( pAttribute2 );
bool differs = !AssertEqualsTest( quiet, src1.Count(), src2.Count() );
bool differs2 = false;
for ( int i = 0; i < src1.Count(); ++i )
{
differs2 |= !AssertEqualElementHierarchies( quiet, src1[ i ]->GetHandle(), src2[ i ]->GetHandle() );
}
return ( !differs && !differs2 );
}
break;
case AT_INT_ARRAY:
return AssertEqualsUtlVector<int>( quiet, pAttribute1, pAttribute2 );
case AT_FLOAT_ARRAY:
return AssertEqualsUtlVector<float>( quiet, pAttribute1, pAttribute2 );
case AT_BOOL_ARRAY:
return AssertEqualsUtlVector<bool>( quiet, pAttribute1, pAttribute2 );
case AT_STRING_ARRAY:
return AssertEqualsUtlVector<CUtlString>( quiet, pAttribute1, pAttribute2 );
case AT_VOID_ARRAY:
return AssertEqualsUtlVector<CUtlBinaryBlock>( quiet, pAttribute1, pAttribute2 );
case AT_OBJECTID_ARRAY:
{
const CDmrArray<DmObjectId_t> src1( pAttribute1 );
const CDmrArray<DmObjectId_t> src2( pAttribute2 );
bool differs = AssertEqualsTest( quiet, src1.Count(), src2.Count() );
return differs; // skip this for now - CreateTestScene currently creates random ids each time...
/*
bool differs2 = false;
for ( int i = 0; i < src1.Count(); ++i )
{
if ( !g_pDataModel->IsEqual( src1[i], src2[i] ) )
{
differs2 = true;
if ( !quiet )
{
Assert( g_pDataModel->IsEqual( src1[i], src2[i] ) );
}
}
}
return ( !differs && !differs2 );
*/
}
break;
case AT_COLOR_ARRAY:
return AssertEqualsUtlVector<Color>( quiet, pAttribute1, pAttribute2 );
case AT_VECTOR2_ARRAY:
return AssertEqualsUtlVector<Vector2D>( quiet, pAttribute1, pAttribute2 );
case AT_VECTOR3_ARRAY:
return AssertEqualsUtlVector<Vector>( quiet, pAttribute1, pAttribute2 );
case AT_VECTOR4_ARRAY:
return AssertEqualsUtlVector<Vector4D>( quiet, pAttribute1, pAttribute2 );
case AT_QANGLE_ARRAY:
return AssertEqualsUtlVector<QAngle>( quiet, pAttribute1, pAttribute2 );
case AT_QUATERNION_ARRAY:
return AssertEqualsUtlVector<Quaternion>( quiet, pAttribute1, pAttribute2 );
case AT_VMATRIX_ARRAY:
return AssertEqualsUtlVector<VMatrix>( quiet, pAttribute1, pAttribute2 );
}
return retval;
}
bool AssertEqualElementHierarchies( bool quiet, DmElementHandle_t src1, DmElementHandle_t src2 )
{
CDmElement *pSrc1 = g_pDataModel->GetElement( src1 );
CDmElement *pSrc2 = g_pDataModel->GetElement( src2 );
if ( !pSrc1 || !pSrc2 )
return false;
// Assume equality
bool retval = true;
if ( pSrc1->GetType() != pSrc2->GetType() )
{
if ( !quiet )
{
AssertMsg( 0, "pSrc1->GetType() == pSrc2->GetType()" );
}
retval = false;
}
if ( Q_strcmp( pSrc1->GetName(), pSrc2->GetName() ) )
{
if ( !quiet )
{
AssertMsg2( 0, "Q_strcmp( %s, %s )", pSrc1->GetName(), pSrc2->GetName() );
}
retval = false;
}
if ( pSrc1->AttributeCount() != pSrc2->AttributeCount() )
{
if ( !quiet )
{
AssertMsg( 0, "pSrc1->NumAttributes() == pSrc2->NumAttributes()" );
}
retval = false;
}
for ( CDmAttribute *pAttribute1 = pSrc1->FirstAttribute(); pAttribute1; pAttribute1 = pAttribute1->NextAttribute() )
{
const char *pName = pAttribute1->GetName();
if ( !pSrc2->HasAttribute( pName ) )
{
if ( !quiet )
{
AssertMsg1( 0, "pSrc2->HasAttribute( %s ) failed\n", pName );
}
retval = false;
}
else
{
CDmAttribute *pAttribute2 = pSrc2->GetAttribute( pName );
bool differs = !AssertEqualAttributes( quiet, pAttribute1, pAttribute2 );
if ( differs )
{
retval = false;
}
}
}
return retval;
}
void TestDeleteOldCR( const char *pSerializationType )
{
DmFileId_t testFileID = g_pDataModel->FindOrCreateFileId( "<TestDeleteOldCR>" );
DmElementHandle_t hRoot = CreateTestScene( testFileID );
int nTestElements = g_pDataModel->NumElementsInFile( testFileID );
const char *pFileName = "DeleteOld.dmx";
CDmElement *pRoot = static_cast< CDmElement* >( g_pDataModel->GetElement( hRoot ) );
bool bOk = g_pDataModel->SaveToFile( pFileName, NULL, pSerializationType, "dmx", pRoot );
Shipping_Assert( bOk );
CDmElement *pReadInRoot = NULL;
DmFileId_t readFileID = g_pDataModel->RestoreFromFile( pFileName, NULL, NULL, &pReadInRoot, CR_DELETE_OLD );
Shipping_Assert( readFileID != DMFILEID_INVALID );
if ( pReadInRoot )
{
Shipping_Assert( pReadInRoot->GetHandle() == hRoot );
Shipping_Assert( g_pDataModel->GetElement( hRoot ) == pReadInRoot );
Shipping_Assert( g_pDataModel->NumElementsInFile( testFileID ) == 0 );
Shipping_Assert( g_pDataModel->NumElementsInFile( readFileID ) == nTestElements );
CDmeHandle< CDmElement > rootHandle( hRoot ); // keeps a reference to root around, even after the file is unloaded
g_pDataModel->UnloadFile( readFileID );
Shipping_Assert( g_pDataModel->NumElementsInFile( readFileID ) == 0 );
Shipping_Assert( g_pDataModel->GetElement( hRoot ) == NULL );
DmFileId_t readFileID2 = g_pDataModel->RestoreFromFile( pFileName, NULL, NULL, &pReadInRoot, CR_DELETE_OLD );
Shipping_Assert( readFileID2 == readFileID );
Shipping_Assert( pReadInRoot->GetHandle() == hRoot );
Shipping_Assert( g_pDataModel->GetElement( hRoot ) == pReadInRoot );
Shipping_Assert( g_pDataModel->NumElementsInFile( testFileID ) == 0 );
Shipping_Assert( g_pDataModel->NumElementsInFile( readFileID ) == nTestElements );
g_pDataModel->RemoveFileId( readFileID );
}
else
{
Msg( "Failed to load %s back from disk!!!", pFileName );
}
g_pDataModel->RemoveFileId( testFileID );
}
void TestDeleteNewCR( const char *pSerializationType )
{
DmFileId_t testFileID = g_pDataModel->FindOrCreateFileId( "<TestDeleteNewCR>" );
DmElementHandle_t hRoot = CreateTestScene( testFileID );
int nTestElements = g_pDataModel->NumElementsInFile( testFileID );
const char *pFileName = "DeleteNew.dmx";
CDmElement *pRoot = static_cast< CDmElement* >( g_pDataModel->GetElement( hRoot ) );
bool bOk = g_pDataModel->SaveToFile( pFileName, NULL, pSerializationType, "dmx", pRoot );
Shipping_Assert( bOk );
CDmElement *pReadInRoot = NULL;
DmFileId_t readFileID = g_pDataModel->RestoreFromFile( pFileName, NULL, NULL, &pReadInRoot, CR_DELETE_NEW );
Shipping_Assert( readFileID != DMFILEID_INVALID );
Shipping_Assert( g_pDataModel->GetElement( hRoot ) == pRoot );
Shipping_Assert( pRoot->GetHandle() == hRoot );
Shipping_Assert( pReadInRoot == pRoot ); // RestoreFromFile now returns the old element when the new root is deleted
Shipping_Assert( g_pDataModel->NumElementsInFile( testFileID ) == nTestElements );
Shipping_Assert( g_pDataModel->NumElementsInFile( readFileID ) == 0 );
g_pDataModel->UnloadFile( readFileID );
Shipping_Assert( g_pDataModel->NumElementsInFile( readFileID ) == 0 );
DmFileId_t readFileID2 = g_pDataModel->RestoreFromFile( pFileName, NULL, NULL, &pReadInRoot, CR_DELETE_NEW );
Shipping_Assert( readFileID2 == readFileID );
Shipping_Assert( g_pDataModel->GetElement( hRoot ) == pRoot );
Shipping_Assert( pRoot->GetHandle() == hRoot );
Shipping_Assert( pReadInRoot == pRoot ); // RestoreFromFile now returns the old element when the new root is deleted
Shipping_Assert( g_pDataModel->NumElementsInFile( testFileID ) == nTestElements );
Shipping_Assert( g_pDataModel->NumElementsInFile( readFileID ) == 0 );
g_pDataModel->RemoveFileId( readFileID );
g_pDataModel->RemoveFileId( testFileID );
}
void TestCopyNewCR( const char *pSerializationType )
{
DmFileId_t testFileID = g_pDataModel->FindOrCreateFileId( "<TestCopyNewCR>" );
DmElementHandle_t hRoot = CreateTestScene( testFileID );
int nTestElements = g_pDataModel->NumElementsInFile( testFileID );
const char *pFileName = "CopyNew.dmx";
CDmElement *pRoot = g_pDataModel->GetElement( hRoot );
bool bOk = g_pDataModel->SaveToFile( pFileName, NULL, pSerializationType, "dmx", pRoot );
Shipping_Assert( bOk );
CDmElement *pReadInRoot = NULL;
DmFileId_t readFileID = g_pDataModel->RestoreFromFile( pFileName, NULL, NULL, &pReadInRoot, CR_COPY_NEW );
Shipping_Assert( readFileID != DMFILEID_INVALID );
if ( pReadInRoot )
{
DmElementHandle_t hReadInRoot = pReadInRoot->GetHandle();
Shipping_Assert( g_pDataModel->GetElement( hRoot ) == pRoot );
Shipping_Assert( pRoot->GetHandle() == hRoot );
Shipping_Assert( pReadInRoot->GetHandle() != hRoot );
Shipping_Assert( !IsUniqueIdEqual( pRoot->GetId(), pReadInRoot->GetId() ) );
Shipping_Assert( g_pDataModel->NumElementsInFile( testFileID ) == nTestElements );
Shipping_Assert( g_pDataModel->NumElementsInFile( readFileID ) == nTestElements );
g_pDataModel->UnloadFile( readFileID );
Shipping_Assert( g_pDataModel->NumElementsInFile( readFileID ) == 0 );
Shipping_Assert( g_pDataModel->GetElement( hReadInRoot ) == NULL );
DmFileId_t readFileID2 = g_pDataModel->RestoreFromFile( pFileName, NULL, NULL, &pReadInRoot, CR_COPY_NEW );
Shipping_Assert( readFileID2 == readFileID );
Shipping_Assert( g_pDataModel->GetElement( hRoot ) == pRoot );
Shipping_Assert( pRoot->GetHandle() == hRoot );
Shipping_Assert( pReadInRoot->GetHandle() != hRoot );
Shipping_Assert( !IsUniqueIdEqual( pRoot->GetId(), pReadInRoot->GetId() ) );
Shipping_Assert( g_pDataModel->NumElementsInFile( testFileID ) == nTestElements );
Shipping_Assert( g_pDataModel->NumElementsInFile( readFileID ) == nTestElements );
g_pDataModel->RemoveFileId( readFileID );
}
else
{
Msg( "Failed to load %s back from disk!!!", pFileName );
}
g_pDataModel->RemoveFileId( testFileID );
}
void TestForceCopyCR( const char *pSerializationType )
{
DmFileId_t testFileID = g_pDataModel->FindOrCreateFileId( "<TestForceCopyCR>" );
DmElementHandle_t hRoot = CreateTestScene( testFileID );
int nTestElements = g_pDataModel->NumElementsInFile( testFileID );
const char *pFileName = "ForceCopy.dmx";
CDmElement *pRoot = static_cast< CDmElement* >( g_pDataModel->GetElement( hRoot ) );
bool bOk = g_pDataModel->SaveToFile( pFileName, NULL, pSerializationType, "dmx", pRoot );
Shipping_Assert( bOk );
CDmElement *pReadInRoot = NULL;
DmFileId_t readFileID = g_pDataModel->RestoreFromFile( pFileName, NULL, NULL, &pReadInRoot, CR_FORCE_COPY );
Shipping_Assert( readFileID != DMFILEID_INVALID );
if ( pReadInRoot )
{
DmElementHandle_t hReadInRoot = pReadInRoot->GetHandle();
Shipping_Assert( g_pDataModel->GetElement( hRoot ) == pRoot );
Shipping_Assert( pRoot->GetHandle() == hRoot );
Shipping_Assert( pReadInRoot->GetHandle() != hRoot );
Shipping_Assert( !IsUniqueIdEqual( pRoot->GetId(), pReadInRoot->GetId() ) );
Shipping_Assert( g_pDataModel->NumElementsInFile( testFileID ) == nTestElements );
Shipping_Assert( g_pDataModel->NumElementsInFile( readFileID ) == nTestElements );
g_pDataModel->UnloadFile( readFileID );
Shipping_Assert( g_pDataModel->NumElementsInFile( readFileID ) == 0 );
Shipping_Assert( g_pDataModel->GetElement( hReadInRoot ) == NULL );
DmFileId_t readFileID2 = g_pDataModel->RestoreFromFile( pFileName, NULL, NULL, &pReadInRoot, CR_FORCE_COPY );
Shipping_Assert( readFileID2 == readFileID );
Shipping_Assert( g_pDataModel->GetElement( hRoot ) == pRoot );
Shipping_Assert( pRoot->GetHandle() == hRoot );
Shipping_Assert( pReadInRoot->GetHandle() != hRoot );
Shipping_Assert( !IsUniqueIdEqual( pRoot->GetId(), pReadInRoot->GetId() ) );
Shipping_Assert( g_pDataModel->NumElementsInFile( testFileID ) == nTestElements );
Shipping_Assert( g_pDataModel->NumElementsInFile( readFileID ) == nTestElements );
g_pDataModel->RemoveFileId( readFileID );
}
else
{
Msg( "Failed to load %s back from disk!!!", pFileName );
}
g_pDataModel->RemoveFileId( testFileID );
}
void TestConflictResolution( const char *pSerializationType )
{
TestDeleteOldCR( pSerializationType );
TestDeleteNewCR( pSerializationType );
TestCopyNewCR( pSerializationType );
TestForceCopyCR( pSerializationType );
}
void TestSerializationMethod( const char *pSerializationType )
{
DmFileId_t testFileID = g_pDataModel->FindOrCreateFileId( "<CreateTestScene>" );
DmElementHandle_t hRoot = CreateTestScene( testFileID );
const char *pFileName = "dmxtest.dmx";
CDmElement *pRoot = static_cast<CDmElement*>(g_pDataModel->GetElement(hRoot));
bool bOk = g_pDataModel->SaveToFile( pFileName, NULL, pSerializationType, "dmx", pRoot );
Shipping_Assert( bOk );
CDmElement *pReadInRoot = NULL;
DmFileId_t dmxFileID = g_pDataModel->RestoreFromFile( pFileName, NULL, NULL, &pReadInRoot, CR_FORCE_COPY );
Shipping_Assert( dmxFileID != DMFILEID_INVALID );
if ( pReadInRoot )
{
AssertEqualElementHierarchies( false, hRoot, pReadInRoot->GetHandle() );
g_pDataModel->RemoveFileId( dmxFileID );
}
else
{
Msg( "Failed to load dmxtest.dmx back from disk!!!" );
}
g_pDataModel->RemoveFileId( testFileID );
TestConflictResolution( pSerializationType );
}
DEFINE_TESTCASE_NOSUITE( DmxSerializationTest )
{
Msg( "Running dmx serialization tests...\n" );
CDisableUndoScopeGuard sg;
TestSerializationMethod( "keyvalues2" );
TestSerializationMethod( "keyvalues2_flat" );
TestSerializationMethod( "xml" );
TestSerializationMethod( "xml_flat" );
TestSerializationMethod( "binary" );
int nEndingCount = g_pDataModel->GetAllocatedElementCount();
AssertEqualsTest( false, 0, nEndingCount );
}

1096
unittests/dmxtest/dmxtestundoredo.cpp

File diff suppressed because it is too large Load Diff

104
unittests/dmxtest/dmxtestvalue.cpp

@ -1,104 +0,0 @@ @@ -1,104 +0,0 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Unit test program for DMX testing (testing the single-value operations)
//
// $NoKeywords: $
//=============================================================================//
#include "unitlib/unitlib.h"
#include "datamodel/dmelement.h"
#include "datamodel/idatamodel.h"
#include "tier1/utlbuffer.h"
#include "filesystem.h"
#include "datamodel/dmehandle.h"
#include "tier2/tier2.h"
#include "movieobjects/dmeshape.h"
DEFINE_TESTCASE_NOSUITE( DmxValueTest )
{
Msg( "Running dmx single value tests...\n" );
CDisableUndoScopeGuard sg;
DmFileId_t fileid = g_pDataModel->FindOrCreateFileId( "<RunValueTests>" );
CDmElement *pElement = CreateElement< CDmElement >( "root", fileid );
CDmElement *pElement2 = CreateElement<CDmElement>( "element1", fileid );
Assert( pElement2 );
CDmElement *pElement3 = CreateElement<CDmElement>( "element2", fileid );
Assert( pElement3 );
CDmeShape *pElement4 = CreateElement<CDmeShape>( "shape", fileid );
Assert( pElement4 );
CDmAttribute *pIntAttribute = pElement->SetValue( "int_test", 5 );
CDmAttribute *pFloatAttribute = pElement->SetValue( "float_test", 4.5f );
CDmAttribute *pBoolAttribute = pElement->SetValue( "bool_test", true );
CDmAttribute *pAttribute = pElement->AddAttribute( "int_convert_test", AT_INT );
// Type conversion set test
pAttribute->SetValue( 5 );
Shipping_Assert( pAttribute->GetValue<int>() == 5 );
pAttribute->SetValue( 4.5f );
Shipping_Assert( pAttribute->GetValue<int>() == 4 );
pAttribute->SetValue( true );
Shipping_Assert( pAttribute->GetValue<int>() == 1 );
pAttribute->SetValue( pIntAttribute );
Shipping_Assert( pAttribute->GetValue<int>() == 5 );
pAttribute->SetValue( pFloatAttribute );
Shipping_Assert( pAttribute->GetValue<int>() == 4 );
pAttribute->SetValue( pBoolAttribute );
Shipping_Assert( pAttribute->GetValue<int>() == 1 );
pAttribute = pElement->AddAttribute( "bool_convert_test", AT_BOOL );
// Type conversion set test
pAttribute->SetValue( 5 );
Shipping_Assert( pAttribute->GetValue<bool>() == true );
pAttribute->SetValue( 4.5f );
Shipping_Assert( pAttribute->GetValue<bool>() == true );
pAttribute->SetValue( false );
Shipping_Assert( pAttribute->GetValue<bool>() == false );
pAttribute->SetValue( pIntAttribute );
Shipping_Assert( pAttribute->GetValue<bool>() == true );
pAttribute->SetValue( pFloatAttribute );
Shipping_Assert( pAttribute->GetValue<bool>() == true );
pAttribute->SetValue( pBoolAttribute );
Shipping_Assert( pAttribute->GetValue<bool>() == true );
pAttribute = pElement->AddAttribute( "float_convert_test", AT_FLOAT );
// Type conversion set test
pAttribute->SetValue( 5 );
Shipping_Assert( pAttribute->GetValue<float>() == 5.0f );
pAttribute->SetValue( 4.5f );
Shipping_Assert( pAttribute->GetValue<float>() == 4.5f );
pAttribute->SetValue( true );
Shipping_Assert( pAttribute->GetValue<float>() == 1.0f );
pAttribute->SetValue( pIntAttribute );
Shipping_Assert( pAttribute->GetValue<float>() == 5.0f );
pAttribute->SetValue( pFloatAttribute );
Shipping_Assert( pAttribute->GetValue<float>() == 4.5f );
pAttribute->SetValue( pBoolAttribute );
Shipping_Assert( pAttribute->GetValue<float>() == 1.0f );
// Type conversion set test
QAngle angles( 90, 0, 0 );
Quaternion quat;
AngleQuaternion( angles, quat );
pAttribute = pElement->AddAttribute( "qangle_convert_test", AT_QANGLE );
pAttribute->SetValue( angles );
Shipping_Assert( pAttribute->GetValue<QAngle>() == angles );
pAttribute->SetValue( quat );
Shipping_Assert( pAttribute->GetValue<QAngle>() == angles );
pAttribute = pElement->AddAttribute( "quat_convert_test", AT_QUATERNION );
pAttribute->SetValue( angles );
Shipping_Assert( pAttribute->GetValue<Quaternion>() == quat );
pAttribute->SetValue( quat );
Shipping_Assert( pAttribute->GetValue<Quaternion>() == quat );
g_pDataModel->RemoveFileId( fileid );
}

1508
unittests/ihvtest1/ihvtest1.cpp

File diff suppressed because it is too large Load Diff

106
unittests/ihvtest1/ihvtest1.vpc

@ -1,106 +0,0 @@ @@ -1,106 +0,0 @@
//-----------------------------------------------------------------------------
// IHVTEST1.VPC
//
// Project Script
//-----------------------------------------------------------------------------
$Macro SRCDIR "..\.."
$Macro OUTBINDIR "$LIBPUBLIC\unittests"
$Include "$SRCDIR\vpc_scripts\source_exe_base.vpc"
$Configuration
{
$Compiler
{
$AdditionalIncludeDirectories "$BASE;$SRCDIR\game\shared"
$PreprocessorDefinitions "$BASE;IHVTEST"
}
}
$Project "ihvtest1"
{
$Folder "Source Files"
{
$File "$SRCDIR\public\bone_setup.cpp"
$File "$SRCDIR\public\collisionutils.cpp"
$File "ihvtest1.cpp"
$File "$SRCDIR\public\studio.cpp"
$File "sys_clock.cpp" [$WIN32]
}
$Folder "Public Header Files"
{
$File "$SRCDIR\public\mathlib\amd3dx.h"
$File "$SRCDIR\public\basehandle.h"
$File "$SRCDIR\public\tier0\basetypes.h"
$File "$SRCDIR\public\bitvec.h"
$File "$SRCDIR\public\bone_accessor.h"
$File "$SRCDIR\public\bone_setup.h"
$File "$SRCDIR\public\bspflags.h"
$File "$SRCDIR\public\clientstats.h"
$File "$SRCDIR\public\cmodel.h"
$File "$SRCDIR\public\CollisionUtils.h"
$File "$SRCDIR\public\tier0\commonmacros.h"
$File "$SRCDIR\public\mathlib\compressed_vector.h"
$File "$SRCDIR\public\const.h"
$File "$SRCDIR\public\tier0\dbg.h"
$File "$SRCDIR\public\tier0\fasttimer.h"
$File "$SRCDIR\public\filesystem.h"
$File "$SRCDIR\public\gametrace.h"
$File "$SRCDIR\public\appframework\IAppSystem.h"
$File "$SRCDIR\public\tier0\icommandline.h"
$File "$SRCDIR\public\ihandleentity.h"
$File "$SRCDIR\public\materialsystem\imaterialproxyfactory.h"
$File "$SRCDIR\public\materialsystem\imaterialsystem.h"
$File "$SRCDIR\public\materialsystem\imaterialsystemhardwareconfig.h"
$File "$SRCDIR\public\tier1\interface.h"
$File "$SRCDIR\public\istudiorender.h"
$File "$SRCDIR\public\materialsystem\materialsystem_config.h"
$File "$SRCDIR\public\mathlib\mathlib.h"
$File "$SRCDIR\public\tier0\mem.h"
$File "$SRCDIR\public\tier0\memalloc.h"
$File "$SRCDIR\public\tier0\memdbgon.h"
$File "$SRCDIR\public\tier0\platform.h"
$File "$SRCDIR\public\tier0\protected_things.h"
$File "$SRCDIR\public\vstdlib\random.h"
$File "$SRCDIR\public\string_t.h"
$File "$SRCDIR\public\tier1\strtools.h"
$File "$SRCDIR\public\studio.h"
$File "$SRCDIR\public\tier1\utlbuffer.h"
$File "$SRCDIR\public\tier1\utldict.h"
$File "$SRCDIR\public\tier1\utlmemory.h"
$File "$SRCDIR\public\tier1\utlrbtree.h"
$File "$SRCDIR\public\tier1\utlsymbol.h"
$File "$SRCDIR\public\tier1\utlvector.h"
$File "$SRCDIR\public\vcollide.h"
$File "$SRCDIR\public\mathlib\vector.h"
$File "$SRCDIR\public\mathlib\vector2d.h"
$File "$SRCDIR\public\mathlib\vector4d.h"
$File "$SRCDIR\public\tier0\vprof.h"
$File "$SRCDIR\public\vstdlib\vstdlib.h"
}
$Folder "Build Bat Files" [$0]
{
$File "copybin.bat"
$File "copycommonsrc.bat"
$File "copydx8.bat"
$File "copygamesharedsrc.bat"
$File "copyihvtestsrc.bat"
$File "copylib.bat"
$File "copymatsyssrc.bat"
$File "copypublicsrc.bat"
$File "copyshaderdx8src.bat"
$File "copysrc.bat"
$File "copystudiorendersrc.bat"
}
$Folder "Link Libraries"
{
$Lib appframework
$Lib mathlib
$Lib $LIBCOMMON\vtuneapi [$WIN32&&!$VS2015]
$Lib $SRCDIR\lib\common\vtuneapi [$WIN32&&$VS2015]
}
}

254
unittests/ihvtest1/sys_clock.cpp

@ -1,254 +0,0 @@ @@ -1,254 +0,0 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <assert.h>
#pragma optimize( "", off )
#pragma pack( push, thing )
#pragma pack( 4 )
static long g_cw, g_single_cw, g_highchop_cw, g_full_cw, g_ceil_cw, g_pushed_cw;
static struct
{
long dummy[8];
} g_fpenv;
#pragma pack( pop, thing )
void __declspec ( naked ) MaskExceptions()
{
_asm
{
fnstenv ds:dword ptr[g_fpenv]
or ds:dword ptr[g_fpenv],03Fh
fldenv ds:dword ptr[g_fpenv]
ret
}
}
void __declspec ( naked ) Sys_SetFPCW()
{
_asm
{
fnstcw ds:word ptr[g_cw]
mov eax,ds:dword ptr[g_cw]
and ah,0F0h
or ah,003h
mov ds:dword ptr[g_full_cw],eax
mov ds:dword ptr[g_highchop_cw],eax
and ah,0F0h
or ah,00Ch
mov ds:dword ptr[g_single_cw],eax
and ah,0F0h
or ah,008h
mov ds:dword ptr[g_ceil_cw],eax
ret
}
}
void __declspec ( naked ) Sys_PushFPCW_SetHigh()
{
_asm
{
fnstcw ds:word ptr[g_pushed_cw]
fldcw ds:word ptr[g_full_cw]
ret
}
}
void __declspec ( naked ) Sys_PopFPCW()
{
_asm
{
fldcw ds:word ptr[g_pushed_cw]
ret
}
}
#pragma optimize( "", on )
//-----------------------------------------------------------------------------
// Purpose: Implements high precision clock
// TODO: Make into an interface?
//-----------------------------------------------------------------------------
class CSysClock
{
public:
// Construction
CSysClock( void );
// Initialization
void Init( void );
void SetStartTime( void );
// Sample the clock
double GetTime( void );
private:
// High performance clock frequency
double m_dClockFrequency;
// Current accumulated time
double m_dCurrentTime;
// How many bits to shift raw 64 bit sample count by
int m_nTimeSampleShift;
// Previous 32 bit sample count
unsigned int m_uiPreviousTime;
bool m_bInitialized;
};
static CSysClock g_Clock;
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CSysClock::CSysClock( void )
{
m_bInitialized = false;
}
//-----------------------------------------------------------------------------
// Purpose: Initialize the clock
//-----------------------------------------------------------------------------
void CSysClock::Init( void )
{
BOOL success;
LARGE_INTEGER PerformanceFreq;
unsigned int lowpart, highpart;
MaskExceptions ();
Sys_SetFPCW ();
// Start clock at zero
m_dCurrentTime = 0.0;
success = QueryPerformanceFrequency( &PerformanceFreq );
assert( success );
// get 32 out of the 64 time bits such that we have around
// 1 microsecond resolution
lowpart = (unsigned int)PerformanceFreq.LowPart;
highpart = (unsigned int)PerformanceFreq.HighPart;
m_nTimeSampleShift = 0;
while ( highpart || ( lowpart > 2000000.0 ) )
{
m_nTimeSampleShift++;
lowpart >>= 1;
lowpart |= (highpart & 1) << 31;
highpart >>= 1;
}
m_dClockFrequency = 1.0 / (double)lowpart;
// Get initial sample
unsigned int temp;
LARGE_INTEGER PerformanceCount;
QueryPerformanceCounter( &PerformanceCount );
if ( !m_nTimeSampleShift )
{
temp = (unsigned int)PerformanceCount.LowPart;
}
else
{
// Rotate counter to right by m_nTimeSampleShift places
temp = ((unsigned int)PerformanceCount.LowPart >> m_nTimeSampleShift) |
((unsigned int)PerformanceCount.HighPart << (32 - m_nTimeSampleShift));
}
// Set first time stamp
m_uiPreviousTime = temp;
m_bInitialized = true;
SetStartTime();
}
void CSysClock::SetStartTime( void )
{
GetTime();
m_dCurrentTime = 0.0;
m_uiPreviousTime = ( unsigned int )m_dCurrentTime;
}
double CSysClock::GetTime( void )
{
LARGE_INTEGER PerformanceCount;
unsigned int temp, t2;
double time;
if ( !m_bInitialized )
{
return 0.0;
}
Sys_PushFPCW_SetHigh();
// Get sample counter
QueryPerformanceCounter( &PerformanceCount );
if ( !m_nTimeSampleShift )
{
temp = (unsigned int)PerformanceCount.LowPart;
}
else
{
// Rotate counter to right by m_nTimeSampleShift places
temp = ((unsigned int)PerformanceCount.LowPart >> m_nTimeSampleShift) |
((unsigned int)PerformanceCount.HighPart << (32 - m_nTimeSampleShift));
}
// check for turnover or backward time
if ( ( temp <= m_uiPreviousTime ) &&
( ( m_uiPreviousTime - temp ) < 0x10000000) )
{
m_uiPreviousTime = temp; // so we can't get stuck
}
else
{
// gap in performance clocks
t2 = temp - m_uiPreviousTime;
// Convert to time using frequencey of clock
time = (double)t2 * m_dClockFrequency;
// Remember old time
m_uiPreviousTime = temp;
// Increment clock
m_dCurrentTime += time;
}
Sys_PopFPCW();
// Convert to float
return m_dCurrentTime;
}
//-----------------------------------------------------------------------------
// Purpose: Sample the high-precision clock
// Output : double
//-----------------------------------------------------------------------------
double Sys_FloatTime( void )
{
return g_Clock.GetTime();
}
//-----------------------------------------------------------------------------
// Purpose: Initialize high-precision clock
//-----------------------------------------------------------------------------
void Sys_InitFloatTime( void )
{
g_Clock.Init();
}

395
unittests/networktest/networktest.cpp

@ -1,395 +0,0 @@ @@ -1,395 +0,0 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// The copyright to the contents herein is the property of Valve, L.L.C.
// The contents may be used and/or copied only with the written permission of
// Valve, L.L.C., or in accordance with the terms and conditions stipulated in
// the agreement/contract under which the contents have been supplied.
//
// $Header: $
// $NoKeywords: $
//
// Material editor
//=============================================================================
#include <windows.h>
#include "appframework/appframework.h"
#include "networksystem/inetworksystem.h"
#include "networksystem/inetworkmessage.h"
#include "bitbuf.h"
#include "filesystem.h"
#include "filesystem_init.h"
#include "tier0/icommandline.h"
#include "vstdlib/cvar.h"
//-----------------------------------------------------------------------------
// Singleton interfaces
//-----------------------------------------------------------------------------
IFileSystem *g_pFileSystem;
INetworkSystem *g_pNetworkSystem;
//-----------------------------------------------------------------------------
// Purpose: Warning/Msg call back through this API
// Input : type -
// *pMsg -
// Output : SpewRetval_t
//-----------------------------------------------------------------------------
SpewRetval_t SpewFunc( SpewType_t type, char const *pMsg )
{
OutputDebugString( pMsg );
if ( type == SPEW_ASSERT )
{
DebuggerBreak();
}
return SPEW_CONTINUE;
}
//-----------------------------------------------------------------------------
// The application object
//-----------------------------------------------------------------------------
class CNetworkTestApp : public CSteamAppSystemGroup
{
typedef CSteamAppSystemGroup BaseClass;
public:
// Methods of IApplication
virtual bool Create();
virtual bool PreInit( );
virtual int Main();
virtual void PostShutdown( );
virtual void Destroy();
virtual const char *GetAppName() { return "NetworkTest"; }
virtual bool AppUsesReadPixels() { return false; }
private:
// Window management
bool CreateAppWindow( char const *pTitle, bool bWindowed, int w, int h );
// Sets up the game path
bool SetupSearchPaths();
HWND m_HWnd;
};
DEFINE_WINDOWED_STEAM_APPLICATION_OBJECT( CNetworkTestApp );
//-----------------------------------------------------------------------------
// Create all singleton systems
//-----------------------------------------------------------------------------
bool CNetworkTestApp::Create()
{
SpewOutputFunc( SpewFunc );
// Add in the cvar factory
AppModule_t cvarModule = LoadModule( VStdLib_GetICVarFactory() );
AddSystem( cvarModule, CVAR_INTERFACE_VERSION );
AppSystemInfo_t appSystems[] =
{
{ "networksystem.dll", NETWORKSYSTEM_INTERFACE_VERSION },
{ "", "" } // Required to terminate the list
};
if ( !AddSystems( appSystems ) )
return false;
g_pFileSystem = (IFileSystem*)FindSystem( FILESYSTEM_INTERFACE_VERSION );
g_pNetworkSystem = (INetworkSystem*)FindSystem( NETWORKSYSTEM_INTERFACE_VERSION );
if (!g_pFileSystem || !g_pNetworkSystem )
return false;
return true;
}
void CNetworkTestApp::Destroy()
{
g_pFileSystem = NULL;
g_pNetworkSystem = NULL;
}
//-----------------------------------------------------------------------------
// Window management
//-----------------------------------------------------------------------------
bool CNetworkTestApp::CreateAppWindow( char const *pTitle, bool bWindowed, int w, int h )
{
WNDCLASSEX wc;
memset( &wc, 0, sizeof( wc ) );
wc.cbSize = sizeof( wc );
wc.style = CS_OWNDC | CS_DBLCLKS;
wc.lpfnWndProc = DefWindowProc;
wc.hInstance = (HINSTANCE)GetAppInstance();
wc.lpszClassName = "Valve001";
wc.hIcon = NULL; //LoadIcon( s_HInstance, MAKEINTRESOURCE( IDI_LAUNCHER ) );
wc.hIconSm = wc.hIcon;
RegisterClassEx( &wc );
// Note, it's hidden
DWORD style = WS_POPUP | WS_CLIPSIBLINGS;
if ( bWindowed )
{
// Give it a frame
style |= WS_OVERLAPPEDWINDOW;
style &= ~WS_THICKFRAME;
}
// Never a max box
style &= ~WS_MAXIMIZEBOX;
RECT windowRect;
windowRect.top = 0;
windowRect.left = 0;
windowRect.right = w;
windowRect.bottom = h;
// Compute rect needed for that size client area based on window style
AdjustWindowRectEx(&windowRect, style, FALSE, 0);
// Create the window
m_HWnd = CreateWindow( wc.lpszClassName, pTitle, style, 0, 0,
windowRect.right - windowRect.left, windowRect.bottom - windowRect.top,
NULL, NULL, (HINSTANCE)GetAppInstance(), NULL );
if (!m_HWnd)
return false;
int CenterX, CenterY;
CenterX = (GetSystemMetrics(SM_CXSCREEN) - w) / 2;
CenterY = (GetSystemMetrics(SM_CYSCREEN) - h) / 2;
CenterX = (CenterX < 0) ? 0: CenterX;
CenterY = (CenterY < 0) ? 0: CenterY;
// In VCR modes, keep it in the upper left so mouse coordinates are always relative to the window.
SetWindowPos (m_HWnd, NULL, CenterX, CenterY, 0, 0,
SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW | SWP_DRAWFRAME);
return true;
}
//-----------------------------------------------------------------------------
// Sets up the game path
//-----------------------------------------------------------------------------
bool CNetworkTestApp::SetupSearchPaths()
{
CFSSteamSetupInfo steamInfo;
steamInfo.m_pDirectoryName = NULL;
steamInfo.m_bOnlyUseDirectoryName = false;
steamInfo.m_bToolsMode = true;
steamInfo.m_bSetSteamDLLPath = true;
steamInfo.m_bSteam = g_pFileSystem->IsSteam();
if ( FileSystem_SetupSteamEnvironment( steamInfo ) != FS_OK )
return false;
CFSMountContentInfo fsInfo;
fsInfo.m_pFileSystem = g_pFileSystem;
fsInfo.m_bToolsMode = true;
fsInfo.m_pDirectoryName = steamInfo.m_GameInfoPath;
if ( FileSystem_MountContent( fsInfo ) != FS_OK )
return false;
// Finally, load the search paths for the "GAME" path.
CFSSearchPathsInit searchPathsInit;
searchPathsInit.m_pDirectoryName = steamInfo.m_GameInfoPath;
searchPathsInit.m_pFileSystem = g_pFileSystem;
if ( FileSystem_LoadSearchPaths( searchPathsInit ) != FS_OK )
return false;
g_pFileSystem->AddSearchPath( steamInfo.m_GameInfoPath, "SKIN", PATH_ADD_TO_HEAD );
char platform[MAX_PATH];
Q_strncpy( platform, steamInfo.m_GameInfoPath, MAX_PATH );
Q_StripTrailingSlash( platform );
Q_strncat( platform, "/../platform", MAX_PATH, MAX_PATH );
g_pFileSystem->AddSearchPath( platform, "PLATFORM" );
return true;
}
//-----------------------------------------------------------------------------
// PreInit, PostShutdown
//-----------------------------------------------------------------------------
bool CNetworkTestApp::PreInit( )
{
// Add paths...
if ( !SetupSearchPaths() )
return false;
const char *pArg;
int iWidth = 1024;
int iHeight = 768;
bool bWindowed = (CommandLine()->CheckParm( "-fullscreen" ) == NULL);
if (CommandLine()->CheckParm( "-width", &pArg ))
{
iWidth = atoi( pArg );
}
if (CommandLine()->CheckParm( "-height", &pArg ))
{
iHeight = atoi( pArg );
}
if (!CreateAppWindow( "NetworkTest", bWindowed, iWidth, iHeight ))
return false;
return true;
}
void CNetworkTestApp::PostShutdown( )
{
}
//-----------------------------------------------------------------------------
// Network message ids
//-----------------------------------------------------------------------------
enum
{
TEST_GROUP = NETWORKSYSTEM_FIRST_GROUP,
};
enum
{
TEST_MESSAGE_1 = 0,
};
//-----------------------------------------------------------------------------
// Test network message
//-----------------------------------------------------------------------------
class CTestNetworkMessage : public CNetworkMessage
{
public:
CTestNetworkMessage() { SetReliable( false ); }
CTestNetworkMessage( int nValue ) : m_Data( nValue ) { SetReliable( false ); }
DECLARE_BASE_MESSAGE( TEST_GROUP, TEST_MESSAGE_1, "Test Message 1" )
bool Process();
int m_Data;
};
bool CTestNetworkMessage::WriteToBuffer( bf_write &buffer )
{
buffer.WriteShort( m_Data );
return !buffer.IsOverflowed();
}
bool CTestNetworkMessage::ReadFromBuffer( bf_read &buffer )
{
m_Data = buffer.ReadShort();
return !buffer.IsOverflowed();
}
bool CTestNetworkMessage::Process()
{
Msg( "Received test message %d\n", m_Data );
return true;
}
//-----------------------------------------------------------------------------
// main application
//-----------------------------------------------------------------------------
int CNetworkTestApp::Main()
{
// Network messages must be registered before the server or client is started
g_pNetworkSystem->RegisterMessage( new CTestNetworkMessage() );
int nRetVal = 0;
if ( !g_pNetworkSystem->StartServer( ) )
return 0;
if ( !g_pNetworkSystem->StartClient( ) )
goto shutdownServer;
// Set the channel up for receiving
INetChannel *pChan = g_pNetworkSystem->ConnectClientToServer( "localhost", 27001 );
if ( !pChan )
goto shutdownClient;
INetChannel *pServerChan = NULL;
{
while( true )
{
// Helps avoid a buffer overflow
Sleep( 1 );
// Send a message out
if ( pChan->GetConnectionState() == CONNECTION_STATE_CONNECTED )
{
CTestNetworkMessage msg( 5 );
pChan->AddNetMsg( &msg, false );
msg.m_Data = 4;
pChan->AddNetMsg( &msg, false );
}
if ( pServerChan )
{
CTestNetworkMessage msg( 6 );
pServerChan->AddNetMsg( &msg, false );
msg.m_Data = 7;
pServerChan->AddNetMsg( &msg, false );
}
g_pNetworkSystem->ClientSendMessages();
g_pNetworkSystem->ServerReceiveMessages();
g_pNetworkSystem->ServerSendMessages();
g_pNetworkSystem->ClientReceiveMessages();
NetworkEvent_t *pEvent = g_pNetworkSystem->FirstNetworkEvent();
for ( ; pEvent; pEvent = g_pNetworkSystem->NextNetworkEvent( ) )
{
switch ( pEvent->m_nType )
{
case NETWORK_EVENT_CONNECTED:
pServerChan = ((NetworkConnectionEvent_t*)pEvent)->m_pChannel;
break;
case NETWORK_EVENT_DISCONNECTED:
if ( pServerChan == ((NetworkDisconnectionEvent_t*)pEvent)->m_pChannel )
{
pServerChan = NULL;
}
break;
case NETWORK_EVENT_MESSAGE_RECEIVED:
{
NetworkMessageReceivedEvent_t *pReceivedEvent = static_cast<NetworkMessageReceivedEvent_t*>( pEvent );
if ( ( pReceivedEvent->m_pNetworkMessage->GetGroup() == TEST_GROUP ) && ( pReceivedEvent->m_pNetworkMessage->GetType() == TEST_MESSAGE_1 ) )
{
static_cast<CTestNetworkMessage*>( pReceivedEvent->m_pNetworkMessage )->Process();
}
}
break;
}
}
}
nRetVal = 1;
g_pNetworkSystem->DisconnectClientFromServer( pChan );
}
shutdownClient:
g_pNetworkSystem->ShutdownClient( );
shutdownServer:
g_pNetworkSystem->ShutdownServer( );
return nRetVal;
}

23
unittests/networktest/networktest.vpc

@ -1,23 +0,0 @@ @@ -1,23 +0,0 @@
//-----------------------------------------------------------------------------
// NETWORKTEST.VPC
//
// Project Script
//-----------------------------------------------------------------------------
$Macro SRCDIR "..\.."
$Macro OUTBINDIR "$LIBPUBLIC"
$Include "$SRCDIR\vpc_scripts\source_exe_win_win32_base.vpc"
$Project "Networktest"
{
$Folder "Source Files"
{
$File "networktest.cpp"
}
$Folder "Link Libraries"
{
$DynamicFile "$SRCDIR\lib\public\appframework.lib"
}
}

BIN
unittests/rt_test/gwolf.tga

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 MiB

87
unittests/rt_test/rt_test.cpp

@ -1,87 +0,0 @@ @@ -1,87 +0,0 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
#include "tier0/platform.h"
#include "tier0/progressbar.h"
#include "bitmap/float_bm.h"
#include "mathlib/mathlib.h"
#include "tier2/tier2.h"
#include "tier0/memdbgon.h"
#include "raytrace.h"
#include "bitmap/tgawriter.h"
void main(int argc,char **argv)
{
InitCommandLineProgram( argc, argv );
if (argc != 5)
{
printf("format is 'rt_test src_image dest_image xsize ysize'\n");
}
else
{
ReportProgress("reading src texture",0,0);
FloatBitMap_t src_texture(argv[1]);
int xsize = atoi( argv[3] );
int ysize = atoi( argv[4] );
// render a simple scene of a terrain, using a bitmap for color data and its alpha channel for the height
RayTracingEnvironment rt_Env;
int id = 1;
float flXScale = (1.0/(src_texture.Width-1) );
float flZScale = (1.0/(src_texture.Height-1) );
for( int y=0; y < src_texture.Height-1; y++ )
for(int x=0 ; x < src_texture.Width-1; x++ )
{
Vector vecVerts[2][2];
for(int iy=0 ; iy < 2; iy++)
for(int ix=0 ; ix < 2; ix++)
{
vecVerts[ix][iy].x = 2.0* ( ( x+ix )*flXScale-0.5 );
if ( ( x+ix == src_texture.Width-1 ) || ( y+iy==src_texture.Height-1 ) )
vecVerts[ix][iy].y = 0;
else
vecVerts[ix][iy].y = 0.3*src_texture.Pixel( x+ix, y+iy, 1 );
vecVerts[ix][iy].z = -2.0* ( ( y+iy )*flZScale-0.5 );
}
Vector vecColor( GammaToLinear(src_texture.Pixel(x,y,0)),
GammaToLinear( src_texture.Pixel( x, y, 1 )),
GammaToLinear( src_texture.Pixel( x, y, 2 )) );
rt_Env.AddTriangle( id++, vecVerts[0][0], vecVerts[1][0], vecVerts[1][1], vecColor );
rt_Env.AddTriangle( id++, vecVerts[0][0], vecVerts[0][1], vecVerts[1][1], vecColor );
}
rt_Env.AddTriangle( id++, Vector(0,0,-.2), Vector(.2,0,.2), Vector( -.2,0,.2), Vector( 0,0,1 ) );
printf("n triangles %d\n",id);
ReportProgress("Creating kd-tree",0,0);
float stime = Plat_FloatTime();
rt_Env.SetupAccelerationStructure();
printf("kd built time := %d\n", (int) ( Plat_FloatTime() - stime ) );
rt_Env.AddInfinitePointLight( Vector( 0,5, 0), Vector( .1,.1,.1 ));
// lets render a frame
uint32 *buf=reinterpret_cast<uint32 *> ( MemAlloc_AllocAligned( xsize * ysize * 4 , 16 ) );
Vector EyePos(0,2,0);
ReportProgress("Rendering",0,0);
// rt_Env.RenderScene( xsize, ysize, xsize, buf, Vector( 0, 0.5, -1.0 ),
// Vector( -1, 1, 0),
// Vector( 1, 1, 0 ),
// Vector( -1, -1, 0 ),
// Vector( 1, -1, 0 ) );
float curtime = Plat_FloatTime();
for(int i=0;i<10;i++)
{
rt_Env.RenderScene( xsize, ysize, xsize, buf,
EyePos,
Vector( -1, 0,1)-EyePos,
Vector( 1, 0, 1 )-EyePos,
Vector( -1, 0, -1 )-EyePos,
Vector( 1, 0, -1 )-EyePos );
}
float etime=Plat_FloatTime()-curtime;
printf("pixels traced and lit per second := %f\n",(10*xsize*ysize)*(1.0/etime));
TGAWriter::WriteTGAFile( "test.tga", xsize, ysize, IMAGE_FORMAT_RGBA8888,
reinterpret_cast<uint8 *> (buf), 4*xsize );
MemAlloc_FreeAligned( buf );
}
}

BIN
unittests/rt_test/rt_test.exe

Binary file not shown.

BIN
unittests/rt_test/rt_test.pdb

Binary file not shown.

39
unittests/rt_test/rt_test.vpc

@ -1,39 +0,0 @@ @@ -1,39 +0,0 @@
//-----------------------------------------------------------------------------
// rt_test.VPC
//
// Project Script
//-----------------------------------------------------------------------------
$Macro SRCDIR "..\.."
$Macro OUTBINDIR "$SRCDIR\unittests\rt_test"
$Include "$SRCDIR\vpc_scripts\source_exe_con_base.vpc"
$Configuration "Debug"
{
$Compiler
{
$PreprocessorDefinitions "$BASE;PROTECTED_THINGS_DISABLE"
}
$Linker
{
$AdditionalDependencies "$BASE winmm.lib"
}
}
$Project "rt_test"
{
$Folder "Source Files"
{
$File "rt_test.cpp"
}
$Folder "Link Libraries"
{
$Lib bitmap
$Lib mathlib
$Lib raytrace
$Lib tier2
}
}
Loading…
Cancel
Save