Пример #1
0
void
Assert::isTrue(bool assertion, const string& message)
{
	if (!assertion) {
		if (message.empty()) {
			throw  AssertionFailedException();
		} else {
			throw  AssertionFailedException(message);
		}
	}
}
Пример #2
0
void
Assert::equals(const Coordinate& expectedValue,
		const Coordinate& actualValue, const string& message)
{
	if (!(actualValue==expectedValue)) {
		throw  AssertionFailedException("Expected " + expectedValue.toString() + " but encountered "
			+ actualValue.toString() + (!message.empty() ? ": " + message : ""));
	}
}
  ConditionState PinStateExpectation::onTick(FakeParticleDevice& device) {
    PinState currentPinState = device.getPinDigitalState(pin);
    uint32_t currentTime = device.getCurrentTimeInMicroseconds();

    if (!haveStartedWaiting) {
      if (currentPinState == desiredState) {
        startedWaitingAt = currentTime;
        haveStartedWaiting = true;
      } else {
        return ConditionState::NotYetPassed;
      }
    }

    if (currentPinState != desiredState) {
      if (currentTime < startedWaitingAt + minTimeInMicroseconds) {
        // If the pin has changed before min required time, fail.
        uint32_t pulseTime = currentTime - startedWaitingAt;

        ostringstream os;
        os << "Expected pin " << pin << " to be " << pinStateToString(desiredState);
        os << " for between " << minTimeInMicroseconds << " and " << maxTimeInMicroseconds << " microseconds,";
        os << " but changed to " << pinStateToString(currentPinState) << " after " << pulseTime << " microseconds.";

        throw AssertionFailedException(os.str());
      } else if (currentTime <= startedWaitingAt + maxTimeInMicroseconds) {
        // If the pin has changed between min and max time, pass.
        return ConditionState::Passed;
      }
    }

    // If we've gone longer than max time, fail.
    if (device.getCurrentTimeInMicroseconds() > startedWaitingAt + maxTimeInMicroseconds) {
      ostringstream os;
      os << "Expected pin " << pin << " to be " << pinStateToString(desiredState);
      os << " for between " << minTimeInMicroseconds << " and " << maxTimeInMicroseconds << " microseconds,";
      os << " but was " << pinStateToString(desiredState) << " for more than " << maxTimeInMicroseconds << " microseconds.";

      throw AssertionFailedException(os.str());
    }

    // Otherwise, wait.
    return ConditionState::NotYetPassed;
  }
Пример #4
0
void		VM::assert( IOperand const & o ) {

	std::istringstream iss;
	double thisValue;
	double operandValue;

	iss.str(_stack.back()->toString());
	iss >> thisValue;
	iss.clear();
	iss.str(o.toString());
	iss >> operandValue;
	bool operandsHaveSameType = (_stack.back()->getType() == o.getType());
	bool operandsAreEqual = (thisValue == operandValue);
	if (!(operandsAreEqual && operandsHaveSameType))
		throw AssertionFailedException();
}
Пример #5
0
	// virtual
	DelayedError::~DelayedError() {
		if (AssertionManager::ErrorMode() == AssertionManager::kErrorModeThrow) {
			// It is bad practice (though perfectly legal C++) to throw exceptions
			// from destructors. Unfortunately, it's the only way to accomplish
			// the syntax that looks like:
			//     CHECK(foo) << "some extra information";
			// DelayedError is never used except from CHECK() macros,
			// guaranteeing that it will never be in a std::vector or
			// similar situation in which it might cause memory leaks. Never
			// the less, CHECK(...)  should never appear in another object's
			// destructor.
			throw AssertionFailedException(ss->str());
		} else {
			cerr << ss->str() << endl;
			exit(-1);
		}
	}
Пример #6
0
void Assert::shouldNeverReachHere(const string& message) {
	throw  AssertionFailedException("Should never reach here"
		+ (!message.empty() ? ": " + message : ""));
}