test_viewdistinctvalues.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  Components.utils.import("resource://app/jsmodules/sbLibraryUtils.jsm");
35 
36  var library = createLibrary("test_viewdistinctvalues", null, false);
37  library.clear();
38 
39  var items = [
40  ["The Beatles", "Abbey Road", "Come Together", "ROCK"],
41  ["The Beatles", "Abbey Road", "Sun King", "ROCK"],
42  ["The Beatles", "Let It Be", "Get Back", "POP"],
43  ["The Beatles", "Let It Be", "Two Of Us", "POP"],
44  ["The Doors", "L.A. Woman", "L.A. Woman", "ROCK"],
45  ["The Doors", "L.A. Woman", "Love Her Madly", "ROCK"]
46  ];
47 
48  function makeItem(i) {
49  var item = library.createMediaItem(
50  newURI("http://foo/" + i + ".mp3"),
51  SBProperties.createArray([
52  [SBProperties.artistName,items[i][0]],
53  [SBProperties.albumName, items[i][1]],
54  [SBProperties.trackName, items[i][2]],
55  [SBProperties.genre, items[i][3]]
56  ]));
57  return item;
58  }
59 
60  var item1 = makeItem(0);
61  var item2 = makeItem(1);
62  var item3 = makeItem(2);
63  var item4 = makeItem(3);
64  var item5 = makeItem(4);
65  var item6 = makeItem(5);
66 
67  var view = library.createView();
68 
69  var enumerator = view.getDistinctValuesForProperty(SBProperties.artistName);
70  assertEqual(enumerator.getNext(), "The Beatles");
71  assertEqual(enumerator.getNext(), "The Doors");
72  assertFalse(enumerator.hasMore());
73 
74  enumerator = view.getDistinctValuesForProperty(SBProperties.albumName);
75  assertEqual(enumerator.getNext(), "Abbey Road");
76  assertEqual(enumerator.getNext(), "L.A. Woman");
77  assertEqual(enumerator.getNext(), "Let It Be");
78  assertFalse(enumerator.hasMore());
79 
80  view.filterConstraint = LibraryUtils.createConstraint([
81  [
82  [SBProperties.artistName, ["The Beatles"]]
83  ]
84  ]);
85 
86  enumerator = view.getDistinctValuesForProperty(SBProperties.artistName);
87  assertEqual(enumerator.getNext(), "The Beatles");
88  assertFalse(enumerator.hasMore());
89 
90  enumerator = view.getDistinctValuesForProperty(SBProperties.albumName);
91  assertEqual(enumerator.getNext(), "Abbey Road");
92  assertEqual(enumerator.getNext(), "Let It Be");
93  assertFalse(enumerator.hasMore());
94 
95  view.filterConstraint = LibraryUtils.createConstraint([
96  [
97  [SBProperties.artistName, ["The Beatles"]]
98  ],
99  [
100  [SBProperties.albumName, ["Let It Be"]]
101  ],
102  ]);
103 
104  enumerator = view.getDistinctValuesForProperty(SBProperties.artistName);
105  assertEqual(enumerator.getNext(), "The Beatles");
106  assertFalse(enumerator.hasMore());
107 
108  enumerator = view.getDistinctValuesForProperty(SBProperties.albumName);
109  assertEqual(enumerator.getNext(), "Let It Be");
110  assertFalse(enumerator.hasMore());
111 }
112 
function assertEqual(aExpected, aActual, aMessage)
function runTest()
Test file.
return null
Definition: FeedWriter.js:1143
function createLibrary(databaseGuid, databaseLocation)
Definition: test_load.js:151
function newURI(aURLString)
function assertFalse(aTest, aMessage)
Javascript wrappers for common library tasks.
_getSelectedPageStyle s i