[Spice-devel] [PATCH spice-streaming-agent 3/4] mjpeg-fallback-test: use BDD structure for test cases

Frediano Ziglio fziglio at redhat.com
Wed Jan 31 13:57:26 UTC 2018


> 
> Behaviour Driven Development defines self-describing, story-like
> structures for testing that at the same time document them and
> descriptive messages when a test fails.
> 
> Signed-off-by: Lukáš Hrázký <lhrazky at redhat.com>
> ---
>  src/unittests/test-mjpeg-fallback.cpp | 88
>  +++++++++++++++++++----------------
>  1 file changed, 48 insertions(+), 40 deletions(-)
> 
> diff --git a/src/unittests/test-mjpeg-fallback.cpp
> b/src/unittests/test-mjpeg-fallback.cpp
> index 08ed406..cb2cb68 100644
> --- a/src/unittests/test-mjpeg-fallback.cpp
> +++ b/src/unittests/test-mjpeg-fallback.cpp
> @@ -6,45 +6,53 @@
>  namespace ssa = SpiceStreamingAgent;
>  
>  
> -TEST_CASE("test parse options", "[mjpeg][options]")
> -{
> -    ssa::MjpegPlugin plugin;
> -
> -    SECTION("correct setup") {
> -        std::vector<ssa::ConfigureOption> options = {
> -            {"framerate", "20"},
> -            {"mjpeg.quality", "90"},
> -            {NULL, NULL}
> -        };
> -
> -        plugin.ParseOptions(options.data());
> -        ssa::MjpegSettings new_options = plugin.Options();
> -        CHECK(new_options.fps == 20);
> -        CHECK(new_options.quality == 90);
> -    }
> -
> -    SECTION("unknown option") {
> -        std::vector<ssa::ConfigureOption> options = {
> -            {"wakaka", "10"},
> -            {NULL, NULL}
> -        };
> -
> -        REQUIRE_THROWS_WITH(
> -            plugin.ParseOptions(options.data()),
> -            "Invalid option 'wakaka'."
> -        );
> -    }
> -
> -    SECTION("invalid option value") {
> -        std::vector<ssa::ConfigureOption> options = {
> -            {"framerate", "10"},
> -            {"mjpeg.quality", "toot"},
> -            {NULL, NULL}
> -        };
> -
> -        REQUIRE_THROWS_WITH(
> -            plugin.ParseOptions(options.data()),
> -            "Invalid value 'toot' for option 'mjpeg.quality'."
> -        );
> +SCENARIO("test parsing mjpeg plugin options", "[mjpeg][options]") {
> +    GIVEN("A new mjpeg plugin") {
> +        ssa::MjpegPlugin plugin;
> +
> +        WHEN("passing correct options") {
> +            std::vector<ssa::ConfigureOption> options = {
> +                {"framerate", "20"},
> +                {"mjpeg.quality", "90"},
> +                {NULL, NULL}
> +            };
> +
> +            plugin.ParseOptions(options.data());
> +            ssa::MjpegSettings new_options = plugin.Options();
> +
> +            THEN("the options are set in the plugin") {
> +                CHECK(new_options.fps == 20);
> +                CHECK(new_options.quality == 90);
> +            }
> +        }
> +
> +        WHEN("passing an unknown option") {
> +            std::vector<ssa::ConfigureOption> options = {
> +                {"wakaka", "10"},
> +                {NULL, NULL}
> +            };
> +
> +            THEN("ParseOptions throws an exception") {
> +                REQUIRE_THROWS_WITH(
> +                    plugin.ParseOptions(options.data()),
> +                    "Invalid option 'wakaka'."
> +                );
> +            }
> +        }
> +
> +        WHEN("passing an invalid option value") {
> +            std::vector<ssa::ConfigureOption> options = {
> +                {"framerate", "40"},
> +                {"mjpeg.quality", "toot"},
> +                {NULL, NULL}
> +            };
> +
> +            THEN("ParseOptions throws an exception") {
> +                REQUIRE_THROWS_WITH(
> +                    plugin.ParseOptions(options.data()),
> +                    "Invalid value 'toot' for option 'mjpeg.quality'."
> +                );
> +            }
> +        }
>      }
>  }

This patch is mainly rewriting patch 2/4 (previous one).
Why not a single patch?

Frediano


More information about the Spice-devel mailing list