Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Consider adding equality operators for various objects in the datamodel

未关闭
#103 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
cpp
领域
api

调研方向

从 include/up-cpp/uri/tools/Utils.h 的第 188-201 行开始,然后检查 URI 工具相等性测试以及 issue 中的 URI_UTILS testUResourceEquals 用例。验证 UResource 句柄的相等性是否一致地处理名称以及可选的实例字段或消息字段,并运行相关的 URI 工具测试,以确认失败用例和相关比较已得到解决。

由索引模型根据 Issue 内容生成。

描述

enhancement

The logic in the '==' operators for URI (and its components do not seem to be correct).

https://github.com/eclipse-uprotocol/up-cpp/blob/494b3313b55aaefe5b8b0376dd761b75fa96a78a/include/up-cpp/uri/tools/Utils.h#L188C1-L201C6

This code is only comparing the instance portion of the URI if the left hand side includes the instance. However the logic should really be like this:

    [[nodiscard]] [[maybe_unused]] auto static
    operator==(const uprotocol::v1::UResource &s, const uprotocol::v1::UResource &o) -> bool {
        // Resources are consider equal if:
        // 1. Names are equal
        // 2. Both Resources do not have an instance OR
        //    both Resource do have an instance and they are the same
        // 3. Both Resources do not have a message OR
        //    both resources have a message and they are the same
        return (s.name() == o.name()) && // Condition 1
               // Condition 2
               ((!s.has_instance() && !o.has_instance()) ||
                (s.has_instance() && o.has_instance() && s.instance() == o.instance())) && // Condition 2
               // Condition 3
               ((!s.has_message() && !o.has_message()) ||
                (s.has_message() && o.has_message() && s.message() == o.message())); // if exists must be same message
    }

A simple test case (it fails right now) shows the problem with the code as is:

TEST(URI_UTILS, testUResourceEquals) {
    using uprotocol::uri::BuildUResource;
    using uprotocol::v1::UResource;
    using uprotocol::uri::operator==;

    // Resource 1 - No Instance
    auto resource_1{BuildUResource().setName("rpc").build()};
    // Resource 2 - With Instance
    auto resource_2{BuildUResource().setName("rpc").setInstance("CreateTopic").build()};
    EXPECT_FALSE(resource_1 == resource_2);
}
主要语言
C++
星标
29
派生
32
PR 合并指标
30 天内没有已合并 PR

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

eclipse-uprotocol/up-cpp 的其他 Issue

查看 eclipse-uprotocol/up-cpp 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。