Skip to content
Snippets Groups Projects
Commit 42d94097 authored by Pietro Incardona's avatar Pietro Incardona
Browse files

Added missing file

parent 3fb09a49
No related branches found
No related tags found
No related merge requests found
/*
* HeapMemory_unit_tests.hpp
*
* Created on: Jul 9, 2015
* Author: i-bird
*/
#ifndef HEAPMEMORY_UNIT_TESTS_HPP_
#define HEAPMEMORY_UNIT_TESTS_HPP_
#include "memory/HeapMemory.hpp"
#include "memory/CudaMemory.cuh"
BOOST_AUTO_TEST_SUITE( HeapMemory_test )
//! [Memory test constants]
#define FIRST_ALLOCATION 1024
#define SECOND_ALLOCATION 4096
//! [Memory test constants]
template<typename T> void test()
{
//! [Allocate some memory and fill with data]
T mem;
mem.allocate(FIRST_ALLOCATION);
BOOST_REQUIRE_EQUAL(mem.size(),FIRST_ALLOCATION);
// get the pointer of the allocated memory and fill
unsigned char * ptr = (unsigned char *)mem.getPointer();
for (size_t i = 0 ; i < mem.size() ; i++)
ptr[i] = i;
//! [Allocate some memory and fill with data]
//! [Resize the memory]
mem.resize(SECOND_ALLOCATION);
unsigned char * ptr2 = (unsigned char *)mem.getPointer();
BOOST_REQUIRE_EQUAL(mem.size(),SECOND_ALLOCATION);
BOOST_REQUIRE_EQUAL(mem.isInitialized(),false);
//! [Resize the memory]
// check that the data are retained
for (size_t i = 0 ; i < FIRST_ALLOCATION ; i++)
{
unsigned char c = i;
BOOST_REQUIRE_EQUAL(ptr2[i],c);
}
{
//! [Copy memory]
T src;
T dst;
src.allocate(FIRST_ALLOCATION);
dst.allocate(SECOND_ALLOCATION);
unsigned char * ptr = (unsigned char *)src.getPointer();
for (size_t i = 0 ; i < src.size() ; i++)
ptr[i] = i;
dst.copy(src);
for (size_t i = 0 ; i < FIRST_ALLOCATION ; i++)
{
unsigned char c=i;
BOOST_REQUIRE_EQUAL(ptr2[i],c);
}
//! [Copy Memory]
}
}
BOOST_AUTO_TEST_CASE( use )
{
test<HeapMemory>();
test<CudaMemory>();
}
BOOST_AUTO_TEST_SUITE_END()
#endif /* HEAPMEMORY_UNIT_TESTS_HPP_ */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment