summaryrefslogtreecommitdiff
path: root/test/unit
diff options
context:
space:
mode:
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/Makefile.am1
-rw-r--r--test/unit/theory/theory_black.h5
-rw-r--r--test/unit/util/listener_black.h156
3 files changed, 161 insertions, 1 deletions
diff --git a/test/unit/Makefile.am b/test/unit/Makefile.am
index 36203725f..9d934a6e0 100644
--- a/test/unit/Makefile.am
+++ b/test/unit/Makefile.am
@@ -48,6 +48,7 @@ UNIT_TESTS += \
util/exception_black \
util/integer_black \
util/integer_white \
+ util/listener_black \
util/rational_black \
util/rational_white \
util/stats_black \
diff --git a/test/unit/theory/theory_black.h b/test/unit/theory/theory_black.h
index bafd572c3..fe8bebdbf 100644
--- a/test/unit/theory/theory_black.h
+++ b/test/unit/theory/theory_black.h
@@ -49,11 +49,14 @@ public:
void setUp() {
d_em = new ExprManager();
d_smt = new SmtEngine(d_em);
- d_nm = NodeManager::fromExprManager(d_em);
d_scope = new SmtScope(d_smt);
+
+ d_nm = NodeManager::fromExprManager(d_em);
}
void tearDown() {
+ delete d_scope;
+ delete d_smt;
delete d_em;
}
diff --git a/test/unit/util/listener_black.h b/test/unit/util/listener_black.h
new file mode 100644
index 000000000..cd3a08d4e
--- /dev/null
+++ b/test/unit/util/listener_black.h
@@ -0,0 +1,156 @@
+/********************* */
+/*! \file output_black.h
+ ** \verbatim
+ ** Original author: Morgan Deters
+ ** Major contributors: none
+ ** Minor contributors (to current version): none
+ ** This file is part of the CVC4 project.
+ ** Copyright (c) 2009-2014 New York University and The University of Iowa
+ ** See the file COPYING in the top-level source directory for licensing
+ ** information.\endverbatim
+ **
+ ** \brief Black box testing of CVC4 output classes.
+ **
+ ** Black box testing of CVC4 output classes.
+ **/
+
+#include <cxxtest/TestSuite.h>
+#include <sstream>
+
+#include "base/listener.h"
+
+using namespace CVC4;
+using namespace std;
+
+class ListenerBlack : public CxxTest::TestSuite {
+
+ std::multiset<std::string> d_events;
+
+ class EventListener : public Listener {
+ public:
+ EventListener(std::multiset<std::string>& events, std::string name)
+ : d_events(events), d_name(name) {}
+ ~EventListener(){}
+
+ virtual void notify() { d_events.insert(d_name); }
+
+ private:
+ std::multiset<std::string>& d_events;
+ std::string d_name;
+ };
+
+public:
+
+ static std::multiset<std::string> mkMultiset(std::string arr[], int len){
+ return std::multiset<std::string>(arr, arr + len);
+ }
+
+ void setUp() {
+ d_events.clear();
+ }
+
+ void tearDown() {
+ d_events.clear();
+ }
+
+ void testEmptyCollection() {
+ // Makes an new collection and tests that it is empty.
+ ListenerCollection* collection = new ListenerCollection;
+ TS_ASSERT(collection->empty());
+ TS_ASSERT_THROWS_NOTHING( delete collection );
+ }
+
+ void testSingletonCollection() {
+ ListenerCollection collection;
+ std::string expected[1] = {"a"};
+ {
+ RegisterListener a(&collection, new EventListener(d_events, "a"));
+ collection.notify();
+ TS_ASSERT(not collection.empty());
+ }
+ TS_ASSERT(collection.empty());
+ TS_ASSERT_EQUALS(d_events, mkMultiset(expected, 1));
+ }
+
+ void testSingleRegisterTearDown() {
+ // Tests that collection succeeds at destruction after
+ // registering a single event.
+ ListenerCollection* collection = new ListenerCollection;
+ {
+ RegisterListener a(collection, new EventListener(d_events, "a"));
+ TS_ASSERT(not collection->empty());
+ // The destructor for a now runs.
+ }
+ TS_ASSERT(collection->empty());
+ TS_ASSERT_THROWS_NOTHING( delete collection );
+ }
+
+ void testMultipleCollection() {
+ ListenerCollection* collection = new ListenerCollection;
+ {
+ RegisterListener c(collection, new EventListener(d_events, "c"));
+ collection->notify();
+ // d_events == {"c"}
+ RegisterListener b(collection, new EventListener(d_events, "b"));
+ RegisterListener a(collection, new EventListener(d_events, "a"));
+ collection->notify();
+ // d_events == {"a", "b", "c", "c"}
+ TS_ASSERT(not collection->empty());
+ }
+ TS_ASSERT(collection->empty());
+ std::string expected[4] = {"a", "b", "c", "c"};
+ TS_ASSERT_EQUALS(d_events, mkMultiset(expected, 4));
+ }
+
+ void testRegisterMiddleTearDown() {
+ // Tests that collection succeeds at destruction after
+ // registering several events.
+ ListenerCollection* collection = new ListenerCollection;
+ {
+ RegisterListener a(collection, new EventListener(d_events, "a"));
+ RegisterListener* b =
+ new RegisterListener(collection, new EventListener(d_events, "b"));
+ RegisterListener c(collection, new EventListener(d_events, "c"));
+
+ collection->notify();
+ delete b;
+ collection->notify();
+ // The destructor for a and c now run.
+ TS_ASSERT(not collection->empty());
+ }
+ TS_ASSERT(collection->empty());
+ TS_ASSERT_THROWS_NOTHING( delete collection );
+ }
+
+
+
+ void testRegisterMultiple() {
+ // This tests adds and notify multiple times.
+ ListenerCollection collection;
+
+ std::vector<RegisterListener*> listeners;
+ for(int i = 0; i < 4 ; ++i){
+ stringstream ss; ss << i;
+ Listener* listener = new EventListener(d_events, ss.str());
+ listeners.push_back(new RegisterListener(&collection, listener));
+ collection.notify();
+ }
+
+ TS_ASSERT(not collection.empty());
+ for(int i=0; i < listeners.size(); ++i){
+ RegisterListener* at_i = listeners[i];
+ delete at_i;
+ }
+ listeners.clear();
+ TS_ASSERT(collection.empty());
+
+ std::string expected[10] =
+ {"0", "0", "0", "0", "1", "1", "1", "2", "2", "3"};
+ TS_ASSERT_EQUALS(d_events, mkMultiset(expected, 10));
+
+ // No more events occur.
+ collection.notify();
+ TS_ASSERT_EQUALS(d_events, mkMultiset(expected, 10));
+ }
+
+};
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback