userver: /data/code/userver/libraries/proto-structs/codegen-tests/src/box/autobox/dependency_on_self_test.cpp Source File
Loading...
Searching...
No Matches
dependency_on_self_test.cpp
1#include <gtest/gtest.h>
2
3#include <optional>
4#include <vector>
5
6#include <userver/utils/box.hpp>
7
8#include <box/autobox/dependency_on_self.structs.usrv.pb.hpp>
9#include <test_utils/type_assertions.hpp>
10
11USERVER_NAMESPACE_BEGIN
12
13TEST(BoxDependencyOnSelf, Direct) {
14 using Scope = box::autobox::structs::DependencyOnSelfDirect;
15 // Boost.Pfr refuses to process a struct in which first field is constructible from the same struct.
16 // So we can't use Boost.Pfr to check that `Scope` has exactly 1 field.
17 AssertFieldType<decltype(Scope::field), utils::Box<Scope>>();
18}
19
20TEST(BoxDependencyOnSelf, Nested) {
21 using Scope = box::autobox::structs::DependencyOnSelfNested;
22 AssertFieldCount<Scope::Nested, 1>();
23 AssertFieldType<decltype(Scope::Nested::field), utils::Box<Scope>>();
24}
25
26TEST(BoxDependencyOnSelf, Optional) {
27 using Scope = box::autobox::structs::DependencyOnSelfOptional;
28 {
29 // Boost.Pfr refuses to process a struct in which first field is constructible from the same struct.
30 // So we can't use Boost.Pfr to check that `Scope` has exactly 1 field.
31 const auto [_] = Scope{};
32 }
33 AssertFieldType<decltype(Scope::field), std::optional<utils::Box<Scope>>>();
34}
35
36TEST(BoxDependencyOnSelf, Repeated) {
37 using Scope = box::autobox::structs::DependencyOnSelfRepeated;
38 AssertFieldCount<Scope, 1>();
39 AssertFieldType<decltype(Scope::field), std::vector<Scope>>();
40}
41
42TEST(BoxDependencyOnSelf, DependencyWithin) {
43 using Scope = box::autobox::structs::DependencyWithinSelf;
44 AssertFieldCount<Scope::B, 1>();
45 AssertFieldType<decltype(Scope::B::field), Scope::A>();
46}
47
48TEST(BoxDependencyOnSelf, DependencyOnSelfCollateral) {
49 using Scope = box::autobox::structs::DependencyOnSelfCollateral;
50
51 {
52 // Boost.Pfr refuses to process a struct in which first field is constructible from the same struct.
53 // So we can't use Boost.Pfr to check that `Scope` has exactly 1 field.
54 const auto [_] = Scope{};
55 }
56 AssertFieldType<decltype(Scope::field), std::optional<utils::Box<Scope>>>();
57
58 AssertFieldCount<Scope::B, 1>();
59 AssertFieldType<decltype(Scope::B::field), Scope::A>();
60}