This is an automated email from the ASF dual-hosted git repository.

asf-gitbox-commits pushed a commit to branch symphony-vba
in repository https://gitbox.apache.org/repos/asf/openoffice.git

commit fa1cb9fa1c0cb95dc7ee2d7c6ee73247ad01889d
Author: Pedro Giffuni <=>
AuthorDate: Fri Oct 30 02:05:52 2026 -0500

    Add JUnit tests for VBA compatibility packages (Packages 2-6)
    
    Tests for Formula2, Application.Match, Application.Run, #If/#Const 
conditional
    compilation, Application.Evaluate, Validation.Add, and StrPtr.
    
    Registers test classes in JunitTest_sc_vba.mk
---
 main/sc/JunitTest_sc_vba.mk                   |  10 +
 main/sc/qa/vba/src/VbaSapColumnOpsTest.java   | 189 ++++++++++++
 main/sc/qa/vba/src/VbaSapFeatureGapsTest.java | 396 ++++++++++++++++++++++++++
 main/sc/qa/vba/src/VbaSapOutlineTest.java     | 235 +++++++++++++++
 main/sc/qa/vba/src/VbaSapRangeOpsTest.java    | 275 ++++++++++++++++++
 main/sc/qa/vba/src/VbaSapStringTest.java      | 284 ++++++++++++++++++
 6 files changed, 1389 insertions(+)

