[go: up one dir, main page]

File: fsize-test.cpp

package info (click to toggle)
finalcut 0.9.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,832 kB
  • sloc: cpp: 90,264; makefile: 546; sh: 412
file content (451 lines) | stat: -rw-r--r-- 15,174 bytes parent folder | download
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
/***********************************************************************
* fsize-test.cpp - FSize unit tests                                    *
*                                                                      *
* This file is part of the FINAL CUT widget toolkit                    *
*                                                                      *
* Copyright 2019-2021 Markus Gans                                      *
*                                                                      *
* FINAL CUT is free software; you can redistribute it and/or modify    *
* it under the terms of the GNU Lesser General Public License as       *
* published by the Free Software Foundation; either version 3 of       *
* the License, or (at your option) any later version.                  *
*                                                                      *
* FINAL CUT is distributed in the hope that it will be useful, but     *
* WITHOUT ANY WARRANTY; without even the implied warranty of           *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
* GNU Lesser General Public License for more details.                  *
*                                                                      *
* You should have received a copy of the GNU Lesser General Public     *
* License along with this program.  If not, see                        *
* <http://www.gnu.org/licenses/>.                                      *
***********************************************************************/

#include <limits>
#include <utility>

#include <cppunit/BriefTestProgressListener.h>
#include <cppunit/CompilerOutputter.h>
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/TestFixture.h>
#include <cppunit/TestResult.h>
#include <cppunit/TestResultCollector.h>
#include <cppunit/TestRunner.h>

#include <final/final.h>

//----------------------------------------------------------------------
// class FSizeTest
//----------------------------------------------------------------------

class FSizeTest : public CPPUNIT_NS::TestFixture
{
  public:
    FSizeTest() = default;

  protected:
    void classNameTest();
    void noArgumentTest();
    void copyConstructorTest();
    void moveConstructorTest();
    void assignmentTest();
    void additionAssignmentTest();
    void subtractionAssignmentTest();
    void equalTest();
    void notEqualTest();
    void greaterTest();
    void LessTest();
    void additionTest();
    void subtractionTest();
    void areaTest();
    void referenceTest();
    void scaleTest();
    void streamInsertionTest();
    void streamExtractionTest();

  private:
    // Adds code needed to register the test suite
    CPPUNIT_TEST_SUITE (FSizeTest);

    // Add a methods to the test suite
    CPPUNIT_TEST (classNameTest);
    CPPUNIT_TEST (noArgumentTest);
    CPPUNIT_TEST (copyConstructorTest);
    CPPUNIT_TEST (moveConstructorTest);
    CPPUNIT_TEST (assignmentTest);
    CPPUNIT_TEST (additionAssignmentTest);
    CPPUNIT_TEST (subtractionAssignmentTest);
    CPPUNIT_TEST (equalTest);
    CPPUNIT_TEST (notEqualTest);
    CPPUNIT_TEST (greaterTest);
    CPPUNIT_TEST (LessTest);
    CPPUNIT_TEST (additionTest);
    CPPUNIT_TEST (subtractionTest);
    CPPUNIT_TEST (areaTest);
    CPPUNIT_TEST (referenceTest);
    CPPUNIT_TEST (scaleTest);
    CPPUNIT_TEST (streamInsertionTest);
    CPPUNIT_TEST (streamExtractionTest);

    // End of test suite definition
    CPPUNIT_TEST_SUITE_END();
};

//----------------------------------------------------------------------
void FSizeTest::classNameTest()
{
  finalcut::FSize p;
  const finalcut::FString& classname = p.getClassName();
  CPPUNIT_ASSERT ( classname == "FSize" );
}

//----------------------------------------------------------------------
void FSizeTest::noArgumentTest()
{
  const finalcut::FSize size{};
  CPPUNIT_ASSERT ( size.getWidth() == 0 );
  CPPUNIT_ASSERT ( size.getHeight() == 0 );
  CPPUNIT_ASSERT ( size.isEmpty() );
}

