From 909b4edc8653b9a41579b9f5fac9bf83126ebd45 Mon Sep 17 00:00:00 2001 From: tastytea Date: Wed, 1 May 2019 13:01:00 +0200 Subject: [PATCH] Added tests for Easy::Application. --- README.adoc | 2 +- tests/test_application.cpp | 77 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 tests/test_application.cpp diff --git a/README.adoc b/README.adoc index e7301ec..c3d410e 100644 --- a/README.adoc +++ b/README.adoc @@ -395,7 +395,7 @@ strings and you can use unsupported fields in an `Entity` by converting it to ==== Entities * [x] Account -* [ ] Application +* [x] Application * [ ] Attachment * [ ] Card * [ ] Context diff --git a/tests/test_application.cpp b/tests/test_application.cpp new file mode 100644 index 0000000..fb42c88 --- /dev/null +++ b/tests/test_application.cpp @@ -0,0 +1,77 @@ +/* This file is part of mastodon-cpp. + * Copyright © 2019 tastytea + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include "easy/entities/application.hpp" + +using std::string; + +SCENARIO ("Easy::Application works as intended", "[entity]") +{ + GIVEN ("An Easy::Application object") + { + Mastodon::Easy::Application app; + bool exception = false; + + WHEN ("It is initialized with valid application data") + { + const string data = "{\"name\" : \"Web\", \"website\" : null}"; + + try + { + app.from_string(data); + } + catch (const std::exception &e) + { + exception = true; + } + + THEN ("No exception is thrown") + AND_THEN ("Application is valid") + AND_THEN ("The attributes are set to the right values") + { + REQUIRE_FALSE(exception); + REQUIRE(app.valid()); + + REQUIRE(app.name() == "Web"); + REQUIRE(app.website() == ""); + } + } + + WHEN ("It is initialized with an empty string") + { + try + { + app.from_string(""); + } + catch (const std::exception &e) + { + exception = true; + } + + THEN ("No exception is thrown") + AND_THEN ("It is not valid") + AND_THEN ("name is empty") + { + REQUIRE_FALSE(exception); + REQUIRE_FALSE(app.valid()); + REQUIRE(app.name() == ""); + } + } + } +}