int main() {
    std::vector<int> vi;
    equal_skips = 0;
    push_back(vi, 123);
    BOOST_TEST_EQ(equal_skips, 0u);
        
    unsigned const cnt =
        #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
            1
        #else
            0
        #endif
    ;

    j jj(456);
    std::vector<j> vj;
    equal_skips = 0;
    push_back(vj, jj);
    BOOST_TEST_EQ(equal_skips, cnt);

    return boost::report_errors();
}
示例#2
0
static void test_polymorphic_pointer_downcast_intrusive()
{
    boost::intrusive_ptr<Base> base (new Derived);

    boost::intrusive_ptr<Derived> derived = boost::polymorphic_pointer_downcast<Derived>( base );

    BOOST_TEST( derived != 0 );

    if( derived != 0 )
    {
        BOOST_TEST_EQ( derived->kind(), "Derived" );
    }
}
示例#3
0
// validate block size control for 4096
void test_block_size_4096() {
  // clean up from any previous run
  rm_hashdb_dir(temp_dir1);
  rm_hashdb_dir(temp_dir2);
  remove(temp_dfxml_file);

  // create new hashdb
  hashdb_settings_t settings;
  commands_t::create(settings, temp_dir1);
  commands_t::create(settings, temp_dir2);

  // import
  commands_t::import(temp_dir1, sample_dfxml4096, "test_repository_name");
  BOOST_TEST_EQ(map_size(temp_dir1), 74);

  // export
  commands_t::do_export(temp_dir1, "temp_dfxml_out.xml");

  // import
  commands_t::import(temp_dir2, "temp_dfxml_out.xml", "test_repository_name");
  BOOST_TEST_EQ(map_size(temp_dir2), 74);
}
示例#4
0
static void test_polymorphic_pointer_downcast_std_shared()
{
    std::shared_ptr<Base> base (new Derived);

    std::shared_ptr<Derived> derived = boost::polymorphic_pointer_downcast<Derived>( base );

    BOOST_TEST( derived != 0 );

    if( derived != 0 )
    {
        BOOST_TEST_EQ( derived->kind(), "Derived" );
    }
}
示例#5
0
int main()
{
    boost::system::error_category const & bt = boost::system::generic_category();

    int ev = ENOENT;

    boost::system::error_code bc( ev, bt );

    BOOST_TEST_EQ( bc.value(), ev );
    BOOST_TEST_EQ( &bc.category(), &bt );

    boost::system::error_condition bn = bt.default_error_condition( ev );

    BOOST_TEST_EQ( bn.value(), ev );
    BOOST_TEST_EQ( &bn.category(), &bt );

    BOOST_TEST( bt.equivalent( ev, bn ) );

    BOOST_TEST( bc == bn );

    return boost::report_errors();
}
 void t2()
 {
     // bitwise ops:
     BOOST_TEST_EQ(ref_type(a|b).str(), test_type(a1 | b1).str());
     BOOST_TEST_EQ((ref_type(a)|=b).str(), (test_type(a1) |= b1).str());
     BOOST_TEST_EQ(ref_type(a&b).str(), test_type(a1 & b1).str());
     BOOST_TEST_EQ((ref_type(a)&=b).str(), (test_type(a1) &= b1).str());
     BOOST_TEST_EQ(ref_type(a^b).str(), test_type(a1 ^ b1).str());
     BOOST_TEST_EQ((ref_type(a)^=b).str(), (test_type(a1) ^= b1).str());
     // Shift ops:
     for (unsigned i = 0; i < 128; ++i)
     {
         BOOST_TEST_EQ(ref_type(a << i).str(), test_type(a1 << i).str());
         BOOST_TEST_EQ(ref_type(a >> i).str(), test_type(a1 >> i).str());
     }
     // gcd/lcm
     BOOST_TEST_EQ(ref_type(gcd(a, b)).str(), test_type(gcd(a1, b1)).str());
     BOOST_TEST_EQ(ref_type(lcm(c, d)).str(), test_type(lcm(c1, d1)).str());
 }
