From 770f525a8a5b22ed02738ff52b30c0e4616ab11c Mon Sep 17 00:00:00 2001 From: Denes Matetelki Date: Thu, 8 Dec 2011 23:37:34 +0100 Subject: [PATCH] Timer checks is setTimer parameter timerId is in the map --- src/Timer.cpp | 7 +++++++ test/test_Timer.hpp | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/Timer.cpp b/src/Timer.cpp index b2b86dc..ad4397b 100644 --- a/src/Timer.cpp +++ b/src/Timer.cpp @@ -70,6 +70,13 @@ bool Timer::setTimer( timer_t timerId, const time_t initExpr_sec, const long initExpr_nsec ) { + if (m_timerUsers.find(timerId) == m_timerUsers.end() ) { + LOG_BEGIN(Logger::ERR) + LOG_SPROP(timerId) + LOG_END("TimerId is not in the map."); + return false; + } + itimerspec its; its.it_value.tv_sec = interval_sec; its.it_value.tv_nsec = interval_nsec; diff --git a/test/test_Timer.hpp b/test/test_Timer.hpp index 9a75e1c..8c8592b 100644 --- a/test/test_Timer.hpp +++ b/test/test_Timer.hpp @@ -185,4 +185,14 @@ private: TS_ASSERT_EQUALS(timer.stopTimer( timerId ), false); } + void testSetTimerWhichIsNotInTheMap() + { + TEST_HEADER; + + Timer timer; + + timer_t timerId = (void*)1234; + TS_ASSERT_EQUALS(timer.setTimer( timerId, 1 ), false); + } + };