annotate data/model/test/TestZoomConstraints.h @ 1539:0b08bc8741c6 zoom

Win32 fix
author Chris Cannam
date Wed, 26 Sep 2018 17:38:34 +0100
parents 2f3a77472c8c
children 05c3fbaec8ea
rev   line source
Chris@1528 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@1528 2
Chris@1528 3 /*
Chris@1530 4 Sonic Visualiser
Chris@1530 5 An audio file viewer and annotation editor.
Chris@1530 6 Centre for Digital Music, Queen Mary, University of London.
Chris@1528 7
Chris@1530 8 This program is free software; you can redistribute it and/or
Chris@1530 9 modify it under the terms of the GNU General Public License as
Chris@1530 10 published by the Free Software Foundation; either version 2 of the
Chris@1530 11 License, or (at your option) any later version. See the file
Chris@1530 12 COPYING included with this distribution for more information.
Chris@1528 13 */
Chris@1528 14
Chris@1528 15 #ifndef TEST_ZOOM_CONSTRAINTS_H
Chris@1528 16 #define TEST_ZOOM_CONSTRAINTS_H
Chris@1528 17
Chris@1528 18 #include "../PowerOfTwoZoomConstraint.h"
Chris@1528 19 #include "../PowerOfSqrtTwoZoomConstraint.h"
Chris@1528 20
Chris@1528 21 #include <QObject>
Chris@1528 22 #include <QtTest>
Chris@1528 23 #include <QDir>
Chris@1528 24
Chris@1528 25 #include <iostream>
Chris@1528 26
Chris@1528 27 using namespace std;
Chris@1528 28
Chris@1528 29 class TestZoomConstraints : public QObject
Chris@1528 30 {
Chris@1528 31 Q_OBJECT
Chris@1528 32
Chris@1531 33 void checkFpp(const ZoomConstraint &c,
Chris@1531 34 ZoomConstraint::RoundingDirection dir,
Chris@1531 35 int n,
Chris@1531 36 int expected) {
Chris@1531 37 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, n),
Chris@1531 38 dir),
Chris@1531 39 ZoomLevel(ZoomLevel::FramesPerPixel, expected));
Chris@1531 40 }
Chris@1531 41
Chris@1528 42 private slots:
Chris@1528 43 void unconstrainedNearest() {
Chris@1528 44 ZoomConstraint c;
Chris@1531 45 checkFpp(c, ZoomConstraint::RoundNearest, 1, 1);
Chris@1531 46 checkFpp(c, ZoomConstraint::RoundNearest, 2, 2);
Chris@1531 47 checkFpp(c, ZoomConstraint::RoundNearest, 3, 3);
Chris@1531 48 checkFpp(c, ZoomConstraint::RoundNearest, 4, 4);
Chris@1531 49 checkFpp(c, ZoomConstraint::RoundNearest, 20, 20);
Chris@1531 50 checkFpp(c, ZoomConstraint::RoundNearest, 32, 32);
Chris@1530 51 auto max = c.getMaxZoomLevel();
Chris@1530 52 QCOMPARE(c.getNearestZoomLevel(max), max);
Chris@1531 53 QCOMPARE(c.getNearestZoomLevel(max.incremented()), max);
Chris@1528 54 }
Chris@1528 55
Chris@1528 56 void unconstrainedUp() {
Chris@1528 57 ZoomConstraint c;
Chris@1531 58 checkFpp(c, ZoomConstraint::RoundUp, 1, 1);
Chris@1531 59 checkFpp(c, ZoomConstraint::RoundUp, 2, 2);
Chris@1531 60 checkFpp(c, ZoomConstraint::RoundUp, 3, 3);
Chris@1531 61 checkFpp(c, ZoomConstraint::RoundUp, 4, 4);
Chris@1531 62 checkFpp(c, ZoomConstraint::RoundUp, 20, 20);
Chris@1531 63 checkFpp(c, ZoomConstraint::RoundUp, 32, 32);
Chris@1530 64 auto max = c.getMaxZoomLevel();
Chris@1531 65 QCOMPARE(c.getNearestZoomLevel(max,
Chris@1531 66 ZoomConstraint::RoundUp), max);
Chris@1531 67 QCOMPARE(c.getNearestZoomLevel(max.incremented(),
Chris@1531 68 ZoomConstraint::RoundUp), max);
Chris@1528 69 }
Chris@1528 70
Chris@1528 71 void unconstrainedDown() {
Chris@1528 72 ZoomConstraint c;
Chris@1531 73 checkFpp(c, ZoomConstraint::RoundDown, 1, 1);
Chris@1531 74 checkFpp(c, ZoomConstraint::RoundDown, 2, 2);
Chris@1531 75 checkFpp(c, ZoomConstraint::RoundDown, 3, 3);
Chris@1531 76 checkFpp(c, ZoomConstraint::RoundDown, 4, 4);
Chris@1531 77 checkFpp(c, ZoomConstraint::RoundDown, 20, 20);
Chris@1531 78 checkFpp(c, ZoomConstraint::RoundDown, 32, 32);
Chris@1530 79 auto max = c.getMaxZoomLevel();
Chris@1531 80 QCOMPARE(c.getNearestZoomLevel(max,
Chris@1531 81 ZoomConstraint::RoundDown), max);
Chris@1531 82 QCOMPARE(c.getNearestZoomLevel(max.incremented(),
Chris@1531 83 ZoomConstraint::RoundDown), max);
Chris@1528 84 }
Chris@1528 85
Chris@1528 86 void powerOfTwoNearest() {
Chris@1528 87 PowerOfTwoZoomConstraint c;
Chris@1531 88 checkFpp(c, ZoomConstraint::RoundNearest, 1, 1);
Chris@1531 89 checkFpp(c, ZoomConstraint::RoundNearest, 2, 2);
Chris@1531 90 checkFpp(c, ZoomConstraint::RoundNearest, 3, 2);
Chris@1531 91 checkFpp(c, ZoomConstraint::RoundNearest, 4, 4);
Chris@1531 92 checkFpp(c, ZoomConstraint::RoundNearest, 20, 16);
Chris@1531 93 checkFpp(c, ZoomConstraint::RoundNearest, 23, 16);
Chris@1531 94 checkFpp(c, ZoomConstraint::RoundNearest, 24, 16);
Chris@1531 95 checkFpp(c, ZoomConstraint::RoundNearest, 25, 32);
Chris@1530 96 auto max = c.getMaxZoomLevel();
Chris@1530 97 QCOMPARE(c.getNearestZoomLevel(max), max);
Chris@1531 98 QCOMPARE(c.getNearestZoomLevel(max.incremented()), max);
Chris@1528 99 }
Chris@1528 100
Chris@1528 101 void powerOfTwoUp() {
Chris@1528 102 PowerOfTwoZoomConstraint c;
Chris@1531 103 checkFpp(c, ZoomConstraint::RoundUp, 1, 1);
Chris@1531 104 checkFpp(c, ZoomConstraint::RoundUp, 2, 2);
Chris@1531 105 checkFpp(c, ZoomConstraint::RoundUp, 3, 4);
Chris@1531 106 checkFpp(c, ZoomConstraint::RoundUp, 4, 4);
Chris@1531 107 checkFpp(c, ZoomConstraint::RoundUp, 20, 32);
Chris@1531 108 checkFpp(c, ZoomConstraint::RoundUp, 32, 32);
Chris@1531 109 checkFpp(c, ZoomConstraint::RoundUp, 33, 64);
Chris@1530 110 auto max = c.getMaxZoomLevel();
Chris@1531 111 QCOMPARE(c.getNearestZoomLevel(max,
Chris@1531 112 ZoomConstraint::RoundUp), max);
Chris@1531 113 QCOMPARE(c.getNearestZoomLevel(max.incremented(),
Chris@1531 114 ZoomConstraint::RoundUp), max);
Chris@1528 115 }
Chris@1528 116
Chris@1528 117 void powerOfTwoDown() {
Chris@1528 118 PowerOfTwoZoomConstraint c;
Chris@1531 119 checkFpp(c, ZoomConstraint::RoundDown, 1, 1);
Chris@1531 120 checkFpp(c, ZoomConstraint::RoundDown, 2, 2);
Chris@1531 121 checkFpp(c, ZoomConstraint::RoundDown, 3, 2);
Chris@1531 122 checkFpp(c, ZoomConstraint::RoundDown, 4, 4);
Chris@1531 123 checkFpp(c, ZoomConstraint::RoundDown, 20, 16);
Chris@1531 124 checkFpp(c, ZoomConstraint::RoundDown, 32, 32);
Chris@1531 125 checkFpp(c, ZoomConstraint::RoundDown, 33, 32);
Chris@1530 126 auto max = c.getMaxZoomLevel();
Chris@1531 127 QCOMPARE(c.getNearestZoomLevel(max,
Chris@1531 128 ZoomConstraint::RoundDown), max);
Chris@1531 129 QCOMPARE(c.getNearestZoomLevel(max.incremented(),
Chris@1531 130 ZoomConstraint::RoundDown), max);
Chris@1528 131 }
Chris@1528 132
Chris@1528 133 void powerOfSqrtTwoNearest() {
Chris@1528 134 PowerOfSqrtTwoZoomConstraint c;
Chris@1531 135 checkFpp(c, ZoomConstraint::RoundNearest, 1, 1);
Chris@1531 136 checkFpp(c, ZoomConstraint::RoundNearest, 2, 2);
Chris@1531 137 checkFpp(c, ZoomConstraint::RoundNearest, 3, 2);
Chris@1531 138 checkFpp(c, ZoomConstraint::RoundNearest, 4, 4);
Chris@1531 139 checkFpp(c, ZoomConstraint::RoundNearest, 18, 16);
Chris@1531 140 checkFpp(c, ZoomConstraint::RoundNearest, 19, 16);
Chris@1531 141 checkFpp(c, ZoomConstraint::RoundNearest, 20, 22);
Chris@1531 142 checkFpp(c, ZoomConstraint::RoundNearest, 23, 22);
Chris@1531 143 checkFpp(c, ZoomConstraint::RoundNearest, 28, 32);
Chris@1528 144 // PowerOfSqrtTwoZoomConstraint makes an effort to ensure
Chris@1528 145 // bigger numbers get rounded to a multiple of something
Chris@1528 146 // simple (64 or 90 depending on whether they are power-of-two
Chris@1528 147 // or power-of-sqrt-two types)
Chris@1531 148 checkFpp(c, ZoomConstraint::RoundNearest, 800, 720);
Chris@1531 149 checkFpp(c, ZoomConstraint::RoundNearest, 1023, 1024);
Chris@1531 150 checkFpp(c, ZoomConstraint::RoundNearest, 1024, 1024);
Chris@1531 151 checkFpp(c, ZoomConstraint::RoundNearest, 1024, 1024);
Chris@1531 152 checkFpp(c, ZoomConstraint::RoundNearest, 1025, 1024);
Chris@1530 153 auto max = c.getMaxZoomLevel();
Chris@1530 154 QCOMPARE(c.getNearestZoomLevel(max), max);
Chris@1531 155 QCOMPARE(c.getNearestZoomLevel(max.incremented()), max);
Chris@1528 156 }
Chris@1528 157
Chris@1528 158 void powerOfSqrtTwoUp() {
Chris@1528 159 PowerOfSqrtTwoZoomConstraint c;
Chris@1531 160 checkFpp(c, ZoomConstraint::RoundUp, 1, 1);
Chris@1531 161 checkFpp(c, ZoomConstraint::RoundUp, 2, 2);
Chris@1531 162 checkFpp(c, ZoomConstraint::RoundUp, 3, 4);
Chris@1531 163 checkFpp(c, ZoomConstraint::RoundUp, 4, 4);
Chris@1531 164 checkFpp(c, ZoomConstraint::RoundUp, 18, 22);
Chris@1531 165 checkFpp(c, ZoomConstraint::RoundUp, 22, 22);
Chris@1531 166 checkFpp(c, ZoomConstraint::RoundUp, 23, 32);
Chris@1531 167 checkFpp(c, ZoomConstraint::RoundUp, 800, 1024);
Chris@1531 168 checkFpp(c, ZoomConstraint::RoundUp, 1023, 1024);
Chris@1531 169 checkFpp(c, ZoomConstraint::RoundUp, 1024, 1024);
Chris@1528 170 // see comment above
Chris@1531 171 checkFpp(c, ZoomConstraint::RoundUp, 1025, 1440);
Chris@1530 172 auto max = c.getMaxZoomLevel();
Chris@1531 173 QCOMPARE(c.getNearestZoomLevel(max,
Chris@1531 174 ZoomConstraint::RoundUp), max);
Chris@1531 175 QCOMPARE(c.getNearestZoomLevel(max.incremented(),
Chris@1531 176 ZoomConstraint::RoundUp), max);
Chris@1528 177 }
Chris@1528 178
Chris@1528 179 void powerOfSqrtTwoDown() {
Chris@1528 180 PowerOfSqrtTwoZoomConstraint c;
Chris@1531 181 checkFpp(c, ZoomConstraint::RoundDown, 1, 1);
Chris@1531 182 checkFpp(c, ZoomConstraint::RoundDown, 2, 2);
Chris@1531 183 checkFpp(c, ZoomConstraint::RoundDown, 3, 2);
Chris@1531 184 checkFpp(c, ZoomConstraint::RoundDown, 4, 4);
Chris@1531 185 checkFpp(c, ZoomConstraint::RoundDown, 18, 16);
Chris@1531 186 checkFpp(c, ZoomConstraint::RoundDown, 22, 22);
Chris@1531 187 checkFpp(c, ZoomConstraint::RoundDown, 23, 22);
Chris@1528 188 // see comment above
Chris@1531 189 checkFpp(c, ZoomConstraint::RoundDown, 800, 720);
Chris@1531 190 checkFpp(c, ZoomConstraint::RoundDown, 1023, 720);
Chris@1531 191 checkFpp(c, ZoomConstraint::RoundDown, 1024, 1024);
Chris@1531 192 checkFpp(c, ZoomConstraint::RoundDown, 1025, 1024);
Chris@1530 193 auto max = c.getMaxZoomLevel();
Chris@1531 194 QCOMPARE(c.getNearestZoomLevel(max,
Chris@1531 195 ZoomConstraint::RoundDown), max);
Chris@1531 196 QCOMPARE(c.getNearestZoomLevel(max.incremented(),
Chris@1531 197 ZoomConstraint::RoundDown), max);
Chris@1528 198 }
Chris@1528 199 };
Chris@1528 200
Chris@1528 201 #endif
Chris@1528 202