int main()
{
    int x = 0;

    // BOOST_TEST

    BOOST_TEST( x == 0 );
    BOOST_TEST( ++x == 1 );
    BOOST_TEST( x++ == 1 );
    BOOST_TEST( x == 2? true: false );
    BOOST_TEST( x == 2? &x: 0 );

    // BOOST_TEST_EQ

    BOOST_TEST_EQ( x, 2 );
    BOOST_TEST_EQ( ++x, 3 );
    BOOST_TEST_EQ( x++, 3 );

    int y = 4;

    BOOST_TEST_EQ( ++x, ++y );
    BOOST_TEST_EQ( x++, y++ );

    // BOOST_TEST_NE

    BOOST_TEST_NE( ++x, y );
    BOOST_TEST_NE( &x, &y );

    // BOOST_TEST_THROWS

    BOOST_TEST_THROWS( throw X(), X );
    BOOST_TEST_THROWS( throw 1, int );

    BOOST_TEST_THROWS( f(true), X );
    BOOST_TEST_THROWS( f(false), int );

    return boost::report_errors();
}
示例#8
0
int main( int, char*[] )
{
    // reused these for simplicity
    double x,y;

    // single point
    mapnik::geometry_type pt(mapnik::Point);
    pt.move_to(10,10);
    BOOST_TEST( mapnik::label::centroid(pt, x, y) );
    BOOST_TEST( x == 10 );
    BOOST_TEST( y == 10 );
    
    // two points
    pt.move_to(20,20);
    BOOST_TEST( mapnik::label::centroid(pt, x, y) );
    BOOST_TEST_EQ( x, 15 );
    BOOST_TEST_EQ( y, 15 );

    // line with two verticies
    mapnik::geometry_type line(mapnik::LineString);
    line.move_to(0,0);
    line.move_to(50,50);
    BOOST_TEST( mapnik::label::centroid(line, x, y) );
    BOOST_TEST( x == 25 );
    BOOST_TEST( y == 25 );
    
    // TODO - centroid and interior should be equal but they appear not to be (check largest)
    // MULTIPOLYGON(((-52 40,-60 32,-68 40,-60 48,-52 40)),((-60 50,-80 30,-100 49.9999999999999,-80.0000000000001 70,-60 50)),((-52 60,-60 52,-68 60,-60 68,-52 60)))

    if (!::boost::detail::test_errors()) {
        std::clog << "C++ label algorithms: \x1b[1;32m✓ \x1b[0m\n";
#if BOOST_VERSION >= 104600
        ::boost::detail::report_errors_remind().called_report_errors_function = true;
#endif
    } else {
        return ::boost::report_errors();
    }
}
示例#9
0
void qbk_tests()
{
    std::string source = "Source";
    quickbook::value q;
    {
        quickbook::file_ptr fake_file = new quickbook::file(
            "(fake file)", source, 105u);
        q = quickbook::qbk_value(
            fake_file,
            fake_file->source.begin(),
            fake_file->source.end());
    }
    BOOST_TEST_EQ(q.get_quickbook(), source);
}
示例#10
0
// import/export: import1, export, import2 should retain size of 74
void test_import_export() {
  hashdb_settings_t settings;
  rm_hashdb_dir(temp_dir1);
  rm_hashdb_dir(temp_dir2);
  remove(temp_dfxml_file);

  // import
  commands_t::create(settings, temp_dir1);
  commands_t::import(temp_dir1, sample_dfxml4096, "repository1");
  commands_t::do_export(temp_dir1, "temp_dfxml_out.xml");
  commands_t::create(settings, temp_dir2);
  commands_t::import(temp_dir2, temp_dfxml_file, "repository2");
  BOOST_TEST_EQ(map_size(temp_dir2), 74);
}
示例#11
0
static void test_polymorphic_pointer_downcast_builtin_fail()
{
    Base * base = new Base;

    int old_count = assertion_failed_count;
    expect_assertion = true;

    BOOST_TEST_THROWS( boost::polymorphic_pointer_downcast<Derived>( base ), expected_assertion ); // should assert

    BOOST_TEST_EQ( assertion_failed_count, old_count + 1 );
    expect_assertion = false;

    delete base;
}
示例#12
0
void TestThreadListAlgorithm()
{
  hadesmem::ThreadList const thread_list_1(::GetCurrentProcessId());

  for (auto const& entry : thread_list_1)
  {
    BOOST_TEST_EQ(entry.GetUsage(), 0UL);
    BOOST_TEST_NE(entry.GetId(), 0UL);
    BOOST_TEST_EQ(entry.GetOwnerId(), ::GetCurrentProcessId());
    BOOST_TEST(entry.GetBasePriority() >= 0L);
    BOOST_TEST(entry.GetBasePriority() <= 31L);
    BOOST_TEST_EQ(entry.GetDeltaPriority(), 0L);
    BOOST_TEST_EQ(entry.GetFlags(), 0UL);
  }

  auto const this_iter = std::find_if(std::begin(thread_list_1),
                                      std::end(thread_list_1),
                                      [](hadesmem::ThreadEntry const& thread)
                                      {
    return thread.GetId() == ::GetCurrentThreadId();
  });
  BOOST_TEST(this_iter != std::end(thread_list_1));
}
示例#13
0
// test check for valid hash block size
void test_block_size_0() {
  // clean up from any previous run
  rm_hashdb_dir(temp_dir1);

  // create new hashdb
  hashdb_settings_t settings;
  settings.hash_block_size = 0;
  commands_t::create(settings, temp_dir1);

  // import
  commands_t::import(temp_dir1, sample_dfxml4096, "test_repository_name");

  // with hash_block_size=0, total should be every hash, including remainder
  BOOST_TEST_EQ(map_size(temp_dir1), 75);
}
void test_push(const int n)
{
    sync_pq pq;
    BOOST_TEST(pq.empty());

    boost::barrier b(n);
    boost::thread_group tg;
    for(int i  = 0; i < n; i++)
    {
        tg.create_thread(boost::bind(call_push, &pq, &b, i));
    }
    tg.join_all();
    BOOST_TEST(!pq.empty());
    BOOST_TEST_EQ(pq.size(), std::size_t(n));
}
示例#15
0
void sort_test()
{
    quickbook::value_builder b;
    b.insert(quickbook::encoded_value("a", 10));
    b.insert(quickbook::encoded_value("b", 2));
    b.insert(quickbook::encoded_value("c", 5));
    b.insert(quickbook::encoded_value("d", 8));
    b.sort_list();
    
    quickbook::value_consumer c = b.release();
    BOOST_TEST(c.check(2)); BOOST_TEST_EQ(c.consume(2).get_encoded(), "b");
    BOOST_TEST(c.check(5)); c.consume(5);
    BOOST_TEST(c.check(8)); c.consume(8);
    BOOST_TEST(c.check(10)); c.consume(10);
    BOOST_TEST(!c.check());
}
示例#16
0
int main() {
    int i = 1; // Test built-in copyable type.
    cp c(1); // Test custom copyable type.
    ncp n(1); // Test non-copyable type.

    // Test free functions (old values without `v`).

    unsigned cnt =
        #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
            1
        #else
            0
        #endif
    ;

    old_checks = 0;
    next(i);
    BOOST_TEST_EQ(old_checks, cnt);
    
    old_checks = 0;
    next(c);
    BOOST_TEST_EQ(old_checks, cnt);

    old_checks = 0;
    next(n);
    BOOST_TEST_EQ(old_checks, 0u);

    // Test virtual functions (old values with `v`).
    
    cnt =
        #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
            2
        #else
            0
        #endif
    ;

    a<int> ai;
    old_checks = 0;
    ai.next(i);
    BOOST_TEST_EQ(old_checks, cnt);
    
    a<cp> ac;
    old_checks = 0;
    ac.next(c);
    BOOST_TEST_EQ(old_checks, cnt);

    a<ncp> an;
    old_checks = 0;
    an.next(n);
    BOOST_TEST_EQ(old_checks, 0u);

    return boost::report_errors();
}
示例#17
0
static void test_polymorphic_pointer_downcast_builtin()
{
    Base * base = new Derived;

    Derived * derived = boost::polymorphic_pointer_downcast<Derived>( base );

    BOOST_TEST( derived != 0 );

    if( derived != 0 )
    {
        BOOST_TEST_EQ( derived->kind(), "Derived" );
    }

    // polymorphic_pointer_downcast can't do crosscasts

    delete base;
}
示例#18
0
void test_concurrent_push_and_pull_on_empty_queue()
{
  boost::sync_bounded_queue<int> q(4);

  boost::barrier go(2);

  boost::future<void> push_done;
  boost::future<int> pull_done;

  try
  {
    push_done=boost::async(boost::launch::async,
#if ! defined BOOST_NO_CXX11_LAMBDAS
        [&q,&go]()
        {
          go.wait();
          q.push(42);
        }
#else
        call_push(q,go)
#endif
    );
    pull_done=boost::async(boost::launch::async,
#if ! defined BOOST_NO_CXX11_LAMBDAS
        [&q,&go]() -> int
        {
          go.wait();
          return q.pull();
        }
#else
        call_pull(q,go)
#endif
    );

    push_done.get();
    BOOST_TEST_EQ(pull_done.get(), 42);
    BOOST_TEST(q.empty());
  }
  catch (...)
  {
    BOOST_TEST(false);
  }
}
int main()
{
  namespace stde = std::experimental;
  static_assert(stde::is_nullable<std::shared_ptr<int>>::value, "ERROR");
  static_assert(stde::meta::is_callable<std::shared_ptr<stde::_t>(int)>::value, "ERROR");

  {
    int v=0;
    std::shared_ptr<int> x = stde::make<std::shared_ptr>(v);
    BOOST_TEST(*x == 0);
  }
  {
    int v=0;
    std::shared_ptr<int> x = std::make_shared<int>(v);
    BOOST_TEST(*x == 0);
  }
  {
    int v=0;
    std::shared_ptr<int> x = stde::make<std::shared_ptr<int>>(v);
    BOOST_TEST(*x == 0);
  }
  {
    int v=1;
    std::shared_ptr<A> x = std::make_shared<A>(v,v);
    BOOST_TEST(x->v == 2);
  }
  {
    int v=1;
    std::shared_ptr<A> x = stde::make<std::shared_ptr<A>>(v,v);
    BOOST_TEST(x->v == 2);
  }
  {
    std::shared_ptr<A> x = stde::make<std::shared_ptr<A>>();
    BOOST_TEST_EQ(x->v,  3);
  }
  {
    int v=0;
    std::shared_ptr<int> x = stde::make<std::shared_ptr<stde::_t>>(v);
    BOOST_TEST(*x == 0);
  }
  return ::boost::report_errors();
}
int main()
{
  namespace stde = std::experimental;
  static_assert(stde::is_nullable<std::unique_ptr<int>>::value, "ERROR");
  static_assert(std::is_same<
      stde::nullable::none_type_t<std::unique_ptr<int>>,
      std::nullptr_t
    >::value, "ERROR");

  static_assert(std::is_same<stde::meta::rebind_t<std::default_delete<int>, long>, std::default_delete<long>>::value, "ERROR");
  {
    std::unique_ptr<int> x = stde::none<std::unique_ptr>();
    BOOST_TEST( ! x);
    BOOST_TEST(! stde::has_value(x));
    BOOST_TEST(stde::holds_alternative_value(x, stde::none()));
    BOOST_TEST(x == stde::none());
    BOOST_TEST(stde::none() == x);
    BOOST_TEST(x == stde::none<std::unique_ptr<stde::_t>>());
  }
  {
    int v=0;
    std::unique_ptr<int> x = std::make_unique<int>(v);
    BOOST_TEST(*x == 0);

    BOOST_TEST(stde::has_value(x));
    BOOST_TEST(stde::holds_alternative_value(x, 0));
    BOOST_TEST(x != stde::none());
    BOOST_TEST(stde::none() != x);
    BOOST_TEST(x != stde::none<std::unique_ptr<stde::_t>>());

  }
  {
    int v=1;
    std::unique_ptr<A> x = std::make_unique<A>(v,v);
    BOOST_TEST(x->v == 2);
  }
  {
    std::unique_ptr<A> x = std::make_unique<A>();
    BOOST_TEST_EQ(x->v,  3);
  }
  return ::boost::report_errors();
}
/**
 * This test computes the sum of the first N integers upto $limit using
 * $n threads for the push operation and $n threads for the pull and count
 * operation. The push operation push a range of numbers on the queue while
 * the pull operation pull from the queue and increments an atomic int.
 * At the end of execution the value of atomic<int> $sum should be the same
 * as n*(n+1)/2 as this is the closed form solution to this problem.
 */
