-
Notifications
You must be signed in to change notification settings - Fork 358
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
Include type-info in sertype_equal for default sertype implementation #1698
Open
dpotman
wants to merge
1
commit into
eclipse-cyclonedds:master
Choose a base branch
from
dpotman:sertype-default-compare-typeinfo
base: master
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.
+123
−1
Open
Changes from all commits
Commits
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 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 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 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,20 @@ | ||
// Copyright(c) 2023 ZettaScale Technology and others | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License v. 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License | ||
// v. 1.0 which is available at | ||
// http://www.eclipse.org/org/documents/edl-v10.php. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause | ||
|
||
@final | ||
struct SertypeDefaultCompare1 { | ||
long f1; | ||
}; | ||
|
||
@final | ||
struct SertypeDefaultCompare2 { | ||
@min(1) @max(10) | ||
long f1; | ||
}; |
This file contains 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,77 @@ | ||
// Copyright(c) 2023 ZettaScale Technology and others | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License v. 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License | ||
// v. 1.0 which is available at | ||
// http://www.eclipse.org/org/documents/edl-v10.php. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause | ||
|
||
#include "CUnit/Theory.h" | ||
#include "dds/dds.h" | ||
#include "dds/ddsi/ddsi_typelib.h" | ||
#include "dds/ddsi/ddsi_typewrap.h" | ||
#include "test_common.h" | ||
#include "test_util.h" | ||
#include "SertypeData.h" | ||
|
||
CU_Test (ddsc_sertype_default, compare) | ||
{ | ||
dds_return_t ret; | ||
dds_entity_t domain = dds_create_domain (0, NULL); | ||
CU_ASSERT_FATAL (domain >= 0); | ||
dds_entity_t participant = dds_create_participant (0, NULL, NULL); | ||
CU_ASSERT_FATAL (participant >= 0); | ||
|
||
char topic_name[100]; | ||
create_unique_topic_name ("ddsc_dynamic_type", topic_name, sizeof (topic_name)); | ||
|
||
dds_topic_descriptor_t SertypeDefaultCompare1a_desc = SertypeDefaultCompare2_desc; | ||
SertypeDefaultCompare1a_desc.m_typename = "SertypeDefaultCompare1"; | ||
dds_entity_t topic1 = dds_create_topic (participant, &SertypeDefaultCompare1_desc, topic_name, NULL, NULL); | ||
dds_entity_t topic2 = dds_create_topic (participant, &SertypeDefaultCompare1a_desc, topic_name, NULL, NULL); | ||
|
||
dds_entity_t rd = dds_create_reader (participant, topic1, NULL, NULL); | ||
dds_entity_t wr = dds_create_writer (participant, topic2, NULL, NULL); | ||
sync_reader_writer (participant, rd, participant, wr); | ||
|
||
dds_typeinfo_t *rd_type_info, *wr_type_info; | ||
const struct ddsi_sertype *rd_sertype, *wr_sertype; | ||
|
||
ret = dds_get_entity_sertype (rd, &rd_sertype); | ||
CU_ASSERT_EQUAL (ret, DDS_RETCODE_OK); | ||
ret = dds_get_entity_sertype (wr, &wr_sertype); | ||
CU_ASSERT_EQUAL (ret, DDS_RETCODE_OK); | ||
|
||
#ifdef DDS_HAS_TYPE_DISCOVERY | ||
ret = dds_get_typeinfo (rd, &rd_type_info); | ||
CU_ASSERT_EQUAL_FATAL (ret, DDS_RETCODE_OK); | ||
ret = dds_get_typeinfo (wr, &wr_type_info); | ||
CU_ASSERT_EQUAL_FATAL (ret, DDS_RETCODE_OK); | ||
|
||
// Minimal types should be equal, but complete types different because of annotation on type 1a | ||
const ddsi_typeid_t * rd_type_min = ddsi_typeinfo_minimal_typeid (rd_type_info); | ||
const ddsi_typeid_t * wr_type_min = ddsi_typeinfo_minimal_typeid (wr_type_info); | ||
const ddsi_typeid_t * rd_type_compl = ddsi_typeinfo_complete_typeid (rd_type_info); | ||
const ddsi_typeid_t * wr_type_compl = ddsi_typeinfo_complete_typeid (wr_type_info); | ||
|
||
CU_ASSERT (ddsi_typeid_compare (rd_type_min, wr_type_min) == 0); | ||
CU_ASSERT (ddsi_typeid_compare (rd_type_compl, wr_type_compl) != 0); | ||
|
||
// Sertypes should be different, because of different complete types | ||
CU_ASSERT_NOT_EQUAL (rd_sertype, wr_sertype); | ||
#else | ||
ret = dds_get_typeinfo (rd, &rd_type_info); | ||
CU_ASSERT_NOT_EQUAL_FATAL (ret, DDS_RETCODE_OK); | ||
ret = dds_get_typeinfo (rd, &wr_type_info); | ||
CU_ASSERT_NOT_EQUAL_FATAL (ret, DDS_RETCODE_OK); | ||
|
||
// Sertypes should be the same, because other than type-info, types are equal | ||
CU_ASSERT_EQUAL (rd_sertype, wr_sertype); | ||
#endif | ||
|
||
dds_free_typeinfo (rd_type_info); | ||
dds_free_typeinfo (wr_type_info); | ||
} | ||
|
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.
Do we really need to deserialize here? Or can we get away with comparing the serialised representation?
For that, we would have to be certain about the endianness and padding, and perhaps something else. The first two are reasonably easy to deal with, the third is of course tricky 😄
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.
The problem is the set of hash type identifiers the type depends on, that is included in a type-info object. The spec (7.6.3.2.1) does not specify any ordering for this list (
TypeInformation.[minimal/complete].dependent_typeids
), and it is also allowed to leave out one or more type identifiers, as long as the dependent type count is correct (TypeInformation.[minimal/complete].dependent_typeid_count
).