void TestRegionList() { using RegionListIterCat = std::iterator_traits<hadesmem::RegionList::iterator>::iterator_category; HADESMEM_DETAIL_STATIC_ASSERT( std::is_base_of<std::input_iterator_tag, RegionListIterCat>::value); using RegionListConstIterCat = std::iterator_traits< hadesmem::RegionList::const_iterator>::iterator_category; HADESMEM_DETAIL_STATIC_ASSERT( std::is_base_of<std::input_iterator_tag, RegionListConstIterCat>::value); hadesmem::Process const process(::GetCurrentProcessId()); hadesmem::RegionList const region_list_1(process); hadesmem::RegionList region_list_2(region_list_1); hadesmem::RegionList region_list_3(std::move(region_list_2)); region_list_2 = std::move(region_list_3); BOOST_TEST(std::begin(region_list_2) != std::end(region_list_2)); auto iter = std::begin(region_list_1); hadesmem::Region const first_region(process, nullptr); BOOST_TEST(iter != std::end(region_list_1)); BOOST_TEST_EQ(*iter, first_region); hadesmem::Region const second_region( process, static_cast<char const* const>(first_region.GetBase()) + first_region.GetSize()); BOOST_TEST(++iter != std::end(region_list_1)); BOOST_TEST_EQ(*iter, second_region); hadesmem::Region last(process, nullptr); do { hadesmem::Region current = *iter; BOOST_TEST(current > last); BOOST_TEST(current >= last); BOOST_TEST(last < current); BOOST_TEST(last <= current); last = current; } while (++iter != std::end(region_list_1)); BOOST_TEST_THROWS( hadesmem::Region( process, static_cast<char const* const>(last.GetBase()) + last.GetSize()), hadesmem::Error); }
void TestRegion() { hadesmem::Process const process(::GetCurrentProcessId()); hadesmem::Region const first_region(process, nullptr); hadesmem::Region first_region_2(first_region); hadesmem::Region first_region_3(std::move(first_region_2)); first_region_2 = std::move(first_region_3); BOOST_TEST_EQ(first_region, first_region_2); if (first_region.GetState() != MEM_FREE) { BOOST_TEST_NE(first_region.GetBase(), static_cast<void*>(nullptr)); BOOST_TEST_NE(first_region.GetAllocBase(), static_cast<void*>(nullptr)); BOOST_TEST_NE(first_region.GetAllocProtect(), 0U); BOOST_TEST_NE(first_region.GetType(), 0U); } first_region.GetProtect(); BOOST_TEST_NE(first_region.GetSize(), 0U); BOOST_TEST_NE(first_region.GetState(), 0U); hadesmem::Region const first_region_other( process, static_cast<PBYTE>(first_region.GetBase()) + 1); BOOST_TEST_EQ(first_region.GetBase(), first_region_other.GetBase()); BOOST_TEST_EQ(first_region.GetAllocBase(), first_region_other.GetAllocBase()); BOOST_TEST_EQ(first_region.GetAllocProtect(), first_region_other.GetAllocProtect()); BOOST_TEST_EQ(first_region.GetSize(), first_region_other.GetSize()); BOOST_TEST_EQ(first_region.GetState(), first_region_other.GetState()); BOOST_TEST_EQ(first_region.GetProtect(), first_region_other.GetProtect()); BOOST_TEST_EQ(first_region.GetType(), first_region_other.GetType()); hadesmem::Region const second_region( process, static_cast<char const* const>(first_region.GetBase()) + first_region.GetSize()); BOOST_TEST_NE(first_region, second_region); BOOST_TEST(first_region < second_region); BOOST_TEST(first_region <= second_region); BOOST_TEST(second_region > first_region); BOOST_TEST(second_region >= first_region); BOOST_TEST(!(first_region > second_region)); BOOST_TEST(!(first_region >= second_region)); BOOST_TEST(!(second_region < first_region)); BOOST_TEST(!(second_region <= first_region)); BOOST_TEST(first_region >= first_region); BOOST_TEST(first_region <= first_region); BOOST_TEST_EQ(first_region, first_region); std::stringstream second_region_str_1; second_region_str_1.imbue(std::locale::classic()); second_region_str_1 << second_region.GetBase(); std::stringstream second_region_str_2; second_region_str_2.imbue(std::locale::classic()); second_region_str_2 << second_region; BOOST_TEST(second_region_str_1.str() == second_region_str_2.str()); std::wstringstream second_region_str_3; second_region_str_3.imbue(std::locale::classic()); second_region_str_3 << second_region.GetBase(); std::wstringstream second_region_str_4; second_region_str_4.imbue(std::locale::classic()); second_region_str_4 << second_region; BOOST_TEST(second_region_str_3.str() == second_region_str_4.str()); }