Skip to content

Commit ce9fd8a

Browse files
committed
Add test for typed option to validate std::any_cast cross DSO
1 parent 20069f4 commit ce9fd8a

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

cpp/src/arrow/filesystem/localfs_test.cc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "arrow/filesystem/path_util.h"
3131
#include "arrow/filesystem/test_util.h"
3232
#include "arrow/filesystem/util_internal.h"
33+
#include "arrow/testing/examplefs.h"
3334
#include "arrow/testing/gtest_util.h"
3435
#include "arrow/testing/matchers.h"
3536
#include "arrow/util/io_util.h"
@@ -84,6 +85,12 @@ Result<std::shared_ptr<FileSystem>> FSFromUriOrPath(const std::string& uri,
8485
////////////////////////////////////////////////////////////////////////////
8586
// Registered FileSystemFactory tests
8687

88+
struct ConcreteTypedOption : ExampleTypedOption {
89+
explicit ConcreteTypedOption(int value) : value_(value) {}
90+
int value() const override { return value_; }
91+
int value_;
92+
};
93+
8794
class SlowFileSystemPublicProps : public SlowFileSystem {
8895
public:
8996
SlowFileSystemPublicProps(std::shared_ptr<FileSystem> base_fs, double average_latency,
@@ -153,9 +160,11 @@ TEST(FileSystemFromUri, LoadedRegisteredFactory) {
153160
std::vector<std::pair<std::string, std::any>> options{
154161
{"example_option_string", std::string("example_value")},
155162
{"example_option_int", 42},
163+
{"example_typed_option",
164+
std::shared_ptr<ExampleTypedOption>(std::make_shared<ConcreteTypedOption>(12345))},
156165
};
157166
ASSERT_OK_AND_ASSIGN(fs, FileSystemFromUri("example:///hey/yo", options, &path));
158-
EXPECT_EQ(path, "/hey/yo/example_value/42");
167+
EXPECT_EQ(path, "/hey/yo/example_value/42/12345");
159168
EXPECT_EQ(fs->type_name(), "local");
160169
}
161170

cpp/src/arrow/testing/examplefs.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "arrow/filesystem/filesystem.h"
2222
#include "arrow/filesystem/filesystem_library.h"
2323
#include "arrow/result.h"
24+
#include "arrow/testing/examplefs.h"
2425
#include "arrow/util/uri.h"
2526

2627
#include <gtest/gtest.h>
@@ -49,6 +50,15 @@ auto kExampleFileSystemModule = ARROW_REGISTER_FILESYSTEM(
4950
if (out_path != nullptr) {
5051
*out_path += "/" + std::to_string(std::any_cast<int>(value));
5152
}
53+
} else if (key == "example_typed_option") {
54+
if (const auto* opt =
55+
std::any_cast<std::shared_ptr<ExampleTypedOption>>(&value)) {
56+
if (out_path != nullptr) {
57+
*out_path += "/" + std::to_string((*opt)->value());
58+
}
59+
} else if (out_path != nullptr) {
60+
*out_path += "/typed_cast_failed";
61+
}
5262
} else {
5363
ADD_FAILURE() << "Unexpected option: " << key;
5464
}

0 commit comments

Comments
 (0)