Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,6 @@ nunavut_out
.hypothesis

.ropeproject

#clangd
.cache
8 changes: 8 additions & 0 deletions src/nunavut/lang/cpp/templates/ServiceType.j2
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,19 @@ struct {{service_name}}
struct _traits_
{
_traits_() = delete;
{%- if T.has_fixed_port_id %}
static constexpr bool HasFixedPortID = true;
static constexpr {{ typename_unsigned_port }} FixedPortId = {{ T.fixed_port_id }}U;
{%- else %}
static constexpr bool HasFixedPortID = false;
{%- endif %}

static constexpr bool IsServiceType = true;
static constexpr bool IsService = true;
static constexpr bool IsRequest = false;
static constexpr bool IsResponse = false;

static constexpr const char* FullNameAndVersion() { return "{{ T }}"; }
};
};

Expand Down
13 changes: 12 additions & 1 deletion test/gentest_lang/test_lang.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from nunavut._namespace import build_namespace_tree
from nunavut._utilities import YesNoDefault
from nunavut.jinja import DSDLCodeGenerator
from nunavut.lang import Language, LanguageClassLoader, LanguageContextBuilder
from nunavut.lang import Language, LanguageClassLoader, LanguageContextBuilder, UnsupportedLanguageError
from nunavut.lang.c import filter_id as c_filter_id
from nunavut.lang.cpp import filter_id as cpp_filter_id
from nunavut.lang.py import filter_id as py_filter_id
Expand Down Expand Up @@ -433,3 +433,14 @@ def test_either_target_or_extension() -> None:
.get_target_language()
.name
)


def test_experimental_language_without_enable_flag() -> None:
"""
Verify that using an experimental language without the include_experimental_languages
flag raises UnsupportedLanguageError. Covers the error path in
LanguageContextBuilder._new_language_w_experimental_handling().
"""
# cpp is experimental (stable_support is not set, defaults to False)
with pytest.raises(UnsupportedLanguageError, match=r"experimental"):
LanguageContextBuilder(include_experimental_languages=False).set_target_language("cpp").create()
6 changes: 6 additions & 0 deletions verification/cpp/suite/test_constant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const bool regulated::basics::Service::Response_0_1::_traits_::IsResponse;
const bool regulated::basics::Service::Response_0_1::_traits_::IsServiceType;
const bool regulated::basics::Service_0_1::_traits_::IsService;
const bool regulated::basics::Service_0_1::_traits_::IsServiceType;
const bool regulated::basics::Service_0_1::_traits_::HasFixedPortID;
const std::uint16_t regulated::basics::Service_0_1::_traits_::FixedPortId;

const std::size_t regulated::basics::Struct__0_1::_traits_::ArrayCapacity::i10_4;
const std::size_t regulated::basics::Struct__0_1::_traits_::ArrayCapacity::f16_le2;
Expand Down Expand Up @@ -101,6 +103,10 @@ TEST(ConstantTests, Service)
// Type parameters.
EXPECT_TRUE(regulated::basics::Service_0_1::_traits_::IsService);
EXPECT_TRUE(regulated::basics::Service_0_1::_traits_::IsServiceType);
EXPECT_TRUE(regulated::basics::Service_0_1::_traits_::HasFixedPortID);
EXPECT_THAT(regulated::basics::Service_0_1::_traits_::FixedPortId, 300);
EXPECT_THAT(regulated::basics::Service_0_1::_traits_::FullNameAndVersion(),
StrEq("regulated.basics.Service.0.1"));

EXPECT_FALSE(regulated::basics::Service::Request_0_1::_traits_::IsService);
EXPECT_TRUE(regulated::basics::Service::Request_0_1::_traits_::IsServiceType);
Expand Down
4 changes: 4 additions & 0 deletions verification/cpp/suite/test_serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ static_assert(
regulated::basics::Service_0_1::_traits_::IsServiceType,
"Service is a service type");

static_assert(
regulated::basics::Service_0_1::_traits_::HasFixedPortID,
"Service has a fixed port ID");

static_assert(
not regulated::basics::Service_0_1::Request::_traits_::IsService,
"Request is not a service");
Expand Down
Loading