Skip to content

Commit

Permalink
Merge branch 'task/#24776-check_utest_setup_for_libelos-cpp' into 'in…
Browse files Browse the repository at this point in the history
…tegration'

Task #24776: check utest setup for libelos cpp

See merge request elektrobit/base-os/elos!139
  • Loading branch information
gehwolf committed Oct 9, 2024
2 parents faf86b7 + 64ead5b commit 74082ce
Show file tree
Hide file tree
Showing 19 changed files with 299 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmake/project.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# SPDX-License-Identifier: MIT
set(ELOS_VERSION 0.65.0)
set(ELOS_VERSION 0.65.1)

# Attention: Aside from the version, as many things as possible in this file
# should be put into functions, as this solves potential issues with commands
Expand Down
1 change: 1 addition & 0 deletions test/utest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ if(UNIT_TESTS)
include(unit_test.cmake)
add_subdirectory(components)
add_subdirectory(libelos)
add_subdirectory(libelos-cpp)
if (ELOS_PLUGINS)
add_subdirectory(plugins)
endif (ELOS_PLUGINS)
Expand Down
7 changes: 7 additions & 0 deletions test/utest/libelos-cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# SPDX-License-Identifier: MIT

add_subdirectory(connect)
add_subdirectory(disconnect)
add_subdirectory(publish)
add_subdirectory(subscribe)

15 changes: 15 additions & 0 deletions test/utest/libelos-cpp/connect/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# SPDX-License-Identifier: MIT
find_package(safu 0.56.2 REQUIRED)
find_package(cmocka_mocks 0.54.2 REQUIRED)

enable_language(CXX)

create_unit_test(
NAME
test_libelos-cpp_connect_utest
SOURCES
case_success.cpp
connect_utest.cpp
LIBRARIES
libelos-cpp_static
)
23 changes: 23 additions & 0 deletions test/utest/libelos-cpp/connect/case_success.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: MIT
#include "connect_utest.h"

int elosTestConnectSuccessSetup(UNUSED void **state) {
return 0;
}

int elosTestConnectSuccessTeardown(UNUSED void **state) {
return 0;
}

void elosTestConnectSuccess(UNUSED void **state) {
using namespace elos;
elosSession_t *testSession = NULL;
safuResultE_t result;
Elos testObject;

TEST("connect");
SHOULD("%s", "create successfully a tcp-ip connection");

result = testObject.connect("0.0.0.0", 54321, &testSession);
assert_int_equal(result, SAFU_RESULT_OK);
}
20 changes: 20 additions & 0 deletions test/utest/libelos-cpp/connect/connect_utest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// SPDX-License-Identifier: MIT
#include "connect_utest.h"

TEST_SUITE_FUNC_PROTOTYPES(connectUtest)

int main() {
const struct CMUnitTest tests[] = {
TEST_CASE(elosTestConnectSuccess),
};

return RUN_TEST_SUITE(tests, connectUtest);
}

static int connectUtestSetup(UNUSED void **state) {
return 0;
}

static int connectUtestTeardown(UNUSED void **state) {
return 0;
}
13 changes: 13 additions & 0 deletions test/utest/libelos-cpp/connect/connect_utest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: MIT
#pragma once
#include <setjmp.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
extern "C" {
#include <cmocka.h>
}
#include <cmocka_extensions/cmocka_extensions.h>
#include <elos/libelos-cpp/libelos-cpp.h>

TEST_CASE_FUNC_PROTOTYPES(elosTestConnectSuccess)
15 changes: 15 additions & 0 deletions test/utest/libelos-cpp/disconnect/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# SPDX-License-Identifier: MIT
find_package(safu 0.56.2 REQUIRED)
find_package(cmocka_mocks 0.54.2 REQUIRED)

enable_language(CXX)

create_unit_test(
NAME
test_libelos-cpp_disconnect_utest
SOURCES
case_success.cpp
disconnect_utest.cpp
LIBRARIES
libelos-cpp_static
)
23 changes: 23 additions & 0 deletions test/utest/libelos-cpp/disconnect/case_success.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: MIT
#include "disconnect_utest.h"

int elosTestDisconnectSuccessSetup(UNUSED void **state) {
return 0;
}

int elosTestDisconnectSuccessTeardown(UNUSED void **state) {
return 0;
}

void elosTestDisconnectSuccess(UNUSED void **state) {
using namespace elos;
elosSession_t *testSession = NULL;
safuResultE_t result;
Elos testObject;

TEST("disconnect");
SHOULD("%s", "successfully close a connection");

result = testObject.disconnect(&testSession);
assert_int_equal(result, SAFU_RESULT_OK);
}
20 changes: 20 additions & 0 deletions test/utest/libelos-cpp/disconnect/disconnect_utest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// SPDX-License-Identifier: MIT
#include "disconnect_utest.h"

TEST_SUITE_FUNC_PROTOTYPES(disconnectUtest)

int main() {
const struct CMUnitTest tests[] = {
TEST_CASE(elosTestDisconnectSuccess),
};

return RUN_TEST_SUITE(tests, disconnectUtest);
}

static int disconnectUtestSetup(UNUSED void **state) {
return 0;
}

