bkietz commented on code in PR #585:
URL: https://github.com/apache/arrow-nanoarrow/pull/585#discussion_r1718509977


##########
src/nanoarrow/integration/ipc_integration.cc:
##########
@@ -0,0 +1,373 @@
+// 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 <cstdlib>
+#include <fstream>
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+#include <nanoarrow/nanoarrow_ipc.hpp>
+#include <nanoarrow/nanoarrow_testing.hpp>
+
+std::string GetEnv(char const* name) {
+  char const* val = std::getenv(name);
+  return val ? val : "";
+}
+
+constexpr auto kUsage = R"(USAGE:
+  # assert that f.arrow reads identical to f.json
+  env COMMAND=VALIDATE    \
+      ARROW_PATH=f.arrow  \
+      JSON_PATH=f.json    \
+      nanoarrow_ipc_json_integration
+
+  # produce f.arrow from f.json
+  env COMMAND=JSON_TO_ARROW  \
+      ARROW_PATH=f.arrow     \
+      JSON_PATH=f.json       \
+      nanoarrow_ipc_json_integration
+
+  # copy f.stream into f.arrow
+  env COMMAND=STREAM_TO_FILE  \
+      ARROW_PATH=f.arrow      \
+      nanoarrow_ipc_json_integration < f.stream
+
+  # copy f.arrow into f.stream
+  env COMMAND=FILE_TO_STREAM  \
+      ARROW_PATH=f.arrow      \
+      nanoarrow_ipc_json_integration > f.stream
+
+  # run all internal test cases
+  nanoarrow_ipc_json_integration
+)";
+
+ArrowErrorCode Validate(struct ArrowError*);
+ArrowErrorCode JsonToArrow(struct ArrowError*);
+ArrowErrorCode StreamToFile(struct ArrowError*);
+ArrowErrorCode FileToStream(struct ArrowError*);
+
+int main(int argc, char** argv) try {
+  std::string command = GetEnv("COMMAND");
+
+  ArrowErrorCode error_code;
+  struct ArrowError error;
+
+  if (command == "VALIDATE") {
+    std::cout << "Validating that " << GetEnv("ARROW_PATH") << " reads 
identical to "
+              << GetEnv("JSON_PATH") << std::endl;
+
+    error_code = Validate(&error);
+  } else if (command == "JSON_TO_ARROW") {
+    std::cout << "Producing " << GetEnv("ARROW_PATH") << " from " << 
GetEnv("JSON_PATH")
+              << std::endl;
+
+    error_code = JsonToArrow(&error);
+  } else if (command == "STREAM_TO_FILE") {
+    error_code = StreamToFile(&error);
+  } else if (command == "FILE_TO_STREAM") {
+    error_code = FileToStream(&error);
+  } else {
+    if (argc == 1 || argv[1] == std::string{"-h"} || argv[1] == 
std::string{"--help"}) {
+      // skip printing usage if for example --gtest_list_tests is used;
+      // that command obviously doesn't need the extra noise
+      std::cerr << kUsage;
+    }
+    testing::InitGoogleTest(&argc, argv);
+    return RUN_ALL_TESTS();

Review Comment:
   I think this should wait for the MaterializedArrayStream follow up. When we 
move it to `nanoarrow_testing.hpp` from here and from `c_data_integration.cc` 
it'll be natural to consolidate `MaterializedArrayStream`'s unit tests in 
`nanoarrow_testing_test`. Doing that here will bloat this PR excessively



-- 
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