void MockSupport::enable()
{
	enabled_ = true;

	for (MockNamedValueListNode* p = data_.begin(); p; p = p->next())
		if (getMockSupport(p)) getMockSupport(p)->enable();
}
Example #2
0
MockNamedValue* MockNamedValueList::getValueByName(const SimpleString& name)
{
    for (MockNamedValueListNode * p = head_; p; p = p->next())
        if (p->getName() == name)
            return p->item();
    return NULL;
}
void MockSupport::installComparator(const SimpleString& typeName, MockNamedValueComparator& comparator)
{
	comparatorRepository_.installComparator(typeName, comparator);

	for (MockNamedValueListNode* p = data_.begin(); p; p = p->next())
		if (getMockSupport(p)) getMockSupport(p)->installComparator(typeName, comparator);
}
Example #4
0
void MockCheckedExpectedCall::outputParameterWasPassed(const SimpleString& name)
{
    for (MockNamedValueListNode* p = outputParameters_->begin(); p; p = p->next()) {
        if (p->getName() == name)
            item(p)->setMatchesActualCall(true);
    }
}
void MockSupport::ignoreOtherCalls()
{
	ignoreOtherCalls_ = true;

	for (MockNamedValueListNode* p = data_.begin(); p; p = p->next())
		if (getMockSupport(p)) getMockSupport(p)->ignoreOtherCalls();
}
void MockExpectedFunctionCall::parameterWasPassed(const SimpleString& name)
{
	for (MockNamedValueListNode* p = parameters_->begin(); p; p = p->next()) {
		if (p->getName() == name)
			item(p)->setFulfilled(true);
	}
}
void MockSupport::installComparators(const MockNamedValueComparatorRepository& repository)
{
	comparatorRepository_.installComparators(repository);

	for (MockNamedValueListNode* p = data_.begin(); p; p = p->next())
		if (getMockSupport(p)) getMockSupport(p)->installComparators(repository);
}
SimpleString MockExpectedFunctionCall::callToString()
{
	SimpleString str;
	if (objectPtr_)
		str = StringFromFormat("(object address: %p)::", objectPtr_);

	str += getName();
	str += " -> ";
	if (expectedCallOrder_ != NO_EXPECTED_CALL_ORDER) {
		str += StringFromFormat("expected call order: <%d> -> ", expectedCallOrder_);
	}

	if (parameters_->begin() == NULL) {
		str += (ignoreOtherParameters_) ? "all parameters ignored" : "no parameters";
		return str;
	}

	for (MockNamedValueListNode* p = parameters_->begin(); p; p = p->next()) {
		str += StringFromFormat("%s %s: <%s>", p->getType().asCharString(), p->getName().asCharString(), getParameterValueString(p->getName()).asCharString());
		if (p->next()) str += ", ";
	}
	if (ignoreOtherParameters_)
		str += ", other parameters are ignored";
	return str;
}
void MockExpectedFunctionCall::resetExpectation()
{
	callOrder_ = NOT_CALLED_YET;
	wasPassedToObject_ = (objectPtr_ == NULL);
	for (MockNamedValueListNode* p = parameters_->begin(); p; p = p->next())
		item(p)->setFulfilled(false);
}
bool MockExpectedFunctionCall::areParametersFulfilled()
{
	for (MockNamedValueListNode* p = parameters_->begin(); p; p = p->next())
		if (! item(p)->isFulfilled())
			return false;
	return true;
}
void MockSupport::clear()
{
	delete lastActualFunctionCall_;
	lastActualFunctionCall_ = NULL;

	tracing_ = false;
	MockFunctionCallTrace::instance().clear();

	expectations_.deleteAllExpectationsAndClearList();
	compositeCalls_.clear();
	ignoreOtherCalls_ = false;
	enabled_ = true;
	callOrder_ = 0;
	expectedCallOrder_ = 0;
	strictOrdering_ = false;

	for (MockNamedValueListNode* p = data_.begin(); p; p = p->next()) {
		MockSupport* support = getMockSupport(p);
		if (support) {
			support->clear();
			delete support;
		}
	}
	data_.clear();
}
void MockSupport::tracing(bool enabled)
{
	tracing_ = enabled;

	for (MockNamedValueListNode* p = data_.begin(); p; p = p->next())
		if (getMockSupport(p)) getMockSupport(p)->tracing(enabled);
}
bool MockSupport::expectedCallsLeft()
{
	int callsLeft = expectations_.hasUnfullfilledExpectations();

	for (MockNamedValueListNode* p = data_.begin(); p; p = p->next())
		if (getMockSupport(p)) callsLeft += getMockSupport(p)->expectedCallsLeft();

	return callsLeft;
}
void MockSupport::checkExpectationsOfLastCall()
{
    if(lastActualFunctionCall_)
        lastActualFunctionCall_->checkExpectations();

	for(MockNamedValueListNode *p = data_.begin();p;p = p->next())
		if(getMockSupport(p) && getMockSupport(p)->lastActualFunctionCall_)
			getMockSupport(p)->lastActualFunctionCall_->checkExpectations();
}
void MockSupport::setMockFailureReporter(MockFailureReporter* reporter)
{
	reporter_ = (reporter != NULL) ? reporter : &defaultReporter_;

	if (lastActualFunctionCall_)
		lastActualFunctionCall_->setMockFailureReporter(reporter_);

	for (MockNamedValueListNode* p = data_.begin(); p; p = p->next())
		if (getMockSupport(p)) getMockSupport(p)->setMockFailureReporter(reporter_);
}
bool MockSupport::wasLastCallFulfilled()
{
	if (lastActualFunctionCall_ && !lastActualFunctionCall_->isFulfilled())
		return false;

	for (MockNamedValueListNode* p = data_.begin(); p; p = p->next())
		if (getMockSupport(p) && !getMockSupport(p)->wasLastCallFulfilled())
				return false;

	return true;
}
Example #17
0
bool MockCheckedExpectedCall::areParametersMatchingActualCall()
{
    MockNamedValueListNode* p;
    for (p = inputParameters_->begin(); p; p = p->next())
        if (! item(p)->isMatchingActualCall())
            return false;
    for (p = outputParameters_->begin(); p; p = p->next())
        if (! item(p)->isMatchingActualCall())
            return false;
    return true;
}
SimpleString MockExpectedFunctionCall::missingParametersToString()
{
	SimpleString str;
	for (MockNamedValueListNode* p = parameters_->begin(); p; p = p->next()) {
		if (! item(p)->isFulfilled()) {
			if (str != "") str += ", ";
			str += StringFromFormat("%s %s", p->getType().asCharString(), p->getName().asCharString());
		}
	}
	return str;
}
Example #19
0
void MockCheckedExpectedCall::resetExpectation()
{
    callOrder_ = NOT_CALLED_YET;
    wasPassedToObject_ = (objectPtr_ == NULL);
    MockNamedValueListNode* p;

    for (p = inputParameters_->begin(); p; p = p->next())
        item(p)->setFulfilled(false);
    for (p = outputParameters_->begin(); p; p = p->next())
        item(p)->setFulfilled(false);
}
Example #20
0
void MockNamedValueList::add(MockNamedValue* newValue)
{
    MockNamedValueListNode* newNode = new MockNamedValueListNode(newValue);
    if (head_ == NULL)
        head_ = newNode;
    else {
        MockNamedValueListNode* lastNode = head_;
        while (lastNode->next()) lastNode = lastNode->next();
        lastNode->setNext(newNode);
    }
}
Example #21
0
void MockCheckedExpectedCall::resetActualCallMatchingState()
{
    actualCallOrder_ = NOT_CALLED_YET;
    wasPassedToObject_ = (objectPtr_ == NULL);
    isActualCallMatchFinalized_ = false;

    MockNamedValueListNode* p;

    for (p = inputParameters_->begin(); p; p = p->next())
        item(p)->setMatchesActualCall(false);
    for (p = outputParameters_->begin(); p; p = p->next())
        item(p)->setMatchesActualCall(false);
}
Example #22
0
void MockSupport::failTestWithUnexpectedCalls()
{
    MockExpectedCallsList expectationsList;
    expectationsList.addExpectations(expectations_);

    for(MockNamedValueListNode *p = data_.begin();p;p = p->next())
        if(getMockSupport(p))
            expectationsList.addExpectations(getMockSupport(p)->expectations_);

    MockExpectedCallsDidntHappenFailure failure(activeReporter_->getTestToFail(), expectationsList);
    clear();
    failTest(failure);
}
Example #23
0
bool MockSupport::hasCallsOutOfOrder()
{
    if (expectations_.hasCallsOutOfOrder())
    {
        return true;
    }
    for (MockNamedValueListNode* p = data_.begin(); p; p = p->next())
        if (getMockSupport(p) && getMockSupport(p)->hasCallsOutOfOrder())
        {
            return true;
        }
    return false;
}
void MockSupport::failTestWithOutOfOrderCalls()
{
    MockExpectedFunctionsList expectationsList;
    expectationsList.addExpectations(expectations_);

    for(MockNamedValueListNode *p = data_.begin();p;p = p->next())
		if(getMockSupport(p))
			expectationsList.addExpectations(getMockSupport(p)->expectations_);

    MockCallOrderFailure failure(reporter_->getTestToFail(), expectationsList);
    clear();
    reporter_->failTest(failure);
}
Example #25
0
SimpleString MockCheckedExpectedCall::missingParametersToString()
{
    SimpleString str;
    MockNamedValueListNode* p;

    for (p = inputParameters_->begin(); p; p = p->next()) {
        if (! item(p)->isMatchingActualCall()) {
            if (str != "") str += ", ";
            str += StringFromFormat("%s %s", p->getType().asCharString(), p->getName().asCharString());
        }
    }
    for (p = outputParameters_->begin(); p; p = p->next()) {
        if (! item(p)->isMatchingActualCall()) {
            if (str != "") str += ", ";
            str += StringFromFormat("%s %s", p->getType().asCharString(), p->getName().asCharString());
        }
    }
    return str;
}
void MockSupport::removeAllComparators()
{
	comparatorRepository_.clear();
	for (MockNamedValueListNode* p = data_.begin(); p; p = p->next())
		if (getMockSupport(p)) getMockSupport(p)->removeAllComparators();
}