static int disconnectUtestTeardown(UNUSED void **state) {
return 0;
}
13 changes: 13 additions & 0 deletions test/utest/libelos-cpp/disconnect/disconnect_utest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: MIT
#pragma once
#include <setjmp.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
extern "C" {
#include <cmocka.h>
}
#include <cmocka_extensions/cmocka_extensions.h>
#include <elos/libelos-cpp/libelos-cpp.h>

TEST_CASE_FUNC_PROTOTYPES(elosTestDisconnectSuccess)
15 changes: 15 additions & 0 deletions test/utest/libelos-cpp/publish/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# SPDX-License-Identifier: MIT
find_package(safu 0.56.2 REQUIRED)
find_package(cmocka_mocks 0.54.2 REQUIRED)

enable_language(CXX)

create_unit_test(
NAME
test_libelos-cpp_publish_utest
SOURCES
case_success.cpp
publish_utest.cpp
LIBRARIES
libelos-cpp_static
)
24 changes: 24 additions & 0 deletions test/utest/libelos-cpp/publish/case_success.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: MIT
#include "publish_utest.h"

int elosTestPublishSuccessSetup(UNUSED void **state) {
return 0;
}

int elosTestPublishSuccessTeardown(UNUSED void **state) {
return 0;
}

void elosTestPublishSuccess(UNUSED void **state) {
using namespace elos;
elosSession_t *testSession = NULL;
elosEvent_t *testEvent = NULL;
safuResultE_t result;
Elos testObject;

TEST("publish");
SHOULD("%s", "successfully publish an event");

result = testObject.publish(&testSession, testEvent);
assert_int_equal(result, SAFU_RESULT_OK);
}
20 changes: 20 additions & 0 deletions test/utest/libelos-cpp/publish/publish_utest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// SPDX-License-Identifier: MIT
#include "publish_utest.h"

TEST_SUITE_FUNC_PROTOTYPES(publishUtest)

int main() {
const struct CMUnitTest tests[] = {
TEST_CASE(elosTestPublishSuccess),
};

return RUN_TEST_SUITE(tests, publishUtest);
}

static int publishUtestSetup(UNUSED void **state) {
return 0;
}

static int publishUtestTeardown(UNUSED void **state) {
return 0;
}
13 changes: 13 additions & 0 deletions test/utest/libelos-cpp/publish/publish_utest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: MIT
#pragma once
#include <setjmp.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
extern "C" {
#include <cmocka.h>
}
#include <cmocka_extensions/cmocka_extensions.h>
#include <elos/libelos-cpp/libelos-cpp.h>

TEST_CASE_FUNC_PROTOTYPES(elosTestPublishSuccess)
15 changes: 15 additions & 0 deletions test/utest/libelos-cpp/subscribe/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# SPDX-License-Identifier: MIT
find_package(safu 0.56.2 REQUIRED)
find_package(cmocka_mocks 0.54.2 REQUIRED)

enable_language(CXX)

create_unit_test(
NAME
test_libelos-cpp_subscribe_utest
SOURCES
case_success.cpp
subscribe_utest.cpp
LIBRARIES
libelos-cpp_static
)
28 changes: 28 additions & 0 deletions test/utest/libelos-cpp/subscribe/case_success.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: MIT
#include <cstddef>

#include "subscribe_utest.h"

int elosTestSubscribeSuccessSetup(UNUSED void **state) {
return 0;
}

int elosTestSubscribeSuccessTeardown(UNUSED void **state) {
return 0;
}

void elosTestSubscribeSuccess(UNUSED void **state) {
using namespace elos;
elosSession_t *testSession = NULL;
const char *testFilterRule = NULL;
size_t testSize = 0;
elosEventQueueId_t *testQueue = NULL;
safuResultE_t result;
Elos testObject;

TEST("subscribe");
SHOULD("%s", "Create a subscription message, send it, evaluate the response and return list of message queue ids");

result = testObject.subscribe(&testSession, &testFilterRule, testSize, testQueue);
assert_int_equal(result, SAFU_RESULT_OK);
}
20 changes: 20 additions & 0 deletions test/utest/libelos-cpp/subscribe/subscribe_utest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// SPDX-License-Identifier: MIT
#include "subscribe_utest.h"

TEST_SUITE_FUNC_PROTOTYPES(subscribeUtest)

int main() {
const struct CMUnitTest tests[] = {
TEST_CASE(elosTestSubscribeSuccess),
};

return RUN_TEST_SUITE(tests, subscribeUtest);
}

static int subscribeUtestSetup(UNUSED void **state) {
return 0;
}

static int subscribeUtestTeardown(UNUSED void **state) {
return 0;
}
13 changes: 13 additions & 0 deletions test/utest/libelos-cpp/subscribe/subscribe_utest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: MIT
#pragma once
#include <setjmp.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
extern "C" {
#include <cmocka.h>
}
#include <cmocka_extensions/cmocka_extensions.h>
#include <elos/libelos-cpp/libelos-cpp.h>

TEST_CASE_FUNC_PROTOTYPES(elosTestSubscribeSuccess)

0 comments on commit 74082ce

Please sign in to comment.