1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <sal/config.h>
#include <config_fonts.h>
#include <vcl/print.hxx>
#include <test/bootstrapfixture.hxx>
#include <smdll.hxx>
#include <document.hxx>
#include <view.hxx>
#include <tmpdevice.hxx>
#include <sfx2/sfxmodelfactory.hxx>
#include <sfx2/bindings.hxx>
#include <sfx2/request.hxx>
#include <sfx2/dispatch.hxx>
#include <editeng/editeng.hxx>
#include <sfx2/zoomitem.hxx>
#include <starmath.hrc>
#include <memory>
typedef tools::SvRef<SmDocShell> SmDocShellRef;
using namespace ::com::sun::star;
namespace {
class Test : public test::BootstrapFixture
{
public:
Test();
// init
virtual void setUp() override;
virtual void tearDown() override;
// tests
void editUndoRedo();
void editMarker();
void editFailure();
void ParseErrorUnexpectedToken();
void ParseErrorPoundExpected();
void ParseErrorColorExpected();
void ParseErrorLgroupExpected();
void ParseErrorRgroupExpected();
void ParseErrorLbraceExpected();
void ParseErrorRbraceExpected();
void ParseErrorParentMismatch();
void ParseErrorRightExpected();
void ParseErrorFontExpected();
void ParseErrorSizeExpected();
void ParseErrorDoubleAlign();
void ParseErrorDoubleSubsupscript();
void replacePlaceholder();
void viewZoom();
#if HAVE_MORE_FONTS
void testSmTmpDeviceRestoreFont();
#endif
CPPUNIT_TEST_SUITE(Test);
CPPUNIT_TEST(editUndoRedo);
CPPUNIT_TEST(editMarker);
CPPUNIT_TEST(editFailure);
CPPUNIT_TEST(ParseErrorUnexpectedToken);
CPPUNIT_TEST(ParseErrorPoundExpected);
CPPUNIT_TEST(ParseErrorColorExpected);
CPPUNIT_TEST(ParseErrorLgroupExpected);
CPPUNIT_TEST(ParseErrorRgroupExpected);
CPPUNIT_TEST(ParseErrorLbraceExpected);
CPPUNIT_TEST(ParseErrorRbraceExpected);
CPPUNIT_TEST(ParseErrorParentMismatch);
CPPUNIT_TEST(ParseErrorRightExpected);
CPPUNIT_TEST(ParseErrorFontExpected);
CPPUNIT_TEST(ParseErrorSizeExpected);
CPPUNIT_TEST(ParseErrorDoubleAlign);
CPPUNIT_TEST(ParseErrorDoubleSubsupscript);
CPPUNIT_TEST(replacePlaceholder);
CPPUNIT_TEST(viewZoom);
#if HAVE_MORE_FONTS
CPPUNIT_TEST(testSmTmpDeviceRestoreFont);
#endif
CPPUNIT_TEST_SUITE_END();
private:
SfxBindings m_aBindings;
std::unique_ptr<SfxDispatcher> m_pDispatcher;
VclPtr<SmCmdBoxWindow> m_pSmCmdBoxWindow;
SmDocShellRef m_xDocShRef;
SmViewShell *m_pViewShell;
};
Test::Test()
: m_pViewShell(nullptr)
{
}
void Test::setUp()
{
BootstrapFixture::setUp();
SmGlobals::ensure();
m_xDocShRef = new SmDocShell(
SfxModelFlags::EMBEDDED_OBJECT |
SfxModelFlags::DISABLE_EMBEDDED_SCRIPTS |
SfxModelFlags::DISABLE_DOCUMENT_RECOVERY);
m_xDocShRef->DoInitNew();
SfxViewFrame *pViewFrame = SfxViewFrame::LoadHiddenDocument(*m_xDocShRef, SFX_INTERFACE_NONE);
CPPUNIT_ASSERT_MESSAGE("Should have a SfxViewFrame", pViewFrame);
m_pDispatcher.reset(new SfxDispatcher(pViewFrame));
m_aBindings.SetDispatcher(m_pDispatcher.get());
m_aBindings.EnterRegistrations();
m_pSmCmdBoxWindow.reset(VclPtr<SmCmdBoxWindow>::Create(&m_aBindings, nullptr, nullptr));
m_aBindings.LeaveRegistrations();
m_pViewShell = m_pSmCmdBoxWindow->GetView();
CPPUNIT_ASSERT_MESSAGE("Should have a SmViewShell", m_pViewShell);
}
void Test::tearDown()
{
m_pSmCmdBoxWindow.disposeAndClear();
m_pDispatcher.reset();
m_xDocShRef->DoClose();
m_xDocShRef.clear();
BootstrapFixture::tearDown();
}
#if HAVE_MORE_FONTS
void Test::testSmTmpDeviceRestoreFont()
{
ScopedVclPtrInstance<Printer> pPrinter;
OUString aFontName("Linux Libertine G");
CPPUNIT_ASSERT(pPrinter->IsFontAvailable(aFontName));
vcl::Font aOriginalFont = pPrinter->GetFont();
aOriginalFont.SetColor(COL_RED);
pPrinter->SetTextColor(COL_RED);
vcl::Font aNewFont;
{
bool bUseMap100th_mm = true;
SmTmpDevice aTmpDev(*pPrinter, bUseMap100th_mm);
aNewFont = pPrinter->GetFont();
aNewFont.SetFamilyName(aFontName);
aTmpDev.SetFont(aNewFont);
CPPUNIT_ASSERT_EQUAL(aFontName, pPrinter->GetFont().GetFamilyName());
CPPUNIT_ASSERT_EQUAL(COL_BLACK, pPrinter->GetTextColor());
}
CPPUNIT_ASSERT(aNewFont != pPrinter->GetFont());
CPPUNIT_ASSERT_EQUAL(COL_RED, pPrinter->GetTextColor());
}
#endif
void Test::editMarker()
{
SmEditWindow& rEditWindow = m_pSmCmdBoxWindow->GetEditWindow();
{
OUString sMarkedText("<?> under <?> under <?>");
rEditWindow.SetText(sMarkedText);
rEditWindow.Flush();
OUString sFinalText = rEditWindow.GetText();
CPPUNIT_ASSERT_EQUAL_MESSAGE("Should be equal text", sMarkedText, sFinalText);
}
{
ESelection aSelection;
rEditWindow.SelNextMark();
rEditWindow.Delete();
rEditWindow.InsertText("a");
rEditWindow.SelNextMark();
rEditWindow.SelNextMark();
rEditWindow.Delete();
rEditWindow.InsertText("c");
// should be safe i.e. do nothing
rEditWindow.SelNextMark();
aSelection = rEditWindow.GetSelection();
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aSelection.nStartPara);
CPPUNIT_ASSERT_EQUAL(sal_Int32(19), aSelection.nStartPos);
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aSelection.nEndPara);
CPPUNIT_ASSERT_EQUAL(sal_Int32(19), aSelection.nEndPos);
rEditWindow.SelPrevMark();
rEditWindow.Delete();
rEditWindow.InsertText("b");
// tdf#106116: should be safe i.e. do nothing
rEditWindow.SelPrevMark();
aSelection = rEditWindow.GetSelection();
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aSelection.nStartPara);
CPPUNIT_ASSERT_EQUAL(sal_Int32(9), aSelection.nStartPos);
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aSelection.nEndPara);
CPPUNIT_ASSERT_EQUAL(sal_Int32(9), aSelection.nEndPos);
rEditWindow.Flush();
OUString sFinalText = rEditWindow.GetText();
CPPUNIT_ASSERT_EQUAL_MESSAGE("Should be a under b under c", OUString("a under b under c"), sFinalText);
}
{
rEditWindow.SetText(OUString());
rEditWindow.Flush();
}
}
void Test::editFailure()
{
m_xDocShRef->SetText("color a b over {a/}");
const SmErrorDesc *pErrorDesc = m_xDocShRef->GetParser()->NextError();
CPPUNIT_ASSERT_MESSAGE("Should be a SmParseError::ColorExpected",
pErrorDesc);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Should be a SmParseError::ColorExpected",
SmParseError::ColorExpected, pErrorDesc->m_eType);
pErrorDesc = m_xDocShRef->GetParser()->PrevError();
CPPUNIT_ASSERT_MESSAGE("Should be a SmParseError::UnexpectedChar",
pErrorDesc);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Should be a SmParseError::UnexpectedChar",
SmParseError::UnexpectedChar, pErrorDesc->m_eType);
pErrorDesc = m_xDocShRef->GetParser()->PrevError();
CPPUNIT_ASSERT_MESSAGE("Should be a SmParseError::RgroupExpected",
pErrorDesc);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Should be a SmParseError::RgroupExpected",
SmParseError::RgroupExpected, pErrorDesc->m_eType);
const SmErrorDesc *pLastErrorDesc = m_xDocShRef->GetParser()->PrevError();
CPPUNIT_ASSERT_MESSAGE("Should be three syntax errors",
pLastErrorDesc);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Should be three syntax errors",
pErrorDesc, pLastErrorDesc);
}
void Test::ParseErrorUnexpectedToken()
{
m_xDocShRef->SetText("\\foo");
const SmErrorDesc *pErrorDesc = m_xDocShRef->GetParser()->NextError();
CPPUNIT_ASSERT(pErrorDesc);
CPPUNIT_ASSERT_EQUAL_MESSAGE("SmParseError::UnexpectedToken expected",
SmParseError::UnexpectedToken, pErrorDesc->m_eType);
}
void Test::ParseErrorPoundExpected()
{
m_xDocShRef->SetText("matrix {1#2##a##b#c}");
const SmErrorDesc *pErrorDesc = m_xDocShRef->GetParser()->NextError();
CPPUNIT_ASSERT(pErrorDesc);
CPPUNIT_ASSERT_EQUAL_MESSAGE("SmParseError::PoundExpected expected",
SmParseError::PoundExpected, pErrorDesc->m_eType);
}
void Test::ParseErrorColorExpected()
{
m_xDocShRef->SetText("color 42 x");
const SmErrorDesc *pErrorDesc = m_xDocShRef->GetParser()->NextError();
CPPUNIT_ASSERT(pErrorDesc);
CPPUNIT_ASSERT_EQUAL_MESSAGE("SmParseError::ColorExpected expected",
SmParseError::ColorExpected, pErrorDesc->m_eType);
}
void Test::ParseErrorLgroupExpected()
{
m_xDocShRef->SetText("stack 42");
const SmErrorDesc *pErrorDesc = m_xDocShRef->GetParser()->NextError();
CPPUNIT_ASSERT(pErrorDesc);
CPPUNIT_ASSERT_EQUAL_MESSAGE("SmParseError::LgroupExpected expected",
SmParseError::LgroupExpected, pErrorDesc->m_eType);
}
void Test::ParseErrorRgroupExpected()
{
m_xDocShRef->SetText("stack {a#b#c)");
const SmErrorDesc *pErrorDesc = m_xDocShRef->GetParser()->NextError();
CPPUNIT_ASSERT(pErrorDesc);
CPPUNIT_ASSERT_EQUAL_MESSAGE("SmParseError::RgroupExpected expected",
SmParseError::RgroupExpected, pErrorDesc->m_eType);
}
void Test::ParseErrorLbraceExpected()
{
m_xDocShRef->SetText("left 42");
const SmErrorDesc *pErrorDesc = m_xDocShRef->GetParser()->NextError();
CPPUNIT_ASSERT(pErrorDesc);
CPPUNIT_ASSERT_EQUAL_MESSAGE("SmParseError::LbraceExpected expected",
SmParseError::LbraceExpected, pErrorDesc->m_eType);
}
void Test::ParseErrorRbraceExpected()
{
m_xDocShRef->SetText("left ( foo right x");
const SmErrorDesc *pErrorDesc = m_xDocShRef->GetParser()->NextError();
CPPUNIT_ASSERT(pErrorDesc);
CPPUNIT_ASSERT_EQUAL_MESSAGE("SmParseError::RbraceExpected expected",
SmParseError::RbraceExpected, pErrorDesc->m_eType);
}
void Test::ParseErrorParentMismatch()
{
m_xDocShRef->SetText("lbrace foo rceil");
const SmErrorDesc *pErrorDesc = m_xDocShRef->GetParser()->NextError();
CPPUNIT_ASSERT(pErrorDesc);
CPPUNIT_ASSERT_EQUAL_MESSAGE("SmParseError::ParentMismatch expected",
SmParseError::ParentMismatch, pErrorDesc->m_eType);
}
void Test::ParseErrorRightExpected()
{
m_xDocShRef->SetText("left ( x mline y )");
const SmErrorDesc *pErrorDesc = m_xDocShRef->GetParser()->NextError();
CPPUNIT_ASSERT(pErrorDesc);
CPPUNIT_ASSERT_EQUAL_MESSAGE("SmParseError::RightExpected expected",
SmParseError::RightExpected, pErrorDesc->m_eType);
}
void Test::ParseErrorFontExpected()
{
m_xDocShRef->SetText("font small bar");
const SmErrorDesc *pErrorDesc = m_xDocShRef->GetParser()->NextError();
CPPUNIT_ASSERT(pErrorDesc);
CPPUNIT_ASSERT_EQUAL_MESSAGE("SmParseError::FontExpected expected",
SmParseError::FontExpected, pErrorDesc->m_eType);
}
void Test::ParseErrorSizeExpected()
{
m_xDocShRef->SetText("size small baz");
const SmErrorDesc *pErrorDesc = m_xDocShRef->GetParser()->NextError();
CPPUNIT_ASSERT(pErrorDesc);
CPPUNIT_ASSERT_EQUAL_MESSAGE("SmParseError::SizeExpected expected",
SmParseError::SizeExpected, pErrorDesc->m_eType);
}
void Test::ParseErrorDoubleAlign()
{
m_xDocShRef->SetText("alignl alignc x");
const SmErrorDesc *pErrorDesc = m_xDocShRef->GetParser()->NextError();
CPPUNIT_ASSERT(pErrorDesc);
CPPUNIT_ASSERT_EQUAL_MESSAGE("SmParseError::DoubleAlign expected",
SmParseError::DoubleAlign, pErrorDesc->m_eType);
}
void Test::ParseErrorDoubleSubsupscript()
{
m_xDocShRef->SetText("x_y_z");
const SmErrorDesc *pErrorDesc = m_xDocShRef->GetParser()->NextError();
CPPUNIT_ASSERT(pErrorDesc);
CPPUNIT_ASSERT_EQUAL_MESSAGE("SmParseError::DoubleSubsupscript expected",
SmParseError::DoubleSubsupscript, pErrorDesc->m_eType);
}
void Test::editUndoRedo()
{
EditEngine &rEditEngine = m_xDocShRef->GetEditEngine();
OUString sStringOne("a under b");
{
rEditEngine.SetText(0, sStringOne);
m_xDocShRef->UpdateText();
OUString sFinalText = m_xDocShRef->GetText();
CPPUNIT_ASSERT_EQUAL_MESSAGE("Strings must match", sFinalText, sStringOne);
}
{
OUString sStringTwo("a over b");
rEditEngine.SetText(0, sStringTwo);
m_xDocShRef->UpdateText();
OUString sFinalText = m_xDocShRef->GetText();
CPPUNIT_ASSERT_EQUAL_MESSAGE("Strings must match", sFinalText, sStringTwo);
}
SfxRequest aUndo(SID_UNDO, SfxCallMode::SYNCHRON, SmDocShell::GetPool());
{
m_xDocShRef->Execute(aUndo);
m_xDocShRef->UpdateText();
OUString sFinalText = m_xDocShRef->GetText();
CPPUNIT_ASSERT_EQUAL_MESSAGE("Strings much match", sFinalText, sStringOne);
}
{
m_xDocShRef->Execute(aUndo);
m_xDocShRef->UpdateText();
OUString sFinalText = m_xDocShRef->GetText();
CPPUNIT_ASSERT_MESSAGE("Must now be empty", sFinalText.isEmpty());
}
SfxRequest aRedo(SID_REDO, SfxCallMode::SYNCHRON, SmDocShell::GetPool());
{
m_xDocShRef->Execute(aRedo);
m_xDocShRef->UpdateText();
OUString sFinalText = m_xDocShRef->GetText();
CPPUNIT_ASSERT_EQUAL_MESSAGE("Strings much match", sFinalText, sStringOne);
}
{
rEditEngine.SetText(0, OUString());
m_xDocShRef->UpdateText();
rEditEngine.ClearModifyFlag();
OUString sFinalText = m_xDocShRef->GetText();
CPPUNIT_ASSERT_MESSAGE("Must be empty", sFinalText.isEmpty());
}
}
void Test::replacePlaceholder()
{
SmEditWindow& rEditWindow = m_pSmCmdBoxWindow->GetEditWindow();
// Test the placeholder replacement. In this case, testing 'a + b', it
// should return '+a + b' when selecting '+<?>' in ElementsDock
rEditWindow.SetText("a + b");
rEditWindow.SelectAll();
rEditWindow.InsertText("+<?>");
OUString sFinalText = rEditWindow.GetText();
CPPUNIT_ASSERT_EQUAL_MESSAGE("Should be '+a + b'", OUString("+a + b"), sFinalText);
}
void Test::viewZoom()
{
sal_uInt16 nOrigZoom, nFinalZoom;
EditEngine &rEditEngine = m_xDocShRef->GetEditEngine();
{
OUString sStringOne("a under b");
rEditEngine.SetText(0, sStringOne);
m_xDocShRef->UpdateText();
OUString sFinalText = m_xDocShRef->GetText();
CPPUNIT_ASSERT_EQUAL_MESSAGE("Strings must match", sFinalText, sStringOne);
}
SmGraphicWindow &rGraphicWindow = m_pViewShell->GetGraphicWindow();
rGraphicWindow.SetSizePixel(Size(1024, 800));
nOrigZoom = rGraphicWindow.GetZoom();
{
SfxRequest aZoomIn(SID_ZOOMIN, SfxCallMode::SYNCHRON, m_pViewShell->GetPool());
m_pViewShell->Execute(aZoomIn);
sal_uInt16 nNextZoom = rGraphicWindow.GetZoom();
CPPUNIT_ASSERT_MESSAGE("Should be bigger", nNextZoom > nOrigZoom);
}
{
SfxRequest aZoomOut(SID_ZOOMOUT, SfxCallMode::SYNCHRON, m_pViewShell->GetPool());
m_pViewShell->Execute(aZoomOut);
nFinalZoom = rGraphicWindow.GetZoom();
CPPUNIT_ASSERT_EQUAL_MESSAGE("Should be equal", nOrigZoom, nFinalZoom);
}
sal_uInt16 nOptimalZoom=0;
{
SfxRequest aZoom(SID_ZOOM_OPTIMAL, SfxCallMode::SYNCHRON, m_pViewShell->GetPool());
m_pViewShell->Execute(aZoom);
nOptimalZoom = rGraphicWindow.GetZoom();
CPPUNIT_ASSERT_MESSAGE("Should be about 800%", nOptimalZoom > nOrigZoom);
}
{
SfxItemSet aSet(SmDocShell::GetPool(), svl::Items<SID_ATTR_ZOOM, SID_ATTR_ZOOM>);
aSet.Put(SvxZoomItem(SvxZoomType::OPTIMAL, 0));
SfxRequest aZoom(SID_ATTR_ZOOM, SfxCallMode::SYNCHRON, aSet);
m_pViewShell->Execute(aZoom);
nFinalZoom = rGraphicWindow.GetZoom();
CPPUNIT_ASSERT_EQUAL_MESSAGE("Should be optimal zoom", nOptimalZoom, nFinalZoom);
}
//To-Do: investigate GetPrinter logic of SvxZoomType::PAGEWIDTH/SvxZoomType::WHOLEPAGE to ensure
//consistent value regardless of
#if 0
{
SfxRequest aZoomOut(SID_ZOOMOUT, SfxCallMode::SYNCHRON, m_pViewShell->GetPool());
m_pViewShell->Execute(aZoomOut);
nFinalZoom = rGraphicWindow.GetZoom();
CPPUNIT_ASSERT_MESSAGE("Should not be optimal zoom", nFinalZoom != nOptimalZoom);
SfxItemSet aSet(m_xDocShRef->GetPool(), SID_ATTR_ZOOM, SID_ATTR_ZOOM);
aSet.Put(SvxZoomItem(SvxZoomType::PAGEWIDTH, 0));
SfxRequest aZoom(SID_ATTR_ZOOM, SfxCallMode::SYNCHRON, aSet);
m_pViewShell->Execute(aZoom);
nFinalZoom = rGraphicWindow.GetZoom();
CPPUNIT_ASSERT_MESSAGE("Should be same as optimal zoom", nFinalZoom == nOptimalZoom);
}
{
SfxRequest aZoomOut(SID_ZOOMOUT, SfxCallMode::SYNCHRON, m_pViewShell->GetPool());
m_pViewShell->Execute(aZoomOut);
nFinalZoom = rGraphicWindow.GetZoom();
CPPUNIT_ASSERT_MESSAGE("Should not be optimal zoom", nFinalZoom != nOptimalZoom);
SfxItemSet aSet(m_xDocShRef->GetPool(), SID_ATTR_ZOOM, SID_ATTR_ZOOM);
aSet.Put(SvxZoomItem(SvxZoomType::WHOLEPAGE, 0));
SfxRequest aZoom(SID_ATTR_ZOOM, SfxCallMode::SYNCHRON, aSet);
m_pViewShell->Execute(aZoom);
nFinalZoom = rGraphicWindow.GetZoom();
CPPUNIT_ASSERT_MESSAGE("Should be same as optimal zoom", nFinalZoom == nOptimalZoom);
}
#endif
{
SfxRequest aZoomOut(SID_ZOOMOUT, SfxCallMode::SYNCHRON, m_pViewShell->GetPool());
m_pViewShell->Execute(aZoomOut);
nFinalZoom = rGraphicWindow.GetZoom();
CPPUNIT_ASSERT_MESSAGE("Should not be optimal zoom", nFinalZoom != nOptimalZoom);
SfxItemSet aSet(SmDocShell::GetPool(), svl::Items<SID_ATTR_ZOOM, SID_ATTR_ZOOM>);
aSet.Put(SvxZoomItem(SvxZoomType::PERCENT, 50));
SfxRequest aZoom(SID_ATTR_ZOOM, SfxCallMode::SYNCHRON, aSet);
m_pViewShell->Execute(aZoom);
nFinalZoom = rGraphicWindow.GetZoom();
CPPUNIT_ASSERT_EQUAL_MESSAGE("Should be 50%", static_cast<sal_uInt16>(50), nFinalZoom);
}
{
SfxItemSet aSet(SmDocShell::GetPool(), svl::Items<SID_ATTR_ZOOM, SID_ATTR_ZOOM>);
aSet.Put(SvxZoomItem(SvxZoomType::PERCENT, 5));
SfxRequest aZoom(SID_ATTR_ZOOM, SfxCallMode::SYNCHRON, aSet);
m_pViewShell->Execute(aZoom);
nFinalZoom = rGraphicWindow.GetZoom();
CPPUNIT_ASSERT_EQUAL_MESSAGE("Should be Clipped to 25%", static_cast<sal_uInt16>(25), nFinalZoom);
}
{
SfxItemSet aSet(SmDocShell::GetPool(), svl::Items<SID_ATTR_ZOOM, SID_ATTR_ZOOM>);
aSet.Put(SvxZoomItem(SvxZoomType::PERCENT, 1000));
SfxRequest aZoom(SID_ATTR_ZOOM, SfxCallMode::SYNCHRON, aSet);
m_pViewShell->Execute(aZoom);
nFinalZoom = rGraphicWindow.GetZoom();
CPPUNIT_ASSERT_EQUAL_MESSAGE("Should be Clipped to 800%", static_cast<sal_uInt16>(800), nFinalZoom);
}
}
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
}
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|