Copilot commented on code in PR #2170:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2170#discussion_r3189306989


##########
extension-framework/cpp-extension-lib/mocklib/src/mock-minifi-c.cpp:
##########
@@ -0,0 +1,135 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdexcept>
+
+#include "minifi-c.h"
+
+MinifiExtension* MINIFI_REGISTER_EXTENSION_FN(MinifiExtensionContext*, const 
MinifiExtensionDefinition*) {
+  throw std::runtime_error("Not implemented");
+}
+
+MinifiStatus MinifiRegisterProcessor(MinifiExtension*, const 
MinifiProcessorClassDefinition*) {
+  throw std::runtime_error("Not implemented");
+}
+
+MinifiStatus MinifiRegisterControllerService(MinifiExtension*, const 
MinifiControllerServiceClassDefinition*) {
+  throw std::runtime_error("Not implemented");
+}
+
+MINIFI_OWNED MinifiPublishedMetrics* MinifiPublishedMetricsCreate(size_t, 
const MinifiStringView*, const double*) {
+  throw std::runtime_error("Not implemented");
+}
+
+MinifiStatus MinifiProcessContextGetProperty(MinifiProcessContext*, 
MinifiStringView, MinifiFlowFile*,
+    void (*)(void* user_ctx, MinifiStringView property_value), void*) {
+  throw std::runtime_error("Not implemented");
+}
+MinifiBool MinifiProcessContextHasNonEmptyProperty(MinifiProcessContext*, 
MinifiStringView) {
+  throw std::runtime_error("Not implemented");
+}
+
+MinifiStatus MinifiProcessContextGetControllerService(MinifiProcessContext*, 
MinifiStringView, MinifiStringView, MinifiControllerService**) {
+  throw std::runtime_error("Not implemented");
+}
+void MinifiProcessContextGetDynamicProperties(MinifiProcessContext*,

Review Comment:
   `MinifiProcessContextGetDynamicProperties` definition does not match the C 
API declaration in `minifi-c.h`: it is missing the `MinifiFlowFile* 
minifi_flow_file` parameter. This will cause a conflicting declaration / link 
failure. Update the mock signature to exactly match the header (including the 
flow file parameter).
   



##########
extension-framework/cpp-extension-lib/mocklib/src/mock-minifi-c.cpp:
##########
@@ -0,0 +1,135 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdexcept>
+
+#include "minifi-c.h"
+
+MinifiExtension* MINIFI_REGISTER_EXTENSION_FN(MinifiExtensionContext*, const 
MinifiExtensionDefinition*) {
+  throw std::runtime_error("Not implemented");
+}
+
+MinifiStatus MinifiRegisterProcessor(MinifiExtension*, const 
MinifiProcessorClassDefinition*) {
+  throw std::runtime_error("Not implemented");
+}
+
+MinifiStatus MinifiRegisterControllerService(MinifiExtension*, const 
MinifiControllerServiceClassDefinition*) {
+  throw std::runtime_error("Not implemented");
+}
+
+MINIFI_OWNED MinifiPublishedMetrics* MinifiPublishedMetricsCreate(size_t, 
const MinifiStringView*, const double*) {
+  throw std::runtime_error("Not implemented");
+}
+
+MinifiStatus MinifiProcessContextGetProperty(MinifiProcessContext*, 
MinifiStringView, MinifiFlowFile*,
+    void (*)(void* user_ctx, MinifiStringView property_value), void*) {
+  throw std::runtime_error("Not implemented");
+}
+MinifiBool MinifiProcessContextHasNonEmptyProperty(MinifiProcessContext*, 
MinifiStringView) {
+  throw std::runtime_error("Not implemented");
+}
+
+MinifiStatus MinifiProcessContextGetControllerService(MinifiProcessContext*, 
MinifiStringView, MinifiStringView, MinifiControllerService**) {
+  throw std::runtime_error("Not implemented");
+}
+void MinifiProcessContextGetDynamicProperties(MinifiProcessContext*,
+    void (*)(void* user_ctx, MinifiStringView dynamic_property_name, 
MinifiStringView dynamic_property_value), void*) {
+  throw std::runtime_error("Not implemented");
+}
+
+MinifiStatus MinifiProcessContextGetSslData(MinifiProcessContext*, 
MinifiStringView,
+    void (*)(void* user_ctx, const MinifiSslData& ssl_data), void*) {

Review Comment:
   `MinifiProcessContextGetSslData` mock signature does not match `minifi-c.h`: 
the callback parameter is declared as `const MinifiSslData&`, but the API 
expects `const MinifiSslData*`. With C linkage this becomes a hard type 
conflict. Adjust the function signature (and callback type) to match the header 
exactly.
   



##########
extension-framework/cpp-extension-lib/mocklib/include/MockLogger.h:
##########
@@ -0,0 +1,36 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <map>
+#include <string>
+
+#include "minifi-cpp/core/logging/Logger.h"
+
+namespace org::apache::nifi::minifi::mock {
+class MockLogger : public core::logging::Logger {
+ public:
+  void set_max_log_size(int) override {}
+  void log_string(const core::logging::LOG_LEVEL level, std::string s) 
override { logs_[level].emplace_back(std::move(s)); }
+  [[nodiscard]] bool should_log(const core::logging::LOG_LEVEL level) override 
{ return level > log_level_; }

Review Comment:
   `MockLogger::should_log` uses `level > log_level_`, which means it will 
*not* log messages at exactly the configured level (e.g., with `trace` it drops 
trace logs). This is inconsistent with the typical logger threshold semantics 
(should log when `level >= threshold`). Adjust the comparison so the mock 
behaves like the real logger.
   



##########
extension-framework/cpp-extension-lib/mocklib/include/MockProcessSession.h:
##########
@@ -0,0 +1,82 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+#include <map>
+#include <ranges>
+
+#include "MockUtils.h"
+#include "api/core/ProcessSession.h"
+#include "range/v3/range/conversion.hpp"
+#include "range/v3/view/transform.hpp"
+
+namespace org::apache::nifi::minifi::mock {
+struct MockFlowFileData {
+  explicit MockFlowFileData(std::string content_str) {
+    this->content = content_str
+           | ranges::views::transform([](char c) { return 
static_cast<std::byte>(c); })
+           | ranges::to<std::vector<std::byte>>();
+  }
+
+  ~MockFlowFileData() = default;
+
+  MockFlowFileData() = default;
+  MockFlowFileData(const MockFlowFileData&) = default;
+  MockFlowFileData(MockFlowFileData&&) = default;
+  MockFlowFileData& operator=(const MockFlowFileData&) = default;
+  MockFlowFileData& operator=(MockFlowFileData&&) = default;
+
+  std::map<std::string, std::string> attributes;
+  std::vector<std::byte> content;
+  bool is_penalized = false;
+  std::string id;
+};
+
+class MockProcessSession : public api::core::ProcessSession {
+ public:
+  MockProcessSession() = default;
+  MockProcessSession(const MockProcessSession&) = delete;
+  MockProcessSession& operator=(const MockProcessSession&) = delete;
+  MockProcessSession(const MockProcessSession&&) = delete;
+  MockProcessSession& operator=(const MockProcessSession&&) = delete;

Review Comment:
   The deleted move operations are declared as `MockProcessSession(const 
MockProcessSession&&)` / `operator=(const MockProcessSession&&)`, which are not 
actual move ctor/assignment signatures (move should be non-const rvalue refs). 
This is confusing and can lead to unintended special member generation rules. 
Replace with `MockProcessSession(MockProcessSession&&) = delete;` and 
`MockProcessSession& operator=(MockProcessSession&&) = delete;`.
   



##########
extension-framework/cpp-extension-lib/mocklib/include/MockStreams.h:
##########
@@ -0,0 +1,97 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <algorithm>
+#include <cstddef>

Review Comment:
   `MockStreams.h` uses `std::memcpy` but does not include `<cstring>`. 
Depending on include order this can fail to compile ("memcpy is not a member of 
std"). Add an explicit `<cstring>` include to make the header self-contained.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to