diff --git a/main/sc/JunitTest_sc_vba.mk b/main/sc/JunitTest_sc_vba.mk
index 19356e9620..9bb6363d75 100644
--- a/main/sc/JunitTest_sc_vba.mk
+++ b/main/sc/JunitTest_sc_vba.mk
@@ -41,6 +41,11 @@ $(eval $(call gb_JunitTest_add_sourcefiles,sc_vba,\
        sc/qa/vba/src/VbaQueryTableTest \
        sc/qa/vba/src/VbaRangeTest \
        sc/qa/vba/src/VbaDictionaryTest \
+       sc/qa/vba/src/VbaSapColumnOpsTest \
+       sc/qa/vba/src/VbaSapFeatureGapsTest \
+       sc/qa/vba/src/VbaSapRangeOpsTest \
+       sc/qa/vba/src/VbaSapOutlineTest \
+       sc/qa/vba/src/VbaSapStringTest \
 ))
 
 $(eval $(call gb_JunitTest_add_classes,sc_vba,\
@@ -51,6 +56,11 @@ $(eval $(call gb_JunitTest_add_classes,sc_vba,\
        org.openoffice.sc.qa.vba.VbaQueryTableTest \
        org.openoffice.sc.qa.vba.VbaRangeTest \
        org.openoffice.sc.qa.vba.VbaDictionaryTest \
+       org.openoffice.sc.qa.vba.VbaSapColumnOpsTest \
+       org.openoffice.sc.qa.vba.VbaSapFeatureGapsTest \
+       org.openoffice.sc.qa.vba.VbaSapRangeOpsTest \
+       org.openoffice.sc.qa.vba.VbaSapOutlineTest \
+       org.openoffice.sc.qa.vba.VbaSapStringTest \
 ))
 
 # vim: set noet sw=4 ts=4:
diff --git a/main/sc/qa/vba/src/VbaSapColumnOpsTest.java 
b/main/sc/qa/vba/src/VbaSapColumnOpsTest.java
new file mode 100644
index 0000000000..5c366cba68
--- /dev/null
+++ b/main/sc/qa/vba/src/VbaSapColumnOpsTest.java
@@ -0,0 +1,189 @@
+/**************************************************************
+ *
+ * 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.
+ *
+ *************************************************************/
+
+package org.openoffice.sc.qa.vba;
+
+import org.junit.Test;
+import org.junit.Before;
+
+import static org.junit.Assert.*;
+
+/**
+ * P1: Tests for VBA ColumnWidth and column visibility APIs.
+ *
+ * Tests the following VBA object model features:
+ * - Range.ColumnWidth get/set
+ * - EntireColumn.ColumnWidth get/set
+ * - Iterating ActiveSheet.Columns collection
+ * - Range.Column property (get column number)
+ * - Columns.Hidden get/set (column visibility toggle)
+ *
+ * Test methodology: BASIC macros exercise the VBA APIs and write
+ * results to cells Z1, Z2, etc. (column 25). Java code verifies via UNO.
+ * Follows AAA pattern with '@TestMethod' markers in comments.
+ */
+public class VbaSapColumnOpsTest extends VbaCompatTest {
+
+    private static final String MODULE_NAME = "ColumnOpsTests";
+
+    private static final String BASIC_SOURCE =
+        "REM  *****  BASIC  *****\n" +
+        "'@TestModule\n" +
+        "Option VBASupport 1\n" +
+
+        "'@TestMethod\n" +
+        "Sub TestColumnWidthGetSet()\n" +
+        "    ' Arrange\n" +
+        "    Range(\"A1\").ColumnWidth = 15\n" +
+        "\n" +
+        "    ' Act & Assert\n" +
+        "    Range(\"Z1\").Value = CDbl(Range(\"A1\").ColumnWidth)\n" +
+        "    Range(\"Z2\").Value = 
CDbl(Range(\"A1\").EntireColumn.ColumnWidth)\n" +
+        "End Sub\n" +
+        "\n" +
+
+        "'@TestMethod\n" +
+        "Sub TestColumnWidthEntireColumn()\n" +
+        "    ' Arrange\n" +
+        "    Range(\"B1\").EntireColumn.ColumnWidth = 25\n" +
+        "\n" +
+        "    ' Act & Assert\n" +
+        "    Range(\"Z1\").Value = CDbl(Range(\"B1\").ColumnWidth)\n" +
+        "End Sub\n" +
+        "\n" +
+
+        "'@TestMethod\n" +
+        "Sub TestColumnIteration()\n" +
+        "    ' Arrange - populate columns A-D\n" +
+        "    Dim i As Integer\n" +
+        "    For i = 1 To 4\n" +
+        "        Cells(1, i).Value = \"col\" & i\n" +
+        "    Next i\n" +
+        "\n" +
+        "    ' Act - count columns beyond B (index > 2)\n" +
+        "    Dim c As Object\n" +
+        "    Dim count As Integer: count = 0\n" +
+        "    For Each c In ActiveSheet.Columns\n" +
+        "        If c.Column > 2 Then count = count + 1\n" +
+        "    Next\n" +
+        "\n" +
+        "    ' Assert\n" +
+        "    Range(\"Z1\").Value = count\n" +
+        "End Sub\n" +
+        "\n" +
+
+        "'@TestMethod\n" +
+        "Sub TestColumnHidden()\n" +
+        "    ' Arrange\n" +
+        "    Columns(\"B\").Hidden = True\n" +
+        "\n" +
+        "    ' Act & Assert\n" +
+        "    Range(\"Z1\").Value = CInt(Columns(\"B\").Hidden)\n" +
+        "\n" +
+        "    ' Restore\n" +
+        "    Columns(\"B\").Hidden = False\n" +
+        "    Range(\"Z2\").Value = CInt(Columns(\"B\").Hidden)\n" +
+        "End Sub\n" +
+        "\n" +
+
+        "'@TestMethod\n" +
+        "Sub TestColumnWidthReset()\n" +
+        "    ' Arrange\n" +
+        "    Range(\"A1\").ColumnWidth = 30\n" +
+        "    Range(\"Z1\").Value = CDbl(Range(\"A1\").ColumnWidth)\n" +
+        "\n" +
+        "    ' Act\n" +
+        "    Range(\"A1\").ColumnWidth = 8.43\n" +
+        "\n" +
+        "    ' Assert\n" +
+        "    Range(\"Z2\").Value = CDbl(Range(\"A1\").ColumnWidth)\n" +
+        "End Sub\n" +
+        "\n" +
+
+        "'@TestMethod\n" +
+        "Sub TestColumnProperty()\n" +
+        "    ' Arrange & Act\n" +
+        "    Dim c As Object\n" +
+        "    Set c = ActiveSheet.Columns(3)\n" +
+        "\n" +
+        "    ' Assert - Column property returns column number\n" +
+        "    Range(\"Z1\").Value = CDbl(c.Column)\n" +
+        "End Sub\n";
+
+    @Before
+    public void setUpVbaModules() throws Exception {
+        addBasicModule(MODULE_NAME, BASIC_SOURCE);
+    }
+
+    @Test
+    public void testColumnWidthGetSet() throws Exception {
+        clearResultRow();
+        runMacro(MODULE_NAME, "TestColumnWidthGetSet");
+        assertEquals("ColumnWidth set to 15 should read 15",
+            15.0, getNumericResult(0), 0.001);
+        assertEquals("EntireColumn.ColumnWidth should match",
+            15.0, getNumericResult(1), 0.001);
+    }
+
+    @Test
+    public void testColumnWidthEntireColumn() throws Exception {
+        clearResultRow();
+        runMacro(MODULE_NAME, "TestColumnWidthEntireColumn");
+        assertEquals("EntireColumn.ColumnWidth = 25 should read 25",
+            25.0, getNumericResult(0), 0.001);
+    }
+
+    @Test
+    public void testColumnIteration() throws Exception {
+        clearResultRow();
+        runMacro(MODULE_NAME, "TestColumnIteration");
+        assertEquals("Columns with index > 2 should be counted",
+            2.0, getNumericResult(0), 0.001);
+    }
+
+    @Test
+    public void testColumnHidden() throws Exception {
+        clearResultRow();
+        runMacro(MODULE_NAME, "TestColumnHidden");
+        assertEquals("Hidden=True should return -1 (VBA True)",
+            -1.0, getNumericResult(0), 0.001);
+        assertEquals("Hidden=False should return 0 (VBA False)",
+            0.0, getNumericResult(1), 0.001);
+    }
+
+    @Test
+    public void testColumnWidthReset() throws Exception {
+        clearResultRow();
+        runMacro(MODULE_NAME, "TestColumnWidthReset");
+        assertEquals("ColumnWidth set to 30 should read 30",
+            30.0, getNumericResult(0), 0.001);
+        assertEquals("ColumnWidth reset to 8.43 should read ~8.43",
+            8.43, getNumericResult(1), 0.01);
+    }
+
+    @Test
+    public void testColumnProperty() throws Exception {
+        clearResultRow();
+        runMacro(MODULE_NAME, "TestColumnProperty");
+        assertEquals("Columns(3).Column should return 3",
+            3.0, getNumericResult(0), 0.001);
+    }
+}
diff --git a/main/sc/qa/vba/src/VbaSapFeatureGapsTest.java 
b/main/sc/qa/vba/src/VbaSapFeatureGapsTest.java
new file mode 100644
index 0000000000..2cb356a1ed
--- /dev/null
+++ b/main/sc/qa/vba/src/VbaSapFeatureGapsTest.java
@@ -0,0 +1,396 @@
+/**************************************************************
+ *
+ * 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.
+ *
+ *************************************************************/
+
+package org.openoffice.sc.qa.vba;
+
+import org.junit.Test;
+import org.junit.Before;
+
+import static org.junit.Assert.*;
+
+/**
+ * P1: Tests for VBA APIs that are confirmed missing or partially supported.
+ *
+ * Tests the following Excel VBA APIs that are NOT fully supported in AOO:
+ * - StrPtr (VBA language function not implemented in AOO BASIC runtime)
+ * - Some Validation.Add types (date validation unsupported)
+ *
+ * Note: The following APIs have been implemented and are now verified to work:
+ * - Range.Formula2 (implemented via delegation to Formula)
+ * - Application.Match (works through invoke/FunctionAccess)
+ * - Application.Evaluate (works via FunctionAccess with formula expressions)
+ * - Application.Run (works through invoke/InvokeMethodDispatch)
+ * - #If/#Const conditional compilation (implemented in parser and tokenizer)
+ *
+ * Test methodology: BASIC macros exercise the VBA APIs and write results
+ * to cells Z1, Z2, etc. (column 25). Java code verifies via UNO.
+ */
+public class VbaSapFeatureGapsTest extends VbaCompatTest {
+
+    private static final String MODULE_NAME = "FeatureGapsTests";
+
+    // Excel VBA constants
+    private static final int XL_VALIDATE_LIST = 30;
+    private static final int XL_VALID_ALERT_STOP = 1;
+    private static final int XL_BETWEEN = 1;
+
+    private static final String BASIC_SOURCE =
+        "REM  *****  BASIC  *****\n" +
+        "'@TestModule\n" +
+        "Option VBASupport 1\n" +
+        "Const xlValidateList = 30\n" +
+        "\n" +
+
+        "'@TestMethod\n" +
+        "Sub TestFormula2Read()\n" +
+        "    ' Arrange - Formula2 is now implemented\n" +
+        "    Range(\"A1\").Value = 10\n" +
+        "    Range(\"B1\").Formula = \"=A1*2\"\n" +
+        "\n" +
+        "    ' Act - read Range.Formula2\n" +
+        "    On Error Resume Next\n" +
+        "    Range(\"AA1\").Value = Range(\"B1\").Formula2\n" +
+        "    Range(\"Z1\").Value = CInt(Err.Number <> 0)\n" +
+        "    On Error GoTo 0\n" +
+        "End Sub\n" +
+        "\n" +
+
+        "'@TestMethod\n" +
+        "Sub TestFormula2Write()\n" +
+        "    ' Arrange\n" +
+        "    Range(\"A1\").Value = 10\n" +
+        "\n" +
+        "    ' Act - write to Range.Formula2\n" +
+        "    On Error Resume Next\n" +
+        "    Range(\"B1\").Formula2 = \"=A1*3\"\n" +
+        "    Range(\"Z1\").Value = CInt(Err.Number <> 0)\n" +
+        "    Range(\"Z2\").Value = Range(\"B1\").Value\n" +
+        "    On Error GoTo 0\n" +
+        "End Sub\n" +
+        "\n" +
+
+        "'@TestMethod\n" +
+        "Sub TestApplicationMatch()\n" +
+        "    ' Arrange\n" +
+        "    Range(\"A1\").Value = 10\n" +
+        "    Range(\"A2\").Value = 20\n" +
+        "    Range(\"A3\").Value = 30\n" +
+        "\n" +
+        "    ' Act - Application.Match via invoke works\n" +
+        "    On Error Resume Next\n" +
+        "    Dim result As Variant\n" +
+        "    result = Application.Match(20, Range(\"A1:A3\"), 0)\n" +
+        "    Range(\"Z1\").Value = CInt(Err.Number <> 0)\n" +
+        "    Range(\"Z2\").Value = CDbl(result)\n" +
+        "    On Error GoTo 0\n" +
+        "End Sub\n" +
+        "\n" +
+
+        "'@TestMethod\n" +
+        "Sub TestApplicationMatchNotFound()\n" +
+        "    ' Arrange\n" +
+        "    Range(\"A1\").Value = 10\n" +
+        "    Range(\"A2\").Value = 20\n" +
+        "    Range(\"A3\").Value = 30\n" +
+        "\n" +
+        "    ' Act - match for value not in range returns error/Nothing\n" +
+        "    On Error Resume Next\n" +
+        "    Dim result As Variant\n" +
+        "    result = Application.Match(99, Range(\"A1:A3\"), 0)\n" +
+        "    Range(\"Z1\").Value = CInt(Err.Number <> 0)\n" +
+        "    Range(\"AA1\").Value = CStr(result)\n" +
+        "    On Error GoTo 0\n" +
+        "End Sub\n" +
+        "\n" +
+
+        "'@TestMethod\n" +
+        "Sub TestApplicationRun()\n" +
+        "    ' Arrange - Application.Run invokes a macro by name\n" +
+        "    Range(\"A1\").Value = 0\n" +
+        "\n" +
+        "    ' Act - call TestHelper via Application.Run\n" +
+        "    On Error Resume Next\n" +
+        "    Application.Run \"TestHelper\"\n" +
+        "    Range(\"Z1\").Value = CInt(Err.Number <> 0)\n" +
+        "    Range(\"Z2\").Value = Range(\"A1\").Value\n" +
+        "    On Error GoTo 0\n" +
+        "End Sub\n" +
+        "\n" +
+
+        "'@TestMethod\n" +
+        "Sub TestHelper()\n" +
+        "    Range(\"A1\").Value = 42\n" +
+        "End Sub\n" +
+        "\n" +
+
+        "'@TestMethod\n" +
+        "Sub TestConditionalCompilationTrue()\n" +
+        "    ' #If True Then should include the true branch\n" +
+        "    #If True Then\n" +
+        "        Range(\"A1\").Value = 1\n" +
+        "    #Else\n" +
+        "        Range(\"A1\").Value = 2\n" +
+        "    #End If\n" +
+        "\n" +
+        "    Range(\"Z1\").Value = Range(\"A1\").Value\n" +
+        "End Sub\n" +
+        "\n" +
+
+        "'@TestMethod\n" +
+        "Sub TestConditionalCompilationFalse()\n" +
+        "    ' #If False Then should skip to #Else branch\n" +
+        "    #If False Then\n" +
+        "        Range(\"A1\").Value = 1\n" +
+        "    #Else\n" +
+        "        Range(\"A1\").Value = 2\n" +
+        "    #End If\n" +
+        "\n" +
+        "    Range(\"Z1\").Value = Range(\"A1\").Value\n" +
+        "End Sub\n" +
+        "\n" +
+
+        "'@TestMethod\n" +
+        "Sub TestConditionalCompilationConst()\n" +
+        "    ' Test #Const and #If with constant comparison\n" +
+        "    #Const USE_A = True\n" +
+        "    #If USE_A Then\n" +
+        "        Range(\"A1\").Value = 100\n" +
+        "    #Else\n" +
+        "        Range(\"A1\").Value = 200\n" +
+        "    #End If\n" +
+        "\n" +
+        "    Range(\"Z1\").Value = Range(\"A1\").Value\n" +
+        "End Sub\n" +
+        "\n" +
+
+        "'@TestMethod\n" +
+        "Sub TestApplicationEvaluateFormula()\n" +
+        "    ' Arrange\n" +
+        "    Range(\"A1\").Value = 10\n" +
+        "    Range(\"A2\").Value = 20\n" +
+        "\n" +
+        "    ' Act - evaluate a formula expression\n" +
+        "    On Error Resume Next\n" +
+        "    Dim result As Variant\n" +
+        "    result = Application.Evaluate(\"A1+A2\")\n" +
+        "    Range(\"Z1\").Value = CInt(Err.Number <> 0)\n" +
+        "    Range(\"Z2\").Value = CDbl(result)\n" +
+        "    On Error GoTo 0\n" +
+        "End Sub\n" +
+        "\n" +
+
+        "'@TestMethod\n" +
+        "Sub TestApplicationEvaluateName()\n" +
+        "    ' Arrange - create a named range\n" +
+        "    ThisWorkbook.Names.Add \"TestName\", \"=Sheet1!$A$1\"\n" +
+        "    Range(\"A1\").Value = 99\n" +
+        "\n" +
+        "    ' Act - evaluate by name\n" +
+        "    On Error Resume Next\n" +
+        "    Dim result As Variant\n" +
+        "    result = Application.Evaluate(\"TestName\")\n" +
+        "    Range(\"Z1\").Value = CDbl(result)\n" +
+        "    Range(\"AA1\").Value = CInt(Err.Number <> 0)\n" +
+        "    On Error GoTo 0\n" +
+        "End Sub\n" +
+        "\n" +
+
+        "'@TestMethod\n" +
+        "Sub TestValidationAddList()\n" +
+        "    ' Arrange\n" +
+        "    Range(\"A1\").Validation.Delete\n" +
+        "\n" +
+        "    ' Act - add list validation\n" +
+        "    Range(\"A1\").Validation.Add Type:=xlValidateList, AlertStyle:=1, 
Operator:=3, Formula1:=\"A,B,C\"\n" +
+        "\n" +
+        "    ' Assert\n" +
+        "    Range(\"Z1\").Value = CDbl(Range(\"A1\").Validation.Type)\n" +
+        "    Range(\"A1\").Value = \"B\"\n" +
+        "    Range(\"AA1\").Value = Range(\"A1\").Value\n" +
+        "End Sub\n" +
+        "\n" +
+
+        "'@TestMethod\n" +
+        "Sub TestValidationAddWholeNumber()\n" +
+        "    ' Arrange\n" +
+        "    Range(\"A2\").Validation.Delete\n" +
+        "\n" +
+        "    ' Act - add whole number validation (xlValidateWholeNumber = 
2)\n" +
+        "    Range(\"A2\").Validation.Add Type:=2, AlertStyle:=1, Operator:=3, 
Formula1:=\"1\", Formula2:=\"10\"\n" +
+        "\n" +
+        "    ' Assert\n" +
+        "    Range(\"Z1\").Value = CDbl(Range(\"A2\").Validation.Type)\n" +
+        "End Sub\n" +
+        "\n" +
+
+        "'@TestMethod\n" +
+        "Sub TestValidationAddUnsupportedType()\n" +
+        "    ' Arrange\n" +
+        "    Range(\"A3\").Validation.Delete\n" +
+        "\n" +
+        "    ' Act - try unsupported validation type (xlValidateDate = 4)\n" +
+        "    On Error Resume Next\n" +
+        "    Range(\"A3\").Validation.Add Type:=4, AlertStyle:=1, Operator:=3, 
Formula1:=\"1/1/2020\", Formula2:=\"12/31/2020\"\n" +
+        "    Range(\"Z1\").Value = CInt(Err.Number <> 0)\n" +
+        "    On Error GoTo 0\n" +
+        "End Sub\n";
+
+    @Before
+    public void setUpVbaModules() throws Exception {
+        addBasicModule(MODULE_NAME, BASIC_SOURCE);
+    }
+
+    // --- Formula2 tests ---
+
+    @Test
+    public void testFormula2Read() throws Exception {
+        clearResultRow();
+        runMacro(MODULE_NAME, "TestFormula2Read");
+        assertEquals("Formula2 should not raise error when implemented",
+            0.0, getNumericResult(0), 0.001);
+    }
+
+    @Test
+    public void testFormula2Write() throws Exception {
+        clearResultRow();
+        runMacro(MODULE_NAME, "TestFormula2Write");
+        assertEquals("Writing to Formula2 should not raise error",
+            0.0, getNumericResult(0), 0.001);
+        assertEquals("Formula2 should set formula correctly (A1*3)",
+            30.0, getNumericResult(1), 0.001);
+    }
+
+    // --- Application.Match tests ---
+
+    @Test
+    public void testApplicationMatch() throws Exception {
+        clearResultRow();
+        runMacro(MODULE_NAME, "TestApplicationMatch");
+        assertEquals("Application.Match should work through invoke",
+            0.0, getNumericResult(0), 0.001);
+        assertEquals("Application.Match should return position 2 for value 20",
+            2.0, getNumericResult(1), 0.001);
+    }
+
+    @Test
+    public void testApplicationMatchNotFound() throws Exception {
+        clearResultRow();
+        runMacro(MODULE_NAME, "TestApplicationMatchNotFound");
+        assertEquals("Application.Match for not-found should return 
empty/Nothing",
+            0.0, getNumericResult(0), 0.001);
+    }
+
+    // --- Application.Run test ---
+
+    @Test
+    public void testApplicationRun() throws Exception {
+        clearResultRow();
+        runMacro(MODULE_NAME, "TestApplicationRun");
+        assertEquals("Application.Run should execute the macro",
+            0.0, getNumericResult(0), 0.001);
+        assertEquals("Helper macro should set A1 to 42",
+            42.0, getNumericResult(1), 0.001);
+    }
+
+    // --- Conditional compilation tests ---
+
+    @Test
+    public void testConditionalCompilationTrue() throws Exception {
+        clearResultRow();
+        runMacro(MODULE_NAME, "TestConditionalCompilationTrue");
+        assertEquals("#If True should include the True branch (1)",
+            1.0, getNumericResult(0), 0.001);
+    }
+
+    @Test
+    public void testConditionalCompilationFalse() throws Exception {
+        clearResultRow();
+        runMacro(MODULE_NAME, "TestConditionalCompilationFalse");
+        assertEquals("#If False should skip to #Else branch (2)",
+            2.0, getNumericResult(0), 0.001);
+    }
+
+    @Test
+    public void testConditionalCompilationConst() throws Exception {
+        clearResultRow();
+        runMacro(MODULE_NAME, "TestConditionalCompilationConst");
+        assertEquals("#Const with #If should include the True branch (100)",
+            100.0, getNumericResult(0), 0.001);
+    }
+
+    // --- StrPtr test (still unimplemented) ---
+
+    @Test
+    public void testStrPtr() throws Exception {
+        clearResultRow();
+        runMacro(MODULE_NAME, "TestStrPtr");
+        assertEquals("StrPtr should not be available (error expected)",
+            1.0, getNumericResult(0), 0.001);
+    }
+
+    // --- Application.Evaluate tests ---
+
+    @Test
+    public void testApplicationEvaluateFormula() throws Exception {
+        clearResultRow();
+        runMacro(MODULE_NAME, "TestApplicationEvaluateFormula");
+        assertEquals("Evaluate should not raise error on formula expressions",
+            0.0, getNumericResult(0), 0.001);
+        assertEquals("Evaluate formula result should be 30",
+            30.0, getNumericResult(1), 0.001);
+    }
+
+    @Test
+    public void testApplicationEvaluateName() throws Exception {
+        clearResultRow();
+        runMacro(MODULE_NAME, "TestApplicationEvaluateName");
+        assertEquals("Evaluate should work on defined names",
+            99.0, getNumericResult(0), 0.001);
+    }
+
+    // --- Validation.Add tests ---
+
+    @Test
+    public void testValidationAddList() throws Exception {
+        clearResultRow();
+        runMacro(MODULE_NAME, "TestValidationAddList");
+        assertEquals("Validation Type for xlValidateList should be 30",
+            30.0, getNumericResult(0), 0.001);
+        assertEquals("Cell value after setting validation should be 'B'",
+            "B", getStringResult(0));
+    }
+
+    @Test
+    public void testValidationAddWholeNumber() throws Exception {
+        clearResultRow();
+        runMacro(MODULE_NAME, "TestValidationAddWholeNumber");
+        assertEquals("Validation Type for WholeNumber should be 2",
+            2.0, getNumericResult(0), 0.001);
+    }
+
+    @Test
+    public void testValidationAddUnsupportedType() throws Exception {
+        clearResultRow();
+        runMacro(MODULE_NAME, "TestValidationAddUnsupportedType");
+        assertEquals("Unsupported validation type should raise error",
+            1.0, getNumericResult(0), 0.001);
+    }
+}
diff --git a/main/sc/qa/vba/src/VbaSapOutlineTest.java 
b/main/sc/qa/vba/src/VbaSapOutlineTest.java
new file mode 100644
index 0000000000..2eca4c859d
--- /dev/null
+++ b/main/sc/qa/vba/src/VbaSapOutlineTest.java
@@ -0,0 +1,235 @@
+/**************************************************************
+ *
+ * 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.
+ *
+ *************************************************************/
+
+package org.openoffice.sc.qa.vba;
+
+import org.junit.Test;
+import org.junit.Before;
+
+import static org.junit.Assert.*;
+
+/**
+ * P2: Tests for VBA Outline and UsedRange object model features.
+ *
+ * Tests the following VBA object model features:
+ * - Worksheet.UsedRange (range object)
+ * - Worksheet.Outline.ShowLevels (row/column outline level expansion)
+ *
+ * Test methodology: BASIC macros exercise the VBA APIs and write
+ * results to cells Z1, Z2, etc. (column 25). Java code verifies via UNO.
+ * Follows AAA pattern with '@TestMethod' markers in comments.
+ */
+public class VbaSapOutlineTest extends VbaCompatTest {
+
+    private static final String MODULE_NAME = "OutlineTests";
+
+    private static final String BASIC_SOURCE =
+        "REM  *****  BASIC  *****\n" +
+        "'@TestModule\n" +
+        "Option VBASupport 1\n" +
+
+        "'@TestMethod\n" +
+        "Sub TestUsedRangeBlank()\n" +
+        "    ' Arrange - blank sheet\n" +
+        "\n" +
+        "    ' Act & Assert\n" +
+        "    Dim ur As Object\n" +
+        "    Set ur = ActiveSheet.UsedRange\n" +
+        "    Range(\"Z1\").Value = ur.Cells.Count\n" +
+        "    Range(\"AA1\").Value = ur.Address\n" +
+        "End Sub\n" +
+        "\n" +
+
+        "'@TestMethod\n" +
+        "Sub TestUsedRangeWithValue()\n" +
+        "    ' Arrange\n" +
+        "    Range(\"A1\").Value = \"data\"\n" +
+        "    Range(\"C3\").Value = 42\n" +
+        "\n" +
+        "    ' Act & Assert\n" +
+        "    Dim ur As Object\n" +
+        "    Set ur = ActiveSheet.UsedRange\n" +
+        "    Range(\"Z1\").Value = ur.Cells.Count\n" +
+        "    Range(\"AA1\").Value = ur.Address\n" +
+        "End Sub\n" +
+        "\n" +
+
+        "'@TestMethod\n" +
+        "Sub TestUsedRangeWithFormula()\n" +
+        "    ' Arrange\n" +
+        "    Range(\"A1\").Value = 10\n" +
+        "    Range(\"B1\").Formula = \"=A1*2\"\n" +
+        "\n" +
+        "    ' Act & Assert\n" +
+        "    Dim ur As Object\n" +
+        "    Set ur = ActiveSheet.UsedRange\n" +
+        "    Range(\"Z1\").Value = ur.Cells.Count\n" +
+        "    Range(\"AA1\").Value = ur.Address\n" +
+        "End Sub\n" +
+        "\n" +
+
+        "'@TestMethod\n" +
+        "Sub TestUsedRangeAfterClear()\n" +
+        "    ' Arrange\n" +
+        "    Range(\"A1\").Value = \"data\"\n" +
+        "    Range(\"Z1\").Value = 1 ' placeholder\n" +
+        "\n" +
+        "    ' Act - clear values\n" +
+        "    Range(\"A1\").ClearContents\n" +
+        "    Dim ur As Object\n" +
+        "    Set ur = ActiveSheet.UsedRange\n" +
+        "    Range(\"AA1\").Value = ur.Address\n" +
+        "End Sub\n" +
+        "\n" +
+
+        "'@TestMethod\n" +
+        "Sub TestShowLevelsRowOnly()\n" +
+        "    ' Arrange - create data and group rows\n" +
+        "    Dim i As Integer\n" +
+        "    For i = 1 To 10\n" +
+        "        Cells(i, 1).Value = \"row\" & i\n" +
+        "    Next i\n" +
+        "    Range(\"A3:A8\").Rows.Group\n" +
+        "\n" +
+        "    ' Act - show 1 row level (collapse)\n" +
+        "    ActiveSheet.Outline.ShowLevels RowLevels:=1\n" +
+        "\n" +
+        "    ' Assert\n" +
+        "    Range(\"Z1\").Value = 1\n" +
+        "    Range(\"AA1\").Value = \"row levels shown\"\n" +
+        "\n" +
+        "    ' Restore\n" +
+        "    ActiveSheet.Outline.ShowLevels RowLevels:=2\n" +
+        "End Sub\n" +
+        "\n" +
+
+        "'@TestMethod\n" +
+        "Sub TestShowLevelsColumnOnly()\n" +
+        "    ' Arrange - create data and group columns\n" +
+        "    Dim i As Integer\n" +
+        "    For i = 1 To 5\n" +
+        "        Cells(1, i).Value = \"col\" & i\n" +
+        "    Next i\n" +
+        "    Range(\"B1:D1\").Columns.Group\n" +
+        "\n" +
+        "    ' Act\n" +
+        "    ActiveSheet.Outline.ShowLevels ColumnLevels:=1\n" +
+        "\n" +
+        "    ' Assert\n" +
+        "    Range(\"Z1\").Value = 1\n" +
+        "    Range(\"AA1\").Value = \"column levels shown\"\n" +
+        "\n" +
+        "    ' Restore\n" +
+        "    ActiveSheet.Outline.ShowLevels ColumnLevels:=2\n" +
+        "End Sub\n" +
+        "\n" +
+
+        "'@TestMethod\n" +
+        "Sub TestShowLevelsCombined()\n" +
+        "    ' Arrange - group both rows and columns\n" +
+        "    Dim i As Integer\n" +
+        "    For i = 1 To 10\n" +
+        "        Cells(i, 1).Value = \"r\" & i\n" +
+        "    Next i\n" +
+        "    For i = 1 To 5\n" +
+        "        Cells(1, i).Value = \"c\" & i\n" +
+        "    Next i\n" +
+        "    Range(\"A3:A8\").Rows.Group\n" +
+        "    Range(\"B1:D1\").Columns.Group\n" +
+        "\n" +
+        "    ' Act\n" +
+        "    ActiveSheet.Outline.ShowLevels RowLevels:=1, ColumnLevels:=1\n" +
+        "\n" +
+        "    ' Assert\n" +
+        "    Range(\"Z1\").Value = 1\n" +
+        "    Range(\"AA1\").Value = \"combined levels shown\"\n" +
+        "End Sub\n";
+
+    @Before
+    public void setUpVbaModules() throws Exception {
+        addBasicModule(MODULE_NAME, BASIC_SOURCE);
+    }
+
+    @Test
+    public void testUsedRangeBlank() throws Exception {
+        clearResultRow();
+        runMacro(MODULE_NAME, "TestUsedRangeBlank");
+        double count = getNumericResult(0);
+        assertTrue("Blank sheet UsedRange should have at least 1 cell", count 
>= 1);
+    }
+
+    @Test
+    public void testUsedRangeWithValue() throws Exception {
+        clearResultRow();
+        runMacro(MODULE_NAME, "TestUsedRangeWithValue");
+        double count = getNumericResult(0);
+        assertEquals("UsedRange with data in A1 and C3 should cover at least 9 
cells (A1:C3)",
+            9.0, count, 0.0);
+        String address = getStringResult(0);
+        assertNotNull("UsedRange address should not be null", address);
+    }
+
+    @Test
+    public void testUsedRangeWithFormula() throws Exception {
+        clearResultRow();
+        runMacro(MODULE_NAME, "TestUsedRangeWithFormula");
+        double count = getNumericResult(0);
+        assertTrue("UsedRange with formula should have at least 2 cells", 
count >= 2);
+    }
+
+    @Test
+    public void testUsedRangeAfterClear() throws Exception {
+        clearResultRow();
+        runMacro(MODULE_NAME, "TestUsedRangeAfterClear");
+        String address = getStringResult(0);
+        assertNotNull("UsedRange after clear should have an address", address);
+    }
+
+    @Test
+    public void testShowLevelsRowOnly() throws Exception {
+        clearResultRow();
+        runMacro(MODULE_NAME, "TestShowLevelsRowOnly");
+        assertEquals("ShowLevels RowLevels should not error",
+            1.0, getNumericResult(0), 0.001);
+        assertEquals("Status should be 'row levels shown'",
+            "row levels shown", getStringResult(0));
+    }
+
+    @Test
+    public void testShowLevelsColumnOnly() throws Exception {
+        clearResultRow();
+        runMacro(MODULE_NAME, "TestShowLevelsColumnOnly");
+        assertEquals("ShowLevels ColumnLevels should not error",
+            1.0, getNumericResult(0), 0.001);
+        assertEquals("Status should be 'column levels shown'",
+            "column levels shown", getStringResult(0));
+    }
+
+    @Test
+    public void testShowLevelsCombined() throws Exception {
+        clearResultRow();
+        runMacro(MODULE_NAME, "TestShowLevelsCombined");
+        assertEquals("ShowLevels combined should not error",
+            1.0, getNumericResult(0), 0.001);
+        assertEquals("Status should be 'combined levels shown'",
+            "combined levels shown", getStringResult(0));
+    }
+}
diff --git a/main/sc/qa/vba/src/VbaSapRangeOpsTest.java 
b/main/sc/qa/vba/src/VbaSapRangeOpsTest.java
new file mode 100644
index 0000000000..4b9f5ee780
--- /dev/null
+++ b/main/sc/qa/vba/src/VbaSapRangeOpsTest.java
@@ -0,0 +1,275 @@
+/**************************************************************
+ *
+ * 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.
+ *
+ *************************************************************/
+
+package org.openoffice.sc.qa.vba;
+
+import org.junit.Test;
+import org.junit.Before;
+
+import static org.junit.Assert.*;
+
+/**
+ * P1: Tests for VBA Range operations derived from SAP IBP samples.
+ *
+ * Tests the following VBA object model features:
+ * - Range.Find with LookIn:=xlValues
+ * - Range.Text property (read-only formatted text)
+ * - Columns(col).Cut and Columns(col).Insert with Shift parameter
+ * - Range.Rows.Group and Range.Rows.Ungroup
+ * - Range.Offset chaining (Offset + EntireRow.Hidden)
+ *
+ * Test methodology: BASIC macros exercise the VBA APIs and write
+ * results to cells Z1, Z2, etc. (column 25). Java code verifies via UNO.
+ * Follows AAA pattern with '@TestMethod' markers in comments.
+ */
+public class VbaSapRangeOpsTest extends VbaCompatTest {
+
+    private static final String MODULE_NAME = "RangeOpsTests";
+
+    // Excel VBA constants
+    private static final int XL_DIRECTION_DOWN = -4162;  // xlDown
+    private static final int XL_SHIFT_TO_RIGHT = -4162;  // xlShiftToRight
+    private static final int XL_LOOK_IN_VALUES = -4163; // xlValues
+    private static final int XL_LOOK_IN_FORMULAS = -4144; // xlFormulas (not 
standard, but used in test)
+
+    private static final String BASIC_SOURCE =
+        "REM  *****  BASIC  *****\n" +
+        "'@TestModule\n" +
+        "Option VBASupport 1\n" +
+        "Const xlValues = -4163\n" +
+        "\n" +
+
+        "'@TestMethod\n" +
+        "Sub TestRangeFind()\n" +
+        "    ' Arrange - populate A1:A10 with strings, set A5 = 'Target'\n" +
+        "    Dim i As Integer\n" +
+        "    For i = 1 To 10\n" +
+        "        Cells(i, 1).Value = \"item\" & i\n" +
+        "    Next i\n" +
+        "    Range(\"A5\").Value = \"Target\"\n" +
+        "\n" +
+        "    ' Act\n" +
+        "    Dim c As Object\n" +
+        "    Set c = Range(\"A1:A10\").Find(\"Target\", LookIn:=xlValues)\n" +
+        "\n" +
+        "    ' Assert\n" +
+        "    If c Is Nothing Then\n" +
+        "        Range(\"Z1\").Value = 0\n" +
+        "    Else\n" +
+        "        Range(\"Z1\").Value = c.Row\n" +
+        "    End If\n" +
+        "End Sub\n" +
+        "\n" +
+
+        "'@TestMethod\n" +
+        "Sub TestRangeText()\n" +
+        "    ' Arrange\n" +
+        "    Range(\"A1\").Value = 42\n" +
+        "\n" +
+        "    ' Act & Assert - .Text returns formatted display text\n" +
+        "    Range(\"AA1\").Value = Range(\"A1\").Text\n" +
+        "    Range(\"Z1\").Value = CDbl(Range(\"A1\").Value)\n" +
+        "End Sub\n" +
+        "\n" +
+
+        "'@TestMethod\n" +
+        "Sub TestRangeTextFormatted()\n" +
+        "    ' Arrange - set a date-formatted cell\n" +
+        "    Range(\"A1\").Value = 44927 ' Jan 1 2023 in OLE date\n" +
+        "    Range(\"A1\").NumberFormat = \"MM/DD/YYYY\"\n" +
+        "\n" +
+        "    ' Act & Assert - .Text should return formatted string\n" +
+        "    Range(\"AA1\").Value = Range(\"A1\").Text\n" +
+        "End Sub\n" +
+        "\n" +
+
+        "'@TestMethod\n" +
+        "Sub TestRangeTextString()\n" +
+        "    ' Arrange\n" +
+        "    Range(\"A1\").Value = \"hello world\"\n" +
+        "\n" +
+        "    ' Act & Assert\n" +
+        "    Range(\"AA1\").Value = Range(\"A1\").Text\n" +
+        "End Sub\n" +
+        "\n" +
+
+        "'@TestMethod\n" +
+        "Sub TestColumnsCutInsert()\n" +
+        "    ' Arrange - put value in A1\n" +
+        "    Range(\"A1\").Value = \"original\"\n" +
+        "\n" +
+        "    ' Act\n" +
+        "    Columns(\"A\").Cut\n" +
+        "    Columns(\"C\").Insert Shift:=-4162\n" +
+        "\n" +
+        "    ' Assert\n" +
+        "    Range(\"AA1\").Value = Range(\"C1\").Value\n" +
+        "End Sub\n" +
+        "\n" +
+
+        "'@TestMethod\n" +
+        "Sub TestRowsGroupUngroup()\n" +
+        "    ' Arrange - put data in rows 3-8\n" +
+        "    Dim i As Integer\n" +
+        "    For i = 3 To 8\n" +
+        "        Cells(i, 1).Value = \"row\" & i\n" +
+        "    Next i\n" +
+        "\n" +
+        "    ' Act - group rows 3-8\n" +
+        "    Range(\"A3:A8\").Rows.Group\n" +
+        "\n" +
+        "    ' Assert - check row count of the range\n" +
+        "    Range(\"Z1\").Value = CDbl(Range(\"A3:A8\").Rows.Count)\n" +
+        "    Range(\"AA1\").Value = \"grouped\"\n" +
+        "\n" +
+        "    ' Cleanup - ungroup\n" +
+        "    Range(\"A3:A8\").Rows.Ungroup\n" +
+        "    Range(\"AA2\").Value = \"ungrouped\"\n" +
+        "End Sub\n" +
+        "\n" +
+
+        "'@TestMethod\n" +
+        "Sub TestOffsetEntireRowHidden()\n" +
+        "    ' Arrange\n" +
+        "    Range(\"A1\").Offset(3, 0).EntireRow.Hidden = True\n" +
+        "\n" +
+        "    ' Act & Assert\n" +
+        "    Range(\"Z1\").Value = CInt(Range(\"A4\").EntireRow.Hidden)\n" +
+        "\n" +
+        "    ' Restore\n" +
+        "    Range(\"A1\").Offset(3, 0).EntireRow.Hidden = False\n" +
+        "    Range(\"Z2\").Value = CInt(Range(\"A4\").EntireRow.Hidden)\n" +
+        "End Sub\n" +
+        "\n" +
+
+        "'@TestMethod\n" +
+        "Sub TestRangeFindNotFound()\n" +
+        "    ' Arrange\n" +
+        "    Dim i As Integer\n" +
+        "    For i = 1 To 5\n" +
+        "        Cells(i, 1).Value = \"item\" & i\n" +
+        "    Next i\n" +
+        "\n" +
+        "    ' Act - search for something that doesn't exist\n" +
+        "    Dim c As Object\n" +
+        "    Set c = Range(\"A1:A5\").Find(\"NonExistent\", 
LookIn:=xlValues)\n" +
+        "\n" +
+        "    ' Assert\n" +
+        "    Range(\"Z1\").Value = IIf(c Is Nothing, 1, 0)\n" +
+        "End Sub\n" +
+        "\n" +
+
+        "'@TestMethod\n" +
+        "Sub TestRangeTextNarrowColumn()\n" +
+        "    ' Arrange\n" +
+        "    Range(\"A1\").Value = \"this is a long string that might be 
truncated\"\n" +
+        "\n" +
+        "    ' Act & Assert - .Text should return the display text\n" +
+        "    Range(\"AA1\").Value = Range(\"A1\").Text\n" +
+        "    Range(\"Z1\").Value = Len(Range(\"AA1\").Value)\n" +
+        "End Sub\n";
+
+    @Before
+    public void setUpVbaModules() throws Exception {
+        addBasicModule(MODULE_NAME, BASIC_SOURCE);
+    }
+
+    @Test
+    public void testRangeFind() throws Exception {
+        clearResultRow();
+        runMacro(MODULE_NAME, "TestRangeFind");
+        assertEquals("Find for 'Target' should return row 5",
+            5.0, getNumericResult(0), 0.001);
+    }
+
+    @Test
+    public void testRangeFindNotFound() throws Exception {
+        clearResultRow();
+        runMacro(MODULE_NAME, "TestRangeFindNotFound");
+        assertEquals("Find for non-existent should return Nothing (1)",
+            1.0, getNumericResult(0), 0.001);
+    }
+
+    @Test
+    public void testRangeText() throws Exception {
+        clearResultRow();
+        runMacro(MODULE_NAME, "TestRangeText");
+        assertEquals("Value of 42 should be 42",
+            42.0, getNumericResult(0), 0.001);
+        assertEquals("Text of 42 should be '42'",
+            "42", getStringResult(0));
+    }
+
+    @Test
+    public void testRangeTextFormatted() throws Exception {
+        clearResultRow();
+        runMacro(MODULE_NAME, "TestRangeTextFormatted");
+        String text = getStringResult(0);
+        assertNotNull("Text for date should not be null", text);
+        assertFalse("Text should not be empty", text.isEmpty());
+    }
+
+    @Test
+    public void testRangeTextString() throws Exception {
+        clearResultRow();
+        runMacro(MODULE_NAME, "TestRangeTextString");
+        assertEquals("Text of 'hello world' should be 'hello world'",
+            "hello world", getStringResult(0));
+    }
+
+    @Test
+    public void testRangeTextNarrowColumn() throws Exception {
+        clearResultRow();
+        runMacro(MODULE_NAME, "TestRangeTextNarrowColumn");
+        String text = getStringResult(0);
+        assertNotNull("Text for long string should not be null", text);
+    }
+
+    @Test
+    public void testColumnsCutInsert() throws Exception {
+        clearResultRow();
+        runMacro(MODULE_NAME, "TestColumnsCutInsert");
+        assertEquals("Cut and Insert should move 'original' to column C",
+            "original", getStringResult(0));
+    }
+
+    @Test
+    public void testRowsGroupUngroup() throws Exception {
+        clearResultRow();
+        runMacro(MODULE_NAME, "TestRowsGroupUngroup");
+        assertEquals("Range A3:A8 should have 6 rows",
+            6.0, getNumericResult(0), 0.001);
+        assertEquals("After Group, status should be 'grouped'",
+            "grouped", getStringResult(0));
+        assertEquals("After Ungroup, status should be 'ungrouped'",
+            "ungrouped", getStringResult(1));
+    }
+
+    @Test
+    public void testOffsetEntireRowHidden() throws Exception {
+        clearResultRow();
+        runMacro(MODULE_NAME, "TestOffsetEntireRowHidden");
+        assertEquals("EntireRow.Hidden after set=True should be -1",
+            -1.0, getNumericResult(0), 0.001);
+        assertEquals("EntireRow.Hidden after set=False should be 0",
+            0.0, getNumericResult(1), 0.001);
+    }
+}
diff --git a/main/sc/qa/vba/src/VbaSapStringTest.java 
b/main/sc/qa/vba/src/VbaSapStringTest.java
new file mode 100644
index 0000000000..23933bddd1
--- /dev/null
+++ b/main/sc/qa/vba/src/VbaSapStringTest.java
@@ -0,0 +1,284 @@
+/**************************************************************
+ *
+ * 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.
+ *
+ *************************************************************/
+
+package org.openoffice.sc.qa.vba;
+
+import org.junit.Test;
+import org.junit.Before;
+
+import static org.junit.Assert.*;
+
+/**
+ * P1: Tests for VBA string functions and operators derived from SAP IBP 
samples.
+ *
+ * Tests the following VBA language features:
+ * - InStr, Mid, Left, Len string parsing functions
+ * - Filter function (array string matching)
+ * - Like operator with wildcard patterns
+ * - Double-quote escape in string literals (""")
+ * - On Error GoTo with Err.Description
+ * - Module-level variable persistence between calls
+ *
+ * Test methodology: BASIC macros exercise the VBA APIs and write
+ * results to cells Z1, Z2, etc. (column 25). Java code verifies via UNO.
+ * Follows AAA pattern with '@TestMethod' markers in comments.
+ */
+public class VbaSapStringTest extends VbaCompatTest {
+
+    private static final String MODULE_NAME = "StringTests";
+
+    private static final String BASIC_SOURCE =
+        "REM  *****  BASIC  *****\n" +
+        "'@TestModule\n" +
+        "Option VBASupport 1\n" +
+        "\n" +
+
+        "'@TestMethod\n" +
+        "Sub TestStringParse()\n" +
+        "    ' Arrange - parse IBIS-style bracket format: 
=[PRDID].[].[PRD_001]\n" +
+        "    Dim s As String: s = \"=[PRDID].[].[PRD_001]\"\n" +
+        "\n" +
+        "    ' Act\n" +
+        "    Dim pos As Integer: pos = InStr(s, \".].[].[]\")\n" +
+        "    Dim result As String: result = Mid(s, pos + 7)\n" +
+        "    result = Left(result, Len(result) - 1)\n" +
+        "\n" +
+        "    ' Assert\n" +
+        "    Range(\"Z1\").Value = Len(result)\n" +
+        "    Range(\"AA1\").Value = result\n" +
+        "End Sub\n" +
+        "\n" +
+
+        "'@TestMethod\n" +
+        "Sub TestFilter()\n" +
+        "    ' Arrange\n" +
+        "    Dim arr As Variant\n" +
+        "    arr = Array(\"[PRDID].[].[PRD_001]\", 
\"[LOCREGION].[].[EUROPE]\")\n" +
+        "\n" +
+        "    ' Act\n" +
+        "    Dim filtered As Variant\n" +
+        "    filtered = Filter(arr, \"[PRDID].[].[]\")\n" +
+        "\n" +
+        "    ' Assert\n" +
+        "    Range(\"Z1\").Value = UBound(filtered) - LBound(filtered) + 1\n" +
+        "    Range(\"AA1\").Value = CStr(filtered(0))\n" +
+        "End Sub\n" +
+        "\n" +
+
+        "'@TestMethod\n" +
+        "Sub TestLikeOperator()\n" +
+        "    ' Arrange\n" +
+        "\n" +
+        "    ' Act & Assert\n" +
+        "    Dim r1 As Integer, r2 As Integer\n" +
+        "    If \"PRD_001\" Like \"*PRD*\" Then r1 = 1 Else r1 = 0\n" +
+        "    If \"ABC_001\" Like \"*IBP*\" Then r2 = 1 Else r2 = 0\n" +
+        "    Range(\"Z1\").Value = r1\n" +
+        "    Range(\"AA1\").Value = r2\n" +
+        "End Sub\n" +
+        "\n" +
+
+        "'@TestMethod\n" +
+        "Sub TestQuoteEscape()\n" +
+        "    ' Arrange\n" +
+        "    Dim s As String\n" +
+        "\n" +
+        "    ' Act\n" +
+        "    s = \"=@ EPMOlapMemberO(\"\"[ABCID]\")\"\n" +
+        "\n" +
+        "    ' Assert\n" +
+        "    Range(\"Z1\").Value = Len(s)\n" +
+        "    Range(\"AA1\").Value = s\n" +
+        "End Sub\n" +
+        "\n" +
+
+        "'@TestMethod\n" +
+        "Sub TestErrorHandling()\n" +
+        "    ' Arrange\n" +
+        "\n" +
+        "    ' Act\n" +
+        "    On Error GoTo ErrHandler\n" +
+        "    Dim x As Integer\n" +
+        "    x = CInt(\"not a number\")\n" +
+        "    Range(\"Z1\").Value = 0\n" +
+        "    Exit Sub\n" +
+        "ErrHandler:\n" +
+        "    Range(\"Z1\").Value = 1\n" +
+        "    Range(\"AA1\").Value = Err.Description\n" +
+        "    Resume Next\n" +
+        "End Sub\n" +
+        "\n" +
+
+        "'@TestMethod\n" +
+        "Sub TestModuleLevelVar()\n" +
+        "    ' Module-level counter is incremented in IncCounter, read here\n" 
+
+        "    Range(\"Z1\").Value = counter\n" +
+        "End Sub\n" +
+        "\n" +
+
+        "'@TestMethod\n" +
+        "Sub TestMidLeftInStrLen()\n" +
+        "    ' Arrange\n" +
+        "    Dim s As String: s = \"Hello World\"\n" +
+        "\n" +
+        "    ' Act & Assert\n" +
+        "    Range(\"Z1\").Value = CDbl(Len(s))\n" +
+        "    Range(\"AA1\").Value = Left(s, 5)\n" +
+        "    Range(\"Z2\").Value = CDbl(InStr(s, \"World\"))\n" +
+        "    Range(\"AA2\").Value = Mid(s, 7)\n" +
+        "End Sub\n" +
+        "\n" +
+
+        "'@TestMethod\n" +
+        "Sub TestFilterMultipleMatches()\n" +
+        "    ' Arrange\n" +
+        "    Dim arr As Variant\n" +
+        "    arr = Array(\"[PRDID].[].[PRD_001]\", \"[PRDID].[].[PRD_002]\", 
\"[LOCREGION].[].[EUROPE]\")\n" +
+        "\n" +
+        "    ' Act\n" +
+        "    Dim filtered As Variant\n" +
+        "    filtered = Filter(arr, \"[PRDID].[].[]\")\n" +
+        "\n" +
+        "    ' Assert\n" +
+        "    Range(\"Z1\").Value = UBound(filtered) - LBound(filtered) + 1\n" +
+        "End Sub\n" +
+        "\n" +
+
+        "'@TestMethod\n" +
+        "Sub TestLikeQuestionMark()\n" +
+        "    ' Arrange\n" +
+        "\n" +
+        "    ' Act & Assert - ? matches single character\n" +
+        "    Dim r1 As Integer, r2 As Integer\n" +
+        "    If \"ABC\" Like \"A?C\" Then r1 = 1 Else r1 = 0\n" +
+        "    If \"ABC\" Like \"A?D\" Then r2 = 1 Else r2 = 0\n" +
+        "    Range(\"Z1\").Value = r1\n" +
+        "    Range(\"AA1\").Value = r2\n" +
+        "End Sub\n" +
+
+        "Dim counter As Integer\n" +
+        "Sub IncCounter(): counter = counter + 1: End Sub\n";
+
+    @Before
+    public void setUpVbaModules() throws Exception {
+        addBasicModule(MODULE_NAME, BASIC_SOURCE);
+    }
+
+    // --- String parsing tests ---
+
+    @Test
+    public void testStringParse() throws Exception {
+        clearResultRow();
+        runMacro(MODULE_NAME, "TestStringParse");
+        assertEquals("Extracted PRD_001 should have length 7",
+            7.0, getNumericResult(0), 0.001);
+        assertEquals("Extracted member should be PRD_001",
+            "PRD_001", getStringResult(0));
+    }
+
+    @Test
+    public void testFilter() throws Exception {
+        clearResultRow();
+        runMacro(MODULE_NAME, "TestFilter");
+        assertEquals("Filter should return 1 element matching [PRDID]",
+            1.0, getNumericResult(0), 0.001);
+        assertEquals("First filtered element should match",
+            "[PRDID].[].[PRD_001]", getStringResult(0));
+    }
+
+    @Test
+    public void testFilterMultipleMatches() throws Exception {
+        clearResultRow();
+        runMacro(MODULE_NAME, "TestFilterMultipleMatches");
+        assertEquals("Filter should return 2 elements matching [PRDID]",
+            2.0, getNumericResult(0), 0.001);
+    }
+
+    @Test
+    public void testLikeOperator() throws Exception {
+        clearResultRow();
+        runMacro(MODULE_NAME, "TestLikeOperator");
+        assertEquals("\"PRD_001\" Like \"*PRD*\" should match (1)",
+            1.0, getNumericResult(0), 0.001);
+        assertEquals("\"ABC_001\" Like \"*IBP*\" should not match (0)",
+            0.0, getNumericResult(1), 0.001);
+    }
+
+    @Test
+    public void testLikeQuestionMark() throws Exception {
+        clearResultRow();
+        runMacro(MODULE_NAME, "TestLikeQuestionMark");
+        assertEquals("\"ABC\" Like \"A?C\" should match (1)",
+            1.0, getNumericResult(0), 0.001);
+        assertEquals("\"ABC\" Like \"A?D\" should not match (0)",
+            0.0, getNumericResult(1), 0.001);
+    }
+
+    @Test
+    public void testQuoteEscape() throws Exception {
+        clearResultRow();
+        runMacro(MODULE_NAME, "TestQuoteEscape");
+        assertEquals("Escaped string length should be 28",
+            28.0, getNumericResult(0), 0.001);
+        assertEquals("Unescaped string should be =@ 
EPMOlapMemberO(\"[ABCID]\")",
+            "=@ EPMOlapMemberO(\"[ABCID]\")", getStringResult(0));
+    }
+
+    // --- Error handling tests ---
+
+    @Test
+    public void testErrorHandling() throws Exception {
+        clearResultRow();
+        runMacro(MODULE_NAME, "TestErrorHandling");
+        assertEquals("Error handler should be triggered (1)",
+            1.0, getNumericResult(0), 0.001);
+        String errorMsg = getStringResult(0);
+        assertNotNull("Err.Description should not be null", errorMsg);
+    }
+
+    // --- Module-level variable test ---
+
+    @Test
+    public void testModuleLevelVarIncrement() throws Exception {
+        clearResultRow();
+        runMacro(MODULE_NAME, "IncCounter");
+        runMacro(MODULE_NAME, "IncCounter");
+        runMacro(MODULE_NAME, "TestModuleLevelVar");
+        assertEquals("Counter should be 2 after two increments",
+            2.0, getNumericResult(0), 0.001);
+    }
+
+    // --- String function tests ---
+
+    @Test
+    public void testMidLeftInStrLen() throws Exception {
+        clearResultRow();
+        runMacro(MODULE_NAME, "TestMidLeftInStrLen");
+        assertEquals("Len('Hello World') should be 11",
+            11.0, getNumericResult(0), 0.001);
+        assertEquals("Left('Hello World', 5) should be 'Hello'",
+            "Hello", getStringResult(0));
+        assertEquals("InStr('Hello World', 'World') should be 7",
+            7.0, getNumericResult(1), 0.001);
+        assertEquals("Mid('Hello World', 7) should be 'World'",
+            "World", getStringResult(1));
+    }
+}

Reply via email to