New C++ API: Add tests for opterm object. (#2756)
authorAina Niemetz <aina.niemetz@gmail.com>
Fri, 14 Dec 2018 18:25:15 +0000 (10:25 -0800)
committerGitHub <noreply@github.com>
Fri, 14 Dec 2018 18:25:15 +0000 (10:25 -0800)
src/api/cvc4cpp.cpp
test/unit/api/CMakeLists.txt
test/unit/api/opterm_black.h [new file with mode: 0644]

index cadad4eff83e2953a398821b949534204e24184e..68b0301ec682341ee333aef3dbe73d1af28797f3 100644 (file)
@@ -635,6 +635,10 @@ class CVC4ApiExceptionStream
   CVC4_PREDICT_FALSE(cond)   \
   ? (void)0 : OstreamVoider() & CVC4ApiExceptionStream().ostream()
 
+#define CVC4_API_CHECK_NOT_NULL                                           \
+  CVC4_API_CHECK(!isNull()) << "Invalid call to '" << __PRETTY_FUNCTION__ \
+                            << "', expected non-null object";
+
 #define CVC4_API_KIND_CHECK(kind)     \
   CVC4_API_CHECK(isDefinedKind(kind)) \
       << "Invalid kind '" << kindToString(kind) << "'";
@@ -1166,9 +1170,17 @@ bool OpTerm::operator==(const OpTerm& t) const { return *d_expr == *t.d_expr; }
 
 bool OpTerm::operator!=(const OpTerm& t) const { return *d_expr != *t.d_expr; }
 
-Kind OpTerm::getKind() const { return intToExtKind(d_expr->getKind()); }
+Kind OpTerm::getKind() const
+{
+  CVC4_API_CHECK_NOT_NULL;
+  return intToExtKind(d_expr->getKind());
+}
 
-Sort OpTerm::getSort() const { return Sort(d_expr->getType()); }
+Sort OpTerm::getSort() const
+{
+  CVC4_API_CHECK_NOT_NULL;
+  return Sort(d_expr->getType());
+}
 
 bool OpTerm::isNull() const { return d_expr->isNull(); }
 
index eeab46f99c17d73a2c85b12f708dadff48d6aa12..8a6be70b9806e642a16aa34f9b3a22852df3b063 100644 (file)
@@ -4,3 +4,4 @@
 cvc4_add_unit_test_black(solver_black api)
 cvc4_add_unit_test_black(sort_black api)
 cvc4_add_unit_test_black(term_black api)
+cvc4_add_unit_test_black(opterm_black api)
diff --git a/test/unit/api/opterm_black.h b/test/unit/api/opterm_black.h
new file mode 100644 (file)
index 0000000..637301d
--- /dev/null
@@ -0,0 +1,57 @@
+/*********************                                                        */
+/*! \file opterm_black.h
+ ** \verbatim
+ ** Top contributors (to current version):
+ **   Aina Niemetz
+ ** This file is part of the CVC4 project.
+ ** Copyright (c) 2009-2018 by the authors listed in the file AUTHORS
+ ** in the top-level source directory) and their institutional affiliations.
+ ** All rights reserved.  See the file COPYING in the top-level source
+ ** directory for licensing information.\endverbatim
+ **
+ ** \brief Black box testing of the Term class
+ **/
+
+#include <cxxtest/TestSuite.h>
+
+#include "api/cvc4cpp.h"
+
+using namespace CVC4::api;
+
+class OpTermBlack : public CxxTest::TestSuite
+{
+ public:
+  void setUp() override {}
+  void tearDown() override {}
+
+  void testGetKind();
+  void testGetSort();
+  void testIsNull();
+
+ private:
+  Solver d_solver;
+};
+
+void OpTermBlack::testGetKind()
+{
+  OpTerm x;
+  TS_ASSERT_THROWS(x.getSort(), CVC4ApiException&);
+  x = d_solver.mkOpTerm(BITVECTOR_EXTRACT_OP, 31, 1);
+  TS_ASSERT_THROWS_NOTHING(x.getKind());
+}
+
+void OpTermBlack::testGetSort()
+{
+  OpTerm x;
+  TS_ASSERT_THROWS(x.getSort(), CVC4ApiException&);
+  x = d_solver.mkOpTerm(BITVECTOR_EXTRACT_OP, 31, 1);
+  TS_ASSERT_THROWS_NOTHING(x.getSort());
+}
+
+void OpTermBlack::testIsNull()
+{
+  OpTerm x;
+  TS_ASSERT(x.isNull());
+  x = d_solver.mkOpTerm(BITVECTOR_EXTRACT_OP, 31, 1);
+  TS_ASSERT(!x.isNull());
+}