Commit c8c62e8c authored by Adrien Dorsaz's avatar Adrien Dorsaz

tests: brace position and indentation

parent 648f5b5e
#include "catch2/catch.hpp"
#include "xmpp/Account.cpp"
SCENARIO("xmpp account creation with jid only", "[xmpp][account]") {
GIVEN("a Jabber Id") {
SCENARIO("xmpp account creation with jid only", "[xmpp][account]")
{
GIVEN("a Jabber Id")
{
ustring jid = "foo.bar@example.com"s;
WHEN("the jabber id is valid") {
THEN("the account is created") {
WHEN("the jabber id is valid")
{
THEN("the account is created")
{
REQUIRE_NOTHROW(Xmpp::Account {jid});
}
AND_THEN("the host meta URI is defined") {
AND_THEN("the host meta URI is defined")
{
REQUIRE((Xmpp::Account {jid}).hostMetaURI());
}
}
WHEN("the jabber id is empty") {
WHEN("the jabber id is empty")
{
jid = ""s;
THEN("exception is thrown") {
THEN("exception is thrown")
{
REQUIRE_THROWS(Xmpp::Account {jid});
}
}
WHEN("the jabber id has not any at symbol") {
WHEN("the jabber id has not any at symbol")
{
jid = "foo.bar.example.com"s;
THEN("exception is thrown") {
THEN("exception is thrown")
{
REQUIRE_THROWS(Xmpp::Account {jid});
}
}
WHEN("the jabber id has two at symbol") {
WHEN("the jabber id has two at symbol")
{
jid += "@"s;
THEN("exception is thrown") {
THEN("exception is thrown")
{
REQUIRE_THROWS(Xmpp::Account {jid});
}
}
WHEN("the jabber id contains a resource") {
WHEN("the jabber id contains a resource")
{
jid += "/resource"s;
THEN("exception is thrown") {
THEN("exception is thrown")
{
REQUIRE_THROWS(Xmpp::Account {jid});
}
}
}
}
SCENARIO("xmpp account creation with jid and webSocketURI (like from settings)", "[xmpp][account]") {
GIVEN("a jabber id and a websocket URI") {
SCENARIO("xmpp account creation with jid and webSocketURI (like from settings)", "[xmpp][account]")
{
GIVEN("a jabber id and a websocket URI")
{
ustring jid = "foo.bar@example.com"s;
ustring webSocketURI = "wss://example.com:1234/ws"s;
WHEN ("the jabber id is valid and the webSocketURI is valid") {
THEN("the account is created") {
WHEN ("the jabber id is valid and the webSocketURI is valid")
{
THEN("the account is created")
{
REQUIRE_NOTHROW(Xmpp::Account {jid, webSocketURI});
}
AND_THEN("the host meta URI is defined") {
AND_THEN("the host meta URI is defined")
{
REQUIRE((Xmpp::Account {jid, webSocketURI}).hostMetaURI());
}
AND_THEN("the web socket URI is defined") {
AND_THEN("the web socket URI is defined")
{
REQUIRE((Xmpp::Account {jid, webSocketURI}).webSocketURI());
}
}
WHEN ("the jabber id is valid and the webSocketURI is invalid") {
WHEN ("the jabber id is valid and the webSocketURI is invalid")
{
webSocketURI = "notvalid"s;
THEN("the account is created") {
THEN("the account is created")
{
REQUIRE_NOTHROW(Xmpp::Account {jid, webSocketURI});
}
AND_THEN("the host meta URI is defined") {
AND_THEN("the host meta URI is defined")
{
REQUIRE((Xmpp::Account {jid, webSocketURI}).hostMetaURI());
}
AND_THEN("the web socket URI is not defined") {
AND_THEN("the web socket URI is not defined")
{
REQUIRE_FALSE((Xmpp::Account {jid, webSocketURI}).webSocketURI());
}
}
......
......@@ -8,84 +8,103 @@
using namespace fakeit;
SCENARIO("xmpp client create", "[xmpp][client]") {
GIVEN("a Jabber Id, a HttpClient and a XRD host-name") {
SCENARIO("xmpp client create", "[xmpp][client]")
{
GIVEN("a Jabber Id, a HttpClient and a XRD host-name")
{
ustring jid = "foo.bar@example.com"s;
IHttpClient *httpClient;
WHEN("httpClient answers with HTTP Status 202 OK and a valid and complete XRD file.") {
WHEN("httpClient answers with HTTP Status 202 OK and a valid and complete XRD file.")
{
Mock<IHttpClient> mockHttpClient;
When(Method(mockHttpClient, send)).AlwaysDo([](auto message){
const char* xrd = XRD_VALID;
soup_message_set_response(message,
"application/xml",
SOUP_MEMORY_COPY,
xrd,
strlen(xrd)
);
soup_message_body_flatten(message->response_body);
return SOUP_STATUS_OK;
});
When(Method(mockHttpClient, send)).AlwaysDo(
[](auto message)
{
const char* xrd = XRD_VALID;
soup_message_set_response(message,
"application/xml",
SOUP_MEMORY_COPY,
xrd,
strlen(xrd)
);
soup_message_body_flatten(message->response_body);
return SOUP_STATUS_OK;
}
);
httpClient = &mockHttpClient.get();
THEN("not any exception is thrown, client can be used") {
THEN("not any exception is thrown, client can be used")
{
REQUIRE_NOTHROW(Xmpp::Client {{jid}, httpClient});
Verify(Method(mockHttpClient, send));
}
}
WHEN("httpClient answers with HTTP Status 202 OK and a valid XRD file, but without link.") {
WHEN("httpClient answers with HTTP Status 202 OK and a valid XRD file, but without link.")
{
Mock<IHttpClient> mockHttpClient;
When(Method(mockHttpClient, send)).AlwaysDo([](auto message){
const char* xrd = XRD_VALID_NOLINK;
soup_message_set_response(message,
"application/xml",
SOUP_MEMORY_COPY,
xrd,
strlen(xrd)
);
soup_message_body_flatten(message->response_body);
return SOUP_STATUS_OK;
});
When(Method(mockHttpClient, send)).AlwaysDo(
[](auto message)
{
const char* xrd = XRD_VALID_NOLINK;
soup_message_set_response(message,
"application/xml",
SOUP_MEMORY_COPY,
xrd,
strlen(xrd)
);
soup_message_body_flatten(message->response_body);
return SOUP_STATUS_OK;
}
);
httpClient = &mockHttpClient.get();
THEN("exception is thrown, client is not usable") {
THEN("exception is thrown, client is not usable")
{
REQUIRE_THROWS(Xmpp::Client {{jid}, httpClient});
Verify(Method(mockHttpClient, send));
}
}
WHEN("httpClient does not answer with HTTP Status 202 OK.") {
WHEN("httpClient does not answer with HTTP Status 202 OK.")
{
Mock<IHttpClient> mockHttpClient;
When(Method(mockHttpClient, send)).Return(500);
httpClient = &mockHttpClient.get();
THEN("exception is thrown, client is not usable") {
THEN("exception is thrown, client is not usable")
{
REQUIRE_THROWS(Xmpp::Client {{jid}, httpClient});
Verify(Method(mockHttpClient, send));
}
}
WHEN("httpClient answers with HTTP Status 202 OK and an invalid XRD file.") {
WHEN("httpClient answers with HTTP Status 202 OK and an invalid XRD file.")
{
Mock<IHttpClient> mockHttpClient;
When(Method(mockHttpClient, send)).AlwaysDo([](auto message){
const char* xrd = XRD_INVALID;
soup_message_set_response(message,
"application/xml",
SOUP_MEMORY_COPY,
xrd,
strlen(xrd)
);
soup_message_body_flatten(message->response_body);
return SOUP_STATUS_OK;
});
When(Method(mockHttpClient, send)).AlwaysDo(
[](auto message)
{
const char* xrd = XRD_INVALID;
soup_message_set_response(message,
"application/xml",
SOUP_MEMORY_COPY,
xrd,
strlen(xrd)
);
soup_message_body_flatten(message->response_body);
return SOUP_STATUS_OK;
}
);
httpClient = &mockHttpClient.get();
THEN("exception is thrown, client is not usable") {
THEN("exception is thrown, client is not usable")
{
REQUIRE_THROWS(Xmpp::Client {{jid}, httpClient});
Verify(Method(mockHttpClient, send));
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment