File indexing completed on 2025-04-13 04:29:48
0001 /* 0002 SPDX-FileCopyrightText: 2022 Jean-Baptiste Mardelle <jb@kdenlive.org> 0003 SPDX-FileCopyrightText: 2017 Nicolas Carion <french.ebook.lover@gmail.com> 0004 SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 #include "test_utils.hpp" 0007 // test specific headers 0008 #include "timeline2/model/snapmodel.hpp" 0009 0010 TEST_CASE("Snap points model test", "[SnapModel]") 0011 { 0012 SnapModel snap; 0013 0014 SECTION("Basic test") 0015 { 0016 // empty 0017 REQUIRE(snap.getClosestPoint(0) == -1); 0018 REQUIRE(snap.getClosestPoint(10) == -1); 0019 0020 snap.addPoint(10); 0021 REQUIRE(snap.getClosestPoint(0) == 10); 0022 REQUIRE(snap.getClosestPoint(10) == 10); 0023 REQUIRE(snap.getClosestPoint(11) == 10); 0024 REQUIRE(snap.getClosestPoint(9) == 10); 0025 REQUIRE(snap.getClosestPoint(999) == 10); 0026 0027 snap.addPoint(10); 0028 REQUIRE(snap.getClosestPoint(0) == 10); 0029 REQUIRE(snap.getClosestPoint(10) == 10); 0030 REQUIRE(snap.getClosestPoint(11) == 10); 0031 REQUIRE(snap.getClosestPoint(9) == 10); 0032 REQUIRE(snap.getClosestPoint(999) == 10); 0033 0034 snap.addPoint(15); 0035 REQUIRE(snap.getClosestPoint(0) == 10); 0036 REQUIRE(snap.getClosestPoint(10) == 10); 0037 REQUIRE(snap.getClosestPoint(11) == 10); 0038 REQUIRE(snap.getClosestPoint(9) == 10); 0039 REQUIRE(snap.getClosestPoint(12) == 10); 0040 REQUIRE(snap.getClosestPoint(13) == 15); 0041 REQUIRE(snap.getClosestPoint(15) == 15); 0042 REQUIRE(snap.getClosestPoint(16) == 15); 0043 REQUIRE(snap.getClosestPoint(999) == 15); 0044 0045 snap.removePoint(10); 0046 REQUIRE(snap.getClosestPoint(0) == 10); 0047 REQUIRE(snap.getClosestPoint(10) == 10); 0048 REQUIRE(snap.getClosestPoint(11) == 10); 0049 REQUIRE(snap.getClosestPoint(9) == 10); 0050 REQUIRE(snap.getClosestPoint(12) == 10); 0051 REQUIRE(snap.getClosestPoint(13) == 15); 0052 REQUIRE(snap.getClosestPoint(15) == 15); 0053 REQUIRE(snap.getClosestPoint(16) == 15); 0054 REQUIRE(snap.getClosestPoint(999) == 15); 0055 0056 snap.removePoint(10); 0057 REQUIRE(snap.getClosestPoint(0) == 15); 0058 REQUIRE(snap.getClosestPoint(10) == 15); 0059 REQUIRE(snap.getClosestPoint(11) == 15); 0060 REQUIRE(snap.getClosestPoint(9) == 15); 0061 REQUIRE(snap.getClosestPoint(12) == 15); 0062 REQUIRE(snap.getClosestPoint(13) == 15); 0063 REQUIRE(snap.getClosestPoint(15) == 15); 0064 REQUIRE(snap.getClosestPoint(16) == 15); 0065 REQUIRE(snap.getClosestPoint(999) == 15); 0066 0067 snap.removePoint(15); 0068 REQUIRE(snap.getClosestPoint(0) == -1); 0069 REQUIRE(snap.getClosestPoint(10) == -1); 0070 REQUIRE(snap.getClosestPoint(11) == -1); 0071 REQUIRE(snap.getClosestPoint(9) == -1); 0072 REQUIRE(snap.getClosestPoint(12) == -1); 0073 REQUIRE(snap.getClosestPoint(13) == -1); 0074 REQUIRE(snap.getClosestPoint(15) == -1); 0075 REQUIRE(snap.getClosestPoint(16) == -1); 0076 REQUIRE(snap.getClosestPoint(999) == -1); 0077 } 0078 0079 SECTION("Snappoint Ignoring") 0080 { 0081 REQUIRE(snap.getClosestPoint(0) == -1); 0082 REQUIRE(snap.getClosestPoint(10) == -1); 0083 0084 snap.addPoint(10); 0085 snap.addPoint(10); 0086 auto state = [&]() { 0087 REQUIRE(snap.getClosestPoint(0) == 10); 0088 REQUIRE(snap.getClosestPoint(10) == 10); 0089 REQUIRE(snap.getClosestPoint(11) == 10); 0090 REQUIRE(snap.getClosestPoint(9) == 10); 0091 REQUIRE(snap.getClosestPoint(999) == 10); 0092 }; 0093 state(); 0094 0095 snap.ignore({10}); 0096 state(); 0097 0098 snap.ignore({10}); 0099 REQUIRE(snap.getClosestPoint(0) == -1); 0100 REQUIRE(snap.getClosestPoint(10) == -1); 0101 snap.unIgnore(); 0102 state(); 0103 0104 snap.addPoint(15); 0105 REQUIRE(snap.getClosestPoint(0) == 10); 0106 REQUIRE(snap.getClosestPoint(10) == 10); 0107 REQUIRE(snap.getClosestPoint(11) == 10); 0108 REQUIRE(snap.getClosestPoint(9) == 10); 0109 REQUIRE(snap.getClosestPoint(12) == 10); 0110 REQUIRE(snap.getClosestPoint(13) == 15); 0111 REQUIRE(snap.getClosestPoint(15) == 15); 0112 REQUIRE(snap.getClosestPoint(16) == 15); 0113 REQUIRE(snap.getClosestPoint(999) == 15); 0114 0115 snap.ignore({15}); 0116 state(); 0117 snap.removePoint(10); 0118 state(); 0119 snap.removePoint(10); 0120 REQUIRE(snap.getClosestPoint(0) == -1); 0121 REQUIRE(snap.getClosestPoint(10) == -1); 0122 0123 snap.unIgnore(); 0124 REQUIRE(snap.getClosestPoint(0) == 15); 0125 REQUIRE(snap.getClosestPoint(10) == 15); 0126 REQUIRE(snap.getClosestPoint(11) == 15); 0127 REQUIRE(snap.getClosestPoint(9) == 15); 0128 REQUIRE(snap.getClosestPoint(999) == 15); 0129 } 0130 }