Classes
AtomicNumber_test.cc File Reference

Tests the AtomicNumber service provider. More...

#include "larexamples/Services/AtomicNumber/Providers/AtomicNumber.h"
#include "larcorealg/TestUtils/unit_test_base.h"
#include "fhiclcpp/fwd.h"
#include "messagefacility/MessageLogger/MessageLogger.h"
#include <string>

Go to the source code of this file.

Classes

struct  Results_t
 Structure to hold enough information to computed the expected results. More...
 

Functions

unsigned int TestConfiguration (std::string testName, std::string configuration, Results_t const &expected)
 
unsigned int TestDefaultConfiguration ()
 
unsigned int TestXenonConfiguration ()
 
int main (int argc, char **argv)
 

Detailed Description

Tests the AtomicNumber service provider.

Author
Gianluca Petrillo (petri.nosp@m.llo@.nosp@m.fnal..nosp@m.gov)
Date
April 13, 2016
See also
AtomicNumber.h

The exit code of the test is the number of triggered errors. This text is expected to pass with 0 errors.

This test does not exercise the configuration via file.

Definition in file AtomicNumber_test.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 117 of file AtomicNumber_test.cc.

117  {
118 
119  unsigned int nErrors = 0;
120  nErrors += TestDefaultConfiguration();
121  nErrors += TestXenonConfiguration();
122 
123  return nErrors;
124 } // main()
unsigned int TestXenonConfiguration()
unsigned int TestDefaultConfiguration()
unsigned int TestConfiguration ( std::string  testName,
std::string  configuration,
Results_t const &  expected 
)

Definition at line 49 of file AtomicNumber_test.cc.

50 {
51 
52  //
53  // configuration of the test
54  //
55 
56  // provide a test name and a push a configuration for "AtomicNumberService"
58  config.AddDefaultServiceConfiguration("AtomicNumberService", configuration);
59 
60  // set up a basic testing environment with that configuration
61  auto TesterEnv = testing::CreateTesterEnvironment(config);
62 
63  //
64  // computation of expected values
65  //
66  unsigned int nErrors = 0; // error count
67 
68  // create a new service provider with configuration from the environment
70  (TesterEnv.ServiceParameters("AtomicNumberService"));
71 
72  //
73  // here goes the test...
74  //
75  unsigned int Z = Zprov.Z();
76  if (Z != expected.Z) {
77  mf::LogError("AtomicNumber_test") << testName
78  << ": wrong atomic number: " << Z
79  << " (expected: " << expected.Z << ")";
80  ++nErrors;
81  }
82 
83  //
84  // done!
85  //
86  return nErrors;
87 } // TestConfiguration()
const char expected[]
Definition: Exception_t.cc:22
Class holding a configuration for a test environment.
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
static Config * config
Definition: config.cpp:1054
TESTENV CreateTesterEnvironment(CONFIG &&config, ARGS...other_args)
Constructs and returns a TesterEnvironment object.
Provides information about the active material in the TPC.
Definition: AtomicNumber.h:38
unsigned int TestDefaultConfiguration ( )

Definition at line 91 of file AtomicNumber_test.cc.

91  {
93  expected.Z = 18;
94 
95  return TestConfiguration("TestDefaultConfiguration", "", expected);
96 
97 } // TestDefaultConfiguration()
const char expected[]
Definition: Exception_t.cc:22
Structure to hold enough information to computed the expected results.
unsigned int TestConfiguration(std::string testName, std::string configuration, Results_t const &expected)
unsigned int Z
atomic number
unsigned int TestXenonConfiguration ( )

Definition at line 101 of file AtomicNumber_test.cc.

101  {
102 
104  expected.Z = 54;
105 
106  return TestConfiguration(
107  "TestXenonConfiguration", // test name
108  R"(
109  AtomicNumber: 54
110  )", // provider configuration
111  expected // expected values
112  );
113 } // TestXenonConfiguration()
const char expected[]
Definition: Exception_t.cc:22
Structure to hold enough information to computed the expected results.
unsigned int TestConfiguration(std::string testName, std::string configuration, Results_t const &expected)
unsigned int Z
atomic number