Unit test framework (#10)

* add first Unit Test
with gtest and cmake dependencies

* optionally build tests or not
added some realistic tests

* added ci compatible run configuration

* added test dependencies -lpthread -lm to work in debian correctly

* added some docs
and option infos
This commit is contained in:
Lukas-Heiligenbrunner
2020-05-07 19:58:16 +02:00
committed by GitHub
parent 335bcf1259
commit 463853dbd7
3 changed files with 77 additions and 4 deletions

30
tests/UnitTest.cpp Normal file
View File

@ -0,0 +1,30 @@
//
// Created by lukas on 06.05.20.
//
#include <FileLogger.h>
#include <api/IPAPI.h>
#include <climits>
#include "gtest/gtest.h"
/**
* Test if default ip is 0.0.0.0 when last ip file doesn't exist.
*/
TEST(ReadIp, testzeroIpIfNotExists) {
FileLogger logger;
std::string oldip = logger.readip();
ASSERT_EQ(oldip, "0.0.0.0");
}
/**
* Test if default ip is 0.0.0.0 when last ip file doesn't exist.
*/
TEST(IPAPI, testIpAPIcheckIPSyntax) {
IPAPI ipapi;
std::string ip = ipapi.getGlobalIp();
if (ip.find('.') == ULONG_MAX) {
// error when ip doesn't contain a .
ASSERT_TRUE(false);
} else {
ASSERT_TRUE(true);
}
}