CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AP_Common/tests/test_cpp.cpp
Views: 1799
1
#include <AP_gtest.h>
2
#include <AP_Common/AP_Common.h>
3
4
int hal = 0;
5
6
class DummyDummy {
7
public:
8
double d = 42.0;
9
uint8_t count = 1;
10
};
11
12
TEST(AP_Common, TEST_CPP)
13
{
14
DummyDummy * test_new = NEW_NOTHROW DummyDummy[1];
15
EXPECT_FALSE(test_new == nullptr);
16
EXPECT_TRUE(sizeof(test_new) == 8);
17
EXPECT_FLOAT_EQ(test_new->count, 1);
18
EXPECT_FLOAT_EQ(test_new->d, 42.0);
19
20
DummyDummy * test_d = (DummyDummy*) ::operator new (sizeof(DummyDummy));
21
EXPECT_FALSE(test_d == nullptr);
22
EXPECT_TRUE(sizeof(test_d) == 8);
23
EXPECT_EQ(test_d->count, 0); // constructor isn't called
24
EXPECT_FLOAT_EQ(test_d->d, 0.0);
25
26
DummyDummy * test_d2 = NEW_NOTHROW DummyDummy;
27
EXPECT_TRUE(sizeof(test_d2) == 8);
28
EXPECT_EQ(test_d2->count, 1);
29
EXPECT_FLOAT_EQ(test_d2->d, 42.0);
30
31
delete[] test_new;
32
delete test_d;
33
delete test_d2;
34
}
35
36
AP_GTEST_MAIN()
37
38