//----------------------------------------------------------------------
void FSizeTest::copyConstructorTest()
{
  const finalcut::FSize s1 (333, 80);
  const finalcut::FSize s2 (s1);
  CPPUNIT_ASSERT ( s2.getWidth() == 333 );
  CPPUNIT_ASSERT ( s2.getHeight() == 80 );
}

//----------------------------------------------------------------------
void FSizeTest::moveConstructorTest()
{
  finalcut::FSize s1 (120, 36);
  const finalcut::FSize s2 (std::move(s1));
  CPPUNIT_ASSERT ( s1.getWidth() == 120 );  // s1 is used after move
  CPPUNIT_ASSERT ( s1.getHeight() == 36 );  // s1 is used after move
  CPPUNIT_ASSERT ( ! s1.isEmpty() );        // s1 is used after move
  CPPUNIT_ASSERT ( s2.getWidth() == 120 );
  CPPUNIT_ASSERT ( s2.getHeight() == 36 );
}

//----------------------------------------------------------------------
void FSizeTest::assignmentTest()
{
  const finalcut::FSize s1 (0, 100);
  CPPUNIT_ASSERT ( s1.getWidth() == 0 );
  CPPUNIT_ASSERT ( s1.getHeight() == 100 );

  finalcut::FSize s2;
  s2 = s1;
  CPPUNIT_ASSERT ( s2.getWidth() == 0 );
  CPPUNIT_ASSERT ( s2.getHeight() == 100 );

  s2.setSize (80, 24);
  CPPUNIT_ASSERT ( s2.getWidth() == 80 );
  CPPUNIT_ASSERT ( s2.getHeight() == 24 );

  s2.setWidth(40);
  CPPUNIT_ASSERT ( s2.getWidth() == 40 );
  CPPUNIT_ASSERT ( s2.getHeight() == 24 );

  s2.setHeight(12);
  CPPUNIT_ASSERT ( s2.getWidth() == 40 );
  CPPUNIT_ASSERT ( s2.getHeight() == 12 );

  const finalcut::FSize size{5, 4};
  s2.setSize (size);
  CPPUNIT_ASSERT ( s2.getWidth() == 5 );
  CPPUNIT_ASSERT ( s2.getHeight() == 4 );

  // Move assignment operator
  finalcut::FSize s3;
  s3 = std::move(s2);
  CPPUNIT_ASSERT ( s2.getWidth() == 5 );   // s2 is used after move
  CPPUNIT_ASSERT ( s2.getHeight() == 4 );  // s2 is used after move
  CPPUNIT_ASSERT ( ! s2.isEmpty() );       // s2 is used after move
  CPPUNIT_ASSERT ( s3.getWidth() == 5 );
  CPPUNIT_ASSERT ( s3.getHeight() == 4 );

  // Value limit
  const finalcut::FSize s4 ( std::numeric_limits<std::size_t>::min()
                           , std::numeric_limits<std::size_t>::max() );
  CPPUNIT_ASSERT ( s4.getWidth() == std::numeric_limits<std::size_t>::min() );
  CPPUNIT_ASSERT ( s4.getHeight() == std::numeric_limits<std::size_t>::max() );
}

//----------------------------------------------------------------------
void FSizeTest::additionAssignmentTest()
{
  finalcut::FSize s1 (1, 2);
  s1 += finalcut::FSize{3, 1};
  CPPUNIT_ASSERT ( s1.getWidth() == 4 );
  CPPUNIT_ASSERT ( s1.getHeight() == 3 );

  s1 += finalcut::FSize{0, 0};
  CPPUNIT_ASSERT ( s1.getWidth() == 4 );
  CPPUNIT_ASSERT ( s1.getHeight() == 3 );

  s1 += finalcut::FSize{1, 2};
  CPPUNIT_ASSERT ( s1.getWidth() == 5 );
  CPPUNIT_ASSERT ( s1.getHeight() == 5 );
  CPPUNIT_ASSERT ( ! s1.isEmpty() );

  // Value limit
  finalcut::FSize s2 ( std::numeric_limits<std::size_t>::max()
                     , std::numeric_limits<std::size_t>::min() );
  CPPUNIT_ASSERT ( s2.getWidth() == std::numeric_limits<std::size_t>::max() );
  CPPUNIT_ASSERT ( s2.getHeight() == std::numeric_limits<std::size_t>::min() );
  s2 += finalcut::FSize{1, 1};
  CPPUNIT_ASSERT ( s2.getWidth() == std::numeric_limits<std::size_t>::max() );
  CPPUNIT_ASSERT ( s2.getHeight() == 1 );
}

