]> git.mdlowis.com Git - archive/parse-utils.git/commitdiff
Completed tests for imarker
authorMike D. Lowis <mike@mdlowis.com>
Mon, 25 Jun 2012 20:47:54 +0000 (16:47 -0400)
committerMike D. Lowis <mike@mdlowis.com>
Mon, 25 Jun 2012 20:47:54 +0000 (16:47 -0400)
source/marker/imarker.cpp
source/marker/imarker.h
tests/test_imarker.cpp [new file with mode: 0644]

index 694406b8d85175f01fc04f9b2f6edac0d63c4208..91a1c137926a92beafa38e939de171aaed97dce1 100644 (file)
@@ -1,5 +1,13 @@
 #include "imarker.h"
 
+IMarker::IMarker() : cur_location(0)
+{
+}
+
+IMarker::~IMarker()
+{
+}
+
 void IMarker::advance(void)
 {
     cur_location++;
index 2dab5f6d3ef1219a85f8d9eb43fe9d5999718eee..d681ead2de65a3a1cca9794b3d5031169c7d5e97 100644 (file)
@@ -9,6 +9,8 @@ class IMarker
         unsigned int cur_location;
         std::vector<unsigned int> 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 (file)
index 0000000..4b3d6a0
--- /dev/null
@@ -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() );
+    }
+}