Thomas Thomas

How to Write a C++ Test Framework

A long time ago I had a question about how Googletest or Catch2 implement their macros to run all the unit tests they write. While writing the implementation for CWT-Cucumber: A C++ Cucumber Interpreter, I needed the same mechanism to achieve this particular behaviour. Registering functions before main is executed. In this article I write a proof of concept for a C++ test framework.

Read More
Thomas Thomas

[C++] Lets Review my Article on Type Erasure

Someone pointed out that my type erasure example in the other article was broken and called a destructor twice. I investigated this and modified the example, adding an emplace method. In the end it still seems understandable to me, so lets check out this C++ Type Erasure.

Read More
Thomas Thomas

Crafting a Cucumber Interpreter in C/C++

I created a C/C++ Cucumber interpreter, based on “Crafting Interpreters” by Robert Nystrom. It compiles a feature file into byte code which is then executed by a vm. The interpreter implementation is C and there are no third party libraries needed to compile and use it. In addition I created C++ bindings to make it easier to use. Check out this article for my initial thoughts and check out the GitHub repository with the project and its examples.

Read More
Thomas Thomas

[C++] A std::tuple To Concatenate Validation Criteria

I recently had this problem that I need to store multiple validation functions which returned a bool and I didn’t want to use std::vector or any other runtime container. Concatenating if statements weren’t a good solution either. Ultimately I came up with a solution where I used std::tuple in combination with std::apply

Read More
Thomas Thomas

[C++] Use Type Erasure To Get Dynamic Polymorphic Behavior

This is a simple and short example to understand the idea of type erasure. In this article we create a simple class which can erase your concrete types and illustrates the general behavior and what it requres to have polymorphic behavior at runtime. For a more comprehensive understanding and include tests, I recommend watching Klaus Iglbergers talk about this topic from CppCon 2022.

Read More
Thomas Thomas

[C++] A Boost Asio Server-Client Example

A simple server-client example in C++ with Boost Asio. Here I create a server which can accept multiple clients. For the demonstration purpose we send a simple string to the server which is then printed to stdout. This is a really simple example but it helps especially when you start with Boost Asio and networking.

Read More
Thomas Thomas

[C++] Static, Dynamic Polymorphism, CRTP and C++20’s Concepts

C++20 offers really nice features and a very great one is concepts. In this article I compare existing techniques to implement interfaces (dynamic polymorphism, CRTP) to a new approach by using concepts. With concepts we have a lot of advantages and it affects the current way we write code. It’s clearer and it’s better to understand.

Read More
Thomas Thomas

[C++] Building And Publishing Conan Packages

Conan is a nice tool to manage packages and dependencies in C++ projects. I already wrote two articles about getting started and how to use Conan with google protobuffer. In this article I create an own library and publish it pre-build on the Artifactory. Now we can access own dependencies from our own Artifactory.

Read More
Thomas Thomas

[C++] Start Using Cucumber

The Cucumber Framewrok enables behavior driven development in your projects. Add tests in a given-when-then style which are readable for basically everyone. In this post we setup cucumber for C++ on a ubuntu machine with it’s dependencies. We’ll use googletest as testframework underneath

Read More
Thomas Thomas

[C++] A C++17 Statemachine using std::tuple and std::variant

One of my favorite design patterns is the state machine pattern. I used to do this pattern with an abstract where then all concrete states inherit from. During runtime I was able to assign new states to a state machine, let’s do this in another way to get rid of dynamic allocation with C++17

Read More
Thomas Thomas

[C/C++] A Lua C API Cheat Sheet

A cheat sheet for the Lua C API with 11 examples to pass variables, functions, tables, arrays, etc. from Lua to C and vice versa. This is a tutorial about the C API and explains how to work with the Lua stack. This is a guide to understand Lua in C and prepares to start writing on Lua bindings.

Read More
Thomas Thomas

[C++] Typed Tests For Interfaces With Googletest

Typed tests with googletest are useful when we want to test interfaces. Typed testing avoids writing redundand tests for each implementation and guarantee that the all derived classes will run the same tests.

Read More