2021-06-19 12:04:17 -03:00
|
|
|
#include <AP_gtest.h>
|
2024-05-26 22:24:10 -03:00
|
|
|
#include <AP_Common/AP_Common.h>
|
2021-06-19 12:04:17 -03:00
|
|
|
|
|
|
|
int hal = 0;
|
|
|
|
|
|
|
|
class DummyDummy {
|
|
|
|
public:
|
|
|
|
double d = 42.0;
|
|
|
|
uint8_t count = 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST(AP_Common, TEST_CPP)
|
|
|
|
{
|
2024-05-26 22:24:10 -03:00
|
|
|
DummyDummy * test_new = NEW_NOTHROW DummyDummy[1];
|
2021-06-19 12:04:17 -03:00
|
|
|
EXPECT_FALSE(test_new == nullptr);
|
|
|
|
EXPECT_TRUE(sizeof(test_new) == 8);
|
2022-08-13 03:59:08 -03:00
|
|
|
EXPECT_FLOAT_EQ(test_new->count, 1);
|
|
|
|
EXPECT_FLOAT_EQ(test_new->d, 42.0);
|
2021-06-19 12:04:17 -03:00
|
|
|
|
2022-08-13 03:59:08 -03:00
|
|
|
DummyDummy * test_d = (DummyDummy*) ::operator new (sizeof(DummyDummy));
|
2021-06-19 12:04:17 -03:00
|
|
|
EXPECT_FALSE(test_d == nullptr);
|
|
|
|
EXPECT_TRUE(sizeof(test_d) == 8);
|
2022-08-13 03:59:08 -03:00
|
|
|
EXPECT_EQ(test_d->count, 0); // constructor isn't called
|
|
|
|
EXPECT_FLOAT_EQ(test_d->d, 0.0);
|
2021-06-19 12:04:17 -03:00
|
|
|
|
2024-05-26 22:24:10 -03:00
|
|
|
DummyDummy * test_d2 = NEW_NOTHROW DummyDummy;
|
2021-06-19 12:04:17 -03:00
|
|
|
EXPECT_TRUE(sizeof(test_d2) == 8);
|
|
|
|
EXPECT_EQ(test_d2->count, 1);
|
|
|
|
EXPECT_FLOAT_EQ(test_d2->d, 42.0);
|
|
|
|
|
|
|
|
delete[] test_new;
|
|
|
|
delete test_d;
|
|
|
|
delete test_d2;
|
|
|
|
}
|
|
|
|
|
2022-08-13 03:59:08 -03:00
|
|
|
AP_GTEST_MAIN()
|