2
0
mirror of https://github.com/boostorg/ublas.git synced 2026-02-22 03:42:19 +00:00

add placement_new test

svn path=/trunk/boost/libs/numeric/ublas/; revision=25603
This commit is contained in:
Michael Stevens
2004-10-07 08:03:11 +00:00
parent 729cc1c1a0
commit c651afce8a
3 changed files with 60 additions and 1 deletions

View File

@@ -116,6 +116,9 @@ test-suite numeric/uBLAS
# <define>$(UBLAS_TESTSET)
# <vacpp><*><define>"BOOST_UBLAS_NO_ELEMENT_PROXIES"
# ]
[ run test/placement_new.cpp
]
[ compile concepts.cpp
: # requirements
<define>EXTERNAL

View File

@@ -49,7 +49,6 @@ test-suite numeric/uBLAS
: # input files
: # requirements
<define>$(UBLAS_TESTSET)
<toolset>intel-linux:<cxxflags>"-fpstkchk" # Try and pick up runtime failures
<toolset>vacpp:<define>"BOOST_UBLAS_NO_ELEMENT_PROXIES"
]
[ run test2/test2.cpp
@@ -100,6 +99,9 @@ test-suite numeric/uBLAS
# <define>$(UBLAS_TESTSET)
# <toolset>vacpp:<define>"BOOST_UBLAS_NO_ELEMENT_PROXIES"
# ]
[ run test/placement_new.cpp
]
[ compile concepts.cpp
: # requirements
<define>EXTERNAL

54
test/placement_new.cpp Normal file
View File

@@ -0,0 +1,54 @@
/*
* Test placement new and array placement new for uBLAS
* See if base pointer is effected by array count cookie
*/
#include <boost/numeric/ublas/config.hpp>
#include <iostream>
// User defined type to capture base pointer on construction
class udt;
udt* base_pointer;
class udt {
public:
udt () {
base_pointer = this;
}
~udt () {} // required for GCC prior to 3.4 to generate cookie
};
int main ()
{
udt a;
udt* ap = &a;
// Capture placement new offsets for a udt
new (ap) udt;
int new_offset = int (base_pointer - ap);
new (ap) udt [1];
int array_new_offset = int (base_pointer - ap);
// Print offsets - we expect 0,0 or 0,sizeof(std::size_t)
std::cout << new_offset <<','<< array_new_offset << std::endl;
// Return status
if (new_offset != 0)
return -1; // Very bad if new has an offset
#ifdef BOOST_UBLAS_USEFUL_ARRAY_PLACEMENT_NEW
bool expect_array_offset = false;
#else
bool expect_array_offset = true;
#endif
// Check match between config and array
if (!expect_array_offset && array_new_offset != 0) {
return -2; // Bad config should not enable array new
}
if (expect_array_offset && array_new_offset == 0) {
return -3; // Config could enable array new
}
return 0;
}