commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] pmt/src/lib .cvsignore Makefile.am pmt.cc qa_pm...


From: Eric Blossom
Subject: [Commit-gnuradio] pmt/src/lib .cvsignore Makefile.am pmt.cc qa_pm...
Date: Tue, 04 Jul 2006 18:19:19 +0000

CVSROOT:        /sources/gnuradio
Module name:    pmt
Changes by:     Eric Blossom <eb>       06/07/04 18:19:19

Modified files:
        src/lib        : .cvsignore Makefile.am pmt.cc 
Added files:
        src/lib        : qa_pmt.cc qa_pmt.h qa_pmt_prims.cc 
                         qa_pmt_prims.h test_pmt.cc 

Log message:
        added QA code

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pmt/src/lib/.cvsignore?cvsroot=gnuradio&r1=1.1.1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/pmt/src/lib/Makefile.am?cvsroot=gnuradio&r1=1.1.1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/pmt/src/lib/pmt.cc?cvsroot=gnuradio&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/pmt/src/lib/qa_pmt.cc?cvsroot=gnuradio&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/pmt/src/lib/qa_pmt.h?cvsroot=gnuradio&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/pmt/src/lib/qa_pmt_prims.cc?cvsroot=gnuradio&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/pmt/src/lib/qa_pmt_prims.h?cvsroot=gnuradio&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/pmt/src/lib/test_pmt.cc?cvsroot=gnuradio&rev=1.1

Patches:
Index: .cvsignore
===================================================================
RCS file: /sources/gnuradio/pmt/src/lib/.cvsignore,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -b -r1.1.1.1 -r1.2
--- .cvsignore  26 Jun 2006 04:50:48 -0000      1.1.1.1
+++ .cvsignore  4 Jul 2006 18:19:19 -0000       1.2
@@ -8,3 +8,4 @@
 *.lo
 howto.cc
 howto.py
+test_pmt

Index: Makefile.am
===================================================================
RCS file: /sources/gnuradio/pmt/src/lib/Makefile.am,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -b -r1.1.1.1 -r1.2
--- Makefile.am 26 Jun 2006 04:50:48 -0000      1.1.1.1
+++ Makefile.am 4 Jul 2006 18:19:19 -0000       1.2
@@ -1,5 +1,5 @@
 #
-# Copyright 2004,2005,2006 Free Software Foundation, Inc.
+# Copyright 2006 Free Software Foundation, Inc.
 # 
 # This file is part of GNU Radio
 # 
@@ -21,18 +21,51 @@
 
 include $(top_srcdir)/Makefile.common
 
-lib_LTLIBRARIES = pmt.la
+TESTS = test_pmt
 
-# These are the source files that go into the shared library
-pmt_la_SOURCES =                       \
+lib_LTLIBRARIES = libpmt.la libpmt-qa.la
+
+# These are the source files that go into the pmt shared library
+libpmt_la_SOURCES =                    \
        pmt.cc
 
 # magic flags
-pmt_la_LDFLAGS = $(NO_UNDEFINED) -module -avoid-version
+libpmt_la_LDFLAGS = $(NO_UNDEFINED) -avoid-version
 
 # link the library against the c++ standard library
-pmt_la_LIBADD =                        \
+libpmt_la_LIBADD =                     \
        -lstdc++                        
 
 include_HEADERS =                      \
        pmt.h
+
+noinst_HEADERS =                       \
+       pmt_int.h                       \
+       qa_pmt.h                        \
+       qa_pmt_prims.h                  
+
+
+# Build the qa code into its own library
+
+libpmt_qa_la_SOURCES =                 \
+       qa_pmt.cc                       \
+       qa_pmt_prims.cc                 
+
+# magic flags
+libpmt_qa_la_LDFLAGS = $(NO_UNDEFINED) -avoid-version
+
+# link the library against the c++ standard library
+libpmt_qa_la_LIBADD =                  \
+       $(CPPUNIT_LIBS)                 \
+       -lstdc++                        
+
+
+noinst_PROGRAMS        =                       \
+       test_pmt
+
+
+LIBPMT   = libpmt.la
+LIBPMTQA = libpmt-qa.la $(LIBPMT)
+
+test_pmt_SOURCES = test_pmt.cc
+test_pmt_LDADD   = $(LIBPMTQA)

Index: pmt.cc
===================================================================
RCS file: /sources/gnuradio/pmt/src/lib/pmt.cc,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- pmt.cc      4 Jul 2006 03:49:36 -0000       1.2
+++ pmt.cc      4 Jul 2006 18:19:19 -0000       1.3
@@ -92,6 +92,8 @@
 const pmt_t PMT_BOOL_T = pmt_t(new pmt_bool());                // singleton
 const pmt_t PMT_BOOL_F = pmt_t(new pmt_bool());                // singleton
 
