test_match_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 
32 var gProps = {};
33 
35 function readCPPProps() {
36  // get the app directory
37  var appDir = Components.classes["@mozilla.org/file/directory_service;1"]
38  .getService(Components.interfaces.nsIProperties)
39  .get("resource:app", Components.interfaces.nsIFile);
40 
41  // Get the root of the source tree
42  // XXX Mook: This sucks :(
43  var topsrcdir = appDir.parent.parent;
44  // mac paths are a bit different
45  if (getPlatform() == "Darwin") {
46  topsrcdir = topsrcdir.parent.parent.parent;
47  }
48  // Get to the C++ file we want to read
49  var file = topsrcdir.clone();
50  for each (var part in ["components", "property", "src", "sbStandardProperties.h"] )
51  file.append(part);
52 
53  var istream = Components.classes["@mozilla.org/network/file-input-stream;1"]
54  .createInstance(Components.interfaces.nsIFileInputStream);
55  istream.init(file, 0x01 /*PR_RDONLY*/, 0400, 0);
56  istream.QueryInterface(Components.interfaces.nsILineInputStream);
57 
58  // read lines and look for the property IDs
59  do {
60  var line = {};
61  var hasMore = istream.readLine(line);
62  var result = line.value.match(/"http:\/\/songbirdnest.com\/data\/1.0#([^"]+)"/);
63  if (result) {
64  gProps[result[1]] = true;
65  }
66  } while(hasMore);
67 
68  istream.close();
69  return true;
70 }
71 
72 function checkJSMProps() {
73  Components.utils.import("resource://app/jsmodules/sbProperties.jsm");
74  var props = {};
75  for (var i in SBProperties) {
76  if (typeof SBProperties[i] != "string") continue;
77  if (SBProperties[i].length <= SBProperties.base.length) {
78  continue;
79  }
80  var prop = SBProperties[i].match(/http:\/\/songbirdnest.com\/data\/1.0#(\w+)/)[1];
81  assertTrue(prop in gProps, "property " + prop + " is only in sbProperties.jsm");
82  props[prop] = true;
83  }
84  for (prop in gProps) {
85  assertTrue(prop in props, "property " + prop + " is not in sbProperties.jsm");
86  }
87 }
88 
89 function runTest() {
90  if (readCPPProps()) {
91  checkJSMProps();
92  }
93 }
var istream
var gProps
Tests to make sure the JS and the C++ properties match.
function getPlatform()
function assertTrue(aTest, aMessage)
function readCPPProps()
StringArrayEnumerator prototype hasMore
observe data
Definition: FeedWriter.js:1329
function runTest()
_getSelectedPageStyle s i
var file