/* * Copyright (c) 2018 Google LLC. * * SPDX-License-Identifier: Apache-2.0 */ /* * This is mainly a parse test that verifies that Zephyr header files * compile in C++ mode. */ #include #include #include #include #include #include #include /* #include conflicts with __bswapXX on native_posix */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* drivers/espi_saf.h requires SoC specific header */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* drivers/pinctrl.h requires SoC specific header */ #include #include #include #include #include /* drivers/reset.h conflicts with assert() for certain platforms */ #include #include #include #include #include #include #include #include #include #include #include #include /* Add RTIO headers to make sure they're CXX compatible */ #include #include #include #include class foo_class { public: foo_class(int foo) : foo(foo) {} int get_foo() const { return foo;} private: int foo; }; struct foo { int v1; }; /* Check that BUILD_ASSERT compiles. */ BUILD_ASSERT(sizeof(foo) == sizeof(int)); static struct foo foos[5]; /* Check that ARRAY_SIZE compiles. */ BUILD_ASSERT(ARRAY_SIZE(foos) == 5, "expected 5 elements"); /* Check that SYS_INIT() compiles. */ static int test_init(void) { return 0; } SYS_INIT(test_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY); /* Check that global static object constructors are called. */ foo_class static_foo(12345678); ZTEST(cxx_tests, test_global_static_ctor) { zassert_equal(static_foo.get_foo(), 12345678); } /* * Check that dynamic memory allocation (usually, the C library heap) is * functional when the global static object constructors are called. */ foo_class *static_init_dynamic_foo = new foo_class(87654321); ZTEST(cxx_tests, test_global_static_ctor_dynmem) { zassert_equal(static_init_dynamic_foo->get_foo(), 87654321); } ZTEST(cxx_tests, test_new_delete) { foo_class *test_foo = new foo_class(10); zassert_equal(test_foo->get_foo(), 10); delete test_foo; } ZTEST_SUITE(cxx_tests, NULL, NULL, NULL, NULL, NULL);