//----------------------------------------------------------------------
void FSizeTest::subtractionAssignmentTest()
{
  finalcut::FSize s1 (10, 20);
  s1 -= finalcut::FSize (2, 5);
  CPPUNIT_ASSERT ( s1.getWidth() == 8 );
  CPPUNIT_ASSERT ( s1.getHeight() == 15 );

  s1 -= finalcut::FSize (1, 0);
  CPPUNIT_ASSERT ( s1.getWidth() == 7 );
  CPPUNIT_ASSERT ( s1.getHeight() == 15 );
  CPPUNIT_ASSERT ( ! s1.isEmpty() );

  s1 -= finalcut::FSize (0, 5);

  CPPUNIT_ASSERT ( s1.getWidth() == 7 );
  CPPUNIT_ASSERT ( s1.getHeight() == 10 );
  CPPUNIT_ASSERT ( ! s1.isEmpty() );

  s1 -= finalcut::FSize (2, 222);
  CPPUNIT_ASSERT ( s1.getWidth() == 5 );
  CPPUNIT_ASSERT ( s1.getHeight() == 0 );
  CPPUNIT_ASSERT ( ! s1.isEmpty() );

  s1 -= finalcut::FSize (1, 0);
  CPPUNIT_ASSERT ( s1.getWidth() == 4 );
  CPPUNIT_ASSERT ( s1.getHeight() == 0 );
  CPPUNIT_ASSERT ( ! s1.isEmpty() );

  s1 -= (finalcut::FSize (3, 0) + finalcut::FSize (1, 0));
  CPPUNIT_ASSERT ( s1.getWidth() == 0 );
  CPPUNIT_ASSERT ( s1.getHeight() == 0 );
  CPPUNIT_ASSERT ( s1.isEmpty() );

  // Value limit
  finalcut::FSize s2 ( std::numeric_limits<std::size_t>::max()
                     , std::numeric_limits<std::size_t>::min() );
  CPPUNIT_ASSERT ( s2.getWidth() == std::numeric_limits<std::size_t>::max() );
  CPPUNIT_ASSERT ( s2.getHeight() == std::numeric_limits<std::size_t>::min() );
  CPPUNIT_ASSERT ( ! s2.isEmpty() );
  s2 -= finalcut::FSize ( std::numeric_limits<std::size_t>::max(),
                          std::numeric_limits<std::size_t>::min() );
  CPPUNIT_ASSERT ( s2.getWidth() == 0 );
  CPPUNIT_ASSERT ( s2.getHeight() == 0 );
  CPPUNIT_ASSERT ( s2.isEmpty() );
  s2 -= finalcut::FSize(10, 10);
  CPPUNIT_ASSERT ( s2.getWidth() == 0 );
  CPPUNIT_ASSERT ( s2.getHeight() == 0 );
  CPPUNIT_ASSERT ( s2.isEmpty() );
}

//----------------------------------------------------------------------
void FSizeTest::equalTest()
{
  const finalcut::FSize s1 (1, 2);
  const finalcut::FSize s2 (1, 2);
  CPPUNIT_ASSERT ( s1 == s2 );
  CPPUNIT_ASSERT ( finalcut::FSize(1, 2) == s2 );
  CPPUNIT_ASSERT ( s1 == finalcut::FSize(1, 2) );
  const finalcut::FSize s3{};
  const finalcut::FSize s4{};
  CPPUNIT_ASSERT ( s3 == s4 );
}

//----------------------------------------------------------------------
void FSizeTest::notEqualTest()
{
  const finalcut::FSize s1 (3, 5);
  const finalcut::FSize s2 (2, 4);
  CPPUNIT_ASSERT ( s1 != s2 );
  CPPUNIT_ASSERT ( finalcut::FSize(1, 2) != s2 );
  CPPUNIT_ASSERT ( s1 != finalcut::FSize(2, 4) );
  CPPUNIT_ASSERT ( finalcut::FSize() != s2 );
  CPPUNIT_ASSERT ( s1 != finalcut::FSize() );
}

