tests: use LimitedIo API for time or IO limits
Change-Id: Id5cc1cea9bf1329e730d92c4099e80adbfc0f500
diff --git a/tests/core/limited-io.hpp b/tests/core/limited-io.hpp
index 7fb4f70..0aae290 100644
--- a/tests/core/limited-io.hpp
+++ b/tests/core/limited-io.hpp
@@ -12,24 +12,41 @@
namespace nfd {
namespace tests {
+/** \brief provides IO operations limit and/or time limit for unit testing
+ */
class LimitedIo
{
public:
LimitedIo();
+ /// indicates why .run returns
enum StopReason
{
+ /// g_io.run() runs normally because there's no work to do
NO_WORK,
+ /// .afterOp() has been invoked nOpsLimit times
EXCEED_OPS,
- EXCEED_TIME
+ /// nTimeLimit has elapsed
+ EXCEED_TIME,
+ /// an exception is thrown
+ EXCEPTION
};
+ /** \brief g_io.run() with operation count and/or time limit
+ *
+ * \param nOpsLimit operation count limit, pass UNLIMITED_OPS for no limit
+ * \param nTimeLimit time limit, pass UNLIMITED_TIME for no limit
+ */
StopReason
run(int nOpsLimit, time::Duration nTimeLimit);
+ /// count an operation
void
afterOp();
+ const std::exception&
+ getLastException() const;
+
private:
void
afterTimeout();
@@ -43,6 +60,7 @@
int m_nOpsRemaining;
EventId m_timeout;
StopReason m_reason;
+ std::exception m_lastException;
};
} // namespace tests