userver: /data/code/userver/libraries/proto-structs/codegen-tests/src/oneof/custom_oneof_type_name_test.cpp Source File
Loading...
Searching...
No Matches
custom_oneof_type_name_test.cpp
1#include <gtest/gtest.h>
2
3#include <concepts>
4
5#include <userver/proto-structs/type_mapping.hpp>
6
7#include <oneof/custom_oneof_type_name.structs.usrv.pb.hpp>
8#include <test_utils/type_assertions.hpp>
9
10USERVER_NAMESPACE_BEGIN
11
12TEST(CustomOneofTypeName, Conflict1) {
13 using Scope = oneof::structs::NameConflict1;
14 AssertFieldCount<Scope::Nested, 1>();
15 // `FooIdCustom` type name was set by `option (userver.structs.oneof).generated_type_name`.
16 // Without the option, it would be called `FooId`, and there would be a naming conflict.
17 AssertFieldType<decltype(Scope::Nested::foo_id), Scope::Nested::FooIdCustom>();
18 static_assert(std::same_as<proto_structs::OneofAlternativeType<0, Scope::Nested::FooIdCustom>, Scope::FooId>);
19}
20
21TEST(CustomOneofTypeName, Conflict2) {
22 using Scope = oneof::structs::NameConflict2;
23 AssertFieldCount<Scope::Nested, 1>();
24 // `TFooIdCustom` type name was set by `option (userver.structs.oneof).generated_type_name`.
25 // Without the option, it would be called `TFooId`, and there would be a naming conflict.
26 AssertFieldType<decltype(Scope::Nested::FooId), Scope::Nested::TFooIdCustom>();
27 static_assert(std::same_as<proto_structs::OneofAlternativeType<0, Scope::Nested::TFooIdCustom>, Scope::TFooId>);
28}
29
30USERVER_NAMESPACE_END