tdf#134576: basic_macros: Add unittest

Change-Id: I6078e0712f7983159ea3b3f2060a1c4b69e9d5c6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99114
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
diff --git a/basic/qa/cppunit/test_nested_struct.cxx b/basic/qa/cppunit/test_nested_struct.cxx
index 009d832..daced48 100644
--- a/basic/qa/cppunit/test_nested_struct.cxx
+++ b/basic/qa/cppunit/test_nested_struct.cxx
@@ -28,6 +28,7 @@ namespace
        void testFixedVarAssign();
        void testFixedVarAssignAlt(); // result is uno-ised and tested
        void testUnoAccess(); // fdo#60117 specific test
        void testTdf134576();

        // Adds code needed to register the test suite
        CPPUNIT_TEST_SUITE(Nested_Struct);
@@ -42,6 +43,7 @@ namespace
        CPPUNIT_TEST(testFixedVarAssign);
        CPPUNIT_TEST(testFixedVarAssignAlt);
        CPPUNIT_TEST(testUnoAccess);
        CPPUNIT_TEST(testTdf134576);

        // End of test suite definition
        CPPUNIT_TEST_SUITE_END();
@@ -296,6 +298,24 @@ void Nested_Struct::testUnoAccess()
    CPPUNIT_ASSERT_EQUAL(200, result );
}

void Nested_Struct::testTdf134576()
{
    MacroSnippet myMacro("Function doUnitTest()\n"
                        "  On Error Resume Next\n"
                        "  For Each a In b\n"
                        "    c.d\n"
                        "  Next\n"
                        "  doUnitTest = 1\n"
                        "End Function\n");

    myMacro.Compile();
    CPPUNIT_ASSERT(!myMacro.HasError());

    // Without the fix in place, it would have crashed here
    SbxVariableRef pNew = myMacro.Run();
    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(1), pNew->GetInteger());
}

  // Put the test suite in the registry
  CPPUNIT_TEST_SUITE_REGISTRATION(Nested_Struct);
}