diff --git a/unit_tests/engine/test_alt_rule_loader.cpp b/unit_tests/engine/test_alt_rule_loader.cpp index a6eae9e89cb..95e5a1b88a3 100644 --- a/unit_tests/engine/test_alt_rule_loader.cpp +++ b/unit_tests/engine/test_alt_rule_loader.cpp @@ -15,6 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +#include #include #include @@ -41,7 +42,10 @@ struct test_object_info { struct test_compile_output : public rule_loader::compile_output { test_compile_output() = default; - ~test_compile_output() = default; + virtual ~test_compile_output() = default; + virtual std::unique_ptr clone() const override { + return std::make_unique(*this); + } std::set defined_test_properties; }; @@ -320,3 +324,33 @@ TEST(engine_loader_alt_loader, falco_engine_alternate_loader) { EXPECT_TRUE(defined_properties.find("other-value") != defined_properties.end()); EXPECT_TRUE(defined_properties.find("not-exists-value") == defined_properties.end()); }; + +TEST(engine_loader_alt_loader, clone_compile_output) { + sinsp inspector; + sinsp_filter_check_list filterchecks; + indexed_vector sources; + + std::shared_ptr cfg = + create_configuration(inspector, filterchecks, sources); + + test_reader reader; + test_collector collector; + test_compiler compiler; + + EXPECT_TRUE(reader.read(*cfg, collector)); + + std::unique_ptr compile_output = compiler.new_compile_output(); + + compiler.compile(*cfg, collector, *compile_output); + + const test_compile_output& original_ref = + dynamic_cast(*(compile_output.get())); + + std::unique_ptr copy = compile_output->clone(); + const test_compile_output& copy_ref = dynamic_cast(*(copy.get())); + + EXPECT_EQ(copy_ref.lists, original_ref.lists); + EXPECT_EQ(copy_ref.macros, original_ref.macros); + EXPECT_EQ(copy_ref.rules, original_ref.rules); + EXPECT_EQ(copy_ref.defined_test_properties, original_ref.defined_test_properties); +}