-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Copyright 2020 Johan Lindquist | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
project(craggy-test) | ||
set(CMAKE_CXX_STANDARD 11) | ||
|
||
# Download and unpack googletest at configure time | ||
configure_file(gtest/CMakeLists.txt.in googletest-download/CMakeLists.txt) | ||
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . | ||
RESULT_VARIABLE result | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download ) | ||
if(result) | ||
message(FATAL_ERROR "CMake step for googletest failed: ${result}") | ||
endif() | ||
execute_process(COMMAND ${CMAKE_COMMAND} --build . | ||
RESULT_VARIABLE result | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download ) | ||
if(result) | ||
message(FATAL_ERROR "Build step for googletest failed: ${result}") | ||
endif() | ||
|
||
# Prevent overriding the parent project's compiler/linker | ||
# settings on Windows | ||
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) | ||
|
||
# Add googletest directly to our build. This defines | ||
# the gtest and gtest_main targets. | ||
add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src | ||
${CMAKE_CURRENT_BINARY_DIR}/googletest-build | ||
EXCLUDE_FROM_ALL) | ||
|
||
# The gtest/gtest_main targets carry header search path | ||
# dependencies automatically when using CMake 2.8.11 or | ||
# later. Otherwise we have to add them here ourselves. | ||
if (CMAKE_VERSION VERSION_LESS 2.8.11) | ||
include_directories("${gtest_SOURCE_DIR}/include") | ||
endif() | ||
|
||
# Now simply link against gtest or gtest_main as needed. Eg | ||
add_executable(craggy-test TestCrypto.cpp) | ||
|
||
include(GoogleTest) | ||
|
||
gtest_discover_tests(craggy-test) | ||
|
||
target_link_libraries(craggy-test craggy) | ||
target_link_libraries(craggy-test gtest_main) | ||
|
||
# add_test(NAME example_test COMMAND craggy-test) | ||
include (CTest) | ||
|
||
# find_program( MEMORYCHECK_COMMAND valgrind ) | ||
# set( MEMORYCHECK_COMMAND_OPTIONS "--trace-children=yes --leak-check=full --tool=memcheck --leak-check=yes --show-reachable=yes --num-callers=20" ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* Copyright 2020 Craggy Contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <cstring> | ||
#include "gtest/gtest.h" | ||
|
||
#include "CraggyCrypto.h" | ||
|
||
namespace { | ||
|
||
TEST(CraggyCryptoTests, FillRandomBytes) { | ||
|
||
auto *originalBytes = new uint8_t[32]; | ||
memset(originalBytes,0,32); | ||
|
||
auto *bytes = new uint8_t[32]; | ||
memset(bytes,0,32); | ||
|
||
CraggyResult craggyResult = CraggyResultSuccess; | ||
|
||
bool result = craggy_fillRandomBytes(bytes, (size_t)32, &craggyResult); | ||
|
||
EXPECT_EQ(true, result); | ||
EXPECT_NE(0, std::memcmp(originalBytes, bytes, 32)); | ||
|
||
delete[] bytes; | ||
|
||
} | ||
|
||
} // namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
cmake_minimum_required(VERSION 3.12) | ||
|
||
project(googletest-download NONE) | ||
|
||
include(ExternalProject) | ||
ExternalProject_Add(googletest | ||
GIT_REPOSITORY https://github.com/google/googletest.git | ||
GIT_TAG main | ||
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src" | ||
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build" | ||
CONFIGURE_COMMAND "" | ||
BUILD_COMMAND "" | ||
INSTALL_COMMAND "" | ||
TEST_COMMAND "" | ||
) |