test_misc.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  var sql;
34  var q;
35  var c;
36 
37  q = newQuery();
38  q.baseTableName = "bbc"
39  q.addColumn(null, "name");
40  c = q.createMatchCriterionString(null, "name",
41  Ci.sbISQLBuilder.MATCH_EQUALS,
42  "o'boy");
43  q.addCriterion(c);
44  sql = "select name from bbc where name = 'o''boy'";
45  assertEqual(sql, q.toString());
46 
47  q = newQuery();
48  q.baseTableName = "bbc"
49  q.addColumn(null, "name");
50  c = q.createMatchCriterionNull(null, "name",
51  Ci.sbISQLBuilder.MATCH_EQUALS);
52  q.addCriterion(c);
53  sql = "select name from bbc where name is null";
54  assertEqual(sql, q.toString());
55 
56  q = newQuery();
57  q.baseTableName = "bbc"
58  q.addColumn(null, "name");
59  q.addOrder(null, "name", true);
60  sql = "select name from bbc order by name asc";
61  assertEqual(sql, q.toString());
62 
63  q = newQuery();
64  q.baseTableName = "bbc"
65  q.addColumn(null, "name");
66  q.addColumn(null, "region");
67  q.addOrder(null, "name", true);
68  q.addOrder(null, "region", false);
69  sql = "select name, region from bbc order by name asc, region desc";
70  assertEqual(sql, q.toString());
71 
72  q = newQuery();
73  q.baseTableName = "bbc"
74  q.addColumn(null, "name");
75  c = q.createMatchCriterionIn(null, "name");
76  c.addString("one");
77  c.addString("two");
78  q.addCriterion(c);
79  sql = "select name from bbc where name in ('one', 'two')";
80  assertEqual(sql, q.toString());
81 
82  q = newQuery();
83  q.baseTableName = "bbc"
84  q.addColumn(null, "name");
85  q.limit = 10;
86  q.offset = 20;
87  sql = "select name from bbc limit 10 offset 20";
88  assertEqual(sql, q.toString());
89 
90  q = newQuery();
91  q.baseTableName = "bbc"
92  q.addColumn(null, "name");
93  q.limitIsParameter = true;
94  q.offsetIsParameter = true;
95  sql = "select name from bbc limit ? offset ?";
96  assertEqual(sql, q.toString());
97 
98  q = newQuery();
99  q.baseTableName = "bbc"
100  q.addColumn(null, "name");
101  try {
102  q.addSubquery(q, null);
103  fail("No exception thrown");
104  }
105  catch(e) {
106  assertEqual(e.result, Cr.NS_ERROR_ILLEGAL_VALUE);
107  }
108 
109  return Components.results.NS_OK;
110 
111 }
112 
113 function newQuery() {
114  return Cc["@songbirdnest.com/Songbird/SQLBuilder/Select;1"]
115  .createInstance(Ci.sbISQLSelectBuilder);
116 }
117 
const Cc
function fail(aMessage)
function assertEqual(aExpected, aActual, aMessage)
function newQuery()
Definition: test_misc.js:113
function runTest()
Test file.
Definition: test_misc.js:31
return null
Definition: FeedWriter.js:1143
const Cr
const Ci