2323#include < ostream>
2424#include < string>
2525
26+ #include " grtest_utils.hpp"
2627#include " grackle.h"
2728
2829namespace grtest {
@@ -42,6 +43,7 @@ enum class ChemPreset {
4243 primchem1,
4344 primchem2,
4445 primchem3,
46+ primchem4_dustspecies3
4547};
4648
4749inline std::string to_string (const ChemPreset& preset) {
@@ -56,6 +58,8 @@ inline std::string to_string(const ChemPreset& preset) {
5658 return " pc=2" ;
5759 case ChemPreset::primchem3:
5860 return " pc=3" ;
61+ case ChemPreset::primchem4_dustspecies3:
62+ return " pc=3-dust_species=4" ;
5963 }
6064}
6165
@@ -98,6 +102,14 @@ inline InitStatus setup_chemistry_data_from_preset(chemistry_data* my_chem,
98102 my_chem->dust_chemistry = 1 ;
99103 return InitStatus::success;
100104 }
105+ case ChemPreset::primchem4_dustspecies3: {
106+ my_chem->primordial_chemistry = 4 ;
107+ my_chem->dust_chemistry = 1 ;
108+ my_chem->metal_chemistry = 1 ;
109+ my_chem->dust_species = 1 ;
110+ my_chem->use_dust_density_field = 1 ;
111+ return InitStatus::success;
112+ }
101113 }
102114}
103115
@@ -195,9 +207,11 @@ class GrackleCtxPack {
195207 bool is_initialized () const { return this ->my_chemistry_ != nullptr ; }
196208
197209 // getter functions
198- const code_units& initial_units () const { return this ->initial_units_ ; }
199- chemistry_data* my_chemistry () { return this ->my_chemistry_ .get (); }
200- chemistry_data_storage* my_rates () { return this ->my_rates_ .get (); }
210+ const code_units& initial_units () const { return initial_units_; }
211+ chemistry_data* my_chemistry () { return my_chemistry_.get (); }
212+ const chemistry_data* my_chemistry () const { return my_chemistry_.get (); }
213+ chemistry_data_storage* my_rates () { return my_rates_.get (); }
214+ const chemistry_data_storage* my_rates () const { return my_rates_.get (); }
201215
202216 // / create an initialized instance from a preset
203217 static GrackleCtxPack create (const FullConfPreset& preset,
@@ -231,25 +245,62 @@ class GrackleCtxPack {
231245 }
232246};
233247
234- // / defines a parameterized test-fixture that can used to run a parametrized
248+ // / test-fixture that can used to run one or more tests with a chemsitry data
249+ // / configuration intialized from a given chemistry presets.
250+ // /
251+ // / This sets up a GrackleCtxPack (where the contents are configured with
252+ // / appropriate presets) and deallocates that memory at the end of the test.
253+ // /
254+ // / How To Use
255+ // / ==========
256+ // / To make use of this fixture in a test-suite called `MyFeatureTest`, you
257+ // / need to either:
258+ // / 1. make a type alias (via `using` or `typedef`), named `MyFeatureTest`, of
259+ // / the relevant instantiation of this class template, OR
260+ // / 2. make a subclass, named `MyFeatureTest`, of the relevant instantiation of
261+ // / this class template
262+ template <ChemPreset chem_preset, InitialUnitPreset unit_preset>
263+ class ConfigPresetFixture : public testing ::Test {
264+ protected:
265+ void SetUp () override {
266+ // called immediately after the constructor (but before the test-case)
267+
268+ grtest::InitStatus status;
269+ pack = GrackleCtxPack::create (FullConfPreset{chem_preset, unit_preset},
270+ &status);
271+ if (!pack.is_initialized ()) {
272+ if (status == InitStatus::datafile_notfound) {
273+ GTEST_SKIP () << " something went wrong with finding the data file" ;
274+ } else {
275+ FAIL () << " Error in initialize_chemistry_data." ;
276+ }
277+ }
278+ }
279+
280+ GrackleCtxPack pack;
281+ };
282+
283+ // / defines a parameterized test-fixture that can be used to run a parametrized
235284// / set of tests that are initialized with different chemistry data presets.
236285// /
237286// / This sets up a GrackleCtxPack (where the contents are configured with
238287// / appropriate presets) and deallocates that memory at the end of the test.
239288// /
240289// / How To Use
241290// / ==========
242- // / To make use of this, you might create a subclass of this type that is named
243- // / for the test suite. I don't love this strategy, but it seems to be the
244- // / standard way to do things. We can revisit this in the future.
291+ // / To make use of this fixture in a test-suite called `MyFeatureTest`, you
292+ // / need to either:
293+ // / 1. make a type alias (via `using` or `typedef`), named `MyFeatureTest`, of
294+ // / this class, OR
295+ // / 2. make a subclass, named `MyFeatureTest`, of this class
245296class ParametrizedConfigPresetFixture
246297 : public testing::TestWithParam<FullConfPreset> {
247298protected:
248299 void SetUp () override {
249300 // called immediately after the constructor (but before the test-case)
250301 grtest::InitStatus status;
251- pack_ = GrackleCtxPack::create (GetParam (), &status);
252- if (!pack_ .is_initialized ()) {
302+ pack = GrackleCtxPack::create (GetParam (), &status);
303+ if (!pack .is_initialized ()) {
253304 if (status == InitStatus::datafile_notfound) {
254305 GTEST_SKIP () << " something went wrong with finding the data file" ;
255306 } else {
@@ -258,7 +309,7 @@ class ParametrizedConfigPresetFixture
258309 }
259310 }
260311
261- GrackleCtxPack pack_ ;
312+ GrackleCtxPack pack ;
262313};
263314
264315} // namespace grtest
0 commit comments