Skip to content

C Code Generation for SCTUnit with GTest

This example demonstrates how to generate GTest code from SCTUnit tests and how to set everything up. The test program can be compiled, executed and integrated in your build process easily.

Example application

The example application and SCTUnit test is based on the previous example Testing State Machines with SCTUnit.

Light switch model

GoogleTest - GTest

GTest is a multi-platform testing framework written in C++ by Google. It allows writing tests for C and C++. You can find the repository here:

Installing GTest

The installation of GTest is based on your operating system. Google provides generic installation instructions:

Setup Projects Properties

For compiling a C++ project in Eclipse is required. Additionnally, the gmock_main and pthread library must be added to the C++ Linker is required. For this test project, the project has already been configured. However, if you want to create your own projects executing tests, you need to add the libraries them. Note: The including order of the library is important!

C++ Linker

Test Code Generation

Code generation for C code has already shown step by step in the previous example C Code Generation. This example contains a code generator c.sgen file for generating the state machine code, which is required. Additionally to that, the tests folder contains a code generator file for the SCTUnit file: c_test.sgen. The generator ID for this example is sctunit::c. You can right click the generator file and generate the code artifacts. This will generate a GTest file (.cc), which can be compiled and executed. You can change the test file and regenerate the test.

Compiling and execution

After generating the code, the project can be compiled: Right click->Build project. After this you can run the created binary. This is the test output:

GTest output

Download examples

Drag to install

Drag to your running itemis CREATE (min. version 2.8.0) workspace.

Back to overview