Boost logo

Boost Users :

From: Gennadiy Rozental (gennadiy.rozental_at_[hidden])
Date: 2005-08-23 00:25:53


[...]
> The existing unit_test main() function is then changed to call a user
> substitutable function which is required to call unit_test_main().

That is a major drawback - we couldn't rely on user concience.

[...]

What we are looking is a global fixure feature. And I think an idea of
global resetable variable could work. How about something like this:

#include <iostream>

class global_fixure {
public:
    global_fixure() { pointer() = this; }
    virtual void setup() = 0;
    virtual void teardown() = 0;

    static global_fixure*& pointer() { static global_fixure* p = 0; return
p; }

protected:
    ~global_fixure() {}
};

template<typename F>
class global_fixure_impl : public global_fixure {
    virtual void setup() { new (m_space) F; }
    virtual void teardown() { ((F*)m_space)->~F(); }

    char m_space[sizeof(F)];
};

#define BOOST_GLOBAL_FIXURE( F ) namespace { global_fixure_impl<F> gf; }

struct MyConfig
{
    MyConfig() { std::cout << "global setup\n"; }
    ~MyConfig() { std::cout << "global teardown\n"; }
};

BOOST_GLOBAL_FIXURE( MyConfig );

int main()
{
    global_fixure* gf = global_fixure::pointer();

    if( gf )
        gf->setup();

    std::cout << "body\n";

    if( gf )
        gf->teardown();

    return 0;
}

I should also consider suites with fixures

Gennadiy


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net