void compute_sum(const int n)
{
    const int limit = 1000;
    sync_pq pq;
    BOOST_TEST(pq.empty());
    boost::atomic<int> sum(0);
    boost::thread_group tg1;
    boost::thread_group tg2;
    for(int i = 0; i < n; i++)
    {
        tg1.create_thread(boost::bind(push_range, &pq, i*(limit/n)+1, (i+1)*(limit/n)+1));
        tg2.create_thread(boost::bind(atomic_pull, &pq, &sum));
    }
    tg1.join_all();
    pq.close();  //Wait until all enqueuing is done before closing.
    BOOST_TEST(pq.closed());
    tg2.join_all();
    BOOST_TEST(pq.empty());
    BOOST_TEST_EQ(sum.load(), limit*(limit+1)/2);
}
示例#22
0
void test_concurrent_push_on_empty_queue()
{
  boost::sync_queue<int> q;
  const unsigned int n = 3;
  boost::barrier go(n);
  boost::future<void> push_done[n];

  try
  {
    for (unsigned int i =0; i< n; ++i)
      push_done[i]=boost::async(boost::launch::async,
                                call_push<int>(&q,&go));

  }
  catch (...)
  {
    BOOST_TEST(false);
  }
  try
  {
    for (unsigned int i = 0; i < n; ++i)
      push_done[i].get();

  }
  catch (...)
  {
    BOOST_TEST(false);
  }
  try
  {
    BOOST_TEST(!q.empty());
    for (unsigned int i =0; i< n; ++i)
      BOOST_TEST_EQ(q.pull(), 42);
    BOOST_TEST(q.empty());

  }
  catch (...)
  {
    BOOST_TEST(false);
  }
}
示例#23
0
void test_concurrent_push_on_empty_queue()
{
  boost::sync_bounded_queue<int> q(4);
  const unsigned int n = 3;
  boost::barrier go(n);
  boost::future<void> push_done[n];

  try
  {
    for (unsigned int i =0; i< n; ++i)
      push_done[i]=boost::async(boost::launch::async,
#if ! defined BOOST_NO_CXX11_LAMBDAS
        [&q,&go]()
        {
          go.wait();
          q.push(42);
        }
#else
        call_push(q,go)
#endif
    );

    for (unsigned int i = 0; i < n; ++i)
      push_done[i].get();

    BOOST_TEST(!q.empty());
    for (unsigned int i =0; i< n; ++i)
      BOOST_TEST_EQ(q.pull(), 42);
    BOOST_TEST(q.empty());

  }
  catch (...)
  {
    BOOST_TEST(false);
  }
}
示例#24
0
void counting_constructions_and_destructions_key()
{
    counter_type::reset();
    std::vector<counter_type> data;
    data.push_back(counter_type(0));
    data.push_back(counter_type(0));
    data.push_back(counter_type(1));
    data.push_back(counter_type(2));
    data.push_back(counter_type(3));
    std::cout << counter_type::counts_alive() << std::endl;
    std::cout.flush();
    const int data_size = static_cast<int>(data.size());
    BOOST_TEST_EQ(counter_type::counts_alive(), data_size);

    /*
       +1 is because all the nodes are copied / destructed in node_ref_from function
       excepting the last one that is only copied. It is only destructed when the destructor is called
    */
    boost::tries::trie_map<counter_type, int> *t = new boost::tries::trie_map<counter_type, int>();
    t->insert(data, 0);
    BOOST_TEST_EQ(counter_type::counts_alive(), data_size * 2 + 1);

    t->insert(data, 0);
    BOOST_TEST_EQ(counter_type::counts_alive(), data_size * 2 + 1);

    t->insert(data.begin(), data.end(), 0);
    BOOST_TEST_EQ(counter_type::counts_alive(), data_size * 2 + 1);

    t->insert(data.begin() + 1, data.end(), 0);
    BOOST_TEST_EQ(counter_type::counts_alive(), data_size * 3 - 1);

    t->clear();
    BOOST_TEST_EQ(counter_type::counts_alive(), data_size + 1);
    delete t;
    /* This check is performed to prove that the comment above is true */
    BOOST_TEST_EQ(counter_type::counts_alive(), data_size);
}
示例#25
0
void test_global_parameter()
{
  boost::unique_lock<boost::mutex> lock(mutex);
  BOOST_TEST_EQ(global_parameter, N_THREADS);
}
示例#26
0
int main()
{
  boost::int64_t i64 = 0x0102030405060708;
  bi::endian_flip(i64);
  BOOST_TEST_EQ(i64, 0x0807060504030201);
  bi::endian_flip(i64);
  BOOST_TEST_EQ(i64, 0x0102030405060708);

  i64 = 0xfefdfcfbfaf9f8f7;
  bi::endian_flip(i64);
  BOOST_TEST_EQ(i64, static_cast<boost::int64_t>(0xf7f8f9fafbfcfdfe));
  bi::endian_flip(i64);
  BOOST_TEST_EQ(i64, static_cast<boost::int64_t>(0xfefdfcfbfaf9f8f7));

  boost::int32_t i32 = 0x01020304;
  bi::endian_flip(i32);
  BOOST_TEST_EQ(i32, 0x04030201);
  bi::endian_flip(i32);
  BOOST_TEST_EQ(i32, 0x01020304);

  i32 = 0xfefdfcfb;
  bi::endian_flip(i32);
  BOOST_TEST_EQ(i32, static_cast<boost::int32_t>(0xfbfcfdfe));
  bi::endian_flip(i32);
  BOOST_TEST_EQ(i32, static_cast<boost::int32_t>(0xfefdfcfb));

  boost::int16_t i16 = 0x0102;
  bi::endian_flip(i16);
  BOOST_TEST_EQ(i16, 0x0201);
  bi::endian_flip(i16);
  BOOST_TEST_EQ(i16, 0x0102);

  i16 = static_cast<boost::int16_t>(static_cast<boost::uint16_t>(0xfefd));
  bi::endian_flip(i16);
  BOOST_TEST_EQ(i16, static_cast<boost::int16_t>(static_cast<boost::uint16_t>(0xfdfe)));
  bi::endian_flip(i16);
  BOOST_TEST_EQ(i16, static_cast<boost::int16_t>(static_cast<boost::uint16_t>(0xfefd)));

  boost::uint64_t ui64 = 0x0102030405060708;
  bi::endian_flip(ui64);
  BOOST_TEST_EQ(ui64, static_cast<boost::uint64_t>(0x0807060504030201));
  bi::endian_flip(ui64);
  BOOST_TEST_EQ(ui64, static_cast<boost::uint64_t>(0x0102030405060708));

  boost::uint32_t ui32 = 0x01020304;
  bi::endian_flip(ui32);
  BOOST_TEST_EQ(ui32, static_cast<boost::uint32_t>(0x04030201));
  bi::endian_flip(ui32);
  BOOST_TEST_EQ(ui32, static_cast<boost::uint32_t>(0x01020304));

  boost::uint16_t ui16 = 0x0102;
  bi::endian_flip(ui16);
  BOOST_TEST_EQ(ui16, 0x0201);
  bi::endian_flip(ui16);
  BOOST_TEST_EQ(ui16, 0x0102);


  return ::boost::report_errors();
}
示例#27
0
文件: region.cpp 项目: lvous/hadesmem
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());
}
示例#28
0
void TestTlsDir()
{
  // Use TLS to ensure that at least one module has a TLS dir
  thread_local static std::int32_t tls_dummy = 0;

  hadesmem::Process const process(::GetCurrentProcessId());

  hadesmem::PeFile pe_file_1(
    process, ::GetModuleHandleW(nullptr), hadesmem::PeFileType::kImage, 0);

  hadesmem::TlsDir tls_dir_1(process, pe_file_1);

  hadesmem::TlsDir tls_dir_2(tls_dir_1);
  BOOST_TEST_EQ(tls_dir_1, tls_dir_2);
  tls_dir_1 = tls_dir_2;
  BOOST_TEST_EQ(tls_dir_1, tls_dir_2);
  hadesmem::TlsDir tls_dir_3(std::move(tls_dir_2));
  BOOST_TEST_EQ(tls_dir_3, tls_dir_1);
  tls_dir_2 = std::move(tls_dir_3);
  BOOST_TEST_EQ(tls_dir_1, tls_dir_2);

  hadesmem::ModuleList modules(process);
  for (auto const& mod : modules)
  {
    hadesmem::PeFile const cur_pe_file(
      process, mod.GetHandle(), hadesmem::PeFileType::kImage, 0);

    std::unique_ptr<hadesmem::TlsDir> cur_tls_dir;
    try
    {
      cur_tls_dir = std::make_unique<hadesmem::TlsDir>(process, cur_pe_file);
    }
    catch (std::exception const& /*e*/)
    {
      continue;
    }

    ++tls_dummy;

    auto const tls_dir_raw =
      hadesmem::Read<IMAGE_TLS_DIRECTORY>(process, cur_tls_dir->GetBase());

    cur_tls_dir->SetStartAddressOfRawData(
      cur_tls_dir->GetStartAddressOfRawData());
    cur_tls_dir->SetEndAddressOfRawData(cur_tls_dir->GetEndAddressOfRawData());
    cur_tls_dir->SetAddressOfIndex(cur_tls_dir->GetAddressOfIndex());
    cur_tls_dir->SetAddressOfCallBacks(cur_tls_dir->GetAddressOfCallBacks());
    cur_tls_dir->SetSizeOfZeroFill(cur_tls_dir->GetSizeOfZeroFill());
    cur_tls_dir->SetCharacteristics(cur_tls_dir->GetCharacteristics());
    std::vector<ULONGLONG> callbacks;
    cur_tls_dir->GetCallbacks(std::back_inserter(callbacks));
    cur_tls_dir->UpdateWrite();
    cur_tls_dir->UpdateRead();

    auto const tls_dir_raw_new =
      hadesmem::Read<IMAGE_TLS_DIRECTORY>(process, cur_tls_dir->GetBase());

    BOOST_TEST_EQ(
      std::memcmp(&tls_dir_raw, &tls_dir_raw_new, sizeof(tls_dir_raw)), 0);

    std::stringstream test_str_1;
    test_str_1.imbue(std::locale::classic());
    test_str_1 << *cur_tls_dir;
    std::stringstream test_str_2;
    test_str_2.imbue(std::locale::classic());
    test_str_2 << cur_tls_dir->GetBase();
    BOOST_TEST_EQ(test_str_1.str(), test_str_2.str());
  }

  BOOST_TEST_NE(tls_dummy, 0);
}
示例#29
0
int main()
{
  const A_int_0 ca;
  A_int_0 a;

#if defined BOOST_THREAD_PROVIDES_INVOKE
  BOOST_TEST_EQ(boost::detail::invoke(f), 1);
  BOOST_TEST_EQ(boost::detail::invoke(&f), 1);
  BOOST_TEST_EQ(boost::detail::invoke(A_int_0()), 4);
  BOOST_TEST_EQ(boost::detail::invoke(a), 4);
  BOOST_TEST_EQ(boost::detail::invoke(ca), 5);
#endif

  BOOST_TEST_EQ(boost::detail::invoke<int>(f), 1);
  BOOST_TEST_EQ(boost::detail::invoke<int>(&f), 1);
  BOOST_TEST_EQ(A_int_0()(), 4);
#if defined BOOST_THREAD_PROVIDES_INVOKE || ! defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  BOOST_TEST_EQ(boost::detail::invoke<int>(A_int_0()), 4);
#else
  //BOOST_TEST_EQ(boost::detail::invoke<int>(A_int_0()), 5);
#endif
  BOOST_TEST_EQ(a(), 4);
  BOOST_TEST_EQ(boost::detail::invoke<int>(a), 4);
  BOOST_TEST_EQ(ca(), 5);
  BOOST_TEST_EQ(boost::detail::invoke<int>(ca), 5);

  return boost::report_errors();
}
示例#30
0
void TestSectionList()
{
  hadesmem::Process const process(::GetCurrentProcessId());

  hadesmem::PeFile pe_file_1(
    process, ::GetModuleHandleW(nullptr), hadesmem::PeFileType::Image, 0);

  hadesmem::NtHeaders nt_headers_1(process, pe_file_1);

  BOOST_TEST(nt_headers_1.GetNumberOfSections() >= 1);

  hadesmem::Section section_1(process, pe_file_1, 0);

  hadesmem::Section section_2(section_1);
  BOOST_TEST_EQ(section_1, section_2);
  section_1 = section_2;
  BOOST_TEST_EQ(section_1, section_2);
  hadesmem::Section section_3(std::move(section_2));
  BOOST_TEST_EQ(section_3, section_1);
  section_2 = std::move(section_3);
  BOOST_TEST_EQ(section_1, section_2);

  hadesmem::ModuleList modules(process);
  for (auto const& mod : modules)
  {
    hadesmem::PeFile const pe_file(
      process, mod.GetHandle(), hadesmem::PeFileType::Image, 0);

    hadesmem::NtHeaders const nt_headers(process, pe_file);
    WORD const num_sections = nt_headers.GetNumberOfSections();

    // Assume every module has at least one section.
    hadesmem::SectionList sections(process, pe_file);
    WORD section_count = 0;
    for (auto& section : sections)
    {
      section_count = static_cast<WORD>(section_count + 1);

      auto const section_header_raw =
        hadesmem::Read<IMAGE_SECTION_HEADER>(process, section.GetBase());

      section.SetName(section.GetName());
      section.SetVirtualAddress(section.GetVirtualAddress());
      section.SetVirtualSize(section.GetVirtualSize());
      section.SetSizeOfRawData(section.GetSizeOfRawData());
      section.SetPointerToRawData(section.GetPointerToRawData());
      section.SetPointerToRelocations(section.GetPointerToRelocations());
      section.SetPointerToLinenumbers(section.GetPointerToLinenumbers());
      section.SetNumberOfRelocations(section.GetNumberOfRelocations());
      section.SetNumberOfLinenumbers(section.GetNumberOfLinenumbers());
      section.SetCharacteristics(section.GetCharacteristics());
      section.UpdateWrite();
      section.UpdateRead();

      auto const section_header_raw_new =
        hadesmem::Read<IMAGE_SECTION_HEADER>(process, section.GetBase());

      BOOST_TEST_EQ(std::memcmp(&section_header_raw,
                                &section_header_raw_new,
                                sizeof(section_header_raw)),
                    0);

      std::stringstream test_str_1;
      test_str_1.imbue(std::locale::classic());
      test_str_1 << section;
      std::stringstream test_str_2;
      test_str_2.imbue(std::locale::classic());
      test_str_2 << section.GetBase();
      BOOST_TEST_EQ(test_str_1.str(), test_str_2.str());
      if (mod.GetHandle() != GetModuleHandle(L"ntdll"))
      {
        hadesmem::PeFile const pe_file_ntdll(process,
                                             ::GetModuleHandleW(L"ntdll"),
                                             hadesmem::PeFileType::Image,
                                             0);
        hadesmem::Section const section_ntdll(process, pe_file_ntdll, 0);
        std::stringstream test_str_3;
        test_str_3.imbue(std::locale::classic());
        test_str_3 << section_ntdll.GetBase();
        BOOST_TEST_NE(test_str_1.str(), test_str_3.str());
      }
    }
    BOOST_TEST(section_count == num_sections);

    // Assume every module has a '.text' section.
    auto text_iter = std::find_if(std::begin(sections),
                                  std::end(sections),
                                  [](hadesmem::Section const& section)
                                  {
      return section.GetName() == ".data";
    });
    BOOST_TEST(text_iter != std::end(sections));
  }
}