adding tests to cmake

This commit is contained in:
Christopher McArthur
2020-01-19 17:25:51 -05:00
parent 96528a8872
commit a9a1b80eda
7 changed files with 25 additions and 5 deletions

View File

@@ -29,3 +29,5 @@ set(JWT_HEADERS
${JWT_INCLUDE_PATH}/jwt-cpp/jwt.h)
install(FILES ${JWT_HEADERS} DESTINATION include/jwt-cpp)
add_subdirectory(tests)

View File

@@ -1,5 +1,5 @@
#include <gtest/gtest.h>
#include "include/jwt-cpp/base.h"
#include "jwt-cpp/base.h"
TEST(BaseTest, Base64Decode) {
ASSERT_EQ("1", jwt::base::decode<jwt::alphabet::base64>("MQ=="));

18
tests/CMakeLists.txt Normal file
View File

@@ -0,0 +1,18 @@
enable_testing()
find_package(GTest CONFIG REQUIRED)
set(TEST_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/BaseTest.cpp
${CMAKE_CURRENT_SOURCE_DIR}/ClaimTest.cpp
${CMAKE_CURRENT_SOURCE_DIR}/HelperTest.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TestMain.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TokenFormatTest.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TokenTest.cpp
)
add_executable(jwt-cpp-test ${TEST_SOURCES})
target_link_libraries(jwt-cpp-test PRIVATE jwt-cpp GTest::gtest GTest::gtest_main GTest::gmock GTest::gmock_main)
add_test(AllTests jwt-cpp-test)

View File

@@ -1,5 +1,5 @@
#include <gtest/gtest.h>
#include "include/jwt-cpp/jwt.h"
#include "jwt-cpp/jwt.h"
TEST(ClaimTest, AudienceAsString) {
std::string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJ0ZXN0In0.WZnM3SIiSRHsbO3O7Z2bmIzTJ4EC32HRBKfLznHhrh4";

View File

@@ -1,5 +1,5 @@
#include <gtest/gtest.h>
#include "include/jwt-cpp/jwt.h"
#include "jwt-cpp/jwt.h"
namespace {
extern std::string google_cert;

View File

@@ -1,5 +1,5 @@
#include <gtest/gtest.h>
#include "include/jwt-cpp/jwt.h"
#include "jwt-cpp/jwt.h"
TEST(TokenFormatTest, MissingDot) {
ASSERT_THROW(jwt::decode("eyJhbGciOiJub25lIiwidHlwIjoiSldTIn0.eyJpc3MiOiJhdXRoMCJ9"), std::invalid_argument);

View File

@@ -1,5 +1,5 @@
#include <gtest/gtest.h>
#include "include/jwt-cpp/jwt.h"
#include "jwt-cpp/jwt.h"
namespace {
extern std::string rsa_priv_key;