test_library_constraints.js
Go to the documentation of this file.
1 /* vim: set sw=2 et : */
2 /*
3  *=BEGIN SONGBIRD GPL
4  *
5  * This file is part of the Songbird web player.
6  *
7  * Copyright(c) 2005-2009 POTI, Inc.
8  * http://www.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 
30 Components.utils.import("resource://app/jsmodules/ArrayConverter.jsm");
31 Components.utils.import("resource://app/jsmodules/sbProperties.jsm");
32 Components.utils.import("resource://app/jsmodules/sbLibraryUtils.jsm");
33 
34 function runTest () {
35  var constraint;
36  var builder = Cc["@songbirdnest.com/Songbird/Library/ConstraintBuilder;1"]
37  .createInstance(Ci.sbILibraryConstraintBuilder);
38 
39  builder.includeConstraint(LibraryUtils.standardFilterConstraint);
40  assertTrue(LibraryUtils.standardFilterConstraint.equals(builder.get()),
41  "constraint builder failed to include standard constraint");
42 
43  builder.includeConstraint(LibraryUtils.standardFilterConstraint);
44  builder.intersect();
45  builder.include(SBProperties.contentType, "audio");
46  constraint = builder.get();
47  builder.parseFromString(String(constraint));
48  assertTrue(constraint.equals(builder.get()),
49  "constraint builder failed to correctly unserialize");
50 
51  builder.includeConstraint(LibraryUtils.standardFilterConstraint);
52  builder.intersect();
53  builder.include(SBProperties.genre, "\u6E2C \u8A66");
54  constraint = builder.get();
55  builder.parseFromString(String(constraint));
56  assertTrue(constraint.equals(builder.get()),
57  "constraint builder failed to correctly unserialize non-ASCII");
58 
59  // test that we're actually building the right constraints
60  builder.includeConstraint(LibraryUtils.standardFilterConstraint);
61  builder.intersect();
62  builder.include(SBProperties.contentType, "audio");
63  builder.intersect();
64  builder.includeList(SBProperties.trackName,
65  ArrayConverter.stringEnumerator(["alpha", "beta"]));
66  constraint = builder.get();
67  var expected = new Object();
68  expected[SBProperties.isList] = ["0"];
69  expected[SBProperties.hidden] = ["0"];
70  expected[SBProperties.contentType] = ["audio"];
71  expected[SBProperties.trackName] = ["alpha", "beta"];
72  for (let group in ArrayConverter.JSEnum(constraint.groups)) {
73  group.QueryInterface(Ci.sbILibraryConstraintGroup);
74  let props = ArrayConverter.JSArray(group.properties);
75  assertEqual(1, props.length, "unexpected property count");
76  assertTrue(props[0] in expected, "unknown property " + props[0]);
77  let values = ArrayConverter.JSArray(group.getValues(props[0]));
78  assertArraysEqual(values, expected[props[0]]);
79  delete expected[props[0]];
80  }
81  for (let prop in expected) {
82  doFail("unexpected remaining property " + prop);
83  }
84 }
85 
const Cc
function assertTrue(aTest, aMessage)
function assertEqual(aExpected, aActual, aMessage)
function assertArraysEqual(a1, a2)
var expected
function runTest()
Advanced DataRemote unit tests.
const Ci
function doFail(text)
Javascript wrappers for common library tasks.
var group