test_migration.js
Go to the documentation of this file.
1 /*
2  *=BEGIN SONGBIRD GPL
3  *
4  * This file is part of the Songbird web player.
5  *
6  * Copyright(c) 2005-2009 POTI, Inc.
7  * http://www.songbirdnest.com
8  *
9  * This file may be licensed under the terms of of the
10  * GNU General Public License Version 2 (the ``GPL'').
11  *
12  * Software distributed under the License is distributed
13  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
14  * express or implied. See the GPL for the specific language
15  * governing rights and limitations.
16  *
17  * You should have received a copy of the GPL along with this
18  * program. If not, go to http://www.gnu.org/licenses/gpl.html
19  * or write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  *=END SONGBIRD GPL
23  */
24 
36  // the schema file may be in a jar, so we alway need to use the chrome url
37  const schemaSpec = "chrome://songbird/content/library/localdatabase/schema.sql";
38  var ioService = Cc["@mozilla.org/network/io-service;1"]
39  .getService(Ci.nsIIOService);
40  var schemaUri = ioService.newURI(schemaSpec, null, null);
41  var channel = ioService.newChannelFromURI(schemaUri);
42  var rawStream = channel.open();
43  var inStream = Cc["@mozilla.org/scriptableinputstream;1"]
44  .createInstance(Ci.nsIScriptableInputStream);
45  inStream.init(rawStream);
46 
47  var data = "", buffer;
48  while ((buffer = inStream.read(~0))) {
49  data += buffer;
50  }
51  inStream.close();
52  rawStream.close();
53 
54  const versionLineReg = /^insert into library_metadata/;
55  for each (var line in data.split(/\n/)) {
56  if (versionLineReg.test(line)) {
57  return parseInt(line.match(/'(\d+)'/)[1]);
58  }
59  }
60 
61  return -1;
62 }
63 
64 function runTest() {
65 
66  var databaseGUID = "test_migration";
67  var library = createLibrary(databaseGUID);
68 
69  var migrationHelper =
70  Cc["@songbirdnest.com/Songbird/Library/LocalDatabase/MigrationHelper;1"]
71  .createInstance(Ci.sbILocalDatabaseMigrationHelper);
72 
73  var latestSchemaVersion = getLatestSchemaVersionFromFile();
74 
75  assertEqual(migrationHelper.getLatestSchemaVersion(),
76  latestSchemaVersion,
77  "Error: Schema Version incorrect. Please ensure that the schema version in schema.sql matches the version in the Migration Helper!");
78 
79  assertEqual(migrationHelper.canMigrate(1, 1000), false);
80  assertEqual(migrationHelper.canMigrate(5, 6), true);
81 }
const Cc
var ioService
function assertEqual(aExpected, aActual, aMessage)
function runTest()
Advanced DataRemote unit tests.
function insert(dbq, size, name)
function getLatestSchemaVersionFromFile()
Test file to ensure that the version information between the schema and the Migration Helper are the ...
return null
Definition: FeedWriter.js:1143
function createLibrary(databaseGuid, databaseLocation)
Definition: test_load.js:151
const Ci
observe data
Definition: FeedWriter.js:1329