From 11173e2c5c822283e53af1713a42b348f2e504e0 Mon Sep 17 00:00:00 2001 From: nyamatongwe Date: Mon, 15 Apr 2013 20:10:51 +1000 Subject: RunStyles can be corrupted by filling 0 length ranges and ranges that go past end so throw std::invalid_argument exceptions for these conditions. Provide a Check method to validate the consistency of a RunStyles and throw std::runtime_error if corruption is detected. --- test/unit/testRunStyles.cxx | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'test') diff --git a/test/unit/testRunStyles.cxx b/test/unit/testRunStyles.cxx index 8fec25b56..3c09dd87a 100644 --- a/test/unit/testRunStyles.cxx +++ b/test/unit/testRunStyles.cxx @@ -2,6 +2,8 @@ #include +#include + #include "Platform.h" #include "SplitVector.h" @@ -311,4 +313,20 @@ TEST_F(RunStylesTest, DeleteEndRun) { EXPECT_EQ(1, prs->EndRun(0)); EXPECT_EQ(0, prs->StartRun(1)); EXPECT_EQ(1, prs->EndRun(1)); + prs->Check(); +} + +TEST_F(RunStylesTest, OutsideBounds) { + prs->InsertSpace(0, 1); + int startFill = 1; + int lengthFill = 1; + try { + prs->FillRange(startFill, 99, lengthFill); + } catch (std::invalid_argument &) { + // Exception is supposed to occur so ignore. + } + EXPECT_EQ(1, prs->Length()); + EXPECT_EQ(1, prs->Runs()); + EXPECT_EQ(0, prs->StartRun(0)); + EXPECT_EQ(1, prs->EndRun(0)); } -- cgit v1.2.3