Skip to content

Commit 84f85be

Browse files
committed
Add unit tests for the template repo base
1 parent 880ccc9 commit 84f85be

3 files changed

Lines changed: 45 additions & 0 deletions

File tree

src/mfast/coder/common/template_repo.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ class template_repo_base {
3737
void add_reset_entry(value_storage *entry) {
3838
reset_entries_.push_back(entry);
3939
}
40+
#ifdef TESTING_TEMPLATE_REPO_BASE
41+
public:
42+
#endif
4043
void add_vector_entry(value_storage *entry) {
4144
if (dictionary_alloc_)
4245
vector_entries_.push_back(entry);

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ add_executable (mfast_test
6161
aggregate_view_test.cpp
6262
simple_coder_test.cpp
6363
scp_reset_test.cpp
64+
template_repo_base.cpp
6465
)
6566

6667
target_link_libraries (mfast_test

tests/template_repo_base.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include "catch.hpp"
2+
3+
#define TESTING_TEMPLATE_REPO_BASE
4+
#include <mfast/coder/common/template_repo.h>
5+
#include <mfast/value_storage.h>
6+
#include <mfast/malloc_allocator.h>
7+
#include <mfast/instructions/template_instruction.h>
8+
#include <mfast/coder/common/dictionary_builder.h>
9+
10+
class template_repo_base_impl : public mfast::template_repo_base
11+
{
12+
public:
13+
template_repo_base_impl(mfast::allocator *dictionary_alloc)
14+
: mfast::template_repo_base(dictionary_alloc) {}
15+
16+
virtual mfast::template_instruction *get_template(uint32_t)
17+
{
18+
return nullptr;
19+
}
20+
};
21+
22+
TEST_CASE("Test template repo base with repeated pointers","[test_template_repo_base]")
23+
{
24+
using namespace mfast;
25+
26+
value_storage* storage_1_ = new value_storage();
27+
{
28+
const char * test_data = "Test_Data";
29+
storage_1_->of_array.len_ = static_cast<uint32_t>(std::strlen(test_data) + 1);
30+
storage_1_->of_array.content_ = malloc_allocator::instance()->allocate(storage_1_->of_array.len_);
31+
storage_1_->of_array.capacity_in_bytes_ = 9;
32+
}
33+
34+
{
35+
template_repo_base_impl templ_repo(malloc_allocator::instance());
36+
templ_repo.add_vector_entry(storage_1_);
37+
templ_repo.add_vector_entry(storage_1_);
38+
}
39+
40+
delete storage_1_;
41+
}

0 commit comments

Comments
 (0)