add pimpl/rimpl tests

git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@472 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
syntheticpp 2006-01-15 22:09:32 +00:00
parent 264e205030
commit 95b163d2bd
7 changed files with 854 additions and 1 deletions

View file

@ -1,5 +1,5 @@
SUBTARGETS = Factory flex_string Longevity OrderedStatic RegressionTest \
SafeFormat ScopeGuard Singleton SmallObj Visitor
SafeFormat ScopeGuard Singleton SmallObj Visitor Pimpl
.PHONY: clean all $(SUBTARGETS)
all: $(SUBTARGETS)

11
test/Pimpl/Makefile Executable file
View file

@ -0,0 +1,11 @@
BIN = main
CC = gcc
CXXFLAGS = -Wall -O2
CPPFLAGS = -I../../include -DNDEBUG
LDFLAGS = -L../../lib
LDLIBS = -lloki
.PHONY: build clean
build: $(BIN)
clean:
rm -f $(BIN) $(BIN).exe $(BIN).o

351
test/Pimpl/Pimpl.vcproj Executable file
View file

@ -0,0 +1,351 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8,00"
Name="Pimpl"
ProjectGUID="{0DCBE03A-DAC7-4669-B29B-102D8F563736}"
RootNamespace="Pimpl"
Keyword="Win32Proj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="Debug"
IntermediateDirectory="Debug"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalOptions="-wd4996"
Optimization="0"
AdditionalIncludeDirectories="..\..\include;c:\sandbox\boost"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE _SECURE_SCL=1"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="4"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="loki.lib"
AdditionalLibraryDirectories="..\..\lib"
GenerateDebugInformation="true"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="Release"
IntermediateDirectory="Release"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
AdditionalIncludeDirectories="..\..\include"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
UsePrecompiledHeader="0"
WarningLevel="4"
Detect64BitPortabilityProblems="false"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkIncremental="1"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath="..\..\include\loki\AbstractPimpl.h"
>
</File>
<File
RelativePath="..\..\include\loki\AssocVector.h"
>
</File>
<File
RelativePath="..\..\include\loki\DataGenerators.h"
>
</File>
<File
RelativePath="..\..\include\loki\EmptyType.h"
>
</File>
<File
RelativePath="..\..\include\loki\Factory.h"
>
</File>
<File
RelativePath="..\..\include\loki\Function.h"
>
</File>
<File
RelativePath="..\..\include\loki\Functor.h"
>
</File>
<File
RelativePath="..\..\include\loki\HierarchyGenerators.h"
>
</File>
<File
RelativePath="..\..\include\loki\LockingPtr.h"
>
</File>
<File
RelativePath="..\..\include\loki\LokiTypeInfo.h"
>
</File>
<File
RelativePath="..\..\include\loki\MultiMethods.h"
>
</File>
<File
RelativePath="..\..\include\loki\NullType.h"
>
</File>
<File
RelativePath="..\..\include\loki\Pimpl.h"
>
</File>
<File
RelativePath="..\..\include\loki\Pimpl.h"
>
</File>
<File
RelativePath="..\..\include\loki\PimplDef.h"
>
</File>
<File
RelativePath="..\..\include\loki\PimplDef.h"
>
</File>
<File
RelativePath="..\..\include\loki\SafeFormat.h"
>
</File>
<File
RelativePath="..\..\include\loki\ScopeGuard.h"
>
</File>
<File
RelativePath="..\..\include\loki\Sequence.h"
>
</File>
<File
RelativePath="..\..\include\loki\Singleton.h"
>
</File>
<File
RelativePath="..\..\include\loki\SmallObj.h"
>
</File>
<File
RelativePath="..\..\include\loki\SmartPtr.h"
>
</File>
<File
RelativePath="..\..\include\loki\static_check.h"
>
</File>
<File
RelativePath="..\..\include\loki\Threads.h"
>
</File>
<File
RelativePath="..\..\include\loki\Tuple.h"
>
</File>
<File
RelativePath="..\..\include\loki\Typelist.h"
>
</File>
<File
RelativePath="..\..\include\loki\TypelistMacros.h"
>
</File>
<File
RelativePath="..\..\include\loki\TypeManip.h"
>
</File>
<File
RelativePath="..\..\include\loki\TypeTraits.h"
>
</File>
<File
RelativePath="..\..\include\loki\Visitor.h"
>
</File>
<Filter
Name="flexstring"
>
<File
RelativePath="..\..\include\loki\flex\allocatorstringstorage.h"
>
</File>
<File
RelativePath="..\..\include\loki\flex\cowstringopt.h"
>
</File>
<File
RelativePath="..\..\include\loki\flex\flex_string.h"
>
</File>
<File
RelativePath="..\..\include\loki\flex\flex_string_details.h"
>
</File>
<File
RelativePath="..\..\include\loki\flex\flex_string_shell.h"
>
</File>
<File
RelativePath="..\..\include\loki\flex\simplestringstorage.h"
>
</File>
<File
RelativePath="..\..\include\loki\flex\smallstringopt.h"
>
</File>
<File
RelativePath="..\..\include\loki\flex\vectorstringstorage.h"
>
</File>
</Filter>
</Filter>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\main.cpp"
>
</File>
<File
RelativePath=".\type.h"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

