Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
solverstack
ScalFMM
Commits
a8e472fa
Commit
a8e472fa
authored
Sep 26, 2013
by
BRAMAS Berenger
Browse files
add utest for allocator
parent
45a79f16
Changes
1
Hide whitespace changes
Inline
Side-by-side
UTests/utestListBlockAllocator.cpp
0 → 100644
View file @
a8e472fa
// ===================================================================================
// Copyright ScalFmm 2011 INRIA, Olivier Coulaud, Bérenger Bramas, Matthias Messner
// olivier.coulaud@inria.fr, berenger.bramas@inria.fr
// This software is a computer program whose purpose is to compute the FMM.
//
// This software is governed by the CeCILL-C and LGPL licenses and
// abiding by the rules of distribution of free software.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public and CeCILL-C Licenses for more details.
// "http://www.cecill.info".
// "http://www.gnu.org/licenses".
// ===================================================================================
#include
"FUTester.hpp"
#include
"../Src/Containers/FBlockAllocator.hpp"
#include
<cstring>
/**
* This file is a unit test for the List block allocator
*/
/**
* This class is simply used to count alloc dealloc
*/
class
TestObject
{
public:
static
int
counter
;
static
int
dealloced
;
int
array
[
50
];
TestObject
(){
memset
(
array
,
0
,
50
*
sizeof
(
int
));
++
counter
;
}
TestObject
(
const
TestObject
&
){
++
counter
;
}
~
TestObject
(){
++
dealloced
;
}
};
int
TestObject
::
counter
(
0
);
int
TestObject
::
dealloced
(
0
);
/** this class test the list container */
class
TestBlock
:
public
FUTester
<
TestBlock
>
{
// Called before each test : simply set counter to 0
void
PreTest
(){
TestObject
::
counter
=
0
;
TestObject
::
dealloced
=
0
;
}
// test copy
void
TestBlockFunction
(){
FListBlockAllocator
<
TestObject
,
10
>
alloc
;
TestObject
*
ptr
[
100
];
for
(
int
idx
=
0
;
idx
<
100
;
++
idx
){
TestObject
*
dl1
=
alloc
.
newObject
();
TestObject
*
dl2
=
alloc
.
newObject
();
alloc
.
deleteObject
(
dl1
);
ptr
[
idx
]
=
alloc
.
newObject
();
alloc
.
deleteObject
(
dl2
);
}
for
(
int
idx
=
0
;
idx
<
100
;
++
idx
){
for
(
int
idxval
=
0
;
idxval
<
50
;
++
idxval
){
ptr
[
idx
]
->
array
[
idxval
]
+=
(
idxval
*
idx
);
}
}
for
(
int
idx
=
0
;
idx
<
100
;
++
idx
){
for
(
int
idxval
=
0
;
idxval
<
50
;
++
idxval
){
uassert
(
ptr
[
idx
]
->
array
[
idxval
]
==
(
idxval
*
idx
));
}
}
for
(
int
idx
=
0
;
idx
<
100
;
++
idx
){
alloc
.
deleteObject
(
ptr
[
idx
]);
}
uassert
(
TestObject
::
counter
==
300
);
uassert
(
TestObject
::
counter
==
TestObject
::
dealloced
);
}
// set test
void
SetTests
(){
AddTest
(
&
TestBlock
::
TestBlockFunction
,
"Test Allocate Deallocate"
);
}
};
// You must do this
TestClass
(
TestBlock
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment