Exemple #1
0
 void fixture::test<3>()
 {
     set_test_name("test add one node");
     int loop =0;
     algorithm::const_hash hash;
     ensure("default hash empty", hash.empty());
     hash.add(0, 1);
     ensure_not("hash not empty", hash.empty());
     ensure_not("hash alive_set not empty", hash.alive_set().empty());
     ensure_equals("hash alive_set has node 0", 
             hash.alive_set().count(0), 1);
     ensure_equals("hash node 0 weight", hash.weight(0), 1);
     loop = random(1, 100);
     for (int i = 0; i < loop; ++i)
     {
         ensure_equals("hash resource to node 0", 
                 hash.hash(random()), 0);
     }
     hash.add(0, 99);
     ensure_not("hash not empty", hash.empty());
     ensure_not("hash alive_set not empty", hash.alive_set().empty());
     ensure_equals("hash alive_set has node 0", 
             hash.alive_set().count(0), 1);
     ensure_equals("hash node 0 weight", hash.weight(0), 100);
     loop = random(1, 100);
     for (int i = 0; i < loop; ++i)
     {
         ensure_equals("hash resource to node 0", 
                 hash.hash(random()), 0);
     }
     ensure_THROW(hash.hash(2), std::range_error);
     ensure_THROW(hash.add(1, algorithm::const_hash::MAX_NODES-99), std::range_error);
     ensure_equals("node 1 has no weight", hash.weight(1), 0);
     ensure_equals("node 1 not in alive_set", hash.alive_set().count(1), 0);
 }
Exemple #2
0
 void fixture::test<4>()
 {
     void* result = reinterpret_cast<void*>(-1);
     data d(result);
     set_test_name("join thread");
     pthreadxx::thread t = pthreadxx::thread::create(d);
     ensure_equals("join return", t.join(), result);
     pthreadxx::thread t1;
     ensure_THROW(t1.join(), pthreadxx::invalid_state);
     ensure_THROW(t.join(), std::invalid_argument);
 }
Exemple #3
0
    void object::test<1>()
    {
        const char *argv1[] = { "self_test", "dummy", "five" };
        ensure_THROW( tut_main(3, argv1), no_such_test );

        const char *argv2[] = { "self_test", "dummy", "5" };
        ensure_THROW( tut_main(3, argv2), no_such_group );

        const char *argv3[] = { "self_test", "main", "99" };
        ensure_THROW( tut_main(3, argv3), no_such_test );
    }
Exemple #4
0
 void fixture::test<2>()
 {
     set_test_name("throw domain_error when hash using empty object");
     algorithm::const_hash hash;
     ensure("default hash empty", hash.empty());
     ensure_THROW(hash.hash(0.5), std::domain_error);
 }
Exemple #5
0
 void fixture::test<6>()
 {
     set_test_name("detach thread");
     pthreadxx::thread t = pthreadxx::thread::create(data());
     ensure_NO_THROW(t.detach());
     pthreadxx::thread t1;
     ensure_THROW(t.detach(), pthreadxx::invalid_state);
 }
Exemple #6
0
    void fixture::test<3>()
    {
        set_test_name("stack_size");
        pthreadxx::thread_attribute attribute;

        attribute.stack_size(PTHREAD_STACK_MIN*10);
        ensure_equals("set 10 times minimal stack size", attribute.stack_size(), PTHREAD_STACK_MIN*10);
        
        ensure_THROW(attribute.stack_size(PTHREAD_STACK_MIN-1), std::invalid_argument);
    }
Exemple #7
0
void object::test<2>()
{
    set_test_name("checks throw");

    try
    {
        ensure_THROW( foo(), foo_exception );
    }
    catch (const failure& ex)
    {
        fail("positive throw doesn't work");
    }
}
Exemple #8
0
void object::test<4>()
{
    set_test_name("checks throw std::exception");

    try
    {
        ensure_THROW( throw_std(), std::exception );
    }
    catch (const failure& ex)
    {
        fail("positive throw expecting std::exception doesn't work");
    }
}
Exemple #9
0
void object::test<1>()
{
    set_test_name("checks throw");

    try
    {
        ensure_THROW( foo(), bar_exception );
        throw std::runtime_error("throw doesn't work");
    }
    catch (const failure& ex)
    {
        if (std::string(ex.what()).find("foo()") == std::string::npos )
        {
            fail("throw doesn't contain proper message");
        }
    }
}
Exemple #10
0
void object::test<5>()
{
    set_test_name("checks throw std::exception");

    try
    {
        ensure_THROW( noop(), std::exception );
        fail("throw doesn't work");
    }
    catch (const failure& ex)
    {
        if (std::string(ex.what()).find("noop()") == std::string::npos )
        {
            fail("throw doesn't contain proper message");
        }
    }
}