From 4b198ccd588b2a5e3ff27463362116175d7539b6 Mon Sep 17 00:00:00 2001 From: tastytea Date: Wed, 2 Jan 2019 10:30:05 +0100 Subject: [PATCH] Added crash / don't crash tests. --- src/tests/test_crash.cpp | 197 ++++++++++++++++++++++++++++++ src/tests/test_ltr_asymmetric.cpp | 1 - src/tests/test_ltr_symmetric.cpp | 1 - src/tests/test_sigil.cpp | 1 - 4 files changed, 197 insertions(+), 3 deletions(-) create mode 100644 src/tests/test_crash.cpp diff --git a/src/tests/test_crash.cpp b/src/tests/test_crash.cpp new file mode 100644 index 0000000..b24b14b --- /dev/null +++ b/src/tests/test_crash.cpp @@ -0,0 +1,197 @@ +#include +#include +#include +#include +#include +#include "identiconpp.hpp" + +using std::string; + +SCENARIO("Please do not crash") +{ + GIVEN("The digest: sha256(test@example.com)") + { + string digest = "973dfe463ec85785f5f95af5ba3906ee" + "db2d931c24e69824a89ea65dba4e813b"; + bool exception = false; + + WHEN("256 bits of entropy is required") + { + try + { + Identiconpp identicon(18, 28, + Identiconpp::algorithm::ltr_symmetric, + "ffffffff", + { + "000000ff", "000000ff", "000000ff", + "000000ff", "000000ff", "000000ff", + "000000ff", "000000ff", "000000ff", + "000000ff", "000000ff", "000000ff", + "000000ff", "000000ff", "000000ff" + }); + identicon.generate(digest); + } + catch (const std::exception &e) + { + exception = true; + } + THEN("Does not crash") + { + REQUIRE(exception == false); + } + } + + WHEN("sigil is fed exactly 8 bit of colors") + { + try + { + std::vector colors(256, "000000ff"); + Identiconpp identicon(1, 1, + Identiconpp::algorithm::sigil, + "ffffffff", colors); + identicon.generate(digest); + } + catch (const std::exception &e) + { + exception = true; + } + THEN("Does not crash") + { + REQUIRE(exception == false); + } + } + } +} + +SCENARIO("Please crash") +{ + GIVEN("The digest: sha256(test@example.com)") + { + string digest = "973dfe463ec85785f5f95af5ba3906ee" + "db2d931c24e69824a89ea65dba4e813b"; + bool exception = false; + + WHEN("257 bits of entropy is required") + { + try + { + Identiconpp identicon(18, 28, + Identiconpp::algorithm::ltr_symmetric, + "ffffffff", + { + "000000ff", "000000ff", "000000ff", + "000000ff", "000000ff", "000000ff", + "000000ff", "000000ff", "000000ff", + "000000ff", "000000ff", "000000ff", + "000000ff", "000000ff", "000000ff", + "000000ff" + }); + identicon.generate(digest); + } + catch (const std::exception &e) + { + exception = true; + } + THEN("Crashes") + { + REQUIRE(exception == true); + } + } + + WHEN("sigil is fed more than 8 bit of colors") + { + try + { + std::vector colors(257, "000000ff"); + Identiconpp identicon(1, 1, + Identiconpp::algorithm::sigil, + "ffffffff", colors); + identicon.generate(digest); + } + catch (const std::exception &e) + { + exception = true; + } + THEN("Crashes") + { + REQUIRE(exception == true); + } + } + + WHEN("background color has too many digits") + { + try + { + Identiconpp identicon(1, 1, + Identiconpp::algorithm::ltr_symmetric, + "ffffffffa"); + identicon.generate(digest); + } + catch (const std::exception &e) + { + exception = true; + } + THEN("Crashes") + { + REQUIRE(exception == true); + } + } + + WHEN("background color has not enough digits") + { + try + { + Identiconpp identicon(1, 1, + Identiconpp::algorithm::ltr_symmetric, + "fffffff"); + identicon.generate(digest); + } + catch (const std::exception &e) + { + exception = true; + } + THEN("Crashes") + { + REQUIRE(exception == true); + } + } + + WHEN("Foreground color has too many digits") + { + try + { + Identiconpp identicon(1, 1, + Identiconpp::algorithm::ltr_symmetric, + "ffffffff", { "000000ffa"}); + identicon.generate(digest); + } + catch (const std::exception &e) + { + exception = true; + } + THEN("Crashes") + { + REQUIRE(exception == true); + } + } + + WHEN("Foreground color has not enough digits") + { + try + { + Identiconpp identicon(1, 1, + Identiconpp::algorithm::ltr_symmetric, + "ffffffff", { "000000f"}); + identicon.generate(digest); + } + catch (const std::exception &e) + { + exception = true; + } + THEN("Crashes") + { + REQUIRE(exception == true); + } + } + } +} diff --git a/src/tests/test_ltr_asymmetric.cpp b/src/tests/test_ltr_asymmetric.cpp index caaffc3..6895352 100644 --- a/src/tests/test_ltr_asymmetric.cpp +++ b/src/tests/test_ltr_asymmetric.cpp @@ -4,7 +4,6 @@ #include "identiconpp.hpp" using std::string; -#include SCENARIO("ltr_asymmetric: Correct placement") { diff --git a/src/tests/test_ltr_symmetric.cpp b/src/tests/test_ltr_symmetric.cpp index d176705..87da324 100644 --- a/src/tests/test_ltr_symmetric.cpp +++ b/src/tests/test_ltr_symmetric.cpp @@ -4,7 +4,6 @@ #include "identiconpp.hpp" using std::string; -#include SCENARIO("ltr_symmetric: Correct placement") { diff --git a/src/tests/test_sigil.cpp b/src/tests/test_sigil.cpp index 2a9a06a..be2c782 100644 --- a/src/tests/test_sigil.cpp +++ b/src/tests/test_sigil.cpp @@ -4,7 +4,6 @@ #include "identiconpp.hpp" using std::string; -#include SCENARIO("sigil: Correct placement") {