diff options
Diffstat (limited to 'gruel/src/lib/pmt')
-rw-r--r-- | gruel/src/lib/pmt/pmt.cc | 33 | ||||
-rw-r--r-- | gruel/src/lib/pmt/qa_pmt_prims.cc | 19 | ||||
-rw-r--r-- | gruel/src/lib/pmt/qa_pmt_prims.h | 2 |
3 files changed, 53 insertions, 1 deletions
diff --git a/gruel/src/lib/pmt/pmt.cc b/gruel/src/lib/pmt/pmt.cc index 42f25b9de9..e50e218380 100644 --- a/gruel/src/lib/pmt/pmt.cc +++ b/gruel/src/lib/pmt/pmt.cc @@ -917,6 +917,39 @@ pmt_msg_accepter_ref(const pmt_t &obj) //////////////////////////////////////////////////////////////////////////// +// Binary Large Object -- currently a u8vector +//////////////////////////////////////////////////////////////////////////// + +bool +pmt_is_blob(pmt_t x) +{ + // return pmt_is_u8vector(x); + return pmt_is_uniform_vector(x); +} + +pmt_t +pmt_make_blob(const void *buf, size_t len_in_bytes) +{ + return pmt_init_u8vector(len_in_bytes, (const uint8_t *) buf); +} + +const void * +pmt_blob_data(pmt_t blob) +{ + size_t len; + return pmt_uniform_vector_elements(blob, len); +} + +size_t +pmt_blob_length(pmt_t blob) +{ + size_t len; + pmt_uniform_vector_elements(blob, len); + return len; +} + + +//////////////////////////////////////////////////////////////////////////// // General Functions //////////////////////////////////////////////////////////////////////////// diff --git a/gruel/src/lib/pmt/qa_pmt_prims.cc b/gruel/src/lib/pmt/qa_pmt_prims.cc index 04fdc1a433..59d9e14d30 100644 --- a/gruel/src/lib/pmt/qa_pmt_prims.cc +++ b/gruel/src/lib/pmt/qa_pmt_prims.cc @@ -23,7 +23,8 @@ #include <qa_pmt_prims.h> #include <cppunit/TestAssert.h> #include <gruel/msg_passing.h> -#include <stdio.h> +#include <cstdio> +#include <cstring> #include <sstream> using namespace pmt; @@ -557,3 +558,19 @@ qa_pmt_prims::test_sets() CPPUNIT_ASSERT(!pmt_subsetp(l3,l2)); } +void +qa_pmt_prims::test_sugar() +{ + CPPUNIT_ASSERT(pmt_is_symbol(mp("my-symbol"))); + CPPUNIT_ASSERT_EQUAL((long) 10, pmt_to_long(mp(10))); + CPPUNIT_ASSERT_EQUAL((double) 1e6, pmt_to_double(mp(1e6))); + CPPUNIT_ASSERT_EQUAL(std::complex<double>(2, 3), + pmt_to_complex(mp(std::complex<double>(2, 3)))); + + int buf[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + pmt_t blob = mp(buf, sizeof(buf)); + const void *data = pmt_blob_data(blob); + size_t nbytes = pmt_blob_length(blob); + CPPUNIT_ASSERT_EQUAL(sizeof(buf), nbytes); + CPPUNIT_ASSERT(memcmp(buf, data, nbytes) == 0); +} diff --git a/gruel/src/lib/pmt/qa_pmt_prims.h b/gruel/src/lib/pmt/qa_pmt_prims.h index fd6f70c8ea..29ba02f11c 100644 --- a/gruel/src/lib/pmt/qa_pmt_prims.h +++ b/gruel/src/lib/pmt/qa_pmt_prims.h @@ -45,6 +45,7 @@ class qa_pmt_prims : public CppUnit::TestCase { CPPUNIT_TEST(test_lists); CPPUNIT_TEST(test_serialize); CPPUNIT_TEST(test_sets); + CPPUNIT_TEST(test_sugar); CPPUNIT_TEST_SUITE_END(); private: @@ -65,6 +66,7 @@ class qa_pmt_prims : public CppUnit::TestCase { void test_lists(); void test_serialize(); void test_sets(); + void test_sugar(); }; #endif /* INCLUDED_QA_PMT_PRIMS_H */ |