test_null_properties.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  var library = createLibrary("test_null_properties", null, false);
36  library.clear();
37 
38  var item = library.createMediaItem(newURI("http://foo.com/"));
39  library.flush();
40  testResource(library, item.guid);
41 
42  var list = library.createMediaList("simple");
43  library.flush();
44  testResource(library, list.guid);
45 }
46 
47 function testResource(library, guid) {
48 
49  var r = library.getItemByGuid(guid);
50  var nullprop = "http://songbirdnest.com/data/1.0#foo";
51 
52  var originalLength = r.getProperties().length;
53  var mediaItemId = r.QueryInterface(Ci.sbILocalDatabaseMediaItem).mediaItemId;
54  var originalProps = countProperties(mediaItemId);
55 
56  assertEqual(r.getProperty(nullprop), null);
57 
58  r.setProperty(nullprop, null);
59  assertEqual(r.getProperties().length, originalLength);
60  assertEqual(r.getProperty(nullprop), null);
61  library.flush();
62  assertEqual(countProperties(mediaItemId), originalProps);
63 
64  var library2 = createLibrary("test_null_properties", null, false);
65  var r2 = library2.getItemByGuid(guid);
66  assertEqual(r2.getProperties().length, originalLength);
67  assertEqual(r2.getProperty(nullprop), null);
68 
69  r.setProperty(nullprop, "");
70  assertEqual(r.getProperties().length, originalLength + 1);
71  assertEqual(r.getProperty(nullprop), "");
72  library.flush();
73  assertEqual(countProperties(mediaItemId), originalProps + 1);
74 
75  var library3 = createLibrary("test_null_properties", null, false);
76  var r3 = library3.getItemByGuid(guid);
77  assertEqual(r3.getProperties().length, originalLength + 1);
78  assertEqual(r3.getProperty(nullprop), "");
79 
80  r.setProperty(nullprop, null);
81  assertEqual(r.getProperties().length, originalLength);
82  assertEqual(r.getProperty(nullprop), null);
83  library.flush();
84  assertEqual(countProperties(mediaItemId), originalProps);
85 
86  var library4 = createLibrary("test_null_properties", null, false);
87  var r4 = library4.getItemByGuid(guid);
88  assertEqual(r4.getProperties().length, originalLength);
89  assertEqual(r4.getProperty(nullprop), null);
90 
91  // try with a top level property
92  r.setProperty(SBProperties.hash, null);
93  assertEqual(r.getProperties().length, originalLength);
94  assertEqual(r.getProperty(SBProperties.hash), null);
95  library.flush();
96 
97  var library5 = createLibrary("test_null_properties", null, false);
98  var r5 = library5.getItemByGuid(guid);
99  assertEqual(r5.getProperties().length, originalLength);
100  assertEqual(r5.getProperty(SBProperties.hash), null);
101 
102  r.setProperty(SBProperties.hash, "");
103  assertEqual(r.getProperties().length, originalLength + 1);
104  assertEqual(r.getProperty(SBProperties.hash), "");
105 
106  var library6 = createLibrary("test_null_properties", null, false);
107  var r6 = library6.getItemByGuid(guid);
108  assertEqual(r6.getProperties().length, originalLength + 1);
109  assertEqual(r6.getProperty(SBProperties.hash), "");
110 
111  r.setProperty(SBProperties.hash, null);
112  assertEqual(r.getProperties().length, originalLength);
113  assertEqual(r.getProperty(SBProperties.hash), null);
114  library.flush();
115 
116  var library7 = createLibrary("test_null_properties", null, false);
117  var r7 = library7.getItemByGuid(guid);
118  assertEqual(r7.getProperties().length, originalLength);
119  assertEqual(r7.getProperty(SBProperties.hash), null);
120 
121 }
122 
123 function countProperties(mediaItemId) {
124  var dbq = Cc["@songbirdnest.com/Songbird/DatabaseQuery;1"]
125  .createInstance(Ci.sbIDatabaseQuery);
126 
127  dbq.setDatabaseGUID("test_null_properties");
128  dbq.setAsyncQuery(false);
129  dbq.addQuery("select count(1) from resource_properties where media_item_id = " + mediaItemId);
130  dbq.execute();
131 
132  var dbr = dbq.getResultObject();
133  return parseInt(dbr.getRowCell(0, 0));
134 }
135 
const Cc
function countProperties(mediaItemId)
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)
const Ci
function testResource(library, guid)