1 /* -------------------------------------------------------------------------- *
2  *                       Simbody(tm): SimTKcommon                             *
3  * -------------------------------------------------------------------------- *
4  * This is part of the SimTK biosimulation toolkit originating from           *
5  * Simbios, the NIH National Center for Physics-Based Simulation of           *
6  * Biological Structures at Stanford, funded under the NIH Roadmap for        *
7  * Medical Research, grant U54 GM072970. See https://simtk.org/home/simbody.  *
8  *                                                                            *
9  * Portions copyright (c) 2008-12 Stanford University and the Authors.        *
10  * Authors: Michael Sherman                                                   *
11  * Contributors:                                                              *
12  *                                                                            *
13  * Licensed under the Apache License, Version 2.0 (the "License"); you may    *
14  * not use this file except in compliance with the License. You may obtain a  *
15  * copy of the License at http://www.apache.org/licenses/LICENSE-2.0.         *
16  *                                                                            *
17  * Unless required by applicable law or agreed to in writing, software        *
18  * distributed under the License is distributed on an "AS IS" BASIS,          *
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   *
20  * See the License for the specific language governing permissions and        *
21  * limitations under the License.                                             *
22  * -------------------------------------------------------------------------- */
23 
24 #include "SimTKcommon.h"
25 #include "SimTKcommon/Testing.h"
26 
27 #include "SimTKcommon/internal/Plugin.h"
28 
29 #include <iostream>
30 #include <string>
31 #include <cstdio>
32 using std::cout;
33 using std::endl;
34 using std::string;
35 using std::printf;
36 
37 using namespace SimTK;
38 
39 class ExportedClass;
40 class MyPlugin : public Plugin {
41 public:
MyPlugin(const std::string & name)42     explicit MyPlugin(const std::string& name)
43     :   Plugin(name) {
44         addSearchDirectory(Pathname::getInstallDir("SimTK_INSTALL_DIR", "SimTK")
45                             + "/lib/plugins/");
46     }
47 
48     SimTK_PLUGIN_DEFINE_FUNCTION1(int,sayHi,const std::string&);
49     SimTK_PLUGIN_DEFINE_FUNCTION(ExportedClass*,TestRuntimeDLL_makeExportedClass);
50     SimTK_PLUGIN_DEFINE_FUNCTION(void, NotPresent);
51 
52 private:
53 };
54 
testDeconstructFileName()55 void testDeconstructFileName() {
56     string name, directory, libPrefix, baseName, debugSuffix, extension;
57     bool isAbsPath;
58     const std::string s = Pathname::getPathSeparator();
59     const std::string d = Pathname::getCurrentDriveLetter();
60     const std::string dd = d.empty() ? std::string() : d + ":";
61     const std::string cwd = Pathname::getCurrentWorkingDirectory();
62     const std::string xd = Pathname::getThisExecutableDirectory();
63 
64 
65     //printf("'%s': %s %s|%s|%s|%s|%s\n", name.c_str(),
66     //    isAbsPath?"ABS":"REL", directory.c_str(), libPrefix.c_str(), baseName.c_str(),
67     //    debugSuffix.c_str(), extension.c_str());
68 
69 
70     directory=libPrefix=baseName=debugSuffix=extension="junk";
71     name = "  \t \n \r ";   // Illegal because nothing but white space
72     SimTK_TEST(!Plugin::deconstructLibraryName(name,
73         isAbsPath, directory, libPrefix, baseName, debugSuffix, extension));
74     SimTK_TEST(!isAbsPath && directory.empty()&&libPrefix.empty()&&baseName.empty()
75                &&debugSuffix.empty()&&extension.empty());
76 
77     directory=libPrefix=baseName=debugSuffix=extension="junk";
78     name = "   This.Is.Not.A.Suffix_A.dylib  "; // OK
79     SimTK_TEST(Plugin::deconstructLibraryName(name,
80         isAbsPath, directory, libPrefix, baseName, debugSuffix, extension));
81     SimTK_TEST(!isAbsPath && directory.empty() && libPrefix.empty()
82         && baseName=="This.Is.Not.A.Suffix_A"
83         && debugSuffix.empty() && extension==".dylib");
84 
85     directory=libPrefix=baseName=debugSuffix=extension="junk";
86     name = "/usr/local/lib/"; // illegal because no file name
87     SimTK_TEST(!Plugin::deconstructLibraryName(name,
88         isAbsPath, directory, libPrefix, baseName, debugSuffix, extension));
89     SimTK_TEST(isAbsPath
90         && directory==(dd+s+"usr"+s+"local"+s+"lib"+s)
91         && libPrefix.empty()&&baseName.empty()
92         && debugSuffix.empty()&&extension.empty());
93 
94     directory=libPrefix=baseName=debugSuffix=extension="junk";
95     name = "lib_D"; // illegal because nothing left after lib prefix and debug suffix
96     SimTK_TEST(!Plugin::deconstructLibraryName(name,
97         isAbsPath, directory, libPrefix, baseName, debugSuffix, extension));
98     SimTK_TEST(!isAbsPath && directory.empty()&&libPrefix=="lib"&&baseName.empty()
99                &&debugSuffix=="_D"&&extension.empty());
100 
101     directory=libPrefix=baseName=debugSuffix=extension="junk";
102     name = "/mylibrary_D."; // OK (empty file type suffix)
103     SimTK_TEST(Plugin::deconstructLibraryName(name,
104         isAbsPath, directory, libPrefix, baseName, debugSuffix, extension));
105     SimTK_TEST(isAbsPath
106         && directory==(dd+s) && libPrefix.empty()&&baseName=="mylibrary"
107         && debugSuffix=="_D"&&extension==".");
108 
109     directory=libPrefix=baseName=debugSuffix=extension="junk";
110     name = "./first/more/../../filename";
111     SimTK_TEST(Plugin::deconstructLibraryName(name,
112         isAbsPath, directory, libPrefix, baseName, debugSuffix, extension));
113     SimTK_TEST(isAbsPath
114         && directory==cwd
115         && libPrefix.empty()&&baseName=="filename"
116         && debugSuffix.empty()&&extension.empty());
117 
118     directory=libPrefix=baseName=debugSuffix=extension="junk";
119     name = "@/../../filename"; // executable path-relative name
120     SimTK_TEST(Plugin::deconstructLibraryName(name,
121         isAbsPath, directory, libPrefix, baseName, debugSuffix, extension));
122 
123     SimTK_TEST(isAbsPath
124         //&& directory==xd
125         && libPrefix.empty()&&baseName=="filename"
126         && debugSuffix.empty()&&extension.empty());
127 
128     directory=libPrefix=baseName=debugSuffix=extension="junk";
129     name = "a"; // OK (very short file name)
130     SimTK_TEST(Plugin::deconstructLibraryName(name,
131         isAbsPath, directory, libPrefix, baseName, debugSuffix, extension));
132     SimTK_TEST(!isAbsPath && directory.empty()&&libPrefix.empty()&&baseName=="a"
133                &&debugSuffix.empty()&&extension.empty());
134 
135 #ifdef _WIN32
136     // Disk specifiers are only recognized on Windows.
137     directory=libPrefix=baseName=debugSuffix=extension="junk";
138     name = "  c:\\Program Files\\lib\\libMyPlugIn_d.dll \n ";   // OK
139     SimTK_TEST(Plugin::deconstructLibraryName(name,
140         isAbsPath, directory, libPrefix, baseName, debugSuffix, extension));
141     SimTK_TEST(isAbsPath &&
142         directory==("c:"+s+"Program Files"+s+"lib"+s) && libPrefix=="lib"
143         && baseName=="MyPlugIn" && debugSuffix=="_d" && extension==".dll");
144 
145     directory=libPrefix=baseName=debugSuffix=extension="junk";
146     name = dd + "mydir/relative.txt"; // cwd relative to specified disk
147     SimTK_TEST(Plugin::deconstructLibraryName(name,
148         isAbsPath, directory, libPrefix, baseName, debugSuffix, extension));
149     SimTK_TEST(isAbsPath
150         && directory==(cwd + "mydir" + s)
151         && libPrefix.empty()&&baseName=="relative"
152         && debugSuffix.empty()&&extension==".txt");
153 #endif
154 }
155 
testPathname()156 void testPathname() {
157 #ifdef _WIN32
158     SimTK_TEST(Pathname::getPathSeparatorChar()=='\\');
159     SimTK_TEST(Pathname::getPathSeparator()=="\\");
160     SimTK_TEST(Pathname::getCurrentDriveLetter().size() == 1);
161     SimTK_TEST(Pathname::getCurrentDrive()==Pathname::getCurrentDriveLetter()+":");
162     SimTK_TEST(Pathname::getRootDirectory() == Pathname::getCurrentDrive() + "\\");
163 #else
164     SimTK_TEST(Pathname::getPathSeparatorChar()=='/');
165     SimTK_TEST(Pathname::getPathSeparator()=="/");
166     SimTK_TEST(Pathname::getCurrentDriveLetter().size() == 0);
167     SimTK_TEST(Pathname::getCurrentDrive()=="");
168     SimTK_TEST(Pathname::getRootDirectory() == "/");
169 #endif
170 
171     // Pathname::getFunctionLibraryDirectory().
172     std::string libraryPath;
173     bool status = Pathname::getFunctionLibraryDirectory(
174                 (void*)Pathname::getPathSeparator,
175                 libraryPath);
176     #ifdef _WIN32
177         // Always returns false; unsupported on Windows.
178         SimTK_TEST(status == false);
179     #else
180         SimTK_TEST(status == true);
181         // For TestPluginStatic, dladdr finds the path to TestPluginStatic
182         // (rather than to a library).
183         std::cout << "Pathname::getFunctionLibraryDirectory() is located in: "
184                   << libraryPath << std::endl;
185     #endif
186 
187 
188     std::string name;
189     bool isAbsPath;
190     std::string directory, fileName, extension;
191     const std::string curDrive =
192         Pathname::getCurrentDriveLetter().empty()
193             ? std::string()
194             : Pathname::getCurrentDriveLetter()+":";
195     const std::string sep = Pathname::getPathSeparator();
196 
197     directory=fileName=extension="junk"; isAbsPath=false;
198     name = "/topdir/seconddir/myFileName.ext";
199     Pathname::deconstructPathname(name, isAbsPath, directory, fileName, extension);
200     SimTK_TEST(isAbsPath
201         && directory==curDrive+sep+"topdir"+sep+"seconddir"+sep
202         && fileName=="myFileName" && extension==".ext");
203 
204     directory=fileName=extension="junk"; isAbsPath=true;
205     name = "topdir/seconddir/myFileName.ext";
206     Pathname::deconstructPathname(name, isAbsPath, directory, fileName, extension);
207     SimTK_TEST(!isAbsPath
208         && directory=="topdir"+sep+"seconddir"+sep
209         && fileName=="myFileName" && extension==".ext");
210 
211 #ifdef _WIN32
212     std::string swd, path, dir, pathname;
213     const std::string cwd = Pathname::getCurrentWorkingDirectory();
214     std::string cwd_nodrive = cwd; cwd_nodrive.erase(0,3);
215     const std::string cwdC = Pathname::getCurrentWorkingDirectory("c");
216     const std::string cwdD = Pathname::getCurrentWorkingDirectory("d");
217     const std::string thisExeDir = Pathname::getThisExecutableDirectory();
218 
219     swd = "   "; path = "C:/topdir/seconddir/myFileName.ext";
220     dir = "c:" + sep + "topdir" + sep + "seconddir" + sep;
221     directory = fileName = extension = "junk";
222     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
223     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
224     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
225     SimTK_TEST(pathname == dir + "myFileName.ext");
226 
227     swd = ""; path = "/topdir/seconddir/myFileName.ext";
228     dir = curDrive + sep + "topdir" + sep + "seconddir" + sep;
229     directory = fileName = extension = "junk";
230     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
231     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
232     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
233     SimTK_TEST(pathname == dir + "myFileName.ext");
234 
235     swd = "  "; path = "C:topdir/seconddir/myFileName.ext";
236     dir = cwdC + "topdir" + sep + "seconddir" + sep;
237     directory = fileName = extension = "junk";
238     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
239     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
240     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
241     SimTK_TEST(pathname == dir + "myFileName.ext");
242 
243     swd = ""; path = "./topdir/seconddir/myFileName.ext";
244     dir = cwd + "topdir" + sep + "seconddir" + sep;
245     directory = fileName = extension = "junk";
246     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
247     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
248     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
249     SimTK_TEST(pathname == dir + "myFileName.ext");
250 
251     swd = " "; path = "topdir/seconddir/myFileName.ext";
252     dir = cwd + "topdir" + sep + "seconddir" + sep;
253     directory = fileName = extension = "junk";
254     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
255     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
256     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
257     SimTK_TEST(pathname == dir + "myFileName.ext");
258 
259     ///
260 
261     swd = "D:/specified"; path = "C:/topdir/seconddir/myFileName.ext";
262     dir = "c:" + sep + "topdir" + sep + "seconddir" + sep;
263     directory = fileName = extension = "junk";
264     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
265     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
266     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
267     SimTK_TEST(pathname == dir + "myFileName.ext");
268 
269     swd = "D:/specified"; path = "/topdir/seconddir/myFileName.ext";
270     dir = "d:" + sep + "topdir" + sep + "seconddir" + sep;
271     directory = fileName = extension = "junk";
272     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
273     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
274     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
275     SimTK_TEST(pathname == dir + "myFileName.ext");
276 
277     swd = "D:/specified"; path = "C:topdir/seconddir/myFileName.ext";
278     dir = "d:" + sep + "specified" + sep + "topdir" + sep + "seconddir" + sep;
279     directory = fileName = extension = "junk";
280     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
281     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
282     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
283     SimTK_TEST(pathname == dir + "myFileName.ext");
284 
285     swd = "D:/specified"; path = "./topdir/seconddir/myFileName.ext";
286     dir = "d:" + sep + "specified" + sep + "topdir" + sep + "seconddir" + sep;
287     directory = fileName = extension = "junk";
288     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
289     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
290     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
291     SimTK_TEST(pathname == dir + "myFileName.ext");
292 
293     swd = "D:/specified"; path = "topdir/seconddir/myFileName.ext";
294     dir = "d:" + sep + "specified" + sep + "topdir" + sep + "seconddir" + sep;
295     directory = fileName = extension = "junk";
296     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
297     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
298     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
299     SimTK_TEST(pathname == dir + "myFileName.ext");
300 
301     swd = "D:/specified"; path = "../seconddir/myFileName.ext";
302     dir = "d:" + sep + "seconddir" + sep;
303     directory = fileName = extension = "junk";
304     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
305     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
306     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
307     SimTK_TEST(pathname == dir + "myFileName.ext");
308 
309     ///
310 
311     swd = "/specified"; path = "C:/topdir/seconddir/myFileName.ext";
312     dir = "c:" + sep + "topdir" + sep + "seconddir" + sep;
313     directory = fileName = extension = "junk";
314     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
315     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
316     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
317     SimTK_TEST(pathname == dir + "myFileName.ext");
318 
319     swd = "/specified"; path = "/topdir/seconddir/myFileName.ext";
320     dir = curDrive + sep + "topdir" + sep + "seconddir" + sep;
321     directory = fileName = extension = "junk";
322     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
323     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
324     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
325     SimTK_TEST(pathname == dir + "myFileName.ext");
326 
327     swd = "/specified"; path = "C:topdir/seconddir/myFileName.ext";
328     dir = curDrive + sep + "specified" + sep + "topdir" + sep + "seconddir" + sep;
329     directory = fileName = extension = "junk";
330     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
331     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
332     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
333     SimTK_TEST(pathname == dir + "myFileName.ext");
334 
335     swd = "/specified"; path = "./topdir/seconddir/myFileName.ext";
336     dir = curDrive + sep + "specified" + sep + "topdir" + sep + "seconddir" + sep;
337     directory = fileName = extension = "junk";
338     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
339     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
340     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
341     SimTK_TEST(pathname == dir + "myFileName.ext");
342 
343     swd = "/specified"; path = "topdir/seconddir/myFileName.ext";
344     dir = curDrive + sep + "specified" + sep + "topdir" + sep + "seconddir" + sep;
345     directory = fileName = extension = "junk";
346     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
347     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
348     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
349     SimTK_TEST(pathname == dir + "myFileName.ext");
350 
351     ///
352 
353     swd = "D:specified"; path = "C:/topdir/seconddir/myFileName.ext";
354     dir = "c:" + sep + "topdir" + sep + "seconddir" + sep;
355     directory = fileName = extension = "junk";
356     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
357     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
358     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
359     SimTK_TEST(pathname == dir + "myFileName.ext");
360 
361     swd = "D:specified"; path = "/topdir/seconddir/myFileName.ext";
362     dir = "d:" + sep + "topdir" + sep + "seconddir" + sep;
363     directory = fileName = extension = "junk";
364     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
365     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
366     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
367     SimTK_TEST(pathname == dir + "myFileName.ext");
368 
369     swd = "D:specified"; path = "C:topdir/seconddir/myFileName.ext";
370     dir = cwdD + "specified" + sep + "topdir" + sep + "seconddir" + sep;
371     directory = fileName = extension = "junk";
372     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
373     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
374     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
375     SimTK_TEST(pathname == dir + "myFileName.ext");
376 
377     swd = "D:specified"; path = "./topdir/seconddir/myFileName.ext";
378     dir = cwdD + "specified" + sep + "topdir" + sep + "seconddir" + sep;
379     directory = fileName = extension = "junk";
380     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
381     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
382     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
383     SimTK_TEST(pathname == dir + "myFileName.ext");
384 
385     swd = "D:specified"; path = "topdir/seconddir/myFileName.ext";
386     dir = cwdD + "specified" + sep + "topdir" + sep + "seconddir" + sep;
387     directory = fileName = extension = "junk";
388     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
389     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
390     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
391     SimTK_TEST(pathname == dir + "myFileName.ext");
392 
393     ///
394 
395     swd = "./specified"; path = "C:/topdir/seconddir/myFileName.ext";
396     dir = "c:" + sep + "topdir" + sep + "seconddir" + sep;
397     directory = fileName = extension = "junk";
398     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
399     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
400     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
401     SimTK_TEST(pathname == dir + "myFileName.ext");
402 
403     swd = "./specified"; path = "/topdir/seconddir/myFileName.ext";
404     dir = curDrive + sep + "topdir" + sep + "seconddir" + sep;
405     directory = fileName = extension = "junk";
406     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
407     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
408     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
409     SimTK_TEST(pathname == dir + "myFileName.ext");
410 
411     swd = "./specified"; path = "C:topdir/seconddir/myFileName.ext";
412     dir = cwd + "specified" + sep + "topdir" + sep + "seconddir" + sep;
413     directory = fileName = extension = "junk";
414     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
415     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
416     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
417     SimTK_TEST(pathname == dir + "myFileName.ext");
418 
419     swd = "./specified"; path = "./topdir/seconddir/myFileName.ext";
420     dir = cwd + "specified" + sep + "topdir" + sep + "seconddir" + sep;
421     directory = fileName = extension = "junk";
422     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
423     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
424     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
425     SimTK_TEST(pathname == dir + "myFileName.ext");
426 
427     swd = "./specified"; path = "topdir/seconddir/myFileName.ext";
428     dir = cwd + "specified" + sep + "topdir" + sep + "seconddir" + sep;
429     directory = fileName = extension = "junk";
430     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
431     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
432     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
433     SimTK_TEST(pathname == dir + "myFileName.ext");
434 
435     ///
436 
437     swd = "specified"; path = "C:/topdir/seconddir/myFileName.ext";
438     dir = "c:" + sep + "topdir" + sep + "seconddir" + sep;
439     directory = fileName = extension = "junk";
440     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
441     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
442     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
443     SimTK_TEST(pathname == dir + "myFileName.ext");
444 
445     swd = "specified"; path = "/topdir/seconddir/myFileName.ext";
446     dir = curDrive + sep + "topdir" + sep + "seconddir" + sep;
447     directory = fileName = extension = "junk";
448     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
449     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
450     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
451     SimTK_TEST(pathname == dir + "myFileName.ext");
452 
453     swd = "specified"; path = "C:topdir/seconddir/myFileName.ext";
454     dir = cwdC + "specified" + sep + "topdir" + sep + "seconddir" + sep;
455     directory = fileName = extension = "junk";
456     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
457     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
458     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
459     SimTK_TEST(pathname == dir + "myFileName.ext");
460 
461     swd = "specified"; path = "./topdir/seconddir/myFileName.ext";
462     dir = cwd + "specified" + sep + "topdir" + sep + "seconddir" + sep;
463     directory = fileName = extension = "junk";
464     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
465     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
466     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
467     SimTK_TEST(pathname == dir + "myFileName.ext");
468 
469     swd = "specified"; path = "topdir/seconddir/myFileName.ext";
470     dir = cwd + "specified" + sep + "topdir" + sep + "seconddir" + sep;
471     directory = fileName = extension = "junk";
472     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
473     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
474     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
475     SimTK_TEST(pathname == dir + "myFileName.ext");
476 
477     ///
478 
479     swd = "specified"; path = "topdir/../../seconddir/myFileName.ext";
480     dir = cwd + "seconddir" + sep;
481     directory = fileName = extension = "junk";
482     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
483     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
484     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
485     SimTK_TEST(pathname == dir + "myFileName.ext");
486 
487     swd = "specified"; path = "";
488     dir = "";
489     directory = fileName = extension = "junk";
490     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
491     SimTK_TEST(directory == dir && fileName == "" && extension == "");
492     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
493     SimTK_TEST(pathname == dir);
494 
495     swd = "."; path = "";
496     dir = "";
497     directory = fileName = extension = "junk";
498     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
499     SimTK_TEST(directory == dir && fileName == "" && extension == "");
500     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
501     SimTK_TEST(pathname == dir);
502 
503     swd = ""; path = ".";
504     dir = cwd;
505     directory = fileName = extension = "junk";
506     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
507     SimTK_TEST(directory == dir && fileName == "" && extension == "");
508     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
509     SimTK_TEST(pathname == dir);
510 
511     swd = "@"; path = "topdir/seconddir/myFileName.ext";
512     dir = thisExeDir + "topdir" + sep + "seconddir" + sep;
513     directory = fileName = extension = "junk";
514     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
515     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
516     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
517     SimTK_TEST(pathname == dir + "myFileName.ext");
518 
519 #else
520     std::string swd, path, dir, pathname;
521     const std::string cwd = Pathname::getCurrentWorkingDirectory();
522     const std::string thisExeDir = Pathname::getThisExecutableDirectory();
523 
524     swd = ""; path = "C:/topdir/seconddir/myFileName.ext";
525     dir = cwd + "C:" + sep + "topdir" + sep + "seconddir" + sep;
526     directory = fileName = extension = "junk";
527     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
528     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
529     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
530     SimTK_TEST(pathname == dir + "myFileName.ext");
531 
532     swd = ""; path = "/topdir/seconddir/myFileName.ext";
533     dir = sep + "topdir" + sep + "seconddir" + sep;
534     directory = fileName = extension = "junk";
535     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
536     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
537     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
538     SimTK_TEST(pathname == dir + "myFileName.ext");
539 
540     swd = ""; path = "C:topdir/seconddir/myFileName.ext";
541     dir = cwd + "C:topdir" + sep + "seconddir" + sep;
542     directory = fileName = extension = "junk";
543     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
544     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
545     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
546     SimTK_TEST(pathname == dir + "myFileName.ext");
547 
548     swd = ""; path = "./topdir/seconddir/myFileName.ext";
549     dir = cwd + "topdir" + sep + "seconddir" + sep;
550     directory = fileName = extension = "junk";
551     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
552     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
553     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
554     SimTK_TEST(pathname == dir + "myFileName.ext");
555 
556     swd = ""; path = "topdir/seconddir/myFileName.ext";
557     dir = cwd + "topdir" + sep + "seconddir" + sep;
558     directory = fileName = extension = "junk";
559     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
560     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
561     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
562     SimTK_TEST(pathname == dir + "myFileName.ext");
563 
564     ///
565 
566     swd = "/specified"; path = "C:/topdir/seconddir/myFileName.ext";
567     dir = sep + "specified" + sep + "C:" + sep + "topdir" + sep + "seconddir" + sep;
568     directory = fileName = extension = "junk";
569     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
570     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
571     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
572     SimTK_TEST(pathname == dir + "myFileName.ext");
573 
574     swd = "/specified"; path = "/topdir/seconddir/myFileName.ext";
575     dir = sep + "topdir" + sep + "seconddir" + sep;
576     directory = fileName = extension = "junk";
577     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
578     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
579     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
580     SimTK_TEST(pathname == dir + "myFileName.ext");
581 
582     swd = "/specified"; path = "C:topdir/seconddir/myFileName.ext";
583     dir = sep + "specified" + sep + "C:topdir" + sep + "seconddir" + sep;
584     directory = fileName = extension = "junk";
585     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
586     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
587     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
588     SimTK_TEST(pathname == dir + "myFileName.ext");
589 
590     swd = "/specified"; path = "./topdir/seconddir/myFileName.ext";
591     dir = sep + "specified" + sep + "topdir" + sep + "seconddir" + sep;
592     directory = fileName = extension = "junk";
593     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
594     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
595     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
596     SimTK_TEST(pathname == dir + "myFileName.ext");
597 
598     swd = "/specified"; path = "topdir/seconddir/myFileName.ext";
599     dir = sep + "specified" + sep + "topdir" + sep + "seconddir" + sep;
600     directory = fileName = extension = "junk";
601     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
602     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
603     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
604     SimTK_TEST(pathname == dir + "myFileName.ext");
605 
606     swd = "/specified"; path = "../seconddir/myFileName.ext";
607     dir = sep + "seconddir" + sep;
608     directory = fileName = extension = "junk";
609     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
610     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
611     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
612     SimTK_TEST(pathname == dir + "myFileName.ext");
613 
614     ///
615 
616     swd = "D:specified"; path = "C:/topdir/seconddir/myFileName.ext";
617     dir = cwd + "D:specified" + sep + "C:" + sep + "topdir" + sep + "seconddir" + sep;
618     directory = fileName = extension = "junk";
619     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
620     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
621     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
622     SimTK_TEST(pathname == dir + "myFileName.ext");
623 
624     swd = "D:specified"; path = "/topdir/seconddir/myFileName.ext";
625     dir = sep + "topdir" + sep + "seconddir" + sep;
626     directory = fileName = extension = "junk";
627     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
628     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
629     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
630     SimTK_TEST(pathname == dir + "myFileName.ext");
631 
632     swd = "D:specified"; path = "C:topdir/seconddir/myFileName.ext";
633     dir = cwd + "D:specified" + sep + "C:topdir" + sep + "seconddir" + sep;
634     directory = fileName = extension = "junk";
635     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
636     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
637     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
638     SimTK_TEST(pathname == dir + "myFileName.ext");
639 
640     swd = "D:specified"; path = "./topdir/seconddir/myFileName.ext";
641     dir = cwd + "D:specified" + sep + "topdir" + sep + "seconddir" + sep;
642     directory = fileName = extension = "junk";
643     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
644     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
645     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
646     SimTK_TEST(pathname == dir + "myFileName.ext");
647 
648     swd = "D:specified"; path = "topdir/seconddir/myFileName.ext";
649     dir = cwd + "D:specified" + sep + "topdir" + sep + "seconddir" + sep;
650     directory = fileName = extension = "junk";
651     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
652     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
653     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
654     SimTK_TEST(pathname == dir + "myFileName.ext");
655 
656     ///
657 
658     swd = "./specified"; path = "C:/topdir/seconddir/myFileName.ext";
659     dir = cwd + "specified" + sep + "C:" + sep + "topdir" + sep + "seconddir" + sep;
660     directory = fileName = extension = "junk";
661     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
662     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
663     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
664     SimTK_TEST(pathname == dir + "myFileName.ext");
665 
666     swd = "./specified"; path = "/topdir/seconddir/myFileName.ext";
667     dir = sep + "topdir" + sep + "seconddir" + sep;
668     directory = fileName = extension = "junk";
669     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
670     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
671     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
672     SimTK_TEST(pathname == dir + "myFileName.ext");
673 
674     swd = "./specified"; path = "X:topdir/seconddir/myFileName.ext";
675     dir = cwd + "specified" + sep + "X:topdir" + sep + "seconddir" + sep;
676     directory = fileName = extension = "junk";
677     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
678     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
679     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
680     SimTK_TEST(pathname == dir + "myFileName.ext");
681 
682     swd = "./specified"; path = "./topdir/seconddir/myFileName.ext";
683     dir = cwd + "specified" + sep + "topdir" + sep + "seconddir" + sep;
684     directory = fileName = extension = "junk";
685     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
686     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
687     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
688     SimTK_TEST(pathname == dir + "myFileName.ext");
689 
690     swd = "./specified"; path = "topdir/seconddir/myFileName.ext";
691     dir = cwd + "specified" + sep + "topdir" + sep + "seconddir" + sep;
692     directory = fileName = extension = "junk";
693     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
694     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
695     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
696     SimTK_TEST(pathname == dir + "myFileName.ext");
697 
698     ///
699 
700     swd = "specified"; path = "C:/topdir/seconddir/myFileName.ext";
701     dir = cwd + "specified" + sep + "C:" + sep + "topdir" + sep + "seconddir" + sep;
702     directory = fileName = extension = "junk";
703     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
704     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
705     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
706     SimTK_TEST(pathname == dir + "myFileName.ext");
707 
708     swd = "specified"; path = "/topdir/seconddir/myFileName.ext";
709     dir = sep + "topdir" + sep + "seconddir" + sep;
710     directory = fileName = extension = "junk";
711     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
712     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
713     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
714     SimTK_TEST(pathname == dir + "myFileName.ext");
715 
716     swd = "specified"; path = "C:topdir/seconddir/myFileName.ext";
717     dir = cwd + "specified" + sep + "C:topdir" + sep + "seconddir" + sep;
718     directory = fileName = extension = "junk";
719     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
720     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
721     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
722     SimTK_TEST(pathname == dir + "myFileName.ext");
723 
724     swd = "specified"; path = "./topdir/seconddir/myFileName.ext";
725     dir = cwd + "specified" + sep + "topdir" + sep + "seconddir" + sep;
726     directory = fileName = extension = "junk";
727     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
728     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
729     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
730     SimTK_TEST(pathname == dir + "myFileName.ext");
731 
732     swd = "specified"; path = "topdir/seconddir/myFileName.ext";
733     dir = cwd + "specified" + sep + "topdir" + sep + "seconddir" + sep;
734     directory = fileName = extension = "junk";
735     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
736     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
737     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
738     SimTK_TEST(pathname == dir + "myFileName.ext");
739 
740     ///
741 
742     swd = "specified"; path = "topdir/../../seconddir/myFileName.ext";
743     dir = cwd + "seconddir" + sep;
744     directory = fileName = extension = "junk";
745     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
746     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
747     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
748     SimTK_TEST(pathname == dir + "myFileName.ext");
749 
750     swd = "specified"; path = "";
751     dir = "";
752     directory = fileName = extension = "junk";
753     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
754     SimTK_TEST(directory == dir && fileName == "" && extension == "");
755     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
756     SimTK_TEST(pathname == dir);
757 
758     swd = "."; path = "";
759     dir = "";
760     directory = fileName = extension = "junk";
761     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
762     SimTK_TEST(directory == dir && fileName == "" && extension == "");
763     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
764     SimTK_TEST(pathname == dir);
765 
766     swd = ""; path = ".";
767     dir = cwd;
768     directory = fileName = extension = "junk";
769     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
770     SimTK_TEST(directory == dir && fileName == "" && extension == "");
771     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
772     SimTK_TEST(pathname == dir);
773 
774     swd = "@"; path = "topdir/seconddir/myFileName.ext";
775     dir = thisExeDir + "topdir" + sep + "seconddir" + sep;
776     directory = fileName = extension = "junk";
777     Pathname::deconstructPathnameUsingSpecifiedWorkingDirectory(swd, path, directory, fileName, extension);
778     SimTK_TEST(directory == dir && fileName == "myFileName" && extension == ".ext");
779     pathname = Pathname::getAbsolutePathnameUsingSpecifiedWorkingDirectory(swd, path);
780     SimTK_TEST(pathname == dir + "myFileName.ext");
781 #endif
782 
783 }
784 
testPlugin()785 void testPlugin() {
786     MyPlugin myPlug("c:\\temp\\TestRuntimeDLL_d.dll");
787 
788     if (myPlug.load()) {
789         std::cout << "fellas length is " << myPlug.sayHi("fellas") << std::endl;
790         myPlug.TestRuntimeDLL_makeExportedClass();
791     } else
792         std::cout << "Plugin load failed, err=" << myPlug.getLastErrorMessage() << std::endl;
793 
794     SimTK_TEST_MUST_THROW(myPlug.NotPresent());
795 
796     if (myPlug.isLoaded()) {
797         SimTK_TEST(myPlug.has_TestRuntimeDLL_makeExportedClass());
798         SimTK_TEST(!myPlug.has_NotPresent());
799     }
800 
801     myPlug.unload();
802     myPlug.addSearchDirectory("@");
803     myPlug.addSearchDirectory(".");
804     myPlug.addSearchDirectory("..");
805     myPlug.addSearchDirectory("/temp");
806     myPlug.addSearchDirectory("c:/temp");
807     myPlug.load("TestRuntimeDLL.so");
808 }
809 
main()810 int main() {
811     cout << "Path of this executable: '" << Pathname::getThisExecutablePath() << "'\n";
812     cout << "Executable directory: '" << Pathname::getThisExecutableDirectory() << "'\n";
813     cout << "Current working directory: '" << Pathname::getCurrentWorkingDirectory() << "'\n";
814     cout << "Current drive letter: '" << Pathname::getCurrentDriveLetter() << "'\n";
815     cout << "Current drive: '" << Pathname::getCurrentDrive() << "'\n";
816     cout << "Path separator: '" << Pathname::getPathSeparator() << "'\n";
817     cout << "Default install dir: '" << Pathname::getDefaultInstallDir() << "'\n";
818     cout << "installDir(SimTK_INSTALL_DIR,/LunchTime/snacks): '"
819         << Pathname::getInstallDir("SimTK_INSTALL_DIR", "/LunchTime/snacks") << "'\n";
820     cout << "installDir(LocalAppData,SimTK): '"
821         << Pathname::getInstallDir("LocalAppData", "SimTK") << "'\n";
822     SimTK_START_TEST("TestPlugin");
823 
824         SimTK_SUBTEST(testPathname);
825         SimTK_SUBTEST(testDeconstructFileName);
826         SimTK_SUBTEST(testPlugin);
827 
828     SimTK_END_TEST();
829 }
830 
831