Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / basic / qa / cppunit / test_language_conditionals.cxx
blobc35d5571e9db68c5d12cb26322db8c94826265ca
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
10 #include "basictest.hxx"
12 #include <cppunit/TestAssert.h>
13 #include <cppunit/TestFixture.h>
14 #include <cppunit/extensions/HelperMacros.h>
16 namespace
18 class Language_Conditionals : public CppUnit::TestFixture
20 public:
21 void testIfNot();
22 void testIfAndNot();
23 void testNENot();
25 CPPUNIT_TEST_SUITE(Language_Conditionals);
27 CPPUNIT_TEST(testIfNot);
28 CPPUNIT_TEST(testIfAndNot);
29 CPPUNIT_TEST(testNENot);
31 CPPUNIT_TEST_SUITE_END();
34 void Language_Conditionals::testIfNot()
36 { // need a block to ensure MacroSnippet is cleaned properly
37 MacroSnippet myMacro("Option VBASupport 1\n"
38 "Option Explicit\n"
39 "\n"
40 "Function doUnitTest() As Integer\n"
41 "Dim op1 As Boolean\n"
42 "op1 = False\n"
43 "If Not op1 Then\n"
44 "doUnitTest = 1\n"
45 "Else\n"
46 "doUnitTest = 0\n"
47 "End If\n"
48 "End Function\n");
49 myMacro.Compile();
50 CPPUNIT_ASSERT(!myMacro.HasError());
51 SbxVariableRef pNew = myMacro.Run();
52 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(1), pNew->GetInteger());
54 { // need a block to ensure MacroSnippet is cleaned properly
55 MacroSnippet myMacro("Option VBASupport 0\n"
56 "Option Explicit\n"
57 "\n"
58 "Function doUnitTest() As Integer\n"
59 "Dim op1 As Boolean\n"
60 "op1 = False\n"
61 "If Not op1 Then\n"
62 "doUnitTest = 1\n"
63 "Else\n"
64 "doUnitTest = 0\n"
65 "End If\n"
66 "End Function\n");
67 myMacro.Compile();
68 CPPUNIT_ASSERT(!myMacro.HasError());
69 SbxVariableRef pNew = myMacro.Run();
70 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(1), pNew->GetInteger());
74 void Language_Conditionals::testIfAndNot()
76 { // need a block to ensure MacroSnippet is cleaned properly
77 MacroSnippet myMacro("Option VBASupport 1\n"
78 "Option Explicit\n"
79 "\n"
80 "Function doUnitTest() As Integer\n"
81 "Dim op1 As Boolean\n"
82 "Dim op2 As Boolean\n"
83 "op1 = True\n"
84 "op2 = False\n"
85 "If op1 And Not op2 Then\n"
86 "doUnitTest = 1\n"
87 "Else\n"
88 "doUnitTest = 0\n"
89 "End If\n"
90 "End Function\n");
91 myMacro.Compile();
92 CPPUNIT_ASSERT(!myMacro.HasError());
93 SbxVariableRef pNew = myMacro.Run();
94 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(1), pNew->GetInteger());
96 { // need a block to ensure MacroSnippet is cleaned properly
97 MacroSnippet myMacro("Option VBASupport 0\n"
98 "Option Explicit\n"
99 "\n"
100 "Function doUnitTest() As Integer\n"
101 "Dim op1 As Boolean\n"
102 "Dim op2 As Boolean\n"
103 "op1 = True\n"
104 "op2 = False\n"
105 "If op1 And Not op2 Then\n"
106 "doUnitTest = 1\n"
107 "Else\n"
108 "doUnitTest = 0\n"
109 "End If\n"
110 "End Function\n");
111 myMacro.Compile();
112 CPPUNIT_ASSERT(!myMacro.HasError());
113 SbxVariableRef pNew = myMacro.Run();
114 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(1), pNew->GetInteger());
118 void Language_Conditionals::testNENot()
120 { // need a block to ensure MacroSnippet is cleaned properly
121 MacroSnippet myMacro("Option VBASupport 1\n"
122 "Option Explicit\n"
123 "\n"
124 "Function doUnitTest() As Integer\n"
125 "Dim op1 As Boolean\n"
126 "Dim op2 As Boolean\n"
127 "op1 = False\n"
128 "op2 = False\n"
129 "If op1 <> Not op2 Then\n"
130 "doUnitTest = 1\n"
131 "Else\n"
132 "doUnitTest = 0\n"
133 "End If\n"
134 "End Function\n");
135 myMacro.Compile();
136 CPPUNIT_ASSERT(!myMacro.HasError());
137 SbxVariableRef pNew = myMacro.Run();
138 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(1), pNew->GetInteger());
140 { // need a block to ensure MacroSnippet is cleaned properly
141 MacroSnippet myMacro("Option VBASupport 0\n"
142 "Option Explicit\n"
143 "\n"
144 "Function doUnitTest() As Integer\n"
145 "Dim op1 As Boolean\n"
146 "Dim op2 As Boolean\n"
147 "op1 = False\n"
148 "op2 = False\n"
149 "If op1 <> Not op2 Then\n"
150 "doUnitTest = 1\n"
151 "Else\n"
152 "doUnitTest = 0\n"
153 "End If\n"
154 "End Function\n");
155 myMacro.Compile();
156 CPPUNIT_ASSERT(!myMacro.HasError());
157 SbxVariableRef pNew = myMacro.Run();
158 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(1), pNew->GetInteger());
162 CPPUNIT_TEST_SUITE_REGISTRATION(Language_Conditionals);
164 } // namespace
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */