Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CoDeLib/Test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
add_executable(CoDeLib_Test
src/main.c
src/TestDeflateInflateZlib.c)

target_include_directories(CoDeLib_Test PUBLIC
Expand All @@ -15,6 +16,9 @@ FetchContent_Declare(
GIT_TAG 860062d51b2e8a75d150337b63ca2a472840d13c # v2.6.0
EXCLUDE_FROM_ALL
)
# Solution to use `CACHE INTERNAL` found here: https://discourse.cmake.org/t/what-is-the-correct-way-to-set-options-of-a-project-before-fetch-content/268/4
# If cache is not used, you will get `Policy CMP0077 is not set: option() honors normal variables.`
set(UNITY_EXTENSION_FIXTURE ON CACHE INTERNAL "")
FetchContent_MakeAvailable(Unity)
target_link_libraries(CoDeLib_Test PRIVATE unity)

Expand Down
36 changes: 16 additions & 20 deletions CoDeLib/Test/src/TestDeflateInflateZlib.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "unity.h"
#include "unity_fixture.h"
#include <CoDeLib/Deflate_zlib/Deflate_zlib.h>
#include <CoDeLib/Inflate_zlib/Inflate_zlib.h>
#include <CoDeLib/RaiiString/RaiiString.h>
Expand All @@ -7,17 +7,23 @@
#include <stdbool.h>
#include <stdio.h>

char *g_pFullPathToBenchmarkTestFiles = NULL;
static char *g_pFullPathToBenchmarkTestFiles = NULL;

void setUp(void) {
// set stuff up here
void SetupTestDeflateInflateZlib(char *pFullPathToBenchmarkTestFiles) {
g_pFullPathToBenchmarkTestFiles = pFullPathToBenchmarkTestFiles;
}

void tearDown(void) {
// clean stuff up here
TEST_GROUP(TestDeflateInflateZlib);

TEST_SETUP(TestDeflateInflateZlib) {
// Nothing
}

TEST_TEAR_DOWN(TestDeflateInflateZlib) {
// Nothing
}

void test_InflateZlibWorkWithDeflateZlib(void) {
TEST(TestDeflateInflateZlib, test_InflateZlibWorkWithDeflateZlib) {
FILE *pInFile = NULL;
FILE *pOutCompressedFile = NULL;
FILE *pOutDecompressedFile = NULL;
Expand All @@ -41,22 +47,12 @@ void test_InflateZlibWorkWithDeflateZlib(void) {
TEST_ASSERT_GREATER_THAN(0, GetFileSizeInBytes(pOutDecompressedFile));
TEST_ASSERT_EQUAL(INFLATE_SUCCESS, statusInflate);

FilesAreEqual(pInFile, pOutDecompressedFile);
TEST_ASSERT(FilesAreEqual(pInFile, pOutDecompressedFile));
fclose(pInFile);
fclose(pOutCompressedFile);
fclose(pOutDecompressedFile);
}

int main(int argc, char **argv) {
// TODO: use getopt(...)
if (argc == 1) {
printf("No arguments provided\n");
return 1;
} else {
g_pFullPathToBenchmarkTestFiles = argv[1];
}

UNITY_BEGIN();
RUN_TEST(test_InflateZlibWorkWithDeflateZlib);
return UNITY_END();
TEST_GROUP_RUNNER(TestDeflateInflateZlib) {
RUN_TEST_CASE(TestDeflateInflateZlib, test_InflateZlibWorkWithDeflateZlib);
}
3 changes: 3 additions & 0 deletions CoDeLib/Test/src/TestDeflateInflateZlib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

void SetupTestDeflateInflateZlib(char *pFullPathToBenchmarkTestFiles);
22 changes: 22 additions & 0 deletions CoDeLib/Test/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "unity_fixture.h"

#include "TestDeflateInflateZlib.h"
#include <CoDeLib/RaiiString/RaiiString.h>

static void RunAllTests(void) { RUN_TEST_GROUP(TestDeflateInflateZlib); }

int main(int argc, const char **argv) {
char *pFullPathToBenchmarkTestFiles;

// TODO: use getopt(...)
if (argc == 1) {
printf("No arguments provided\n");
return 1;
} else {
pFullPathToBenchmarkTestFiles = (char *)argv[1];
}

SetupTestDeflateInflateZlib(pFullPathToBenchmarkTestFiles);

return UnityMain(argc, argv, RunAllTests);
}
30 changes: 20 additions & 10 deletions Scripts/RunTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ def RunTests(
buildEnv: EnvironmentConfig.EnvironmentConfiguration,
buildConfig: EnvironmentConfig.BuildConfig,
testList: List[str],
) -> List[str]:
) -> tuple[bool, List[str]]:
RawTestResultsFileNames = []
success = True

BuildTypeString = EnvironmentConfig.BuildConfig.ToCMakeBuildType(buildConfig)
targetPlatformString = EnvironmentConfig.Platform.PlatformToOsName(
Expand Down Expand Up @@ -118,18 +119,19 @@ def RunTests(

TestResultsFileRaw = open(RawTestResultsFileNames[-1], "w")

subprocess.run(
result = subprocess.run(
TestCommand,
shell=True,
check=True,
check=False,
stdout=TestResultsFileRaw,
)

PrependTestHeaderInRawResultsFile(testHeader, RawTestResultsFileNames[-1])

TestResultsFileRaw.close()

return RawTestResultsFileNames
if result.returncode != 0:
success = False

return (success, RawTestResultsFileNames)


# =====================================================================================
Expand All @@ -147,13 +149,21 @@ def RunTests(
RepositoryRootPath, targetPlatform
)

RawResultFiles = RunTests(BuildEnv, EnvironmentConfig.BuildConfig.DEBUG, TestList)
AppendTestResultToTotalResultFile(TestResultsFileName, RawResultFiles)
[successDebug, RawResultFilesDebug] = RunTests(
BuildEnv, EnvironmentConfig.BuildConfig.DEBUG, TestList
)
AppendTestResultToTotalResultFile(TestResultsFileName, RawResultFilesDebug)

RawResultFiles = RunTests(BuildEnv, EnvironmentConfig.BuildConfig.RELEASE, TestList)
AppendTestResultToTotalResultFile(TestResultsFileName, RawResultFiles)
[successRelease, RawResultFilesRelease] = RunTests(
BuildEnv, EnvironmentConfig.BuildConfig.RELEASE, TestList
)
AppendTestResultToTotalResultFile(TestResultsFileName, RawResultFilesRelease)

# Print the content of BenchmarkResultFileName to the console
print("\n")
with open(TestResultsFileName, "r") as file:
print(file.read())

if not successDebug or not successRelease:
print("Test failed")
exit(1)