214
test/Pimpl/main.cpp Executable file
View file

@ -0,0 +1,214 @@
////////////////////////////////////////////////////////////////////////////////
// The Loki Library
// Copyright (c) 2006 Peter Kümmel
// Permission to use, copy, modify, distribute and sell this software for any
// purpose is hereby granted without fee, provided that the above copyright
// notice appear in all copies and that both that copyright notice and this
// permission notice appear in supporting documentation.
// The author makes no representations about the
// suitability of this software for any purpose. It is provided "as is"
// without express or implied warranty.
////////////////////////////////////////////////////////////////////////////////
// $Header:
#ifdef _MSC_VER
#pragma warning (disable: 4512)
#endif
#define LOKI_INHERITED_PIMPL_NAME d
#define LOKI_INHERITED_RIMPL_NAME d
#include "type.h"
#include <loki/Pimpldef.h>
#include <loki/SafeFormat.h>
/////////////////////////////////////////
// Definition of Impl<A>
/////////////////////////////////////////
namespace Loki // gcc!!
{
template<>
struct Impl<A> : public SmallObject<> // inherit SmallObj for speed up
{
Impl() : data(0) {Printf("A created\n");}
~Impl(){Printf("A destroyed, data=%d\n")(data);}
int data;
};
}
/////////////////////////////////////////
// class A definition
/////////////////////////////////////////
A::A()
{}
void A::foo()
{
(*d).data = 1;
d->data = 111;
}
/////////////////////////////////////////
// Definition of Impl<B>
/////////////////////////////////////////
namespace Loki // gcc!!
{
template<>
struct Impl<B> : public SmallObject<> // inherit SmallObj for speed up
{
Impl() : data(0) {Printf("B created\n");}
~Impl(){Printf("B destroyed, data=%d\n")(data);}
int data;
};
}
/////////////////////////////////////////
// class B definition
/////////////////////////////////////////
B::B() : Loki::Pimpl<B>::Owner()
{}
void B::foo()
{
(*d).data = 2;
d->data = 222;
}
/////////////////////////////////////////
// Definition of Impl<C>
/////////////////////////////////////////
namespace Loki // gcc!!
{
template<>
struct Impl<C> : public SmallObject<> // inherit SmallObj for speed up
{
Impl(): data(0) {Printf("C created\n");}
~Impl(){Printf("C destroyed, data=%d\n")(data);}
int data;
};
}
/////////////////////////////////////////
// class C definition
/////////////////////////////////////////
C::C() : d(rlife)
{}
void C::foo()
{
d.data = 333;
}
/////////////////////////////////////////
// Definition of Impl<D>
/////////////////////////////////////////
namespace Loki // gcc!!
{
template<>
struct Impl<D> : public SmallObject<> // inherit SmallObj for speed up
{
Impl(): data(0) {Printf("D created\n");}
~Impl(){Printf("D destroyed, data=%d\n")(data);}
int data;
};
}
/////////////////////////////////////////
// class D definition
/////////////////////////////////////////
D::D() : Loki::Rimpl<D>::Owner()
{}
void D::foo()
{
d.data = 444;
}
/////////////////////////////////////////
// main
/////////////////////////////////////////
void test_more();
int main()
{
A* a = new A;
B* b = new B;
C* c = new C;
D* d = new D;
a->foo();
b->foo();
c->foo();
d->foo();
delete a;
delete b;
delete c;
delete d;
test_more();
#if defined(__BORLANDC__) || defined(_MSC_VER)
system("PAUSE");
#endif
return 0;
}
////////////////////
// more test code
////////////////////
P1::P1(){d->data = 1;}
P2::P2(){d->data = 2;}
P3::P3(){d->data = 3;}
P4::P4(){d->data = 4;}
P5::P5(){d->data = 5;}
R1::R1(){d.data = 11;}
R2::R2(){d.data = 22;}
R3::R3(){d.data = 33;}
R4::R4():d(t){d.data = 44;}
R5::R5():d(t){d.data = 55;}
R6::R6():d(t){d.data = 66;}
void test_more()
{
Loki::Printf("\nmore tests:\n");
P1* p1 = new P1;
P2* p2 = new P2;
P3* p3 = new P3;
P4* p4 = new P4;
P5* p5 = new P5;
R1* r1 = new R1;
R2* r2 = new R2;
R3* r3 = new R3;
R4* r4 = new R4;
R5* r5 = new R5;
R6* r6 = new R6;
delete p1;
delete p2;
delete p3;
delete p4;
delete p5;
delete r1;
delete r2;
delete r3;
delete r4;
delete r5;
delete r6;
}

6
test/Pimpl/make.msvc.bat Executable file
View file

@ -0,0 +1,6 @@
cl -c -Zm200 -O2 -DNDEBUG -MT -EHsc -GR -W0 -wd4710 -I"." -I"..\..\include" main.cpp
link /NOLOGO /SUBSYSTEM:CONSOLE /incremental:no /OUT:"main-msvc.exe" ..\..\lib\loki.lib main.obj
del *.obj

267
test/Pimpl/type.h Executable file
View file

@ -0,0 +1,267 @@
////////////////////////////////////////////////////////////////////////////////
// The Loki Library
// Copyright (c) 2006 Peter Kümmel
// Permission to use, copy, modify, distribute and sell this software for any
// purpose is hereby granted without fee, provided that the above copyright
// notice appear in all copies and that both that copyright notice and this
// permission notice appear in supporting documentation.
// The author makes no representations about the
// suitability of this software for any purpose. It is provided "as is"
// without express or implied warranty.
////////////////////////////////////////////////////////////////////////////////
// $Header:
#include <loki/Pimpl.h>
//#define TEST_WITH_BOOST
#ifdef TEST_WITH_BOOST
#include <boost/shared_ptr.hpp>
#endif
#include <loki/SmartPtr.h>
#include <loki/SmallObj.h>
using Loki::Pimpl;
using Loki::Rimpl;
/////////////////////////////////////////
// class A declaration
/////////////////////////////////////////
class A
{
public:
A();
void foo();
private:
Pimpl<A>::Type d;
};
/////////////////////////////////////////
// class B declaration
/////////////////////////////////////////
class B : private Pimpl<B>::Owner
{
public:
B();
void foo();
};
/////////////////////////////////////////
// class C declaration
/////////////////////////////////////////
class C
{
public:
C();
void foo();
private:
Rimpl<C>::Life rlife;
Rimpl<C>::Type& d;
};
/////////////////////////////////////////
// class D declaration
/////////////////////////////////////////
class D : private Rimpl<D>::Owner
{
public:
D();
void foo();
};
////////////////////
// more test code
////////////////////
// Pimpl
typedef Loki::PtrImpl
<
Loki::Impl<B>
>
Pimpl1;
typedef Loki::PtrImpl
<
Loki::Impl<B>,
Loki::SmartPtr<Loki::Impl<B> >,
Loki::DontDeletePimpl
>
Pimpl2;
typedef Loki::PtrImpl
<
Loki::Impl<B>,
#ifdef TEST_WITH_BOOST
boost::shared_ptr<Loki::Impl<B> >,
#else
Loki::SmartPtr<Loki::Impl<B> >,
#endif
Loki::DontDeletePimpl
>
Pimpl3;
typedef Loki::PtrImpl
<
Loki::Impl<B>,
Loki::SmartPtr<Loki::Impl<B> >,
Loki::DontDeletePimpl,
Loki::DeclaredPimpl
>
Pimpl4;
typedef Loki::PtrImpl
<
Loki::Impl<B>,
#ifdef TEST_WITH_BOOST
boost::shared_ptr<Loki::Impl<B> >,
#else
Loki::SmartPtr<Loki::Impl<B> >,
#endif
Loki::DontDeletePimpl,
Loki::DeclaredPimpl
>
Pimpl5;
// Pimpl
typedef Loki::PtrImpl
<
Loki::Impl<B>,
Loki::Impl<B>*,
Loki::AutoDeletePimpl,
Loki::InheritedRimpl
>
Rimpl1;
typedef Loki::PtrImpl
<
Loki::Impl<B>,
Loki::SmartPtr<Loki::Impl<B> >,
Loki::DontDeletePimpl,
Loki::InheritedRimpl
>
Rimpl2;
typedef Loki::PtrImpl
<
Loki::Impl<B>,
#ifdef TEST_WITH_BOOST
boost::shared_ptr<Loki::Impl<B> >,
#else
Loki::SmartPtr<Loki::Impl<B> >,
#endif
Loki::DontDeletePimpl,
Loki::InheritedRimpl
>
Rimpl3;
typedef Loki::PtrImpl
<
Loki::Impl<B>,
Loki::Impl<B>*,
Loki::AutoDeletePimpl,
Loki::DeclaredRimpl
>
Rimpl4;
typedef Loki::PtrImpl
<
Loki::Impl<B>,
Loki::SmartPtr<Loki::Impl<B> >,
Loki::DontDeletePimpl,
Loki::DeclaredRimpl
>
Rimpl5;
typedef Loki::PtrImpl
<
Loki::Impl<B>,
#ifdef TEST_WITH_BOOST
boost::shared_ptr<Loki::Impl<B> >,
#else
Loki::SmartPtr<Loki::Impl<B> >,
#endif
Loki::DontDeletePimpl,
Loki::DeclaredRimpl
>
Rimpl6;
typedef Loki::PtrImpl
<
Loki::Impl<B>,
//Loki::Impl<B>*,
Loki::SmartPtr<Loki::Impl<B> >,
//boost::shared_ptr<Loki::Impl<B> >,
//Loki::AutoDeletePimpl, // compiler error when used with smart pointers, this is o.k.
Loki::DontDeletePimpl,
Loki::DeclaredPimpl
//Loki::InheritedPimpl,
>
Pimpl8;
template<class T>
struct R
{
typedef Loki::PimplLife
<
T,
T*,
Loki::AutoDeletePimpl
>
Life;
};
struct P1 : private Pimpl1 {P1();};
struct P2 : private Pimpl2 {P2();};
struct P3 : private Pimpl3 {P3();};
struct P4 {Pimpl4 d; P4();};
struct P5 {Pimpl5 d; P5();};
struct R1 : private Rimpl1 {R1();};
struct R2 : private Rimpl2 {R2();};
struct R3 : private Rimpl3 {R3();};
struct R4 {Rimpl4& d; R<Rimpl4>::Life t; R4();};
struct R5 {Rimpl5& d; R<Rimpl5>::Life t; R5();};
struct R6 {Rimpl6& d; R<Rimpl6>::Life t; R6();};

View file

@ -15,6 +15,10 @@ cd OrderedStatic
call make.msvc.bat
cd ..
cd Pimpl
call make.msvc.bat
cd ..
cd RegressionTest
call make.msvc.bat
cd ..