OTest2
A C++ testing framework
|
Go to the documentation of this file.
38 struct CaseGenerated::Impl {
42 const Context* context;
44 StateRegistry state_registry;
45 std::string entering_state;
46 std::vector<FceMarshalerPtr> start_ups;
47 std::vector<FceMarshalerPtr> tear_downs;
51 const Impl&) =
delete;
53 const Impl&) =
delete;
57 const Context& context_,
58 const std::string& name_);
62 CaseGenerated::Impl::Impl(
63 CaseGenerated* owner_,
64 const Context& context_,
65 const std::string& name_) :
76 CaseGenerated::Impl::~Impl() {
82 const std::string& name_) :
84 pimpl(new Impl(this, context_, name_)) {
99 if(index_ >= 0 && index_ < pimpl->start_ups.size()) {
101 pimpl->start_ups[index_]->runFunction(context_);
113 assert(me_.get() ==
this);
116 std::make_shared<CmdFirstState>(
117 std::static_pointer_cast<CaseOrdinary>(me_)));
123 assert(index_ >= 0 && index_ < pimpl->tear_downs.size());
126 pimpl->tear_downs[index_]->runFunction(context_);
131 return pimpl->state_registry.getState(pimpl->entering_state);
135 const std::string& name_)
const {
136 return pimpl->state_registry.getState(name_);
140 return *pimpl->context;
144 const std::string& name_,
146 pimpl->state_registry.registerState(name_, state_);
150 const std::string& name_) {
151 pimpl->entering_state = name_;
157 assert(start_up_ !=
nullptr && tear_down_ !=
nullptr);
159 pimpl->start_ups.push_back(start_up_);
160 pimpl->tear_downs.push_back(tear_down_);
virtual std::string getName() const
Get object's name.
CaseGenerated & operator=(const CaseGenerated &)=delete
virtual void tearDownObject(const Context &context_, int index_) override
Execute tear-down function at specified index.
virtual const Context & otest2Context() const
Get the OTest2 context.
void setEnteringState(const std::string &name_)
Set name of the entering (first) state.
virtual ~CaseGenerated()
Dtor.
void pushCommand(CommandPtr command_)
Push a command into the stack.
std::shared_ptr< FceMarshaler > FceMarshalerPtr
std::shared_ptr< Object > ObjectPtr
Shared pointer to a testing object.
virtual StatePtr getState(const std::string &name_) const override
Get state with specified name_.
CommandStack *const command_stack
virtual bool startUpObject(const Context &context_, int index_) override
Execute start-up function at specified index.
bool runUserCode(const Context &context_, std::function< void(const Context &)> ftor_) noexcept
std::shared_ptr< Scenario > ScenarioPtr
Shared pointer of the scenario object.
void registerFixture(FceMarshalerPtr start_up_, FceMarshalerPtr tear_down_)
Register a pair of start-up and tear-down functions.
std::shared_ptr< State > StatePtr
Pointer to test state objects.
An ordinary case object scheduled by the CmdFirstState, CmdRunState and CmdState commands.
virtual StatePtr getFirstState() const override
Get the initial state.
CaseGenerated(const CaseGenerated &)=delete
void registerState(const std::string &name_, StatePtr state_)
Register new test state.
virtual void scheduleBody(const Context &context_, ScenarioPtr scenario_, ObjectPtr me_) override
Schedule body of the testing object.
void odelete(T_ *&object_)
Delete a pointer and set it invalid.