Skip to content

Commit 0a151d0

Browse files
committed
tests: cpp: Extended c++ test case to cover new/delete
Extended c++ test case to cover the zephyr implementation of new and delete. Signed-off-by: Jan Van Winkel <[email protected]>
1 parent fc99e53 commit 0a151d0

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

tests/application_development/cpp/prj.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ CONFIG_CPLUSPLUS=y
22
CONFIG_NET_BUF=y
33
CONFIG_ZTEST=y
44
CONFIG_ZTEST_STACKSIZE=2048
5+
CONFIG_MINIMAL_LIBC_MALLOC_ARENA_SIZE=128

tests/application_development/cpp/src/main.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@
3131

3232
#include <ztest.h>
3333

34+
class foo_class {
35+
public:
36+
foo_class(int foo) : foo(foo) {}
37+
int get_foo() const { return foo;}
38+
private:
39+
int foo;
40+
};
41+
3442
struct foo {
3543
int v1;
3644
};
@@ -49,7 +57,19 @@ static int test_init(struct device *dev)
4957

5058
SYS_INIT(test_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY);
5159

60+
61+
static void test_new_delete(void)
62+
{
63+
foo_class *test_foo = new foo_class(10);
64+
zassert_equal(test_foo->get_foo(), 10, NULL);
65+
delete test_foo;
66+
}
67+
5268
void test_main(void)
5369
{
54-
/* Does nothing. This is a compile only test. */
70+
ztest_test_suite(cpp_tests,
71+
ztest_unit_test(test_new_delete)
72+
);
73+
74+
ztest_run_test_suite(cpp_tests);
5575
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
tests:
22
misc.app_dev.cpp:
33
arch_exclude: posix
4-
build_only: true
4+
platform_exclude: qemu_x86_coverage
55
tags: cpp

0 commit comments

Comments
 (0)