diff options
author | Neil <nyamatongwe@gmail.com> | 2013-11-18 14:44:25 +1100 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2013-11-18 14:44:25 +1100 |
commit | b9df8e756ea1531479cd6ba1ab37536a09dd9d08 (patch) | |
tree | a1898a911541d9022f5734822703876ae5989048 /test/unit | |
parent | 937808c28c8ab9e40eb9a4548407a8883f087229 (diff) | |
download | scintilla-mirror-b9df8e756ea1531479cd6ba1ab37536a09dd9d08.tar.gz |
Add some tests for CellBuffer.
Diffstat (limited to 'test/unit')
-rw-r--r-- | test/unit/makefile | 1 | ||||
-rw-r--r-- | test/unit/test.mak | 1 | ||||
-rw-r--r-- | test/unit/testCellBuffer.cxx | 140 | ||||
-rw-r--r-- | test/unit/unitTest.cxx | 11 |
4 files changed, 152 insertions, 1 deletions
diff --git a/test/unit/makefile b/test/unit/makefile index b3621ac57..de3b09d1c 100644 --- a/test/unit/makefile +++ b/test/unit/makefile @@ -39,6 +39,7 @@ CXXFLAGS += -Wall -Wextra TESTSRC=test*.cxx # Files being tested from scintilla/src directory TESTEDSRC=\ + ../../src/CellBuffer.cxx \ ../../src/CharClassify.cxx \ ../../src/ContractionState.cxx \ ../../src/Decoration.cxx \ diff --git a/test/unit/test.mak b/test/unit/test.mak index d224b9e91..934b0aa12 100644 --- a/test/unit/test.mak +++ b/test/unit/test.mak @@ -12,6 +12,7 @@ CXXFLAGS = /EHsc /wd 4805 $(INCLUDEDIRS) TESTSRC=test*.cxx # Files being tested from scintilla/src directory TESTEDSRC=\ + ../../src/CellBuffer.cxx \ ../../src/CharClassify.cxx \ ../../src/ContractionState.cxx \ ../../src/Decoration.cxx \ diff --git a/test/unit/testCellBuffer.cxx b/test/unit/testCellBuffer.cxx new file mode 100644 index 000000000..691271927 --- /dev/null +++ b/test/unit/testCellBuffer.cxx @@ -0,0 +1,140 @@ +// Unit Tests for Scintilla internal data structures + +#include <cstring> +#include <stdexcept> +#include <algorithm> + +#include "Platform.h" + +#include "SplitVector.h" +#include "Partitioning.h" +#include "RunStyles.h" +#include "CellBuffer.h" + +#include "catch.hpp" + +// Test CellBuffer. + +TEST_CASE("CellBuffer") { + + const char sText[] = "Scintilla"; + const size_t sLength = strlen(sText); + + CellBuffer cb; + + SECTION("InsertOneLine") { + bool startSequence = false; + const char *cpChange = cb.InsertString(0, sText, sLength, startSequence); + REQUIRE(startSequence); + REQUIRE(sLength == cb.Length()); + REQUIRE(memcmp(cpChange, sText, sLength) == 0); + REQUIRE(1 == cb.Lines()); + REQUIRE(0 == cb.LineStart(0)); + REQUIRE(0 == cb.LineFromPosition(0)); + REQUIRE(sLength == cb.LineStart(1)); + REQUIRE(0 == cb.LineFromPosition(sLength)); + REQUIRE(cb.CanUndo()); + REQUIRE(!cb.CanRedo()); + } + + SECTION("InsertTwoLines") { + const char sText2[] = "Two\nLines"; + const size_t sLength2 = strlen(sText2); + bool startSequence = false; + const char *cpChange = cb.InsertString(0, sText2, sLength2, startSequence); + REQUIRE(startSequence); + REQUIRE(sLength2 == cb.Length()); + REQUIRE(memcmp(cpChange, sText2, sLength2) == 0); + REQUIRE(2 == cb.Lines()); + REQUIRE(0 == cb.LineStart(0)); + REQUIRE(0 == cb.LineFromPosition(0)); + REQUIRE(4 == cb.LineStart(1)); + REQUIRE(1 == cb.LineFromPosition(5)); + REQUIRE(sLength2 == cb.LineStart(2)); + REQUIRE(1 == cb.LineFromPosition(sLength2)); + REQUIRE(cb.CanUndo()); + REQUIRE(!cb.CanRedo()); + } + + SECTION("UndoOff") { + REQUIRE(cb.IsCollectingUndo()); + cb.SetUndoCollection(false); + REQUIRE(!cb.IsCollectingUndo()); + bool startSequence = false; + const char *cpChange = cb.InsertString(0, sText, sLength, startSequence); + REQUIRE(!startSequence); + REQUIRE(sLength == cb.Length()); + REQUIRE(memcmp(cpChange, sText, sLength) == 0); + REQUIRE(!cb.CanUndo()); + REQUIRE(!cb.CanRedo()); + } + + SECTION("UndoRedo") { + const char sTextDeleted[] = "ci"; + const char sTextAfterDeletion[] = "Sntilla"; + bool startSequence = false; + const char *cpChange = cb.InsertString(0, sText, sLength, startSequence); + REQUIRE(startSequence); + REQUIRE(sLength == cb.Length()); + REQUIRE(memcmp(cpChange, sText, sLength) == 0); + REQUIRE(memcmp(cb.BufferPointer(), sText, sLength) == 0); + REQUIRE(cb.CanUndo()); + REQUIRE(!cb.CanRedo()); + const char *cpDeletion = cb.DeleteChars(1, 2, startSequence); + REQUIRE(startSequence); + REQUIRE(memcmp(cpDeletion, sTextDeleted, strlen(sTextDeleted)) == 0); + REQUIRE(memcmp(cb.BufferPointer(), sTextAfterDeletion, strlen(sTextAfterDeletion)) == 0); + REQUIRE(cb.CanUndo()); + REQUIRE(!cb.CanRedo()); + + int steps = cb.StartUndo(); + REQUIRE(steps == 1); + cb.PerformUndoStep(); + REQUIRE(memcmp(cb.BufferPointer(), sText, sLength) == 0); + REQUIRE(cb.CanUndo()); + REQUIRE(cb.CanRedo()); + + steps = cb.StartUndo(); + REQUIRE(steps == 1); + cb.PerformUndoStep(); + REQUIRE(cb.Length() == 0); + REQUIRE(!cb.CanUndo()); + REQUIRE(cb.CanRedo()); + + steps = cb.StartRedo(); + REQUIRE(steps == 1); + cb.PerformRedoStep(); + REQUIRE(memcmp(cb.BufferPointer(), sText, sLength) == 0); + REQUIRE(cb.CanUndo()); + REQUIRE(cb.CanRedo()); + + steps = cb.StartRedo(); + REQUIRE(steps == 1); + cb.PerformRedoStep(); + REQUIRE(memcmp(cb.BufferPointer(), sTextAfterDeletion, strlen(sTextAfterDeletion)) == 0); + REQUIRE(cb.CanUndo()); + REQUIRE(!cb.CanRedo()); + + cb.DeleteUndoHistory(); + REQUIRE(!cb.CanUndo()); + REQUIRE(!cb.CanRedo()); + } + + SECTION("LineEndTypes") { + REQUIRE(cb.GetLineEndTypes() == 0); + cb.SetLineEndTypes(1); + REQUIRE(cb.GetLineEndTypes() == 1); + cb.SetLineEndTypes(0); + REQUIRE(cb.GetLineEndTypes() == 0); + } + + SECTION("ReadOnly") { + REQUIRE(!cb.IsReadOnly()); + cb.SetReadOnly(true); + REQUIRE(cb.IsReadOnly()); + bool startSequence = false; + cb.InsertString(0, sText, sLength, startSequence); + REQUIRE(cb.Length() == 0); + } + +} diff --git a/test/unit/unitTest.cxx b/test/unit/unitTest.cxx index 49c8253b8..9a45b1d93 100644 --- a/test/unit/unitTest.cxx +++ b/test/unit/unitTest.cxx @@ -9,10 +9,10 @@ CharClassify Decoration DecorationList + CellBuffer To do: PerLine * - CellBuffer * Range StyledText CaseFolder ... @@ -45,3 +45,12 @@ void Platform::Assert(const char *c, const char *file, int line) { fprintf(stderr, "Assertion [%s] failed at %s %d\n", c, file, line); abort(); } + +void Platform::DebugPrintf(const char *format, ...) { + char buffer[2000]; + va_list pArguments; + va_start(pArguments, format); + vsprintf(buffer, format, pArguments); + va_end(pArguments); + fprintf(stderr, "%s", buffer); +} |