test_guidarray_sortmulti.js
Go to the documentation of this file.
1 /*
2 //
3 // BEGIN SONGBIRD GPL
4 //
5 // This file is part of the Songbird web player.
6 //
7 // Copyright(c) 2005-2008 POTI, Inc.
8 // http://songbirdnest.com
9 //
10 // This file may be licensed under the terms of of the
11 // GNU General Public License Version 2 (the "GPL").
12 //
13 // Software distributed under the License is distributed
14 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
15 // express or implied. See the GPL for the specific language
16 // governing rights and limitations.
17 //
18 // You should have received a copy of the GPL along with this
19 // program. If not, go to http://www.gnu.org/licenses/gpl.html
20 // or write to the Free Software Foundation, Inc.,
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 //
23 // END SONGBIRD GPL
24 //
25 */
26 
31 function runTest () {
32 
33  Components.utils.import("resource://app/jsmodules/sbProperties.jsm");
34 
35  // Note on property_id values used below:
36  // 1 = trackName
37  // 2 = albumName
38  // 3 = artistName
39  // 6 = trackNumber
40  // 11 = lastPlayTime
41 
42  var sqlArtistAscAlbumAsc = <>
43 select
44  rp0.media_item_id,
45  rp0.obj_sortable || ' ' || rp1.obj_sortable
46 from
47  resource_properties rp0
48  join resource_properties rp1 on rp0.media_item_id = rp1.media_item_id
49 where
50  rp0.property_id = 3 and
51  rp1.property_id = 2
52 order by
53  rp0.obj_sortable asc,
54  rp1.obj_sortable asc,
55  rp0.media_item_id asc;
56  </>.toString();
57 
58  var sqlAlbumAscTrackAsc = <>
59 select
60  rp0.media_item_id,
61  rp0.obj_sortable || ' ' || rp1.obj_sortable
62 from
63  resource_properties rp0
64  join resource_properties rp1 on rp0.media_item_id = rp1.media_item_id
65 where
66  rp0.property_id = 2 and
67  rp1.property_id = 6
68 order by
69  rp0.obj_sortable asc,
70  rp1.obj_sortable asc,
71  rp0.media_item_id asc;
72  </>.toString();
73 
74  var sqlAlbumAscTrackAscNull = <>
75 select
76  media_item_id,
77  '(null)'
78 from
79  media_items
80 where
81  media_item_id not in (
82  select
83  media_item_id
84  from
85  resource_properties
86  where
87  property_id = 2
88  )
89 order by
90  media_item_id asc;
91  </>.toString();
92 
93  var sqlAlbumAscTrackDesc = <>
94 select
95  rp0.media_item_id,
96  rp0.obj_sortable || ' ' || rp1.obj_sortable
97 from
98  resource_properties rp0
99  join resource_properties rp1 on rp0.media_item_id = rp1.media_item_id
100 where
101  rp0.property_id = 2 and
102  rp1.property_id = 6
103 order by
104  rp0.obj_sortable asc,
105  rp1.obj_sortable desc,
106  rp0.media_item_id asc;
107  </>.toString();
108 
109  var sqlArtistAscAlbumAscTrackAsc = <>
110 select
111  rp0.media_item_id,
112  rp0.obj_sortable || ' ' || rp1.obj_sortable || ' ' || rp2.obj_sortable
113 from
114  resource_properties rp0
115  join resource_properties rp1 on rp0.media_item_id = rp1.media_item_id
116  join resource_properties rp2 on rp0.media_item_id = rp2.media_item_id
117 where
118  rp0.property_id = 3 and
119  rp1.property_id = 2 and
120  rp2.property_id = 6
121 order by
122  rp0.obj_sortable asc,
123  rp1.obj_sortable asc,
124  rp2.obj_sortable asc,
125  rp0.media_item_id asc;
126  </>.toString();
127 
128  var sqlArtistAscAlbumAscTrackAscNull = <>
129 select
130  media_item_id,
131  '(null)'
132 from
133  media_items
134 where
135  media_item_id not in (
136  select
137  media_item_id
138  from
139  resource_properties
140  where
141  property_id = 3
142  )
143 order by
144  media_item_id asc;
145  </>.toString();
146 
147  var sqlTrackNameAscLastPlayTimeDesc = <>
148 select
149  rp0.media_item_id,
150  rp0.obj_sortable || ' ' || rp1.obj_sortable
151 from
152  resource_properties rp0
153  left join resource_properties rp1 on rp0.media_item_id = rp1.media_item_id and rp1.property_id = 11
154 where
155  rp0.property_id = 1
156 order by
157  rp0.obj_sortable asc,
158  rp1.obj_sortable desc,
159  rp0.media_item_id asc;
160  </>.toString();
161 
162  var sqlTrackNameAscLastPlayTimeDescNull = <>
163 select
164  media_item_id,
165  '(null)'
166 from
167  media_items
168 where
169  media_item_id not in (
170  select
171  media_item_id
172  from
173  resource_properties
174  where
175  property_id = 1
176  )
177 order by
178  media_item_id asc;
179  </>.toString();
180 
181  var databaseGUID = "test_guidarray_sortmulti";
182  var library = createLibrary(databaseGUID);
183  var array;
184 
185  var d = execQuery(databaseGUID, sqlArtistAscAlbumAsc);
186  var d_null = execQuery(databaseGUID, sqlAlbumAscTrackAscNull);
187  var dataSortArtistAscAlbumAsc = d.concat(d_null);
188 
189  d = execQuery(databaseGUID, sqlAlbumAscTrackAsc);
190  // sqlAlbumAscTrackAscNull is the same for both test, so just resuse it
191  d_null = execQuery(databaseGUID, sqlAlbumAscTrackAscNull);
192  dataSortAlbumAscTrackAsc = d.concat(d_null);
193 
194  d = execQuery(databaseGUID, sqlAlbumAscTrackDesc);
195  // sqlAlbumAscTrackAscNull is the same for both test, so just resuse it
196  d_null = execQuery(databaseGUID, sqlAlbumAscTrackAscNull);
197  var dataSortAlbumAscTrackDesc = d.concat(d_null);
198 
199  d = execQuery(databaseGUID, sqlArtistAscAlbumAscTrackAsc);
200  d_null = execQuery(databaseGUID, sqlArtistAscAlbumAscTrackAscNull);
201  var dataSortArtistAscAlbumAscTrackAsc = d.concat(d_null);
202 
203  d = execQuery(databaseGUID, sqlTrackNameAscLastPlayTimeDesc);
204  d_null = execQuery(databaseGUID, sqlTrackNameAscLastPlayTimeDescNull);
205  var dataSortTrackNameAscLastPlayTimeDesc = d.concat(d_null);
206 
207  // Try a variety of fetch sizes to expose edge cases
208  var fetchSizes = [0, 1, 2, 5, 7, 10, 50, 100, 200];
209 
210  for(var i = 0; i < fetchSizes.length; i++) {
211  array = makeArray(library);
212  array.baseTable = "media_items";
213  array.addSort(SBProperties.artistName, true);
214  array.addSort(SBProperties.albumName, true);
215  array.fetchSize = fetchSizes[i];
216 
217  assertSortArray(array, dataSortArtistAscAlbumAsc);
218 
219  array = makeArray(library);
220  array.baseTable = "media_items";
221  array.addSort(SBProperties.albumName, true);
222  array.addSort(SBProperties.trackNumber, true);
223  array.fetchSize = fetchSizes[i];
224 
225  assertSortArray(array, dataSortAlbumAscTrackAsc);
226 
227  array = makeArray(library);
228  array.baseTable = "media_items";
229  array.addSort(SBProperties.albumName, true);
230  array.addSort(SBProperties.trackNumber, false);
231  array.fetchSize = fetchSizes[i];
232 
233  assertSortArray(array, dataSortAlbumAscTrackDesc);
234 
235  array = makeArray(library);
236  array.baseTable = "media_items";
237  array.addSort(SBProperties.artistName, true);
238  array.addSort(SBProperties.albumName, true);
239  array.addSort(SBProperties.trackNumber, true);
240  array.fetchSize = fetchSizes[i];
241 
242  assertSortArray(array, dataSortArtistAscAlbumAscTrackAsc);
243 
244  array = makeArray(library);
245  array.baseTable = "media_items";
246  array.addSort(SBProperties.trackName, true);
247  array.addSort(SBProperties.lastPlayTime, false);
248  array.fetchSize = fetchSizes[i];
249 
250  assertSortArray(array, dataSortTrackNameAscLastPlayTimeDesc);
251  }
252 
253 }
254 
256 
257  assertEqual(array.length, data.length);
258 
259  for (var i = 0; i < array.length; i++) {
260  assertEqual(array.getMediaItemIdByIndex(i), data[i][0]);
261  }
262 }
inArray array
_selectMonthYear select
function assertSortArray(array, data)
trim makeArray
function assertEqual(aExpected, aActual, aMessage)
function d(s)
function runTest()
Test file.
function createLibrary(databaseGuid, databaseLocation)
Definition: test_load.js:151
observe data
Definition: FeedWriter.js:1329
_getSelectedPageStyle s i