Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / compilerplugins / clang / test / xmlimport.cxx
blobfa1d42a2f1ede3d14288794938960cf99e249eaa
1 /* -*- Mode: C++; tab-width: 2; 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 "sal/config.h"
12 // Cannot include this, makes clang crash
13 //#include "xmloff/xmlimp.hxx"
14 // Cannot include this, cannot be found
15 //#include <xmloff/xmlictxt.hxx>
17 #include <com/sun/star/uno/Reference.hxx>
18 #include <rtl/ref.hxx>
20 namespace com::sun::star::xml::sax
22 class XAttributeList;
23 class XFastContextHandler;
26 class SvXMLImportContext;
27 typedef rtl::Reference<SvXMLImportContext> SvXMLImportContextRef;
28 class SvXMLImportContext
30 public:
31 virtual ~SvXMLImportContext() {}
33 virtual void startFastElement() {}
34 virtual void endFastElement() {}
35 virtual void characters(const OUString&) {}
36 virtual css::uno::Reference<css::xml::sax::XFastContextHandler> createFastChildContext()
38 return nullptr;
40 virtual css::uno::Reference<css::xml::sax::XFastContextHandler> createUnknownChildContext()
42 return nullptr;
45 virtual void StartElement(const css::uno::Reference<css::xml::sax::XAttributeList>&) {}
46 virtual void EndElement() {}
47 virtual void Characters(const OUString&) {}
48 virtual SvXMLImportContextRef CreateChildContext() { return nullptr; }
50 void acquire();
51 void release();
53 void xxx(); // just here to avoid triggering a warning I don't want to check for
56 class Test1 : public SvXMLImportContext
58 public:
59 // expected-error@+1 {{cannot override both startFastElement and StartElement [loplugin:xmlimport]}}
60 virtual void startFastElement() override { xxx(); }
61 // expected-error@+1 {{cannot override both startFastElement and StartElement [loplugin:xmlimport]}}
62 virtual void StartElement(const css::uno::Reference<css::xml::sax::XAttributeList>&) override
64 xxx();
68 class Test2 : public SvXMLImportContext
70 public:
71 // expected-error@+1 {{cannot override both endFastElement and EndElement [loplugin:xmlimport]}}
72 virtual void endFastElement() override { xxx(); }
73 // expected-error@+1 {{cannot override both endFastElement and EndElement [loplugin:xmlimport]}}
74 virtual void EndElement() override { xxx(); }
77 class Test3 : public SvXMLImportContext
79 public:
80 // expected-error@+1 {{cannot override both characters and Characters [loplugin:xmlimport]}}
81 virtual void Characters(const OUString&) override { xxx(); }
82 // expected-error@+1 {{cannot override both characters and Characters [loplugin:xmlimport]}}
83 virtual void characters(const OUString&) override { xxx(); }
86 class Test7 : public SvXMLImportContext
88 public:
89 virtual void startFastElement() override
91 // expected-error@+1 {{don't call this superclass method [loplugin:xmlimport]}}
92 SvXMLImportContext::startFastElement();
94 virtual void endFastElement() override
96 // expected-error@+1 {{don't call this superclass method [loplugin:xmlimport]}}
97 SvXMLImportContext::endFastElement();
99 virtual void characters(const OUString& rChars) override
101 // expected-error@+1 {{don't call this superclass method [loplugin:xmlimport]}}
102 SvXMLImportContext::characters(rChars);
104 virtual css::uno::Reference<css::xml::sax::XFastContextHandler>
105 createFastChildContext() override
107 // expected-error@+1 {{don't call this superclass method [loplugin:xmlimport]}}
108 return SvXMLImportContext::createFastChildContext();
110 virtual css::uno::Reference<css::xml::sax::XFastContextHandler>
111 createUnknownChildContext() override
113 // expected-error@+1 {{don't call this superclass method [loplugin:xmlimport]}}
114 return SvXMLImportContext::createUnknownChildContext();
118 class Test8 : public SvXMLImportContext
120 public:
121 virtual void
122 StartElement(const css::uno::Reference<css::xml::sax::XAttributeList>& xAttrList) override
124 // expected-error@+1 {{don't call this superclass method [loplugin:xmlimport]}}
125 SvXMLImportContext::StartElement(xAttrList);
127 virtual void EndElement() override
129 // expected-error@+1 {{don't call this superclass method [loplugin:xmlimport]}}
130 SvXMLImportContext::EndElement();
132 virtual void Characters(const OUString& rChars) override
134 // expected-error@+1 {{don't call this superclass method [loplugin:xmlimport]}}
135 SvXMLImportContext::Characters(rChars);
137 virtual SvXMLImportContextRef CreateChildContext() override
139 // expected-error@+1 {{don't call this superclass method [loplugin:xmlimport]}}
140 return SvXMLImportContext::CreateChildContext();
144 // no warning expected
145 class Test9a : public SvXMLImportContext
147 public:
148 virtual void StartElement(const css::uno::Reference<css::xml::sax::XAttributeList>&) override
150 xxx();
153 class Test9b : public Test9a
155 public:
156 virtual void
157 StartElement(const css::uno::Reference<css::xml::sax::XAttributeList>& xAttrList) override
159 Test9a::StartElement(xAttrList);
163 class Test10a : public SvXMLImportContext
165 public:
166 // expected-error@+1 {{empty, should be removed [loplugin:xmlimport]}}
167 virtual void startFastElement() override {}
168 // expected-error@+1 {{empty, should be removed [loplugin:xmlimport]}}
169 virtual void endFastElement() override {}
170 // expected-error@+1 {{empty, should be removed [loplugin:xmlimport]}}
171 virtual void characters(const OUString&) override {}
172 // expected-error@+1 {{empty, should be removed [loplugin:xmlimport]}}
173 virtual css::uno::Reference<css::xml::sax::XFastContextHandler>
174 createFastChildContext() override
176 return nullptr;
178 // expected-error@+1 {{empty, should be removed [loplugin:xmlimport]}}
179 virtual css::uno::Reference<css::xml::sax::XFastContextHandler>
180 createUnknownChildContext() override
182 return nullptr;
185 // no warning expected
186 class Test10b : public SvXMLImportContext
188 public:
189 virtual void StartElement(const css::uno::Reference<css::xml::sax::XAttributeList>&) override {}
190 virtual void EndElement() override {}
191 virtual void Characters(const OUString&) override {}
192 virtual SvXMLImportContextRef CreateChildContext() override { return nullptr; }
195 enum XmlTokens
197 XML_TOK_1
200 void test20(sal_uInt32 p, sal_uInt16 q, XmlTokens e)
202 // expected-error@+1 {{comparing XML_TOK enum to 'sal_uInt32', expected sal_uInt16 [loplugin:xmlimport]}}
203 if (p == XML_TOK_1)
205 // no warning expected
206 if (q == XML_TOK_1)
208 switch (p)
210 // expected-error@+1 {{comparing XML_TOK enum to 'sal_uInt32', expected sal_uInt16 [loplugin:xmlimport]}}
211 case XML_TOK_1:
212 break;
214 switch (q)
216 // no warning expected
217 case XML_TOK_1:
218 break;
220 switch (e)
222 // no warning expected
223 case XML_TOK_1:
224 break;
227 void callInt32(sal_Int32);
228 void test21()
230 // expected-error@+1 {{passing XML_TOK enum to 'sal_Int32', wrong param or XML token type [loplugin:xmlimport]}}
231 callInt32(XML_TOK_1);
233 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */