Skip to content

Commit

Permalink
improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
xtofalex committed Mar 28, 2024
1 parent 41a0ce1 commit 6d07d52
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/snl/snl/kernel/SNLUniverse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ SNLUniverse* SNLUniverse::create() {

void SNLUniverse::preCreate() {
super::preCreate();
//FIXME: verify that no other Universe exists
if (universe_) {
throw SNLException("SNLUniverse already exists");
}
}

void SNLUniverse::postCreate() {
Expand Down
1 change: 1 addition & 0 deletions test/snl/python/snl_wrapping/test_snldesign.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ def testCreationError(self):
d = snl.SNLDesign.create(self.lib, "DESIGN")
with self.assertRaises(RuntimeError) as context: snl.SNLDesign.create("ERROR", "ERROR", "ERROR")
with self.assertRaises(RuntimeError) as context: snl.SNLDesign.create(d, "DESIGN")
with self.assertRaises(RuntimeError) as context: snl.SNLDesign.create(d, "DESIGN")
with self.assertRaises(RuntimeError) as context: snl.SNLDesign.createPrimitive("ERROR", "ERROR", "ERROR")
with self.assertRaises(RuntimeError) as context: snl.SNLDesign.createPrimitive(d, "PRIMITIVE")
with self.assertRaises(RuntimeError) as context: snl.SNLScalarTerm.create(d)
Expand Down
3 changes: 3 additions & 0 deletions test/snl/python/snl_wrapping/test_snldesign_clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ def testUniquifyInterface1(self):

def testErrors(self):
with self.assertRaises(RuntimeError) as context: self.design.clone("ERROR", "ERROR")
newDesign = self.design.clone("cloned")
self.assertIsNotNone(newDesign)
with self.assertRaises(RuntimeError) as context: self.design.clone("cloned")

if __name__ == '__main__':
unittest.main()
4 changes: 4 additions & 0 deletions test/snl/python/snl_wrapping/test_snldesign_modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ def testSeqWithBusses1(self):
self.assertEqual(4, sum(1 for t in snl.SNLDesign.getClockRelatedInputs(c)))
self.assertEqual(4, sum(1 for t in snl.SNLDesign.getClockRelatedOutputs(c)))

def testCreationErrors(self):
prim = snl.SNLDesign.createPrimitive(self.primitives, "design")
with self.assertRaises(RuntimeError) as context: snl.SNLDesign.createPrimitive(self.designs, "design")

def testCombiErrors(self):
design = snl.SNLDesign.createPrimitive(self.primitives, "design")
i0 = snl.SNLScalarTerm.create(design, snl.SNLTerm.Direction.Input, "I0")
Expand Down
1 change: 1 addition & 0 deletions test/snl/python/snl_wrapping/test_snlnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def test0(self):
self.assertIsInstance(i1Net, snl.SNLDesignObject)
self.assertIsNotNone(i1Net)
self.assertEqual("I1", i1Net.getName())
with self.assertRaises(RuntimeError) as context: snl.SNLBusNet.create(self.design, 4, 0, "I1")
self.assertEqual(4, i1.getMSB())
self.assertEqual(0, i1.getLSB())
self.assertEqual(5, i1.getSize())
Expand Down
1 change: 1 addition & 0 deletions test/snl/python/snl_wrapping/test_snluniverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def test(self):
snl.SNLUniverse.create()
self.assertIsNotNone(snl.SNLUniverse.get())
self.assertIsNone(snl.SNLUniverse.get().getTopDesign())
with self.assertRaises(RuntimeError) as context: snl.SNLUniverse.create()

if __name__ == '__main__':
unittest.main()
8 changes: 8 additions & 0 deletions test/snl/snl/kernel/SNLUniverseTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "gtest/gtest.h"

#include "SNLUniverse.h"
#include "SNLException.h"
using namespace naja::SNL;

class SNLUniverseTest: public ::testing::Test {
Expand Down Expand Up @@ -32,4 +33,11 @@ TEST_F(SNLUniverseTest, testGetSNLObjects1) {
EXPECT_EQ(nullptr, universe->getBusTermBit(SNLID(SNLID::Type::TermBit, 1, 1, 1, 0, 1, 1)));
EXPECT_EQ(nullptr, universe->getNet(SNLID::DesignObjectReference(2, 3, 1, 1)));
EXPECT_EQ(nullptr, universe->getInstance(SNLID::DesignObjectReference(1, 1, 1, 1)));
}

TEST_F(SNLUniverseTest, testUniverseClashError) {
ASSERT_EQ(nullptr, SNLUniverse::get());
SNLUniverse::create();
ASSERT_NE(nullptr, SNLUniverse::get());
EXPECT_THROW(SNLUniverse::create(), SNLException);
}

0 comments on commit 6d07d52

Please sign in to comment.