2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014,2015,2016, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
37 * Tests basic file name option implementation.
39 * \author Teemu Murtola <teemu.murtola@gmail.com>
40 * \ingroup module_options
44 #include "gromacs/options/filenameoption.h"
46 #include <gtest/gtest.h>
48 #include "gromacs/fileio/filetypes.h"
49 #include "gromacs/options/options.h"
50 #include "gromacs/options/optionsassigner.h"
51 #include "gromacs/utility/exceptions.h"
53 #include "testutils/testasserts.h"
58 using gmx::FileNameOption
;
60 TEST(FileNameOptionTest
, HandlesRequiredDefaultValueWithoutExtension
)
64 ASSERT_NO_THROW_GMX(options
.addOption(
65 FileNameOption("f").store(&value
).required()
66 .filetype(gmx::eftGenericData
).outputFile()
67 .defaultBasename("testfile")));
68 EXPECT_EQ("testfile.dat", value
);
70 gmx::OptionsAssigner
assigner(&options
);
71 EXPECT_NO_THROW_GMX(assigner
.start());
72 EXPECT_NO_THROW_GMX(assigner
.finish());
73 EXPECT_NO_THROW_GMX(options
.finish());
75 EXPECT_EQ("testfile.dat", value
);
78 TEST(FileNameOptionTest
, HandlesRequiredOptionWithoutValue
)
82 ASSERT_NO_THROW_GMX(options
.addOption(
83 FileNameOption("f").store(&value
).required()
84 .filetype(gmx::eftGenericData
).outputFile()
85 .defaultBasename("testfile")));
86 EXPECT_EQ("testfile.dat", value
);
88 gmx::OptionsAssigner
assigner(&options
);
89 EXPECT_NO_THROW_GMX(assigner
.start());
90 EXPECT_NO_THROW_GMX(assigner
.startOption("f"));
91 EXPECT_NO_THROW_GMX(assigner
.finishOption());
92 EXPECT_NO_THROW_GMX(assigner
.finish());
93 EXPECT_NO_THROW_GMX(options
.finish());
95 EXPECT_EQ("testfile.dat", value
);
98 TEST(FileNameOptionTest
, HandlesOptionalUnsetOption
)
100 gmx::Options options
;
102 ASSERT_NO_THROW_GMX(options
.addOption(
103 FileNameOption("f").store(&value
)
104 .filetype(gmx::eftTrajectory
).outputFile()
105 .defaultBasename("testfile")));
106 EXPECT_TRUE(value
.empty());
108 gmx::OptionsAssigner
assigner(&options
);
109 EXPECT_NO_THROW_GMX(assigner
.start());
110 EXPECT_NO_THROW_GMX(assigner
.finish());
111 EXPECT_NO_THROW_GMX(options
.finish());
113 EXPECT_TRUE(value
.empty());
116 TEST(FileNameOptionTest
, HandlesOptionalDefaultValueWithoutExtension
)
118 gmx::Options options
;
120 ASSERT_NO_THROW_GMX(options
.addOption(
121 FileNameOption("f").store(&value
)
122 .filetype(gmx::eftIndex
).outputFile()
123 .defaultBasename("testfile")));
124 EXPECT_TRUE(value
.empty());
126 gmx::OptionsAssigner
assigner(&options
);
127 EXPECT_NO_THROW_GMX(assigner
.start());
128 EXPECT_NO_THROW_GMX(assigner
.startOption("f"));
129 EXPECT_NO_THROW_GMX(assigner
.finishOption());
130 EXPECT_NO_THROW_GMX(assigner
.finish());
131 EXPECT_NO_THROW_GMX(options
.finish());
133 EXPECT_EQ("testfile.ndx", value
);
136 TEST(FileNameOptionTest
, HandlesRequiredCustomDefaultExtension
)
138 gmx::Options options
;
140 ASSERT_NO_THROW_GMX(options
.addOption(
141 FileNameOption("f").store(&value
).required()
142 .filetype(gmx::eftTrajectory
).outputFile()
143 .defaultBasename("testfile")
144 .defaultType(efPDB
)));
145 EXPECT_EQ("testfile.pdb", value
);
147 gmx::OptionsAssigner
assigner(&options
);
148 EXPECT_NO_THROW_GMX(assigner
.start());
149 EXPECT_NO_THROW_GMX(assigner
.finish());
150 EXPECT_NO_THROW_GMX(options
.finish());
152 EXPECT_EQ("testfile.pdb", value
);
155 TEST(FileNameOptionTest
, HandlesOptionalCustomDefaultExtension
)
157 gmx::Options options
;
159 ASSERT_NO_THROW_GMX(options
.addOption(
160 FileNameOption("f").store(&value
)
161 .filetype(gmx::eftTrajectory
).outputFile()
162 .defaultBasename("testfile")
163 .defaultType(efPDB
)));
164 EXPECT_TRUE(value
.empty());
166 gmx::OptionsAssigner
assigner(&options
);
167 EXPECT_NO_THROW_GMX(assigner
.start());
168 EXPECT_NO_THROW_GMX(assigner
.startOption("f"));
169 EXPECT_NO_THROW_GMX(assigner
.finishOption());
170 EXPECT_NO_THROW_GMX(assigner
.finish());
171 EXPECT_NO_THROW_GMX(options
.finish());
173 EXPECT_EQ("testfile.pdb", value
);
176 TEST(FileNameOptionTest
, GivesErrorOnUnknownFileSuffix
)
178 gmx::Options options
;
180 ASSERT_NO_THROW_GMX(options
.addOption(
181 FileNameOption("f").store(&value
)
182 .filetype(gmx::eftIndex
).outputFile()));
183 EXPECT_TRUE(value
.empty());
185 gmx::OptionsAssigner
assigner(&options
);
186 EXPECT_NO_THROW_GMX(assigner
.start());
187 EXPECT_NO_THROW_GMX(assigner
.startOption("f"));
188 EXPECT_THROW_GMX(assigner
.appendValue("testfile.foo"), gmx::InvalidInputError
);
189 EXPECT_NO_THROW_GMX(assigner
.finishOption());
190 EXPECT_NO_THROW_GMX(assigner
.finish());
191 EXPECT_NO_THROW_GMX(options
.finish());
193 EXPECT_TRUE(value
.empty());
196 TEST(FileNameOptionTest
, GivesErrorOnInvalidFileSuffix
)
198 gmx::Options options
;
200 ASSERT_NO_THROW_GMX(options
.addOption(
201 FileNameOption("f").store(&value
)
202 .filetype(gmx::eftTrajectory
).outputFile()));
203 EXPECT_TRUE(value
.empty());
205 gmx::OptionsAssigner
assigner(&options
);
206 EXPECT_NO_THROW_GMX(assigner
.start());
207 EXPECT_NO_THROW_GMX(assigner
.startOption("f"));
208 EXPECT_THROW_GMX(assigner
.appendValue("testfile.dat"), gmx::InvalidInputError
);
209 EXPECT_NO_THROW_GMX(assigner
.finishOption());
210 EXPECT_NO_THROW_GMX(assigner
.finish());
211 EXPECT_NO_THROW_GMX(options
.finish());
213 EXPECT_TRUE(value
.empty());