Skip to content

Commit

Permalink
test: add runtime testing for C++ (#1364)
Browse files Browse the repository at this point in the history
* test: add c++ runtime tests

Signed-off-by: Kartik Jolapara <[email protected]>

* chore: add generating and testing scripts

Signed-off-by: Kartik Jolapara <[email protected]>

* chore: add README.md and .gitignore for c++ runtime tests

Signed-off-by: Kartik Jolapara <[email protected]>

* fix: Complete the issues with json parsing in c++ runtime testing

Signed-off-by: Kartik Jolapara <[email protected]>

* feat: add ci workflow for c++ runtime testing

Signed-off-by: Kartik Jolapara <[email protected]>

* fix: change .gitignore

Signed-off-by: Kartik Jolapara <[email protected]>

* fix: clean unnecessary testing of the own implementation of serialization

Signed-off-by: Kartik Jolapara <[email protected]>

* chore: comment and remote json utility from c++ runtime testing for now not needed

Signed-off-by: Kartik Jolapara <[email protected]>

* fix: Remove hardcoded libraries and include git submodule in the c++ runtime testing

Signed-off-by: Kartik Jolapara <[email protected]>

* fix: clone git submodule in cpp runtime testing

Signed-off-by: Kartik Jolapara <[email protected]>

* fix: update submodule cloning in github workflow

Signed-off-by: Kartik Jolapara <[email protected]>

---------

Signed-off-by: Kartik Jolapara <[email protected]>
Co-authored-by: Jonas Lagoni <[email protected]>
  • Loading branch information
codingmickey and jonaslagoni authored Jul 30, 2023
1 parent d7ccab8 commit 84b0e37
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 1 deletion.
32 changes: 32 additions & 0 deletions .github/workflows/runtime-cplusplus-testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Runtime testing C++ models
on:
push:
pull_request:
types: [opened, reopened, synchronize, ready_for_review]
paths:
- 'src/generators/cplusplus/**'
- 'test/runtime/runtime-cplusplus/**'
- 'test/runtime/**cplusplus**'

jobs:
test:
name: Runtime testing C++ Models
if: "github.event.pull_request.draft == false &&!((github.actor == 'asyncapi-bot' && startsWith(github.event.pull_request.title, 'ci: update global workflows')) || (github.actor == 'asyncapi-bot' && startsWith(github.event.pull_request.title, 'chore(release):')) || (github.actor == 'allcontributors' && startsWith(github.event.pull_request.title, 'docs: add')))"
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: 14
- name: Build library
run: npm install && npm run build:prod
- name: Setup Cpp (C++ / C)
uses: aminya/[email protected]
- name: Generate C++ models
run: npm run generate:runtime:cplusplus
- name: Clone git submodules
run: git submodule update --init --recursive
- name: Run runtime tests
run: npm run test:runtime:cplusplus
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "test/runtime/runtime-cplusplus/src/utils/doctest"]
path = test/runtime/runtime-cplusplus/src/utils/doctest
url = https://github.com/doctest/doctest
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@
"test:blackbox:java": "cross-env CI=true jest ./test/blackbox/blackbox-java.spec.ts",
"test:runtime:java": "cross-env CI=true jest ./test/runtime/runtime-java.spec.ts",
"generate:runtime:java": "cross-env CI=true ts-node ./test/runtime/runtime-java.ts",
"test:runtime:cplusplus": "cross-env CI=true jest ./test/runtime/runtime-cplusplus.spec.ts",
"generate:runtime:cplusplus": "cross-env CI=true ts-node ./test/runtime/runtime-cplusplus.ts",
"test:runtime:kotlin": "cross-env CI=true jest ./test/runtime/runtime-kotlin.spec.ts",
"generate:runtime:kotlin": "cross-env CI=true ts-node ./test/runtime/runtime-kotlin.ts",
"test:runtime:rust": "cross-env CI=true jest ./test/runtime/runtime-rust.spec.ts",
Expand All @@ -123,4 +125,4 @@
"publishConfig": {
"access": "public"
}
}
}
12 changes: 12 additions & 0 deletions test/runtime/runtime-cplusplus.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { execCommand } from '../blackbox/utils/Utils';
import path from 'path';

jest.setTimeout(50000);

test('C++ runtime testing', async () => {
const compileCommand = `cd ${path.resolve(
__dirname,
'./runtime-cplusplus/src'
)} && c++ -std=c++17 -o AddressTest.out AddressTest.cpp && ./AddressTest.out`;
await execCommand(compileCommand);
});
15 changes: 15 additions & 0 deletions test/runtime/runtime-cplusplus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { CplusplusFileGenerator } from '../../src';
import path from 'path';
import input from './generic-input.json';

const generator = new CplusplusFileGenerator();

generator.generateToFiles(
input,
path.resolve(
// eslint-disable-next-line no-undef
__dirname,
'./runtime-cplusplus/src/lib/generated'
),
{ namespace: 'TestNamespace' }
);
32 changes: 32 additions & 0 deletions test/runtime/runtime-cplusplus/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Prerequisites
*.d

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app
9 changes: 9 additions & 0 deletions test/runtime/runtime-cplusplus/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Modelina C++ Runtime project

This is the Modelina C++ runtime project that is used to test the Java-generated code from Modelina at runtime to ensure that everything works as expected.

Here is how it works:

- The models are first generated during the build phase of the project, by running the root npm script `npm run generate:runtime:cplusplus`. These models are pre-defined with the [generic input](../generic-input.json).
- The tests are manually added and changed.
- When the project is tested, it tests the generated models at runtime for semantic errors.
27 changes: 27 additions & 0 deletions test/runtime/runtime-cplusplus/src/AddressTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "utils/doctest/doctest/doctest.h"
// #include "utils/nlohmann/json.hpp"

#include <string>
#include <vector>

#include "lib/generated/address.hpp"

// using json = nlohmann::json;

TEST_CASE("Should make an object of the generated class")
{
AsyncapiModels::address address;
address.street_name = "Test address 2";
address.house_number = 2.0;
address.marriage = true;
address.members = 2.0;
std::vector<std::variant<std::string, double, std::any>> array_type;
array_type.push_back(2.0);
array_type.push_back(std::string("test"));
address.array_type = array_type;
AsyncapiModels::nested_object obj;
obj.test = "test";
address.nested_object = obj;
}
1 change: 1 addition & 0 deletions test/runtime/runtime-cplusplus/src/utils/doctest
Submodule doctest added at ae7a13

0 comments on commit 84b0e37

Please sign in to comment.