nearby: snapshot as of cl/296436629

Signed-off-by: Alexey Polyudov <apolyudov@google.com>
Change-Id: I2cf5bf225b76f4c1541954651f3a7544a14e0cec
This commit is contained in:
Alexey Polyudov
2020-04-04 12:52:31 -07:00
parent 598516303b
commit 204f76077d
195 changed files with 27318 additions and 0 deletions
+47
View File
@@ -0,0 +1,47 @@
#include "platform/container_of.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
namespace location::nearby {
TEST(OffsetOf, OffsetOfTest) {
struct [[gnu::packed]] S {
char x;
double y;
};
EXPECT_EQ(OffsetOf(&S::x), 0U);
EXPECT_EQ(OffsetOf(&S::y), sizeof(S::x));
}
TEST(OffsetOf, ExplicitOffsetOfTest) {
struct [[gnu::packed]] S1 { int x; };
struct [[gnu::packed]] S2 { double y; };
struct [[gnu::packed]] S : public S1, S2 { char t; };
EXPECT_EQ((OffsetOf<decltype(std::declval<S>().x), S>(&S::x)), 0U);
EXPECT_EQ((OffsetOf<decltype(std::declval<S>().y), S>(&S::y)), sizeof(S::x));
}
TEST(ContainerOf, ContainerOfTest) {
struct [[gnu::packed]] S {
char x;
double y;
} s;
char* p = &s.x;
double* q = &s.y;
EXPECT_EQ(ContainerOf(p, &S::x), &s);
EXPECT_EQ(ContainerOf(q, &S::y), &s);
}
TEST(ContainerOf, ContainerOfTestConst) {
struct [[gnu::packed]] S {
char x;
double y;
} s;
const char* p = &s.x;
const double* q = &s.y;
EXPECT_EQ(ContainerOf(p, &S::x), &s);
EXPECT_EQ(ContainerOf(q, &S::y), &s);
}
} // namespace location::nearby