|
| 1 | + |
| 2 | +//////////////////////////////////////////////////////////////////////////////// |
| 3 | +// // |
| 4 | +// This file is part of NCrystal (see https://mctools.github.io/ncrystal/) // |
| 5 | +// // |
| 6 | +// Copyright 2015-2024 NCrystal developers // |
| 7 | +// // |
| 8 | +// Licensed under the Apache License, Version 2.0 (the "License"); // |
| 9 | +// you may not use this file except in compliance with the License. // |
| 10 | +// You may obtain a copy of the License at // |
| 11 | +// // |
| 12 | +// http://www.apache.org/licenses/LICENSE-2.0 // |
| 13 | +// // |
| 14 | +// Unless required by applicable law or agreed to in writing, software // |
| 15 | +// distributed under the License is distributed on an "AS IS" BASIS, // |
| 16 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // |
| 17 | +// See the License for the specific language governing permissions and // |
| 18 | +// limitations under the License. // |
| 19 | +// // |
| 20 | +//////////////////////////////////////////////////////////////////////////////// |
| 21 | + |
| 22 | +#include "NCTestPlugin.hh" |
| 23 | +#include "NCrystal/internal/utils/NCMsg.hh" |
| 24 | +#include "NCrystal/dump/NCDump.hh" |
| 25 | + |
| 26 | +void NCP::customPluginTest() |
| 27 | +{ |
| 28 | + //This function is called by NCrystal after the plugin is loaded, but only if |
| 29 | + //the NCRYSTAL_PLUGIN_RUNTESTS environment variable is set to "1". In case of |
| 30 | + //errors or anything about the plugin not working, simply throw an exception |
| 31 | + //(which is what the nc_assert_always function does below, but feel free to |
| 32 | + //simply throw an exception directly). |
| 33 | + |
| 34 | + NCRYSTAL_MSG("Testing plugin "<<pluginName()); |
| 35 | + |
| 36 | + //Create some test NCMAT data. For simplicity we will here base it on an |
| 37 | + //existing file, but add our @CUSTOMPLUGIN section (see NCPhysicsModel.cc for |
| 38 | + //a description of the format).: |
| 39 | + |
| 40 | + //Make sure we can load: |
| 41 | + NCRYSTAL_MSG("Loading 'plugins::SANSND/ncplugin-SANSND_nanodiamond.ncmat'"); |
| 42 | + NCRYSTAL_MSG(" -> info object:"); |
| 43 | + auto info |
| 44 | + = NC::createInfo("plugins::SANSND/ncplugin-SANSND_nanodiamond.ncmat"); |
| 45 | + NC::dump(info); |
| 46 | + |
| 47 | + NCRYSTAL_MSG(" -> scatter process:"); |
| 48 | + auto sc |
| 49 | + = NC::createScatter("plugins::SANSND/ncplugin-SANSND_nanodiamond.ncmat"); |
| 50 | + NCRYSTAL_RAWOUT(sc.underlying().jsonDescription()) |
| 51 | + |
| 52 | + //Sanity check, some standard material does NOT have sans: |
| 53 | + nc_assert_always( NC::createScatter("stdlib::Al_sg225.ncmat" |
| 54 | + ";comp=sans").isNull() ); |
| 55 | + //But our nanodiamonds do: |
| 56 | + nc_assert_always( ! NC::createScatter("plugins::SANSND/ncplugin-SANSND_nanodiamond.ncmat" |
| 57 | + ";comp=sans").isNull() ); |
| 58 | + |
| 59 | + |
| 60 | + NCRYSTAL_MSG("All tests of plugin "<<pluginName()<<" were successful!"); |
| 61 | +} |
0 commit comments