Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * Copyright 2012 LibreOffice contributors.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : */
9 : : #include "basictest.hxx"
10 : : #include "osl/file.hxx"
11 : : #include "osl/process.h"
12 : :
13 : : #include "basic/sbmod.hxx"
14 : : #include "basic/sbmeth.hxx"
15 : : namespace
16 : : {
17 [ - + ]: 24 : class Nested_Struct : public BasicTestBase
18 : : {
19 : : public:
20 : 12 : Nested_Struct() {};
21 : : void testAssign1();
22 : : void testOldAssign();
23 : : void testUnfixedVarAssign();
24 : : void testFixedVarAssign();
25 : : // Adds code needed to register the test suite
26 [ + - ][ + - ]: 6 : CPPUNIT_TEST_SUITE(Nested_Struct);
[ + - ][ + - ]
[ # # ]
27 : :
28 : : // Declares the method as a test to call
29 [ + - ][ + - ]: 3 : CPPUNIT_TEST(testAssign1);
[ + - ][ + - ]
[ + - ][ + - ]
30 [ + - ][ + - ]: 3 : CPPUNIT_TEST(testOldAssign);
[ + - ][ + - ]
[ + - ][ + - ]
31 [ + - ][ + - ]: 3 : CPPUNIT_TEST(testUnfixedVarAssign);
[ + - ][ + - ]
[ + - ][ + - ]
32 [ + - ][ + - ]: 3 : CPPUNIT_TEST(testFixedVarAssign);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
33 : :
34 : : // End of test suite definition
35 [ + - ][ + - ]: 6 : CPPUNIT_TEST_SUITE_END();
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
36 : : };
37 : :
38 : : // tests the new behaviour, we should be able to
39 : : // directly modify the value of the nested 'HorizontalLine' struct
40 : 3 : rtl::OUString sTestSource1(
41 : : "Function simpleNestStructAccess() as Integer\n"
42 : : "Dim b0 as new \"com.sun.star.table.TableBorder\"\n"
43 : : "b0.HorizontalLine.OuterLineWidth = 9\n"
44 : : "simpleNestStructAccess = b0.HorizontalLine.OuterLineWidth\n"
45 : : "End Function\n"
46 : 3 : );
47 : :
48 : : // tests the old behaviour, we should still be able
49 : : // to use the old workaround of
50 : : // a) creating a new instance BorderLine,
51 : : // b) cloning the new instance with the value of b0.HorizontalLine
52 : : // c) modifying the new instance
53 : : // d) setting b0.HorizontalLine with the value of the new instance
54 : 3 : rtl::OUString sTestSource2(
55 : : "Function simpleRegressionTestOld()\n"
56 : : "Dim b0 as new \"com.sun.star.table.TableBorder\", l as new \"com.sun.star.table.BorderLine\"\n"
57 : : "l = b0.HorizontalLine\n"
58 : : "l.OuterLineWidth = 9\n"
59 : : "b0.HorizontalLine = l\n"
60 : : "simpleRegressionTestOld = b0.HorizontalLine.OuterLineWidth\n"
61 : : "End Function\n"
62 : 3 : );
63 : :
64 : : // it should be legal to assign a variant to a struct ( and copy by val )
65 : : // make sure we aren't copying by reference, we make sure that l is not
66 : : // a reference copy of b0.HorizontalLine, each one should have an
67 : : // OuterLineWidth of 4 & 9 respectively and we should be returning
68 : : // 13 the sum of the two ( hopefully unique values if we haven't copied by reference )
69 : 3 : rtl::OUString sTestSource3(
70 : : "Function testUnfixedVarAssign()\n"
71 : : "Dim b0 as new \"com.sun.star.table.TableBorder\"\n"
72 : : "l = b0.HorizontalLine\n"
73 : : "l.OuterLineWidth = 9\n"
74 : : "b0.HorizontalLine = l\n"
75 : : "l.OuterLineWidth = 4\n"
76 : : "testUnfixedVarAssign = b0.HorizontalLine.OuterLineWidth + l.OuterLineWidth\n"
77 : : "End Function\n"
78 : 3 : );
79 : :
80 : : // nearly the same as above but this time for a fixed type
81 : : // variable
82 : 3 : rtl::OUString sTestSource4(
83 : : "Function testFixedVarAssign()\n"
84 : : "Dim b0 as new \"com.sun.star.table.TableBorder\", l as new \"com.sun.star.table.BorderLine\"\n"
85 : : "l = b0.HorizontalLine\n"
86 : : "l.OuterLineWidth = 9\n"
87 : : "b0.HorizontalLine = l\n"
88 : : "l.OuterLineWidth = 4\n"
89 : : "testFixedVarAssign = b0.HorizontalLine.OuterLineWidth + l.OuterLineWidth\n"
90 : : "End Function\n"
91 : 3 : );
92 : :
93 : 3 : void Nested_Struct::testAssign1()
94 : : {
95 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT_MESSAGE( "No resource manager", basicDLL().GetBasResMgr() != NULL );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
96 [ + - ][ + - ]: 3 : StarBASICRef pBasic = new StarBASIC();
97 [ + - ]: 3 : ResetError();
98 [ + - ][ + - ]: 3 : StarBASIC::SetGlobalErrorHdl( LINK( this, Nested_Struct, BasicErrorHdl ) );
99 : :
100 [ + - ][ + - ]: 3 : SbModule* pMod = pBasic->MakeModule( rtl::OUString( "TestModule" ), sTestSource1 );
[ + - ][ + - ]
[ + - ]
101 [ + - ]: 3 : pMod->Compile();
102 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT_MESSAGE("testAssign1 fails with compile error",!HasError() );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
103 [ + - ]: 3 : SbMethod* pMeth = static_cast<SbMethod*>(pMod->Find( rtl::OUString("simpleNestStructAccess"), SbxCLASS_METHOD ));
104 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT_MESSAGE("testAssign1 no method found", pMeth );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
105 : 3 : SbxVariableRef refTemp = pMeth;
106 : : // forces a broadcast
107 [ + - ][ + - ]: 3 : SbxVariableRef pNew = new SbxMethod( *((SbxMethod*)pMeth));
108 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT(pNew->GetInteger() == 9 );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
109 : 3 : }
110 : :
111 : 3 : void Nested_Struct::testOldAssign()
112 : : {
113 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT_MESSAGE( "No resource manager", basicDLL().GetBasResMgr() != NULL );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
114 [ + - ][ + - ]: 3 : StarBASICRef pBasic = new StarBASIC();
115 [ + - ]: 3 : ResetError();
116 [ + - ][ + - ]: 3 : StarBASIC::SetGlobalErrorHdl( LINK( this, Nested_Struct, BasicErrorHdl ) );
117 : :
118 [ + - ][ + - ]: 3 : SbModule* pMod = pBasic->MakeModule( rtl::OUString( "TestModule" ), sTestSource2 );
[ + - ][ + - ]
[ + - ]
119 [ + - ]: 3 : pMod->Compile();
120 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT_MESSAGE("testOldAssign fails with compile error",!HasError() );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
121 [ + - ]: 3 : SbMethod* pMeth = static_cast<SbMethod*>(pMod->Find( rtl::OUString("simpleRegressionTestOld"), SbxCLASS_METHOD ));
122 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT_MESSAGE("testOldAssign no method found", pMeth );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
123 : 3 : SbxVariableRef refTemp = pMeth;
124 : : // forces a broadcast
125 [ + - ][ + - ]: 3 : SbxVariableRef pNew = new SbxMethod( *((SbxMethod*)pMeth));
126 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT(pNew->GetInteger() == 9 );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
127 : 3 : }
128 : :
129 : 3 : void Nested_Struct::testUnfixedVarAssign()
130 : : {
131 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT_MESSAGE( "No resource manager", basicDLL().GetBasResMgr() != NULL );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
132 [ + - ][ + - ]: 3 : StarBASICRef pBasic = new StarBASIC();
133 [ + - ]: 3 : ResetError();
134 [ + - ][ + - ]: 3 : StarBASIC::SetGlobalErrorHdl( LINK( this, Nested_Struct, BasicErrorHdl ) );
135 : :
136 [ + - ][ + - ]: 3 : SbModule* pMod = pBasic->MakeModule( rtl::OUString( "TestModule" ), sTestSource3 );
[ + - ][ + - ]
[ + - ]
137 [ + - ]: 3 : pMod->Compile();
138 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT_MESSAGE("testUnfixedVarAssign fails with compile error",!HasError() );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
139 [ + - ]: 3 : SbMethod* pMeth = static_cast<SbMethod*>(pMod->Find( rtl::OUString("testUnfixedVarAssign"), SbxCLASS_METHOD ));
140 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT_MESSAGE("testUnfixedVarAssign no method found", pMeth );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
141 : 3 : SbxVariableRef refTemp = pMeth;
142 : : // forces a broadcast
143 [ + - ][ + - ]: 3 : SbxVariableRef pNew = new SbxMethod( *((SbxMethod*)pMeth));
144 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT(pNew->GetInteger() == 13 );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
145 : 3 : }
146 : :
147 : 3 : void Nested_Struct::testFixedVarAssign()
148 : : {
149 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT_MESSAGE( "No resource manager", basicDLL().GetBasResMgr() != NULL );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
150 [ + - ][ + - ]: 3 : StarBASICRef pBasic = new StarBASIC();
151 [ + - ]: 3 : ResetError();
152 [ + - ][ + - ]: 3 : StarBASIC::SetGlobalErrorHdl( LINK( this, Nested_Struct, BasicErrorHdl ) );
153 : :
154 [ + - ][ + - ]: 3 : SbModule* pMod = pBasic->MakeModule( rtl::OUString( "TestModule" ), sTestSource4 );
[ + - ][ + - ]
[ + - ]
155 [ + - ]: 3 : pMod->Compile();
156 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT_MESSAGE("testFixedVarAssign fails with compile error",!HasError() );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
157 [ + - ]: 3 : SbMethod* pMeth = static_cast<SbMethod*>(pMod->Find( rtl::OUString("testFixedVarAssign"), SbxCLASS_METHOD ));
158 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT_MESSAGE("testFixedVarAssign no method found", pMeth );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
159 : 3 : SbxVariableRef refTemp = pMeth;
160 : : // forces a broadcast
161 [ + - ][ + - ]: 3 : SbxVariableRef pNew = new SbxMethod( *((SbxMethod*)pMeth));
162 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT(pNew->GetInteger() == 13 );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
163 : 3 : }
164 : :
165 : : // Put the test suite in the registry
166 : 3 : CPPUNIT_TEST_SUITE_REGISTRATION(Nested_Struct);
167 : : } // namespace
168 [ + - ][ + - ]: 12 : CPPUNIT_PLUGIN_IMPLEMENT();
[ + - ][ + - ]
[ + - ][ # # ]
169 : :
170 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|