diff --git a/coding/coding_tests/file_container_test.cpp b/coding/coding_tests/file_container_test.cpp index 05f788d7c3..55be9717fb 100644 --- a/coding/coding_tests/file_container_test.cpp +++ b/coding/coding_tests/file_container_test.cpp @@ -5,6 +5,7 @@ #include "../../base/logging.hpp" #include "../../base/string_utils.hpp" +#include "../../base/scope_guard.hpp" UNIT_TEST(FilesContainer_Smoke) @@ -233,6 +234,51 @@ UNIT_TEST(FilesMappingContainer_Handle) FileWriter::DeleteFileX(fName); } +UNIT_TEST(FilesMappingContainer_MoveHandle) +{ + static uint8_t const kNumMapTests = 200; + class HandleWrapper + { + public: + HandleWrapper(FilesMappingContainer::Handle&& handle) : m_handle(move(handle)) + { + TEST(m_handle.IsValid(), ()); + } + + private: + FilesMappingContainer::Handle m_handle; + }; + + string const containerPath = "file_container.tmp"; + string const tagName = "dummy"; + + MY_SCOPE_GUARD(deleteContainerFileGuard, bind(&FileWriter::DeleteFileX, cref(containerPath))); + + { + FilesContainerW writer(containerPath); + FileWriter w = writer.GetWriter(tagName); + w.Write(tagName.c_str(), tagName.size()); + } + + { + FilesMappingContainer cont(containerPath); + + FilesMappingContainer::Handle h1 = cont.Map(tagName); + TEST(h1.IsValid(), ()); + + FilesMappingContainer::Handle h2(move(h1)); + TEST(h2.IsValid(), ()); + TEST(!h1.IsValid(), ()); + + for (int i = 0; i < kNumMapTests; ++i) + { + FilesMappingContainer::Handle parent_handle = cont.Map(tagName); + HandleWrapper tmp(move(parent_handle)); + } + + } +} + UNIT_TEST(FilesMappingContainer_Smoke) { string const fName = "file_container.tmp"; diff --git a/coding/file_container.hpp b/coding/file_container.hpp index 9137b15786..31329ebf65 100644 --- a/coding/file_container.hpp +++ b/coding/file_container.hpp @@ -145,9 +145,9 @@ public: : m_base(base), m_origBase(alignBase), m_size(size), m_origSize(origSize) { } - Handle(Handle && h) + Handle(Handle && h) : Handle() { - Assign(std::move(h)); + Assign(move(h)); } ~Handle();