From 6bea81157b2644d9a78f37e008da4604cfe54f0d Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Mon, 7 Oct 2024 06:02:50 -0700 Subject: [PATCH] Added test --- test/test_Native_Registry.cpp | 50 +++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 test/test_Native_Registry.cpp diff --git a/test/test_Native_Registry.cpp b/test/test_Native_Registry.cpp new file mode 100644 index 00000000..a4c892a0 --- /dev/null +++ b/test/test_Native_Registry.cpp @@ -0,0 +1,50 @@ +#include "unittest.hpp" +#include "embed_ruby.hpp" + +#include +#include + +using namespace Rice; + +TESTSUITE(NativeRegistry); + +SETUP(NativeRegistry) +{ + embed_ruby(); +} + +TESTCASE(collisions) +{ + std::array classes; + int scale = 1000; + + for (int i = 0; i < std::size(classes); i++) + { + Class cls(anonymous_class()); + + for (int j = 0; j < scale; j++) + { + cls.define_function("int" + std::to_string(j), []() { return 1; }); + cls.define_function("long" + std::to_string(j), []() { return 1L; }); + cls.define_function("double" + std::to_string(j), []() { return 1.0; }); + cls.define_function("float" + std::to_string(j), []() { return 1.0f; }); + cls.define_function("bool" + std::to_string(j), []() { return true; }); + } + + classes[i] = cls; + } + + for (auto& cls : classes) + { + auto obj = cls.call("new"); + + for (int j = 0; j < scale; j++) + { + obj.call("int" + std::to_string(j)); + obj.call("long" + std::to_string(j)); + obj.call("double" + std::to_string(j)); + obj.call("float" + std::to_string(j)); + obj.call("bool" + std::to_string(j)); + } + } +}