transport: simulate convertion dbxml to xml
[abstract.git] / transport / sqlite / test / aaConverterTest.js
blobdc509856e61c7e422ee6747a37ee566492e51cb3
1 /* vim:set ts=2 sw=2 sts=2 et cindent tw=79 ft=javascript: */
2 /*
3  * Copyright (C) 2010 Sergey Yanovich <ynvich@gmail.com>
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of the
8  * License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
21 const nsCI                   = Components.interfaces;
22 const moduleName             = "aaConverterTest";
23 const moduleCID              = "{30e4bf20-504a-44fd-9473-3dc0294f4827}";
24 const moduleContractID       = "@aasii.org/transport/sqlite/test/converter;1";
26 Components.utils.import("resource:///modules/aaTestVC.jsm");
29  * Module entry point
30  * The NSGetModule function is the magic entry point that XPCOM uses to find
31  * what XPCOM components this module provides
32  */
33 function NSGetModule(comMgr, fileSpec)
35   var loader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
36     .getService(Components.interfaces.mozIJSSubScriptLoader);
37   loader.loadSubScript("resource:///modules/nsTestFrame.jsm");
39   var aaVCTestModule = JSTestModule();
40   aaVCTestModule.init = ModuleInit;
41   aaVCTestModule.init();
42   return aaVCTestModule;
45 function ModuleInit()
47   this._name = moduleName;
48   this._CID = Components.ID(moduleCID);
49   this._contractID = moduleContractID;
51   this._add(select_sqlite_table_CID, select_sqlite_table_contractID,
52       select_sqlite_table_name, select_sqlite_table_test,
53       select_sqlite_table_check);
56 function doLoadURI(runner, uri)
58   runner.testWindow.document.getElementById("content").docShell
59     .QueryInterface(nsCI.nsIWebNavigation)
60     .loadURI(uri, nsCI.nsIWebNavigation.LOAD_FLAGS_NONE, null, null, null);
63 const select_sqlite_table_contractID =
64   "@aasii.org/transport/sqlite/test/converter/select-sqlite-table;1";
65 const select_sqlite_table_name = "aaConverterTestSelectSqliteTable";
66 const select_sqlite_table_CID =
67   Components.ID("{fca3d21e-3e35-40d4-a086-1ff9bd44b72e}");
69 function select_sqlite_table_test(runner)
71   doLoadURI(runner, "sqlite:///tmp/transport.sqlite?sql" +
72       "=SELECT id,tag FROM test");
73   runner.watchWindow = getFrame(runner).contentWindow;
76 function firstChildIsResult(elem) {
77   if (elem.firstChild.nodeValue.trim() == "1" ||
78       elem.firstChild.nodeValue.trim() == "hello") {
79     return true;
80   }
81   return false;
84 function select_sqlite_table_check(runner)
86   var doc = runner.testWindow.document;
87   var web = doc.getElementById("content").docShell
88     .QueryInterface(nsCI.nsIWebNavigation);
89   var result = false;
90   // check
91   var id = web.document.documentElement.getElementsByTagName("id");
92   if (id.length == 1) {
93     if (firstChildIsResult(id[0])) {
94       result = true;
95     }
96   }
97   if (result)
98   {
99     var tag = web.document.documentElement.getElementsByTagName("tag");
100     if (tag.length == 1) {
101       if (firstChildIsResult(tag[0])) {
102         result = true;
103       }
104       else
105       {
106         result = false;
107       }
108     }
109     else
110     {
111       result = false;
112     }
113   }
114   if (!result) {
115     runner.addJSFailure("aaConverterTest - Not correct select sqlite data");
116   }