+pmt_bool::pmt_bool(){}
+
 bool
 pmt_is_true(pmt_t obj)
 {
@@ -133,10 +135,7 @@
 static const unsigned int SYMBOL_HASH_TABLE_SIZE = 701;
 static std::vector<pmt_t> s_symbol_hash_table(SYMBOL_HASH_TABLE_SIZE);
 
-pmt_symbol::pmt_symbol(const std::string &name)
-  : d_name(name)
-{
-}
+pmt_symbol::pmt_symbol(const std::string &name) : d_name(name){}
 
 
 static unsigned int
@@ -146,7 +145,7 @@
   unsigned int g = 0;
 
   for (std::string::const_iterator p = s.begin(); p != s.end(); p++){
-    h = (h << 4) + *p;
+    h = (h << 4) + (*p & 0xff);
     g = h & 0xf0000000;
     if (g){
       h = h ^ (g >> 24);
@@ -203,12 +202,15 @@
 //                             Integer
 ////////////////////////////////////////////////////////////////////////////
 
+pmt_integer::pmt_integer(long value) : d_value(value) {}
+
 bool
 pmt_is_integer(pmt_t x)
 {
   return x->is_integer();
 }
 
+
 pmt_t
 pmt_from_long(long x)
 {
@@ -228,6 +230,8 @@
 //                              Real
 ////////////////////////////////////////////////////////////////////////////
 
+pmt_real::pmt_real(double value) : d_value(value) {}
+
 bool 
 pmt_is_real(pmt_t x)
 {
@@ -255,6 +259,8 @@
 //                              Complex
 ////////////////////////////////////////////////////////////////////////////
 
+pmt_complex::pmt_complex(std::complex<double> value) : d_value(value) {}
+
 bool 
 pmt_is_complex(pmt_t x)
 {
@@ -286,6 +292,9 @@
 
 const pmt_t PMT_NIL = pmt_t(new pmt_null());           // singleton
 
+pmt_null::pmt_null() {}
+pmt_pair::pmt_pair(pmt_t car, pmt_t cdr) : d_car(car), d_cdr(cdr) {}
+
 bool
 pmt_is_null(pmt_t x)
 {
@@ -327,7 +336,7 @@
 {
   if (pair->is_pair())
     _pair(pair)->set_car(obj);
-  
+  else
   throw pmt_wrong_type("pmt_set_car", pair);
 }
 
@@ -336,6 +345,6 @@
 {
   if (pair->is_pair())
     _pair(pair)->set_cdr(obj);
-  
+  else
   throw pmt_wrong_type("pmt_set_cdr", pair);
 }

Index: qa_pmt.cc
===================================================================
RCS file: qa_pmt.cc
diff -N qa_pmt.cc
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ qa_pmt.cc   4 Jul 2006 18:19:19 -0000       1.1
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2006 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/*
+ * This class gathers together all the test cases for pmt into
+ * a single test suite.  As you create new test cases, add them here.
+ */
+
+#include <qa_pmt.h>
+#include <qa_pmt_prims.h>
+
+CppUnit::TestSuite *
+qa_pmt::suite ()
+{
+  CppUnit::TestSuite   *s = new CppUnit::TestSuite ("pmt");
+
+  s->addTest (qa_pmt_prims::suite ());
+  //s->addTest (qa_gr_circular_file::suite ());
+  //s->addTest (qa_gr_fxpt::suite ());
+  
+  return s;
+}

Index: qa_pmt.h
===================================================================
RCS file: qa_pmt.h
diff -N qa_pmt.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ qa_pmt.h    4 Jul 2006 18:19:19 -0000       1.1
@@ -0,0 +1,36 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2006 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef INCLUDED_QA_PMT_H
+#define INCLUDED_QA_PMT_H
+
+#include <cppunit/TestSuite.h>
+
+//! collect all the tests for pmt
+
+class qa_pmt {
+ public:
+  //! return suite of tests for all of pmt
+  static CppUnit::TestSuite *suite ();
+};
+
+#endif /* INCLUDED_QA_PMT_H */

Index: qa_pmt_prims.cc
===================================================================
RCS file: qa_pmt_prims.cc
diff -N qa_pmt_prims.cc
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ qa_pmt_prims.cc     4 Jul 2006 18:19:19 -0000       1.1
@@ -0,0 +1,157 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2006 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <qa_pmt_prims.h>
+#include <cppunit/TestAssert.h>
+#include <pmt.h>
+#include <stdio.h>
+
+void
+qa_pmt_prims::test_symbols()
+{
+  CPPUNIT_ASSERT(!pmt_is_symbol(PMT_BOOL_T));
+  CPPUNIT_ASSERT(!pmt_is_symbol(PMT_BOOL_F));
+  CPPUNIT_ASSERT_THROW(pmt_symbol_to_string(PMT_BOOL_F), pmt_wrong_type);
+
+  pmt_t sym1 = pmt_string_to_symbol("test");
+  CPPUNIT_ASSERT(pmt_is_symbol(sym1));
+  CPPUNIT_ASSERT_EQUAL(std::string("test"), pmt_symbol_to_string(sym1));
+  CPPUNIT_ASSERT(pmt_is_true(sym1));
+  CPPUNIT_ASSERT(!pmt_is_false(sym1));
+
+  pmt_t sym2 = pmt_string_to_symbol("foo");
+  pmt_t sym3 = pmt_string_to_symbol("test");
+  CPPUNIT_ASSERT_EQUAL(sym1, sym3);
+  CPPUNIT_ASSERT(sym1 != sym2);
+  CPPUNIT_ASSERT(sym1 == sym3);
+
+  static const int N = 2048;
+  std::vector<pmt_t> v1(N);
+  std::vector<pmt_t> v2(N);
+
+  // generate a bunch of symbols
+  for (int i = 0; i < N; i++){
+    char buf[100];
+    snprintf(buf, sizeof(buf), "test-%d", i);
+    v1[i] = pmt_string_to_symbol(buf);
+  }
+
+  // confirm that they are all unique
+  for (int i = 0; i < N; i++)
+    for (int j = i + 1; j < N; j++)
+      CPPUNIT_ASSERT(v1[i] != v1[j]);
+
+  // generate the same symbols again
+  for (int i = 0; i < N; i++){
+    char buf[100];
+    snprintf(buf, sizeof(buf), "test-%d", i);
+    v2[i] = pmt_string_to_symbol(buf);
+  }
+
+  // confirm that we get the same ones back
+  for (int i = 0; i < N; i++)
+    CPPUNIT_ASSERT(v1[i] == v2[i]);
+}
+
+void
+qa_pmt_prims::test_booleans()
+{
+  pmt_t sym = pmt_string_to_symbol("test");
+  CPPUNIT_ASSERT(pmt_is_bool(PMT_BOOL_T));
+  CPPUNIT_ASSERT(pmt_is_bool(PMT_BOOL_F));
+  CPPUNIT_ASSERT(!pmt_is_bool(sym));
+  CPPUNIT_ASSERT_EQUAL(pmt_from_bool(false), PMT_BOOL_F);
+  CPPUNIT_ASSERT_EQUAL(pmt_from_bool(true), PMT_BOOL_T);
+  CPPUNIT_ASSERT_EQUAL(false, pmt_to_bool(PMT_BOOL_F));
+  CPPUNIT_ASSERT_EQUAL(true, pmt_to_bool(PMT_BOOL_T));
+  CPPUNIT_ASSERT_THROW(pmt_to_bool(sym), pmt_wrong_type);
+}
+
+void
+qa_pmt_prims::test_integers()
+{
+  pmt_t p1 = pmt_from_long(1);
+  pmt_t m1 = pmt_from_long(-1);
+  CPPUNIT_ASSERT(!pmt_is_integer(PMT_BOOL_T));
+  CPPUNIT_ASSERT(pmt_is_integer(p1));
+  CPPUNIT_ASSERT(pmt_is_integer(m1));
+  CPPUNIT_ASSERT_THROW(pmt_to_long(PMT_BOOL_T), pmt_wrong_type);
+  CPPUNIT_ASSERT_EQUAL(-1L, pmt_to_long(m1));
+  CPPUNIT_ASSERT_EQUAL(1L, pmt_to_long(p1));
+}
+
+void
+qa_pmt_prims::test_reals()
+{
+  pmt_t p1 = pmt_from_double(1);
+  pmt_t m1 = pmt_from_double(-1);
+  CPPUNIT_ASSERT(!pmt_is_real(PMT_BOOL_T));
+  CPPUNIT_ASSERT(pmt_is_real(p1));
+  CPPUNIT_ASSERT(pmt_is_real(m1));
+  CPPUNIT_ASSERT_THROW(pmt_to_double(PMT_BOOL_T), pmt_wrong_type);
+  CPPUNIT_ASSERT_EQUAL(-1.0, pmt_to_double(m1));
+  CPPUNIT_ASSERT_EQUAL(1.0, pmt_to_double(p1));
+  CPPUNIT_ASSERT_EQUAL(1.0, pmt_to_double(pmt_from_long(1)));
+}
+
+void
+qa_pmt_prims::test_complexes()
+{
+  pmt_t p1 = pmt_make_rectangular(2, -3);
+  pmt_t m1 = pmt_make_rectangular(-3, 2);
+  CPPUNIT_ASSERT(!pmt_is_complex(PMT_BOOL_T));
+  CPPUNIT_ASSERT(pmt_is_complex(p1));
+  CPPUNIT_ASSERT(pmt_is_complex(m1));
+  CPPUNIT_ASSERT_THROW(pmt_to_complex(PMT_BOOL_T), pmt_wrong_type);
+  CPPUNIT_ASSERT_EQUAL(std::complex<double>(2, -3), pmt_to_complex(p1));
+  CPPUNIT_ASSERT_EQUAL(std::complex<double>(-3, 2), pmt_to_complex(m1));
+  CPPUNIT_ASSERT_EQUAL(std::complex<double>(1.0, 0), 
pmt_to_complex(pmt_from_long(1)));
+  CPPUNIT_ASSERT_EQUAL(std::complex<double>(1.0, 0), 
pmt_to_complex(pmt_from_double(1.0)));
+}
+
+void
+qa_pmt_prims::test_pairs()
+{
+  CPPUNIT_ASSERT(pmt_is_null(PMT_NIL));
+  CPPUNIT_ASSERT(!pmt_is_pair(PMT_NIL));
+  pmt_t s1 = pmt_string_to_symbol("s1");
+  pmt_t s2 = pmt_string_to_symbol("s2");
+  pmt_t s3 = pmt_string_to_symbol("s3");
+
+  pmt_t c1 = pmt_cons(s1, PMT_NIL);
+  CPPUNIT_ASSERT(pmt_is_pair(c1));
+  CPPUNIT_ASSERT(!pmt_is_pair(s1));
+  CPPUNIT_ASSERT_EQUAL(s1, pmt_car(c1));
+  CPPUNIT_ASSERT_EQUAL(PMT_NIL, pmt_cdr(c1));
+
+  pmt_t c3 = pmt_cons(s3, PMT_NIL);
+  pmt_t c2 = pmt_cons(s2, c3);
+  pmt_set_cdr(c1, c2);
+  CPPUNIT_ASSERT_EQUAL(c2, pmt_cdr(c1));
+  pmt_set_car(c1, s3);
+  CPPUNIT_ASSERT_EQUAL(s3, pmt_car(c1));
+
+  CPPUNIT_ASSERT_THROW(pmt_cdr(PMT_NIL), pmt_wrong_type);
+  CPPUNIT_ASSERT_THROW(pmt_car(PMT_NIL), pmt_wrong_type);
+  CPPUNIT_ASSERT_THROW(pmt_set_car(s1, PMT_NIL), pmt_wrong_type);
+  CPPUNIT_ASSERT_THROW(pmt_set_cdr(s1, PMT_NIL), pmt_wrong_type);
+}

Index: qa_pmt_prims.h
===================================================================
RCS file: qa_pmt_prims.h
diff -N qa_pmt_prims.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ qa_pmt_prims.h      4 Jul 2006 18:19:19 -0000       1.1
@@ -0,0 +1,50 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2006 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#ifndef INCLUDED_QA_PMT_PRIMS_H
+#define INCLUDED_QA_PMT_PRIMS_H
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/TestCase.h>
+
+class qa_pmt_prims : public CppUnit::TestCase {
+
+  CPPUNIT_TEST_SUITE(qa_pmt_prims);
+  CPPUNIT_TEST(test_symbols);
+  CPPUNIT_TEST(test_booleans);
+  CPPUNIT_TEST(test_integers);
+  CPPUNIT_TEST(test_reals);
+  CPPUNIT_TEST(test_complexes);
+  CPPUNIT_TEST(test_pairs);
+  CPPUNIT_TEST_SUITE_END();
+
+ private:
+  void test_symbols();
+  void test_booleans();
+  void test_integers();
+  void test_reals();
+  void test_complexes();
+  void test_pairs();
+
+};
+
+#endif /* INCLUDED_QA_PMT_PRIMS_H */
+

Index: test_pmt.cc
===================================================================
RCS file: test_pmt.cc
diff -N test_pmt.cc
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ test_pmt.cc 4 Jul 2006 18:19:19 -0000       1.1
@@ -0,0 +1,37 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2006 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <cppunit/TextTestRunner.h>
+#include <qa_pmt.h>
+
+int 
+main(int argc, char **argv)
+{
+  
+  CppUnit::TextTestRunner      runner;
+
+  runner.addTest(qa_pmt::suite ());
+  
+  bool was_successful = runner.run("", false);
+
+  return was_successful ? 0 : 1;
+}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]