test_proxy.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 var gComplete = 0;
32 
33 function dbqCallback() {
34 
35 }
36 
37 dbqCallback.prototype = {
38  onQueryEnd: function(resultObject, dbGUID, query) {
39  assertEqual(resultObject.getRowCount(), 2);
40 
41  gComplete++;
42 
43  if(gComplete == 2)
44  testFinished();
45  }
46 };
47 
48 dbqCallback.prototype.constructor = dbqCallback;
49 
50 function runTest () {
51 
52  var dbq = Cc["@songbirdnest.com/Songbird/DatabaseQuery;1"]
53  .createInstance(Ci.sbIDatabaseQuery);
54 
55  var ios = Cc["@mozilla.org/network/io-service;1"]
56  .createInstance(Ci.nsIIOService);
57 
58  var dir = Cc["@mozilla.org/file/directory_service;1"]
59  .createInstance(Ci.nsIProperties);
60 
61  var testdir = dir.get("ProfD", Ci.nsIFile);
62 
63  var actualdir = testdir.clone();
64  actualdir.append("db_tests");
65 
66  if(!actualdir.exists())
67  {
68  try {
69  actualdir.create(Ci.nsIFile.DIRECTORY_TYPE, 0700);
70  } catch(e) {
71  //Some failures might be handled later. Some might be ignored.
72  throw e;
73  }
74  }
75 
76  var uri = ios.newFileURI(actualdir);
77  dbq.databaseLocation = uri;
78 
79  assertEqual(dbq.databaseLocation.spec, uri.spec);
80 
81  dbq.setDatabaseGUID("test_sync");
82  dbq.addQuery("drop table proxy_test");
83  dbq.addQuery("create table proxy_test (name text, value text)");
84  dbq.addQuery("insert into proxy_test values ('test 0', 'testing... 0')");
85  dbq.addQuery("insert into proxy_test values ('test 1', 'testing... 1')");
86 
87  dbq.execute();
88  dbq.waitForCompletion();
89  dbq.resetQuery();
90 
91  dbq.addSimpleQueryCallback(new dbqCallback());
92  dbq.addSimpleQueryCallback(new dbqCallback());
93 
94  dbq.addQuery("select * from proxy_test");
95  dbq.execute();
96 
97  testPending();
98 
99  return Components.results.NS_OK;
100 }
101 
const Cc
function testFinished()
function assertEqual(aExpected, aActual, aMessage)
var gComplete
Test file.
Definition: test_proxy.js:31
function runTest()
Advanced DataRemote unit tests.
Definition: test_proxy.js:50
var uri
Definition: FeedWriter.js:1135
const Ci
var ios
Definition: head_feeds.js:5
function testPending()
function dbqCallback()
Definition: test_proxy.js:33