Skip to content

Commit

Permalink
+ Тесты и тестовое приложение.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ezhik452 committed Jan 30, 2021
1 parent 3e0e3b9 commit c7435a4
Show file tree
Hide file tree
Showing 14 changed files with 20,598 additions and 35 deletions.
7 changes: 4 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ project(SimpleStaticAllocator)

set(CMAKE_CXX_STANDARD 17)

add_executable(TestApp main.cpp)
target_link_libraries(TestApp SimpleStaticAllocator)
add_subdirectory(externals/catch2)

add_subdirectory(lib)
add_subdirectory(lib)
add_subdirectory(tests)
add_subdirectory(app)
24 changes: 24 additions & 0 deletions app/AllocatorWrapper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "AllocatorWrapper.h"

namespace OS {
AllocatorLib::SimpleStaticAllocator<
AllocatorWrapper::ChunkType,
AllocatorWrapper::CHUNK_SIZE,
AllocatorWrapper::POOL_SIZE> AllocatorWrapper::allocator(lockAllocatorMutex, releaseAllocatorMutex);

void AllocatorWrapper::lockAllocatorMutex() {
//TODO: add mutex lock
}

void AllocatorWrapper::releaseAllocatorMutex() {
//TODO: add mutex release
}

AllocatorWrapper::ChunkTypePointer AllocatorWrapper::allocate() {
return allocator.allocate();
}

void AllocatorWrapper::free(ChunkTypePointer chunk) {
allocator.free(chunk);
}
}
32 changes: 32 additions & 0 deletions app/AllocatorWrapper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#ifndef _ALLOCATOR_WRAPPER_H_
#define _ALLOCATOR_WRAPPER_H_

#include "SimpleStaticAllocator.h"

namespace OS {

class AllocatorWrapper {
private:
static constexpr size_t CHUNK_SIZE = 2;
static constexpr size_t POOL_SIZE = 10;

using ChunkType = uint8_t;
using ChunkTypePointer = ChunkType *;

private:
static AllocatorLib::SimpleStaticAllocator<ChunkType, CHUNK_SIZE, POOL_SIZE> allocator;

private:
static void lockAllocatorMutex();

static void releaseAllocatorMutex();

public:
static ChunkTypePointer allocate();

static void free(ChunkTypePointer chunk);
};

}

#endif
5 changes: 5 additions & 0 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
set(target "app")

add_executable(${target} main.cpp AllocatorWrapper.cpp AllocatorWrapper.h)

target_link_libraries(${target} PRIVATE simpleStaticAllocator)
7 changes: 7 additions & 0 deletions app/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "AllocatorWrapper.h"

int main()
{
auto chunk = OS::AllocatorWrapper::allocate();
OS::AllocatorWrapper::free(chunk);
}
5 changes: 5 additions & 0 deletions externals/catch2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
set(target "catch2")

add_library(${target} src/catch_amalgamated.cpp)

target_include_directories(${target} PUBLIC include)
Loading

0 comments on commit c7435a4

Please sign in to comment.