summaryrefslogtreecommitdiff
path: root/gruel/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'gruel/src/lib')
-rw-r--r--gruel/src/lib/pmt/pmt.cc47
-rw-r--r--gruel/src/lib/pmt/pmt_int.h14
-rw-r--r--gruel/src/lib/pmt/pmt_io.cc2
-rw-r--r--gruel/src/lib/pmt/qa_pmt_prims.cc13
-rw-r--r--gruel/src/lib/pmt/qa_pmt_prims.h2
-rw-r--r--gruel/src/lib/test_gruel.cc57
6 files changed, 133 insertions, 2 deletions
diff --git a/gruel/src/lib/pmt/pmt.cc b/gruel/src/lib/pmt/pmt.cc
index aa1688d24..f9cf6b4bf 100644
--- a/gruel/src/lib/pmt/pmt.cc
+++ b/gruel/src/lib/pmt/pmt.cc
@@ -105,6 +105,12 @@ _integer(pmt_t x)
return dynamic_cast<pmt_integer*>(x.get());
}
+static pmt_uint64 *
+_uint64(pmt_t x)
+{
+ return dynamic_cast<pmt_uint64*>(x.get());
+}
+
static pmt_real *
_real(pmt_t x)
{
@@ -305,6 +311,40 @@ pmt_to_long(pmt_t x)
}
////////////////////////////////////////////////////////////////////////////
+// Uint64
+////////////////////////////////////////////////////////////////////////////
+
+pmt_uint64::pmt_uint64(uint64_t value) : d_value(value) {}
+
+bool
+pmt_is_uint64(pmt_t x)
+{
+ return x->is_uint64();
+}
+
+
+pmt_t
+pmt_from_uint64(uint64_t x)
+{
+ return pmt_t(new pmt_uint64(x));
+}
+
+uint64_t
+pmt_to_uint64(pmt_t x)
+{
+ if(x->is_uint64())
+ return _uint64(x)->value();
+ if(x->is_integer())
+ {
+ long tmp = _integer(x)->value();
+ if(tmp >= 0)
+ return (uint64_t) tmp;
+ }
+
+ throw pmt_wrong_type("pmt_to_uint64", x);
+}
+
+////////////////////////////////////////////////////////////////////////////
// Real
////////////////////////////////////////////////////////////////////////////
@@ -929,6 +969,9 @@ pmt_eqv(const pmt_t& x, const pmt_t& y)
if (x->is_integer() && y->is_integer())
return _integer(x)->value() == _integer(y)->value();
+ if (x->is_uint64() && y->is_uint64())
+ return _uint64(x)->value() == _uint64(y)->value();
+
if (x->is_real() && y->is_real())
return _real(x)->value() == _real(y)->value();
@@ -947,6 +990,9 @@ pmt_eqv_raw(pmt_base *x, pmt_base *y)
if (x->is_integer() && y->is_integer())
return _integer(x)->value() == _integer(y)->value();
+ if (x->is_uint64() && y->is_uint64())
+ return _uint64(x)->value() == _uint64(y)->value();
+
if (x->is_real() && y->is_real())
return _real(x)->value() == _real(y)->value();
@@ -1328,6 +1374,7 @@ pmt_dump_sizeof()
printf("sizeof(pmt_bool) = %3zd\n", sizeof(pmt_bool));
printf("sizeof(pmt_symbol) = %3zd\n", sizeof(pmt_symbol));
printf("sizeof(pmt_integer) = %3zd\n", sizeof(pmt_integer));
+ printf("sizeof(pmt_uint64) = %3zd\n", sizeof(pmt_uint64));
printf("sizeof(pmt_real) = %3zd\n", sizeof(pmt_real));
printf("sizeof(pmt_complex) = %3zd\n", sizeof(pmt_complex));
printf("sizeof(pmt_null) = %3zd\n", sizeof(pmt_null));
diff --git a/gruel/src/lib/pmt/pmt_int.h b/gruel/src/lib/pmt/pmt_int.h
index 50683ffb5..ea28e37b4 100644
--- a/gruel/src/lib/pmt/pmt_int.h
+++ b/gruel/src/lib/pmt/pmt_int.h
@@ -47,6 +47,7 @@ public:
virtual bool is_symbol() const { return false; }
virtual bool is_number() const { return false; }
virtual bool is_integer() const { return false; }
+ virtual bool is_uint64() const { return false; }
virtual bool is_real() const { return false; }
virtual bool is_complex() const { return false; }
virtual bool is_null() const { return false; }
@@ -118,6 +119,19 @@ public:
long value() const { return d_value; }
};
+class pmt_uint64 : public pmt_base
+{
+public:
+ uint64_t d_value;
+
+ pmt_uint64(uint64_t value);
+ //~pmt_uint64(){}
+
+ bool is_number() const { return true; }
+ bool is_uint64() const { return true; }
+ uint64_t value() const { return d_value; }
+};
+
class pmt_real : public pmt_base
{
public:
diff --git a/gruel/src/lib/pmt/pmt_io.cc b/gruel/src/lib/pmt/pmt_io.cc
index 179e6b72c..b909c1b64 100644
--- a/gruel/src/lib/pmt/pmt_io.cc
+++ b/gruel/src/lib/pmt/pmt_io.cc
@@ -64,6 +64,8 @@ pmt_write(pmt_t obj, std::ostream &port)
else if (pmt_is_number(obj)){
if (pmt_is_integer(obj))
port << pmt_to_long(obj);
+ else if (pmt_is_uint64(obj))
+ port << pmt_to_uint64(obj);
else if (pmt_is_real(obj))
port << pmt_to_double(obj);
else if (pmt_is_complex(obj)){
diff --git a/gruel/src/lib/pmt/qa_pmt_prims.cc b/gruel/src/lib/pmt/qa_pmt_prims.cc
index f2414c72c..985361f13 100644
--- a/gruel/src/lib/pmt/qa_pmt_prims.cc
+++ b/gruel/src/lib/pmt/qa_pmt_prims.cc
@@ -104,6 +104,19 @@ qa_pmt_prims::test_integers()
}
void
+qa_pmt_prims::test_uint64s()
+{
+ pmt_t p1 = pmt_from_uint64((uint64_t)1);
+ pmt_t m1 = pmt_from_uint64((uint64_t)8589934592ULL);
+ CPPUNIT_ASSERT(!pmt_is_uint64(PMT_T));
+ CPPUNIT_ASSERT(pmt_is_uint64(p1));
+ CPPUNIT_ASSERT(pmt_is_uint64(m1));
+ CPPUNIT_ASSERT_THROW(pmt_to_uint64(PMT_T), pmt_wrong_type);
+ CPPUNIT_ASSERT_EQUAL((uint64_t)8589934592ULL, (uint64_t)pmt_to_uint64(m1));
+ CPPUNIT_ASSERT_EQUAL((uint64_t)1ULL, (uint64_t)pmt_to_uint64(p1));
+}
+
+void
qa_pmt_prims::test_reals()
{
pmt_t p1 = pmt_from_double(1);
diff --git a/gruel/src/lib/pmt/qa_pmt_prims.h b/gruel/src/lib/pmt/qa_pmt_prims.h
index 29ba02f11..efc5c6050 100644
--- a/gruel/src/lib/pmt/qa_pmt_prims.h
+++ b/gruel/src/lib/pmt/qa_pmt_prims.h
@@ -31,6 +31,7 @@ class qa_pmt_prims : public CppUnit::TestCase {
CPPUNIT_TEST(test_symbols);
CPPUNIT_TEST(test_booleans);
CPPUNIT_TEST(test_integers);
+ CPPUNIT_TEST(test_uint64s);
CPPUNIT_TEST(test_reals);
CPPUNIT_TEST(test_complexes);
CPPUNIT_TEST(test_pairs);
@@ -52,6 +53,7 @@ class qa_pmt_prims : public CppUnit::TestCase {
void test_symbols();
void test_booleans();
void test_integers();
+ void test_uint64s();
void test_reals();
void test_complexes();
void test_pairs();
diff --git a/gruel/src/lib/test_gruel.cc b/gruel/src/lib/test_gruel.cc
index 669303447..f4b9fc4e2 100644
--- a/gruel/src/lib/test_gruel.cc
+++ b/gruel/src/lib/test_gruel.cc
@@ -1,6 +1,6 @@
/* -*- c++ -*- */
/*
- * Copyright 2006,2009 Free Software Foundation, Inc.
+ * Copyright 2006,2009,2010 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
@@ -21,17 +21,70 @@
*/
#include <cppunit/TextTestRunner.h>
+#include <cppunit/XmlOutputter.h>
+
+#include <stdlib.h>
+#include <sys/stat.h>
+
#include "pmt/qa_pmt.h"
+static void get_unittest_path (const char *filename, char *fullpath, size_t pathsize);
+
int
main(int argc, char **argv)
{
+ char path[200];
+ get_unittest_path ("gruel.xml", path, 200);
- CppUnit::TextTestRunner runner;
+ CppUnit::TextTestRunner runner;
+ std::ofstream xmlfile(path);
+ CppUnit::XmlOutputter *xmlout = new CppUnit::XmlOutputter(&runner.result(), xmlfile);
runner.addTest(qa_pmt::suite ());
+ runner.setOutputter(xmlout);
bool was_successful = runner.run("", false);
return was_successful ? 0 : 1;
}
+
+
+// NOTE: These are defined in gr_unittest.h for the rest of the project;
+// rewriting here since we don't depend on gnuradio-core in gruel
+
+#ifdef MKDIR_TAKES_ONE_ARG
+#define gr_mkdir(pathname, mode) mkdir(pathname)
+#else
+#define gr_mkdir(pathname, mode) mkdir((pathname), (mode))
+#endif
+
+/*
+ * Mostly taken from gr_preferences.cc/h
+ * The simplest thing that could possibly work:
+ * the key is the filename; the value is the file contents.
+ */
+
+static void
+ensure_unittest_path (const char *grpath, const char *path)
+{
+ struct stat statbuf;
+ if (stat (path, &statbuf) == 0 && S_ISDIR (statbuf.st_mode))
+ return;
+
+ // blindly try to make it // FIXME make this robust. C++ SUCKS!
+ gr_mkdir (grpath, 0750);
+ gr_mkdir (path, 0750);
+}
+
+static void
+get_unittest_path (const char *filename, char *fullpath, size_t pathsize)
+{
+ char path[200];
+ char grpath[200];
+ snprintf (grpath, sizeof(grpath), "%s/.gnuradio", getenv ("HOME"));
+ snprintf (path, sizeof(path), "%s/unittests", grpath);
+ snprintf (fullpath, pathsize, "%s/%s", path, filename);
+
+ ensure_unittest_path(grpath, path);
+}
+