Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ianna committed Mar 20, 2019
1 parent d5ee0fb commit 642e621
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 5 deletions.
2 changes: 1 addition & 1 deletion DetectorDescription/DDCMS/interface/Filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace cms {

struct Filter {
std::vector<std::string_view> keys;
struct std::unique_ptr<Filter> next;
std::unique_ptr<Filter> next;
struct Filter* up;
};

Expand Down
1 change: 1 addition & 0 deletions DetectorDescription/DDCMS/test/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<use name="cppunit"/>
<bin name="testDDFilteredView" file="DDFilteredView.cppunit.cc,testRunner.cpp">
<use name="DetectorDescription/DDCMS"/>
<use name="dd4hep"/>
</bin>
<bin name="testFilter" file="Filter.cppunit.cc,testRunner.cpp">
<use name="DetectorDescription/DDCMS"/>
Expand Down
24 changes: 21 additions & 3 deletions DetectorDescription/DDCMS/test/DDFilteredView.cppunit.cc
Original file line number Diff line number Diff line change
@@ -1,26 +1,44 @@
#include <cppunit/extensions/HelperMacros.h>

#include "DetectorDescription/DDCMS/interface/DDFilteredView.h"
#include "DetectorDescription/DDCMS/interface/DDDetector.h"
#include "FWCore/ParameterSet/interface/FileInPath.h"
#include "DD4hep/Detector.h"

#include <string>
#include <memory>

#include "cppunit/TestAssert.h"
#include "cppunit/TestFixture.h"

using namespace cms;
using namespace std;

class testDDFilteredView : public CppUnit::TestFixture {

CPPUNIT_TEST_SUITE(testDDFilteredView);
CPPUNIT_TEST(checkFilteredView);
CPPUNIT_TEST_SUITE_END();

public:

void setUp() override {}
void setUp() override;
void tearDown() override {}
void checkFilteredView();

private:

string fileName_;
};

CPPUNIT_TEST_SUITE_REGISTRATION(testDDFilteredView);

void testDDFilteredView::setUp() {
fileName_ = edm::FileInPath("DetectorDescription/DDCMS/data/cms-2015-muon-geometry.xml").fullPath();
}

void testDDFilteredView::checkFilteredView()
{
cms::DDFilteredView fview();
unique_ptr<DDDetector> det = make_unique<DDDetector>("DUMMY", fileName_);
DDFilteredView fview(det.get(), det->description()->worldVolume());
}
46 changes: 46 additions & 0 deletions DetectorDescription/DDCMS/test/ExpandedNodes.cppunit.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include <cppunit/extensions/HelperMacros.h>

#include "DetectorDescription/DDCMS/interface/ExpandedNodes.h"

#include <iostream>

#include "cppunit/TestAssert.h"
#include "cppunit/TestFixture.h"

using namespace cms;
using namespace std;

class testExpandedNodes : public CppUnit::TestFixture {

CPPUNIT_TEST_SUITE(testExpandedNodes);
CPPUNIT_TEST(checkExpandedNodes);
CPPUNIT_TEST_SUITE_END();

public:

void setUp() override;
void tearDown() override {}
void checkExpandedNodes();

private:
ExpandedNodes nodes_;
};

CPPUNIT_TEST_SUITE_REGISTRATION(testExpandedNodes);

void
testExpandedNodes::setUp() {
nodes_.tags = { 1., 2., 3. };
nodes_.offsets = { 1., 2., 3. };
nodes_.copyNos = { 1, 2, 3 };
}

void
testExpandedNodes::checkExpandedNodes() {
cout << "Expanded Nodes...\n";
CPPUNIT_ASSERT(nodes_.tags.size() == nodes_.offsets.size());
CPPUNIT_ASSERT(nodes_.tags.size() == nodes_.copyNos.size());

for(auto const& i : nodes_.tags)
cout << i << " ";
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class DTLayer;
namespace cms {

class DDDetector;
struct DDFilteredView;
class DDFilteredView;
struct MuonNumbering;
struct DDSpecPar;

Expand Down

0 comments on commit 642e621

Please sign in to comment.