Commit 066c6f9e authored by Samuel Debionne's avatar Samuel Debionne

Fix membuffer and add unit tests

parent 21404faf
......@@ -374,9 +374,7 @@ endif()
if(LIMA_ENABLE_TESTS)
enable_testing()
add_subdirectory(control/test)
if (NOT WIN32)
add_subdirectory(common/test)
endif()
add_subdirectory(common/test)
endif()
#--------------------------------------------------------------------------------
......
......@@ -53,7 +53,7 @@ class LIMACORE_API MemBuffer
MemBuffer& operator=(const MemBuffer&);
// MemBuffer are move-constructible or move-assignable.
MemBuffer(MemBuffer&&) = default;
MemBuffer(MemBuffer&&);
MemBuffer& operator=(MemBuffer&&) = default;
#ifdef LIMA_USE_NUMA
......
......@@ -248,6 +248,18 @@ MemBuffer::MemBuffer(const MemBuffer& buffer)
deepCopy(buffer);
}
MemBuffer::MemBuffer(MemBuffer&& rhs)
{
// Stealing buffer ressource
m_ptr = std::move(rhs.m_ptr);
m_size = std::move(rhs.m_size);
m_allocator = std::move(rhs.m_allocator);
// Repare rhs (we don't it to be deallocated twice)
rhs.m_ptr = nullptr;
rhs.m_size = 0;
}
MemBuffer::~MemBuffer()
{
release();
......
......@@ -20,6 +20,9 @@
# along with this program; if not, see <http://www.gnu.org/licenses/>.
############################################################################
set(test_src testregex)
set(test_src test_membuffer)
if (NOT WIN32)
list(APPEND test_src test_regex)
endif()
limatools_run_camera_tests("${test_src}" ${NAME})
//###########################################################################
// This file is part of LImA, a Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This software 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 License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//###########################################################################
#include <cassert>
#include <cstdlib>
#include <iostream>
#include <utility>
#include "lima/MemUtils.h"
using namespace lima;
void test_empty()
{
//Default construction
MemBuffer b;
assert(b.getSize() == 0);
//Copy construction
MemBuffer c(b);
assert(b.getSize() == 0);
//Copy assignement
MemBuffer d = b;
//Move construction
MemBuffer e(std::move(b));
//Move assignement
MemBuffer f = std::move(b);
}
void test_alloc()
{
//Default construction
MemBuffer b(1);
assert(b.getSize() == 1);
//Copy construction
MemBuffer c(b);
assert(c.getSize() == 1);
assert(c.getConstPtr() != b.getConstPtr());
//Copy assignement
MemBuffer d = b;
assert(d.getSize() == 1);
assert(d.getConstPtr() != b.getConstPtr());
//Move construction (from lvalue)
const void *ptr = b.getConstPtr();
MemBuffer e(std::move(b));
assert(e.getSize() == 1);
assert(e.getConstPtr() == ptr);
assert(b.getConstPtr() == nullptr);
assert(b.getSize() == 0);
//Move assignement (from lvalue)
MemBuffer f = std::move(e);
assert(f.getSize() == 1);
assert(f.getConstPtr() == ptr);
assert(e.getConstPtr() == nullptr);
assert(e.getSize() == 0);
//Move construction (from rvalue)
MemBuffer g(MemBuffer(1));
assert(g.getSize() == 1);
//Move assignement (from rvalue)
MemBuffer h = MemBuffer(1);
assert(g.getSize() == 1);
}
int main(int argc, char *argv[])
{
try {
test_empty();
test_alloc();
} catch (Exception e) {
std::cerr << "LIMA Exception: " << e << std::endl;
}
return 0;
}
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