//----------------------------------------------------------------------
void FSizeTest::greaterTest()
{
  const finalcut::FSize s1 (5, 9);
  const finalcut::FSize s2 (3, 5);
  CPPUNIT_ASSERT ( s1 > s2 );
  CPPUNIT_ASSERT ( s1 >= s2 );

  const finalcut::FSize s3 (5, 9);
  CPPUNIT_ASSERT ( s1 >= s3 );
  CPPUNIT_ASSERT ( s1 >= finalcut::FSize(4, 9) );
  CPPUNIT_ASSERT ( s1 >= finalcut::FSize(5, 8) );
  CPPUNIT_ASSERT ( s1 >= finalcut::FSize(4, 8) );
  CPPUNIT_ASSERT ( s1 > finalcut::FSize(4, 8) );
}

//----------------------------------------------------------------------
void FSizeTest::LessTest()
{
  const finalcut::FSize s1 (2, 2);
  const finalcut::FSize s2 (4, 4);
  CPPUNIT_ASSERT ( s1 < s2 );
  CPPUNIT_ASSERT ( s1 <= s2 );

  const finalcut::FSize s3 (2, 2);
  CPPUNIT_ASSERT ( s1 <= s3 );
  CPPUNIT_ASSERT ( s1 <= finalcut::FSize(3, 2) );
  CPPUNIT_ASSERT ( s1 <= finalcut::FSize(2, 3) );
  CPPUNIT_ASSERT ( s1 <= finalcut::FSize(3, 3) );
  CPPUNIT_ASSERT ( s1 < finalcut::FSize(3, 3) );
}

//----------------------------------------------------------------------
void FSizeTest::additionTest()
{
  const finalcut::FSize s1 (1, 2);
  const finalcut::FSize s2 (5, 8);
  const finalcut::FSize s3 = s1 + s2;
  CPPUNIT_ASSERT ( s3.getWidth() == 6 );
  CPPUNIT_ASSERT ( s3.getHeight() == 10 );
  CPPUNIT_ASSERT ( s1 + s2 == finalcut::FSize(6, 10) );
  CPPUNIT_ASSERT ( s1 + finalcut::FSize() == s1 );
  CPPUNIT_ASSERT ( finalcut::FSize() + s2 == s2 );
  CPPUNIT_ASSERT ( finalcut::FSize() + finalcut::FSize() == finalcut::FSize() );
}

//----------------------------------------------------------------------
void FSizeTest::subtractionTest()
{
  const finalcut::FSize s1 (100, 20);
  const finalcut::FSize s2 (10, 3);
  const finalcut::FSize s3 = s1 - s2;
  CPPUNIT_ASSERT ( s3.getWidth() == 90 );
  CPPUNIT_ASSERT ( s3.getHeight() == 17 );
  CPPUNIT_ASSERT ( s1 - s2 == finalcut::FSize(90, 17) );
  CPPUNIT_ASSERT ( s1 - finalcut::FSize() == s1 );
  CPPUNIT_ASSERT ( finalcut::FSize() - finalcut::FSize() == finalcut::FSize() );
  CPPUNIT_ASSERT ( s3 - finalcut::FSize(100, 20) == finalcut::FSize(0, 0) );
}

//----------------------------------------------------------------------
void FSizeTest::areaTest()
{
  const finalcut::FSize s1 (99, 101);
  CPPUNIT_ASSERT ( s1.getWidth() == 99 );
  CPPUNIT_ASSERT ( s1.getHeight() == 101 );
  CPPUNIT_ASSERT ( s1.getArea() == 9999 );

  const finalcut::FSize s2 (33, 87);
  CPPUNIT_ASSERT ( s2.getWidth() == 33 );
  CPPUNIT_ASSERT ( s2.getHeight() == 87 );
  CPPUNIT_ASSERT ( s2.getArea() == 2871 );
}

//----------------------------------------------------------------------
void FSizeTest::referenceTest()
{
  finalcut::FSize s1 (1, 1);
  CPPUNIT_ASSERT ( s1.getWidth() == 1 );
  CPPUNIT_ASSERT ( s1.getHeight() == 1 );

  s1.width_ref()++;
  s1.height_ref()++;
  CPPUNIT_ASSERT ( s1.getWidth() == 2 );
  CPPUNIT_ASSERT ( s1.getHeight() == 2 );

  std::size_t& width = s1.width_ref();
  std::size_t& height = s1.height_ref();
  width += 4;
  height += 2;
  CPPUNIT_ASSERT ( s1.getWidth() == 6 );
  CPPUNIT_ASSERT ( s1.getHeight() == 4 );
}

//----------------------------------------------------------------------
void FSizeTest::scaleTest()
{
  finalcut::FSize s1 (15, 15);
  CPPUNIT_ASSERT ( s1.getWidth() == 15 );
  CPPUNIT_ASSERT ( s1.getHeight() == 15 );
  CPPUNIT_ASSERT ( s1 == finalcut::FSize(15, 15) );

  const finalcut::FPoint p1 (-2, -3);
  s1.scaleBy(p1);
  CPPUNIT_ASSERT ( s1.getWidth() == 13 );
  CPPUNIT_ASSERT ( s1.getHeight() == 12 );
  CPPUNIT_ASSERT ( s1 == finalcut::FSize(13, 12) );

  const finalcut::FPoint p2 (3, 2);
  s1.scaleBy(p2);
  CPPUNIT_ASSERT ( s1.getWidth() == 16 );
  CPPUNIT_ASSERT ( s1.getHeight() == 14 );
  CPPUNIT_ASSERT ( s1 == finalcut::FSize(16, 14) );

  s1.scaleBy(1, -1);
  CPPUNIT_ASSERT ( s1.getWidth() == 17 );
  CPPUNIT_ASSERT ( s1.getHeight() == 13 );
  CPPUNIT_ASSERT ( s1 == finalcut::FSize(17, 13) );

  s1.scaleBy(-2, 2);
  CPPUNIT_ASSERT ( s1.getWidth() == 15 );
  CPPUNIT_ASSERT ( s1.getHeight() == 15 );
  CPPUNIT_ASSERT ( s1 == finalcut::FSize(15, 15) );

  s1.scaleBy(-20, 0);
  CPPUNIT_ASSERT ( s1.getWidth() == 5 );
  CPPUNIT_ASSERT ( s1.getHeight() == 15 );
  CPPUNIT_ASSERT ( s1 == finalcut::FSize(5, 15) );

  s1.scaleBy(0, -20);
  CPPUNIT_ASSERT ( s1.getWidth() == 5 );
  CPPUNIT_ASSERT ( s1.getHeight() == 5 );
  CPPUNIT_ASSERT ( s1 == finalcut::FSize(5, 5) );
}

//----------------------------------------------------------------------
void FSizeTest::streamInsertionTest()
{
  finalcut::FSize out;
  std::stringstream stream;
  stream.str("10 5");
  stream >> out;
  CPPUNIT_ASSERT ( out.getWidth() == 10 );
  CPPUNIT_ASSERT ( out.getHeight() == 5 );

  stream.clear();
  stream.str("0 9");
  stream >> out;
  CPPUNIT_ASSERT ( out.getWidth() == 0 );
  CPPUNIT_ASSERT ( out.getHeight() == 9 );
}

//----------------------------------------------------------------------
void FSizeTest::streamExtractionTest()
{
  finalcut::FSize in;
  in.setSize (7, 5);
  std::stringstream stream;
  stream << in;
  CPPUNIT_ASSERT ( stream.str() == "7 5" );

  in.setSize (127, 150);
  stream.clear();
  stream.str("");
  stream << in;
  CPPUNIT_ASSERT ( stream.str() == "127 150" );
}

// Put the test suite in the registry
CPPUNIT_TEST_SUITE_REGISTRATION (FSizeTest);

// The general unit test main part
#include <main-test.inc>