From 7eef0df1c60243246c20183ea02373b9e8d27500 Mon Sep 17 00:00:00 2001 From: "Mike D. Lowis" Date: Mon, 25 Jun 2012 16:47:54 -0400 Subject: [PATCH] Completed tests for imarker --- source/marker/imarker.cpp | 8 ++++ source/marker/imarker.h | 2 + tests/test_imarker.cpp | 81 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 tests/test_imarker.cpp diff --git a/source/marker/imarker.cpp b/source/marker/imarker.cpp index 694406b..91a1c13 100644 --- a/source/marker/imarker.cpp +++ b/source/marker/imarker.cpp @@ -1,5 +1,13 @@ #include "imarker.h" +IMarker::IMarker() : cur_location(0) +{ +} + +IMarker::~IMarker() +{ +} + void IMarker::advance(void) { cur_location++; diff --git a/source/marker/imarker.h b/source/marker/imarker.h index 2dab5f6..d681ead 100644 --- a/source/marker/imarker.h +++ b/source/marker/imarker.h @@ -9,6 +9,8 @@ class IMarker unsigned int cur_location; std::vector markers; public: + IMarker(); + virtual ~IMarker(); void advance(void); unsigned int location(void); void location(unsigned int index); diff --git a/tests/test_imarker.cpp b/tests/test_imarker.cpp new file mode 100644 index 0000000..4b3d6a0 --- /dev/null +++ b/tests/test_imarker.cpp @@ -0,0 +1,81 @@ +// Unit Test Framework Includes +#include "UnitTest++.h" + +// Supporting Includes + +// File To Test +#include "imarker.h" + +using namespace UnitTest; + +//----------------------------------------------------------------------------- +// Helper Functions +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +// Begin Unit Tests +//----------------------------------------------------------------------------- +namespace { + //------------------------------------------------------------------------- + // Test location() setter and getter + //------------------------------------------------------------------------- + TEST(Verify_location_returns_the_current_index_location) + { + IMarker marker; + + CHECK( 0 == marker.location() ); + marker.location(1); + CHECK( 1 == marker.location() ); + marker.location(2); + CHECK( 2 == marker.location() ); + marker.location(42); + CHECK( 42 == marker.location() ); + } + + //------------------------------------------------------------------------- + // Test advance() method + //------------------------------------------------------------------------- + TEST(Verify_advance_increments_the_index_value) + { + IMarker marker; + CHECK( 0 == marker.location() ); + marker.advance(); + CHECK( 1 == marker.location() ); + marker.advance(); + CHECK( 2 == marker.location() ); + marker.advance(); + CHECK( 3 == marker.location() ); + } + + //------------------------------------------------------------------------- + // Test mark() and release() methods + //------------------------------------------------------------------------- + TEST(Verify_mark_and_release_will_mark_indexes_and_roll_back_to_those_locations) + { + IMarker marker; + CHECK( 0 == marker.mark() ); + marker.location(10); + CHECK( 10 == marker.mark() ); + marker.location(42); + marker.release(); + CHECK( 10 == marker.location() ); + marker.release(); + CHECK( 0 == marker.location() ); + } + + //------------------------------------------------------------------------- + // Test isMarked() method + //------------------------------------------------------------------------- + TEST(Verify_isMarked_returns_false_if_no_marks) + { + IMarker marker; + CHECK( false == marker.isMarked() ); + } + + TEST(Verify_isMarked_returns_true_if_marked) + { + IMarker marker; + marker.mark(); + CHECK( true == marker.isMarked() ); + } +} -- 2.54.0