-
Notifications
You must be signed in to change notification settings - Fork 86
mw::com: missing test cases #707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
KrishaDeshkool
wants to merge
3
commits into
eclipse-score:main
Choose a base branch
from
KrishaDeshkool:improve_test_case_fpr2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| /******************************************************************************** | ||
| * Copyright (c) 2026 Contributors to the Eclipse Foundation | ||
| * | ||
| * See the NOTICE file(s) distributed with this work for additional | ||
| * information regarding copyright ownership. | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * terms of the Apache License Version 2.0 which is available at | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| ********************************************************************************/ | ||
| #include "score/mw/com/impl/method_type.h" | ||
|
|
||
| #include <gtest/gtest.h> | ||
|
|
||
| namespace score::mw::com::impl | ||
| { | ||
| namespace | ||
| { | ||
|
|
||
| TEST(MethodTypeToStringTest, ReturnsMethodForKMethod) | ||
| { | ||
| // When converting a MethodType of kMethod to string | ||
| // Then the result is "Method" | ||
| EXPECT_EQ(to_string(MethodType::kMethod), "Method"); | ||
| } | ||
|
|
||
| TEST(MethodTypeToStringTest, ReturnsGetForKGet) | ||
| { | ||
| // When converting a MethodType of kGet to string | ||
| // Then the result is "Get" | ||
| EXPECT_EQ(to_string(MethodType::kGet), "Get"); | ||
| } | ||
|
|
||
| TEST(MethodTypeToStringTest, ReturnsSetForKSet) | ||
| { | ||
| // When converting a MethodType of kSet to string | ||
| // Then the result is "Set" | ||
| EXPECT_EQ(to_string(MethodType::kSet), "Set"); | ||
| } | ||
|
|
||
| TEST(MethodTypeToStringTest, ReturnsUnknownForKUnknown) | ||
| { | ||
| // When converting a MethodType of kUnknown to string | ||
| // Then the result is "Unknown" | ||
| EXPECT_EQ(to_string(MethodType::kUnknown), "Unknown"); | ||
| } | ||
|
|
||
| TEST(MethodTypeToStringTest, ReturnsInvalidForOutOfRangeValue) | ||
| { | ||
| // Given an out-of-range MethodType value | ||
| const auto invalid_value = static_cast<MethodType>(255U); | ||
|
|
||
| // When converting to string | ||
| // Then the result is "Invalid" | ||
| EXPECT_EQ(to_string(invalid_value), "Invalid"); | ||
| } | ||
|
|
||
| } // namespace | ||
| } // namespace score::mw::com::impl |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,13 +19,21 @@ | |
|
|
||
| #include "score/mw/com/impl/proxy_field.h" | ||
|
|
||
| #include "score/mw/com/impl/bindings/mock_binding/proxy_event.h" | ||
| #include "score/mw/com/impl/bindings/mock_binding/proxy_method.h" | ||
| #include "score/mw/com/impl/com_error.h" | ||
| #include "score/mw/com/impl/runtime.h" | ||
| #include "score/mw/com/impl/runtime_mock.h" | ||
| #include "score/mw/com/impl/test/binding_factory_resources.h" | ||
| #include "score/mw/com/impl/test/proxy_resources.h" | ||
| #include "score/mw/com/impl/test/runtime_mock_guard.h" | ||
|
|
||
| #include <gmock/gmock.h> | ||
| #include <gtest/gtest.h> | ||
| #include <array> | ||
| #include <cstddef> | ||
| #include <memory> | ||
| #include <string_view> | ||
| #include <type_traits> | ||
|
|
||
| namespace score::mw::com::impl | ||
|
|
@@ -330,5 +338,129 @@ TEST(ProxyFieldNotifierGatingTest, OnlyNotifierApiExistsWhenNoTagsArePresent) | |
| static_assert(!has_set<DefaultField>::value); | ||
| } | ||
|
|
||
| /// \brief Test fixture for the runtime behavior of ProxyField's Get / Set API. | ||
| class ProxyFieldGetSetFixture : public ::testing::Test | ||
| { | ||
| public: | ||
| void SetUp() override | ||
| { | ||
| ON_CALL(runtime_mock_guard_.runtime_mock_, GetTracingFilterConfig()).WillByDefault(Return(nullptr)); | ||
|
|
||
| ON_CALL(get_method_binding_mock_, GetReturnValueBuffer(0)) | ||
| .WillByDefault(Return(score::Result<score::cpp::span<std::byte>>{ | ||
| score::cpp::span{return_type_buffer_.data(), return_type_buffer_.size()}})); | ||
| ON_CALL(get_method_binding_mock_, GetInArgsBuffer(0)) | ||
| .WillByDefault(Return(score::Result<score::cpp::span<std::byte>>{ | ||
| score::cpp::span{in_args_buffer_.data(), in_args_buffer_.size()}})); | ||
| ON_CALL(get_method_binding_mock_, DoCall(0)).WillByDefault(Return(score::ResultBlank{})); | ||
|
|
||
| ON_CALL(set_method_binding_mock_, GetReturnValueBuffer(0)) | ||
| .WillByDefault(Return(score::Result<score::cpp::span<std::byte>>{ | ||
| score::cpp::span{return_type_buffer_.data(), return_type_buffer_.size()}})); | ||
| ON_CALL(set_method_binding_mock_, GetInArgsBuffer(0)) | ||
| .WillByDefault(Return(score::Result<score::cpp::span<std::byte>>{ | ||
| score::cpp::span{in_args_buffer_.data(), in_args_buffer_.size()}})); | ||
| ON_CALL(set_method_binding_mock_, DoCall(0)).WillByDefault(Return(score::ResultBlank{})); | ||
| } | ||
|
|
||
| ProxyField<TestSampleType, WithGetter> CreateFieldWithGetOnly(const std::string_view name = "TestField") | ||
| { | ||
| return ProxyField<TestSampleType, WithGetter>{ | ||
| name, | ||
| std::make_unique<mock_binding::ProxyEventFacade<TestSampleType>>(proxy_event_mock_), | ||
| nullptr, | ||
| std::make_unique<mock_binding::ProxyMethodFacade>(get_method_binding_mock_)}; | ||
| } | ||
|
|
||
| ProxyField<TestSampleType, WithSetter, WithNotifier> CreateFieldWithSetAndNotifier( | ||
| const std::string_view name = "TestField") | ||
| { | ||
| return ProxyField<TestSampleType, WithSetter, WithNotifier>{ | ||
| name, | ||
| std::make_unique<mock_binding::ProxyEventFacade<TestSampleType>>(proxy_event_mock_), | ||
| std::make_unique<mock_binding::ProxyMethodFacade>(set_method_binding_mock_)}; | ||
| } | ||
|
|
||
| alignas(8) std::array<std::byte, 1024U> return_type_buffer_{}; | ||
| alignas(8) std::array<std::byte, 1024U> in_args_buffer_{}; | ||
| RuntimeMockGuard runtime_mock_guard_{}; | ||
| mock_binding::ProxyEvent<TestSampleType> proxy_event_mock_{}; | ||
| mock_binding::ProxyMethod get_method_binding_mock_{}; | ||
| mock_binding::ProxyMethod set_method_binding_mock_{}; | ||
| }; | ||
|
|
||
| TEST_F(ProxyFieldGetSetFixture, GetDelegatesToProxyMethodBinding) | ||
| { | ||
| // Given a Get-enabled ProxyField and a mock method binding with a value pre-written into the return buffer | ||
| auto field = CreateFieldWithGetOnly(); | ||
| const TestSampleType expected_value{123U}; | ||
| return_type_buffer_[0] = static_cast<std::byte>(expected_value); | ||
|
|
||
| // Expecting that the binding returns a buffer for the return value and then calls the method | ||
| EXPECT_CALL(get_method_binding_mock_, GetReturnValueBuffer(0U)); | ||
| EXPECT_CALL(get_method_binding_mock_, DoCall(0U)); | ||
|
|
||
| // When calling Get() | ||
| auto result = field.Get(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you also put a value in the return buffer and check that it's returned in result? |
||
|
|
||
| // Then the call succeeds and returns the buffered value | ||
| ASSERT_TRUE(result.has_value()); | ||
| EXPECT_EQ(*result.value(), expected_value); | ||
| } | ||
|
|
||
| TEST_F(ProxyFieldGetSetFixture, SetDelegatesToProxyMethodBindingAndCopiesValueIntoInArgsBuffer) | ||
| { | ||
| // Given a ProxyField with a setter (WithSetter, WithNotifier) | ||
| auto field = CreateFieldWithSetAndNotifier(); | ||
| const TestSampleType value{42U}; | ||
|
|
||
| // Expecting that the binding returns buffers for in-args and return value and then calls the method | ||
| EXPECT_CALL(set_method_binding_mock_, GetInArgsBuffer(0U)); | ||
| EXPECT_CALL(set_method_binding_mock_, GetReturnValueBuffer(0U)); | ||
| EXPECT_CALL(set_method_binding_mock_, DoCall(0U)); | ||
|
|
||
| // When Set is called | ||
| auto result = field.Set(value); | ||
|
|
||
| // Then the call succeeds and the value lands in the in-args buffer | ||
| ASSERT_TRUE(result.has_value()); | ||
| EXPECT_EQ(static_cast<TestSampleType>(in_args_buffer_[0]), value); | ||
| } | ||
|
|
||
| TEST_F(ProxyFieldGetSetFixture, GetPropagatesBindingError) | ||
| { | ||
| // Given a Get-enabled ProxyField (WithGetter) | ||
| auto field = CreateFieldWithGetOnly(); | ||
|
|
||
| // Expecting that the binding returns an error when asked for the return value buffer | ||
| EXPECT_CALL(get_method_binding_mock_, GetReturnValueBuffer(0U)) | ||
| .WillOnce(Return(MakeUnexpected(ComErrc::kBindingFailure))); | ||
|
|
||
| // When calling Get() | ||
| auto result = field.Get(); | ||
|
|
||
| // Then the error is propagated back to the caller | ||
| ASSERT_FALSE(result.has_value()); | ||
| EXPECT_EQ(result.error(), ComErrc::kBindingFailure); | ||
| } | ||
|
|
||
| TEST_F(ProxyFieldGetSetFixture, SetPropagatesBindingError) | ||
| { | ||
| // Given a Set-enabled ProxyField (WithSetter, WithNotifier) | ||
| auto field = CreateFieldWithSetAndNotifier(); | ||
| const TestSampleType value{42U}; | ||
|
|
||
| // Expecting that the binding returns an error when asked for the in-args buffer | ||
| EXPECT_CALL(set_method_binding_mock_, GetInArgsBuffer(0U)) | ||
| .WillOnce(Return(MakeUnexpected(ComErrc::kBindingFailure))); | ||
|
|
||
| // When Set is called | ||
| auto result = field.Set(value); | ||
|
|
||
| // Then the error is propagated back to the caller | ||
| ASSERT_FALSE(result.has_value()); | ||
| EXPECT_EQ(result.error(), ComErrc::kBindingFailure); | ||
| } | ||
|
|
||
| } // namespace | ||
| } // namespace score::mw::com::impl | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we should also have a death test in case MethodType::kUnknown is provided (if we don't already have one)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added an assert and added a test too.