File indexing completed on 2024-05-19 12:34:29
0001 /**************************************************************************************** 0002 * Copyright (c) 2011 Ralf Engels <ralf-engels@gmx.de> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify it under * 0005 * the terms of the GNU General Public License as published by the Free Software * 0006 * Foundation; either version 2 of the License, or (at your option) any later * 0007 * version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0012 * * 0013 * You should have received a copy of the GNU General Public License along with * 0014 * this program. If not, see <http://www.gnu.org/licenses/>. * 0015 ****************************************************************************************/ 0016 0017 #include "TestTrackSet.h" 0018 0019 #include "dynamic/TrackSet.h" 0020 0021 #include "core/support/Amarok.h" 0022 #include "core/support/Debug.h" 0023 0024 0025 QTEST_GUILESS_MAIN( TestTrackSet ) 0026 0027 TestTrackSet::TestTrackSet() 0028 { 0029 QStringList testUids; 0030 testUids << "uid-1" << "uid-2" << "uid-3" << "uid-4" << "uid-5" << "uid-6"; 0031 m_trackCollection = new Dynamic::TrackCollection( testUids ); 0032 0033 QCOMPARE( m_trackCollection->count(), 6 ); 0034 } 0035 0036 void 0037 TestTrackSet::init() 0038 { } 0039 0040 void 0041 TestTrackSet::cleanup() 0042 { 0043 QCOMPARE( m_trackCollection->count(), 6 ); 0044 } 0045 0046 void 0047 TestTrackSet::testOutstanding() 0048 { 0049 Dynamic::TrackSet set; 0050 QCOMPARE( set.isOutstanding(), true ); 0051 0052 Dynamic::TrackSet set2( m_trackCollection, true ); 0053 QCOMPARE( set2.isOutstanding(), false ); 0054 } 0055 0056 void 0057 TestTrackSet::testEmptyFull() 0058 { 0059 Dynamic::TrackSet set2( m_trackCollection, true ); 0060 QCOMPARE( set2.isEmpty(), false ); 0061 QCOMPARE( set2.isFull(), true ); 0062 0063 set2.reset( false ); 0064 QCOMPARE( set2.isEmpty(), true ); 0065 QCOMPARE( set2.isFull(), false ); 0066 0067 set2.reset( true ); 0068 QCOMPARE( set2.isEmpty(), false ); 0069 QCOMPARE( set2.isFull(), true ); 0070 0071 0072 QCOMPARE( set2.contains("uid-1"), true ); 0073 QStringList testUids; 0074 testUids << "uid-1"; 0075 set2.subtract( testUids ); 0076 QCOMPARE( set2.isEmpty(), false ); 0077 QCOMPARE( set2.isFull(), false ); 0078 QCOMPARE( set2.contains("uid-1"), false ); 0079 0080 Dynamic::TrackSet set3( m_trackCollection, false ); 0081 QCOMPARE( set3.isEmpty(), true ); 0082 QCOMPARE( set3.isFull(), false ); 0083 } 0084 0085 void 0086 TestTrackSet::testUnite() 0087 { 0088 Dynamic::TrackSet set( m_trackCollection, false ); 0089 0090 // -- use string lists 0091 QStringList testUids; 0092 testUids << "uid-1" << "uid-2"; 0093 set.unite( testUids ); 0094 0095 QCOMPARE( set.contains("uid-1"), true ); 0096 QCOMPARE( set.contains("uid-2"), true ); 0097 QCOMPARE( set.contains("uid-3"), false ); 0098 0099 QStringList testUids2; 0100 testUids2 << "uid-2" << "uid-3"; 0101 set.unite( testUids2 ); 0102 0103 QCOMPARE( set.contains("uid-1"), true ); 0104 QCOMPARE( set.contains("uid-2"), true ); 0105 QCOMPARE( set.contains("uid-3"), true ); 0106 0107 // -- use another set 0108 QStringList testUids3; 0109 testUids3 << "uid-3" << "uid-4"; 0110 Dynamic::TrackSet set2( m_trackCollection, false ); 0111 set2.unite( testUids3 ); 0112 0113 set.unite( set2 ); 0114 QCOMPARE( set.contains("uid-2"), true ); 0115 QCOMPARE( set.contains("uid-3"), true ); 0116 QCOMPARE( set.contains("uid-4"), true ); 0117 QCOMPARE( set.contains("uid-5"), false ); 0118 } 0119 0120 void 0121 TestTrackSet::testIntersect() 0122 { 0123 Dynamic::TrackSet set( m_trackCollection, true ); 0124 0125 // -- use string lists 0126 QStringList testUids; 0127 testUids << "uid-1" << "uid-2"; 0128 set.intersect( testUids ); 0129 0130 QCOMPARE( set.contains("uid-1"), true ); 0131 QCOMPARE( set.contains("uid-2"), true ); 0132 QCOMPARE( set.contains("uid-3"), false ); 0133 0134 QStringList testUids2; 0135 testUids2 << "uid-2" << "uid-3"; 0136 set.intersect( testUids2 ); 0137 0138 QCOMPARE( set.contains("uid-1"), false ); 0139 QCOMPARE( set.contains("uid-2"), true ); 0140 QCOMPARE( set.contains("uid-3"), false ); 0141 0142 // -- use another set 0143 QStringList testUids3; 0144 testUids3 << "uid-2" << "uid-3"; 0145 Dynamic::TrackSet set2( m_trackCollection, false ); 0146 set2.unite( testUids3 ); 0147 0148 set.intersect( set2 ); 0149 QCOMPARE( set.contains("uid-2"), true ); 0150 QCOMPARE( set.contains("uid-3"), false ); 0151 QCOMPARE( set.contains("uid-4"), false ); 0152 } 0153 0154 void 0155 TestTrackSet::testSubtract() 0156 { 0157 Dynamic::TrackSet set( m_trackCollection, true ); 0158 0159 // -- use string lists 0160 QStringList testUids; 0161 testUids << "uid-1" << "uid-2"; 0162 set.subtract( testUids ); 0163 0164 QCOMPARE( set.contains("uid-1"), false ); 0165 QCOMPARE( set.contains("uid-2"), false ); 0166 QCOMPARE( set.contains("uid-3"), true ); 0167 0168 QStringList testUids2; 0169 testUids2 << "uid-2" << "uid-3"; 0170 set.subtract( testUids2 ); 0171 0172 QCOMPARE( set.contains("uid-1"), false ); 0173 QCOMPARE( set.contains("uid-2"), false ); 0174 QCOMPARE( set.contains("uid-3"), false ); 0175 QCOMPARE( set.contains("uid-4"), true ); 0176 0177 // -- use another set 0178 QStringList testUids3; 0179 testUids3 << "uid-3" << "uid-4"; 0180 Dynamic::TrackSet set2( m_trackCollection, false ); 0181 set2.unite( testUids3 ); 0182 0183 set.subtract( set2 ); 0184 QCOMPARE( set.contains("uid-3"), false ); 0185 QCOMPARE( set.contains("uid-4"), false ); 0186 QCOMPARE( set.contains("uid-5"), true ); 0187 0188 } 0189 0190 void 0191 TestTrackSet::testEqual() 0192 { 0193 0194 } 0195