Files
openfoam/applications/test/fileName/fileNameTest.C
Mark Olesen 0571f5393e rename Foam::dotFoam() -> Foam::findEtcFile() with an optional 'mandatory' argument
- if mandatory is true, findEtcFile() will abort with a message (via cerr).
  This allows a non-existent file to be caught at the lowest level and avoid
  error handling in IFstream, which might not be initialized at that stage.
2008-12-12 19:16:32 +01:00

77 lines
2.4 KiB
C

/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Application
fileName
Description
\*---------------------------------------------------------------------------*/
#include "fileName.H"
#include "IOstreams.H"
#include "OSspecific.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main()
{
wordList wrdList(5);
wrdList[0] = "hello";
wrdList[1] = "hello1";
wrdList[2] = "hello2";
wrdList[3] = "hello3";
wrdList[4] = "hello4.hmm";
fileName pathName(wrdList);
Info<< "pathName = " << pathName << endl;
Info<< "pathName.name() = " << pathName.name() << endl;
Info<< "pathName.path() = " << pathName.path() << endl;
Info<< "pathName.ext() = " << pathName.ext() << endl;
Info<< "pathName.components() = " << pathName.components() << endl;
Info<< "pathName.component(2) = " << pathName.component(2) << endl;
// test findEtcFile
Info<< "\n\nfindEtcFile tests:" << nl
<< " controlDict => " << findEtcFile("controlDict") << nl
<< " badName => " << findEtcFile("badName") << endl;
Info<< "This should emit a fatal error:" << endl;
Info<< " badName(die) => " << findEtcFile("badName", true) << nl
<< endl;
Info<< "\nEnd" << endl;
return 0;
}
// ************************************************************************* //