Skip to content

Commit

Permalink
Added tests for CustomNetworkReply.
Browse files Browse the repository at this point in the history
  • Loading branch information
ugnelis committed May 5, 2018
1 parent 5d7b4a1 commit 7fa2234
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 3 deletions.
7 changes: 4 additions & 3 deletions tests/CMakeLists.txt
Expand Up @@ -33,14 +33,15 @@ include_directories("${PROJECT_SOURCE_DIR}/src")

# Source files.
set(SOURCE_FILES
utils/customnetworkreply_test.cpp
${PROJECT_SOURCE_DIR}/src/utils/customnetworkreply.cpp
${PROJECT_SOURCE_DIR}/src/utils/customnetworkreply.h
utils/language_test.cpp
${PROJECT_SOURCE_DIR}/src/utils/language.cpp
${PROJECT_SOURCE_DIR}/src/utils/language.h
utils/requestmanager_test.cpp
${PROJECT_SOURCE_DIR}/src/utils/requestmanager.cpp
${PROJECT_SOURCE_DIR}/src/utils/requestmanager.h
${PROJECT_SOURCE_DIR}/src/utils/customnetworkreply.cpp
${PROJECT_SOURCE_DIR}/src/utils/customnetworkreply.h)
${PROJECT_SOURCE_DIR}/src/utils/requestmanager.h)

# Tell CMake to create the executable.
add_executable(unit_tests ${SOURCE_FILES} ${RESOURCE_FILES_ADDED} ${UI_HEADERS})
Expand Down
54 changes: 54 additions & 0 deletions tests/utils/customnetworkreply_test.cpp
@@ -0,0 +1,54 @@
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include <QList>
#include <QNetworkReply>
#include "utils/customnetworkreply.h"

TEST(CustomNetworkReplyTests, setContentType_CheckContentType_True) {
CustomNetworkReply reply;
reply.setContentType("application/json");
QList<QNetworkReply::RawHeaderPair> rawHeaderList = reply.rawHeaderPairs();

ASSERT_EQ("application/json", rawHeaderList.at(0).second);
}

TEST(CustomNetworkReplyTests, setContent_GiveQStringAsAValue_True) {
CustomNetworkReply reply;
reply.setContent(QString("This is test!"));
QByteArray content = reply.readAll();

ASSERT_EQ(QString("This is test!"), content);
}

TEST(CustomNetworkReplyTests, setContent_GiveQByteArrayAsAValue_True) {
CustomNetworkReply reply;
reply.setContent(QByteArray("This is test!"));
QByteArray content = reply.readAll();

ASSERT_EQ(QString("This is test!"), content);
}

TEST(CustomNetworkReplyTests, abort_DoNotDoAnything_True) {
CustomNetworkReply reply;
reply.setContent(QByteArray(""));
QByteArray content = reply.readAll();
reply.abort();

ASSERT_EQ(QString(""), content);
}

TEST(CustomNetworkReplyTests, bytesAvailable_CheckBytes_True) {
CustomNetworkReply reply;
reply.setContent(QByteArray("This is test!"));

qint64 bytesAvailable = reply.bytesAvailable();

ASSERT_EQ(13, bytesAvailable);
}

TEST(CustomNetworkReplyTests, isSequential_CheckIfItIsSequeantial_True) {
CustomNetworkReply reply;
bool isSequential = reply.isSequential();

ASSERT_EQ(true, isSequential);
}

0 comments on commit 7fa2234

Please sign in to comment.