Commit decc9508 authored by Marcus D. Hanwell's avatar Marcus D. Hanwell
Browse files

ENH: Added test using vtkNew in class ivars.

This tests whether vtkNew can be used with incomplete types in class
headers, containing the vtkObject until class destruction. Had to jump
through a few hoops as vtkSmartPointer currently requires a complete
type on assignment.

Change-Id: I77ed0ccd65f0193248b0f162059e2944a8d4244f
parent 1a608359
......@@ -31,7 +31,7 @@ CREATE_TEST_SOURCELIST(Tests ${KIT}CxxTests.cxx
EXTRA_INCLUDE vtkTestDriver.h
)
ADD_EXECUTABLE(${KIT}CxxTests ${Tests})
ADD_EXECUTABLE(${KIT}CxxTests ${Tests} vtkTestNewVar.cxx)
TARGET_LINK_LIBRARIES(${KIT}CxxTests vtkCommon)
SET (TestsToRun ${Tests})
......
......@@ -23,6 +23,8 @@
#include "vtkSmartPointer.h"
#include "vtkWeakPointer.h"
#include "vtkTestNewVar.h"
int TestNew(int,char *[])
{
bool error = false;
......@@ -65,5 +67,22 @@ int TestNew(int,char *[])
<< si->GetReferenceCount() << endl;
}
vtkNew<vtkTestNewVar> newVarObj;
if (newVarObj->GetPointsRefCount() != 1)
{
error = true;
cerr << "The mmeber pointer failed to set the correct reference count: "
<< newVarObj->GetPointsRefCount() << endl;
}
vtkSmartPointer<vtkObject> points = newVarObj->GetPoints();
if (points->GetReferenceCount() != 2)
{
error = true;
cerr << "Error, vtkNew failed to keep the object it contained, "
<< "or the smart pointer failed to increment it. Reference count: "
<< points->GetReferenceCount() << endl;
}
return error ? 1 : 0;
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkTestNewVar.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkTestNewVar.h"
#include "vtkPoints2D.h"
#include "vtkObjectFactory.h"
vtkStandardNewMacro(vtkTestNewVar);
vtkTestNewVar::vtkTestNewVar()
{
}
vtkTestNewVar::~vtkTestNewVar()
{
}
vtkIdType vtkTestNewVar::GetPointsRefCount()
{
// Note - this is valid until class destruction and then Delete() will be
// called on the Data object, decrementing its reference count.
return this->Points->GetReferenceCount();
}
vtkObject * vtkTestNewVar::GetPoints()
{
return this->Points.GetPointer();
}
void vtkTestNewVar::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "Points: " << endl;
this->Points->PrintSelf(os, indent.GetNextIndent());
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkTestNewVar.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME Test of vtkNew.
// .SECTION Description
// Tests instantiations of the vtkNew class template.
#ifndef __vtkTestNewVar_h
#define __vtkTestNewVar_h
#include "vtkObject.h"
#include "vtkNew.h"
class vtkPoints2D;
class vtkTestNewVar : public vtkObject
{
public:
static vtkTestNewVar * New();
vtkTypeMacro(vtkTestNewVar, vtkObject)
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// Get the reference count for the points object.
vtkIdType GetPointsRefCount();
// Description:
// This is just for testing - return the points as a vtkObject so that it can
// be assigned to a vtkSmartPointer without including the vtkPoints2D header
// and defeating part of the point of the test.
vtkObject * GetPoints();
protected:
vtkTestNewVar();
~vtkTestNewVar();
vtkNew<vtkPoints2D> Points;
private:
vtkTestNewVar(const vtkTestNewVar&); // Not implemented.
void operator=(const vtkTestNewVar&); // Not implemented.
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment