test_guidarray_length.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  var databaseGUID = "test_guidarray_length";
34  var library = createLibrary(databaseGUID);
35  var listId = library.QueryInterface(Ci.sbILocalDatabaseLibrary).getMediaItemIdForGuid("7e8dcc95-7a1d-4bb3-9b14-d4906a9952cb");
36  var a;
37 
38  var array = Cc["@songbirdnest.com/Songbird/Library/LocalDatabase/GUIDArray;1"]
39  .createInstance(Ci.sbILocalDatabaseGUIDArray);
40  array.databaseGUID = databaseGUID;
41  array.propertyCache =
42  library.QueryInterface(Ci.sbILocalDatabaseLibrary).propertyCache;
43 
44  // Length checks, use the same sort for all of these since it does not
45  // matter
46  array.baseTable = "media_items";
47  array.addSort("http://songbirdnest.com/data/1.0#albumName", true);
48 
49  // Full library, unfiltered
50  assertEqual(array.length, 101);
51 
52  // Full library, property filtered
53  array.addFilter("http://songbirdnest.com/data/1.0#albumName",
54  new StringArrayEnumerator(["back in black"]),
55  false);
56  assertEqual(array.length, 10);
57  // Add another filter level
58  array.addFilter("http://songbirdnest.com/data/1.0#artistName",
59  new StringArrayEnumerator(["ac/dc"]),
60  false);
61  assertEqual(array.length, 10);
62  // And another
63  array.addFilter("http://songbirdnest.com/data/1.0#trackName",
64  new StringArrayEnumerator(["hells bells"]),
65  false);
66  assertEqual(array.length, 1);
67  array.clearFilters();
68 
69  // Full library, top level filter
70  array.addFilter("http://songbirdnest.com/data/1.0#contentURL",
71  new StringArrayEnumerator(["file:///home/steve/Shoot%20to%20Thrill.mp3",
72  "file:///home/steve/That%20Jim.mp3",
73  "file:///home/steve/You%20Shook%20Me%20All%20Night%20Long.mp3"]),
74  false);
75  assertEqual(array.length, 3);
76  // Add another filter level
77  array.addFilter("http://songbirdnest.com/data/1.0#contentLength",
78  new StringArrayEnumerator(["3300", "840"]),
79  false);
80  assertEqual(array.length, 2);
81  array.clearFilters();
82 
83  // Full library, mixed filtered
84  array.addFilter("http://songbirdnest.com/data/1.0#contentURL",
85  new StringArrayEnumerator(["file:///home/steve/Shoot%20to%20Thrill.mp3",
86  "file:///home/steve/That%20Jim.mp3",
87  "file:///home/steve/You%20Shook%20Me%20All%20Night%20Long.mp3"]),
88  false);
89  array.addFilter("http://songbirdnest.com/data/1.0#artistName",
90  new StringArrayEnumerator(["ac/dc"]),
91  false);
92  assertEqual(array.length, 2);
93  array.clearFilters();
94 
95  // Full library, property search
96  array.addFilter("http://songbirdnest.com/data/1.0#artistName",
97  new StringArrayEnumerator(["ac"]),
98  true);
99  assertEqual(array.length, 47);
100 
101  array.clearFilters();
102 
103  // Full library, mixed property filter and search
104  array.addFilter("http://songbirdnest.com/data/1.0#artistName",
105  new StringArrayEnumerator(["ac/dc"]),
106  false);
107  array.addFilter("http://songbirdnest.com/data/1.0#trackName",
108  new StringArrayEnumerator(["hell"]),
109  true);
110  assertEqual(array.length, 1);
111  array.clearFilters();
112 
113  // Length tests on simple media list
114  array.baseTable = "simple_media_lists";
115  array.baseConstraintColumn = "media_item_id";
116  array.baseConstraintValue = listId;
117 
118  // Simple media list, unfiltered
119  assertEqual(array.length, 20);
120 
121  // Simple media list, property filtered
122  array.addFilter("http://songbirdnest.com/data/1.0#artistName",
123  new StringArrayEnumerator(["ac/dc"]),
124  false);
125  assertEqual(array.length, 10);
126  // Add a filter
127  array.addFilter("http://songbirdnest.com/data/1.0#albumName",
128  new StringArrayEnumerator(["back in black"]),
129  false);
130  assertEqual(array.length, 10);
131  array.clearFilters();
132 
133  // Simple media list, top level filter
134  array.addFilter("http://songbirdnest.com/data/1.0#contentURL",
135  new StringArrayEnumerator(["file:///home/steve/Shoot%20to%20Thrill.mp3",
136  "file:///home/steve/Take%20on%20Me.mp3",
137  "file:///home/steve/You%20Shook%20Me%20All%20Night%20Long.mp3",
138  "file:///home/steve/Train%20of%20Thought.mp3"]),
139  false);
140  assertEqual(array.length, 4);
141  // Add another filter
142  array.addFilter("http://songbirdnest.com/data/1.0#contentLength",
143  new StringArrayEnumerator(["2760", "660"]),
144  false);
145  assertEqual(array.length, 2);
146  array.clearFilters();
147 
148  // Simple media list, mixed filtered
149  array.addFilter("http://songbirdnest.com/data/1.0#contentURL",
150  new StringArrayEnumerator(["file:///home/steve/Shoot%20to%20Thrill.mp3",
151  "file:///home/steve/Take%20on%20Me.mp3",
152  "file:///home/steve/You%20Shook%20Me%20All%20Night%20Long.mp3",
153  "file:///home/steve/Train%20of%20Thought.mp3"]),
154  false);
155  array.addFilter("http://songbirdnest.com/data/1.0#albumName",
156  new StringArrayEnumerator(["back in black"]),
157  false);
158  assertEqual(array.length, 2);
159  array.clearFilters();
160 
161  // Simple media list, property search
162  array.addFilter("http://songbirdnest.com/data/1.0#artistName",
163  new StringArrayEnumerator(["ac"]),
164  true);
165  assertEqual(array.length, 10);
166 
167  // Add another search
168  array.addFilter("http://songbirdnest.com/data/1.0#albumName",
169  new StringArrayEnumerator(["back"]),
170  true);
171  assertEqual(array.length, 10);
172  array.clearFilters();
173 
174  // Simple media list, mixed property filter and search
175  array.addFilter("http://songbirdnest.com/data/1.0#artistName",
176  new StringArrayEnumerator(["ac/dc"]),
177  false);
178  array.addFilter("http://songbirdnest.com/data/1.0#trackName",
179  new StringArrayEnumerator(["hell"]),
180  true);
181  assertEqual(array.length, 1);
182  array.clearFilters();
183 }
184 
const Cc
inArray array
function assertEqual(aExpected, aActual, aMessage)
function runTest()
Test file.
function createLibrary(databaseGuid, databaseLocation)
Definition: test_load.js:151
function StringArrayEnumerator(aArray)
const Ci