1 | /* vim:set ts=2 sw=2 et cindent: */
|
---|
2 | /* ***** BEGIN LICENSE BLOCK *****
|
---|
3 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
---|
4 | *
|
---|
5 | * The contents of this file are subject to the Mozilla Public License Version
|
---|
6 | * 1.1 (the "License"); you may not use this file except in compliance with
|
---|
7 | * the License. You may obtain a copy of the License at
|
---|
8 | * http://www.mozilla.org/MPL/
|
---|
9 | *
|
---|
10 | * Software distributed under the License is distributed on an "AS IS" basis,
|
---|
11 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
---|
12 | * for the specific language governing rights and limitations under the
|
---|
13 | * License.
|
---|
14 | *
|
---|
15 | * The Original Code is Mozilla IPC.
|
---|
16 | *
|
---|
17 | * The Initial Developer of the Original Code is IBM Corporation.
|
---|
18 | * Portions created by the Initial Developer are Copyright (C) 2004
|
---|
19 | * the Initial Developer. All Rights Reserved.
|
---|
20 | *
|
---|
21 | * Contributor(s):
|
---|
22 | * Darin Fisher <[email protected]>
|
---|
23 | *
|
---|
24 | * Alternatively, the contents of this file may be used under the terms of
|
---|
25 | * either the GNU General Public License Version 2 or later (the "GPL"), or
|
---|
26 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
---|
27 | * in which case the provisions of the GPL or the LGPL are applicable instead
|
---|
28 | * of those above. If you wish to allow use of your version of this file only
|
---|
29 | * under the terms of either the GPL or the LGPL, and not to allow others to
|
---|
30 | * use your version of this file under the terms of the MPL, indicate your
|
---|
31 | * decision by deleting the provisions above and replace them with the notice
|
---|
32 | * and other provisions required by the GPL or the LGPL. If you do not delete
|
---|
33 | * the provisions above, a recipient may use your version of this file under
|
---|
34 | * the terms of any one of the MPL, the GPL or the LGPL.
|
---|
35 | *
|
---|
36 | * ***** END LICENSE BLOCK ***** */
|
---|
37 |
|
---|
38 | /**
|
---|
39 | * This file contains code that mirrors the code in TestDConnect.cpp:DoTest
|
---|
40 | */
|
---|
41 |
|
---|
42 | const ipcIService = Components.interfaces.ipcIService;
|
---|
43 | const ipcIDConnectService = Components.interfaces.ipcIDConnectService;
|
---|
44 | const nsIFile = Components.interfaces.nsIFile;
|
---|
45 | const nsILocalFile = Components.interfaces.nsILocalFile;
|
---|
46 | const nsIEventQueueService = Components.interfaces.nsIEventQueueService;
|
---|
47 |
|
---|
48 | // XXX use directory service for this
|
---|
49 | const TEST_PATH = "/tmp";
|
---|
50 |
|
---|
51 | var serverID = 0;
|
---|
52 |
|
---|
53 | function findServer()
|
---|
54 | {
|
---|
55 | var ipc = Components.classes["@mozilla.org/ipc/service;1"].getService(ipcIService);
|
---|
56 | serverID = ipc.resolveClientName("test-server");
|
---|
57 | }
|
---|
58 |
|
---|
59 | function doTest()
|
---|
60 | {
|
---|
61 | var dcon = Components.classes["@mozilla.org/ipc/dconnect-service;1"]
|
---|
62 | .getService(ipcIDConnectService);
|
---|
63 |
|
---|
64 | var file = dcon.createInstanceByContractID(serverID, "@mozilla.org/file/local;1", nsIFile);
|
---|
65 |
|
---|
66 | var localFile = file.QueryInterface(nsILocalFile);
|
---|
67 |
|
---|
68 | localFile.initWithPath(TEST_PATH);
|
---|
69 |
|
---|
70 | if (file.path != TEST_PATH)
|
---|
71 | {
|
---|
72 | dump("*** path test failed [path=" + file.path + "]\n");
|
---|
73 | return;
|
---|
74 | }
|
---|
75 |
|
---|
76 | dump("file exists: " + file.exists() + "\n");
|
---|
77 |
|
---|
78 | var clone = file.clone();
|
---|
79 |
|
---|
80 | const node = "hello.txt";
|
---|
81 | clone.append(node);
|
---|
82 | dump("files are equal: " + file.equals(clone) + "\n");
|
---|
83 |
|
---|
84 | if (!clone.exists())
|
---|
85 | clone.create(nsIFile.NORMAL_FILE_TYPE, 0600);
|
---|
86 |
|
---|
87 | clone.moveTo(null, "helloworld.txt");
|
---|
88 |
|
---|
89 | var localObj = Components.classes["@mozilla.org/file/local;1"].createInstance(nsILocalFile);
|
---|
90 | localObj.initWithPath(TEST_PATH);
|
---|
91 | dump("file.equals(localObj) = " + file.equals(localObj) + "\n");
|
---|
92 | dump("localObj.equals(file) = " + localObj.equals(file) + "\n");
|
---|
93 | }
|
---|
94 |
|
---|
95 | function setupEventQ()
|
---|
96 | {
|
---|
97 | var eqs = Components.classes["@mozilla.org/event-queue-service;1"]
|
---|
98 | .getService(nsIEventQueueService);
|
---|
99 | eqs.createMonitoredThreadEventQueue();
|
---|
100 | }
|
---|
101 |
|
---|
102 | setupEventQ();
|
---|
103 | findServer();
|
---|
104 | dump("\n---------------------------------------------------\n");
|
---|
105 | doTest();
|
---|
106 | dump("---------------------------------------------------\n\n");
|
---|