Make the first test, and fix destructor protection issue brought up in
authorbruceperens <bruceperens@01035d8c-6547-0410-b346-abe4f91aad63>
Fri, 17 Jan 2014 23:50:41 +0000 (23:50 +0000)
committerbruceperens <bruceperens@01035d8c-6547-0410-b346-abe4f91aad63>
Fri, 17 Jan 2014 23:50:41 +0000 (23:50 +0000)
compiling the first test.

git-svn-id: https://svn.code.sf.net/p/freetel/code@1371 01035d8c-6547-0410-b346-abe4f91aad63

freedv-server/CMakeLists.txt
freedv-server/source/drivers.h
freedv-server/source/test/base.cpp [new file with mode: 0644]

index 1d7f491fb4080bb8b4ffa8acd89620a81810c701..ee11e24de607b00a0d17a617fa316d36160dd2fc 100644 (file)
@@ -116,15 +116,32 @@ set(Optional.sources
   source/big_main.cpp
   source/tiny_main.cpp
 )
+
+set(Optional.sources
+  source/big_main.cpp
+  source/tiny_main.cpp
+)
+
+set(Test.sources
+  source/test/base.cpp
+)
+
+set(Test.headers
+  googletest/include/gtest/gtest.h
+)
+
 load_parameters(cxx-flags)
-set_source_files_properties(${Compile.sources} ${Optional.sources} PROPERTIES COMPILE_FLAGS "-std=c++11")
+set_source_files_properties(${Compile.sources} ${Optional.sources} ${Test.sources} PROPERTIES COMPILE_FLAGS "-std=c++11")
+set_source_files_properties(${Compile.sources} ${Optional.sources} ${Test.sources} PROPERTIES COMPILE_FLAGS "-std=c++11")
 
 
 add_executable(freedv-server ${Compile.sources} source/big_main.cpp)
 
 # Googletest unit testing.
 add_subdirectory(googletest)
-add_executable(freedv-gtest ${Compile.sources})
+include_directories(googletest/include)
+include_directories(source)
+add_executable(freedv-gtest ${Compile.sources} ${Test.sources} ${Test.headers})
 set_target_properties(freedv-gtest PROPERTIES LINK_FLAGS "-L googletest")
 target_link_libraries(freedv-gtest gtest_main.a libgtest.a pthread)
 add_dependencies(freedv-gtest gtest gtest_main)
index b474d9f6cd01090ec3ada6a78a05211005005f28..f5676d1ff73b10c631364f8f4813a28ffba33675 100644 (file)
@@ -43,10 +43,10 @@ namespace FreeDV {
        /// \param _parameters Driver-specific configuration parameters.
                        Base(const char * _name, const char * _parameters);
 
+  public:
        /// Destroy the base class.
-       virtual         ~Base();
+       virtual         ~Base() = 0;
 
-  public:
        /// Return true if the object is owned by a UserInterface object and
        /// should not be destroyed separately.
        /// The return value is invariant for a particular object (or possibly
@@ -84,10 +84,10 @@ namespace FreeDV {
        /// \param parameters Driver-specific configuration parameters.
                        AudioInput(const char * name, const char * parameters);
 
+  public:
        /// Destroy an AudioInput device instance.
        virtual         ~AudioInput() = 0;
 
-  public:
        /// Get the current audio level.
        /// \return The current audio level.
        /// The value is normalized to the range of 0.0 to 1.0.
@@ -112,10 +112,10 @@ namespace FreeDV {
        /// \param parameters Driver-specific configuration parameters.
                        AudioOutput(const char * name, const char * parameters);
 
+  public:
        /// Destroy an AudioOutput device instance.
        virtual         ~AudioOutput() = 0;
 
-  public:
        /// Get the current audio level.
        /// The value is normalized to the range of 0.0 to 1.0.
        virtual float   level() = 0;
@@ -138,10 +138,10 @@ namespace FreeDV {
        /// \param parameters Driver-specific configuration parameters.
                        Codec(const char * name, const char * parameters);
 
+  public:
        /// Destroy a codec instance.
        virtual         ~Codec() = 0;
 
-  public:
        /// Encode from an array of the signed 16-bit integer type to an
        /// array of the unsigned 8-bit integer type (this is usually
        /// implemented as unsigned char).
@@ -215,7 +215,6 @@ namespace FreeDV {
                        : Base(name, parameters), do_exit(false)
                        {
                        }
-       virtual         ~EventHandler() = 0;
 
        /// If set_exit() has been called, return true once.
        /// \return True if set_exit has been called. The next and subsequent
@@ -240,6 +239,8 @@ namespace FreeDV {
        /// Cause get_exit() to return true the next time it is called.
        inline void     set_exit() { do_exit = true; }
   public:
+       virtual         ~EventHandler() = 0;
+
        /// Run the event loop.
        /// The default implementation iterates checking get_exit(), returning
        /// if its value is true and otherwise and calling iterate().
@@ -281,10 +282,10 @@ namespace FreeDV {
        /// \param parameters Driver-specific configuration parameters.
                        Keying(const char * name, const char * parameters);
 
+  public:
        /// Destroy the radio keying device instance.
        virtual         ~Keying() = 0;
 
-  public:
        /// Key or un-key the transmitter.
        /// \param value If true, key the transmitter. If false, un-key.
        virtual void    key(bool value) = 0;
@@ -299,6 +300,7 @@ namespace FreeDV {
        /// \param parameters Driver-specific configuration parameters.
                        Modem(const char * name, const char * parameters);
 
+  public:
        virtual         ~Modem() = 0;
   };
 
@@ -322,9 +324,10 @@ namespace FreeDV {
        /// \param parameters Driver-specific configuration parameters.
                        PTTInput(const char * name, const char * parameters);
 
-       virtual         ~PTTInput() = 0;
 
   public:
+       virtual         ~PTTInput() = 0;
+
        /// Set the function that will be called when the push-to-talk input
        /// changes its value.
        void            set_callback(void (*value)(bool));
@@ -343,6 +346,7 @@ namespace FreeDV {
        /// \param parameters Driver-specific configuration parameters.
                        TextInput(const char * name, const char * parameters);
 
+  public:
        virtual         ~TextInput() = 0;
   };
 
@@ -371,6 +375,7 @@ namespace FreeDV {
        /// device driver parameters.
                                UserInterface(const char * name, const char * parameters, Interfaces * _interfaces);
 
+  public:
        virtual                 ~UserInterface() = 0;
   };
 
diff --git a/freedv-server/source/test/base.cpp b/freedv-server/source/test/base.cpp
new file mode 100644 (file)
index 0000000..01c9ab0
--- /dev/null
@@ -0,0 +1,28 @@
+// Tests for the Base class.
+#include <drivers.h>
+#include <gtest/gtest.h>
+
+using namespace FreeDV;
+
+class BaseTest : public ::testing::Test {
+protected:
+       Base *  b;
+
+       BaseTest()
+       : b(0)
+       {
+       }
+
+  void SetUp() {
+    // Base is a virtual base class, so we use one of its descendant classes.
+    b = Driver::AudioSink("");
+  }
+
+  void TearDown() {
+    delete b;
+  }
+};
+
+TEST_F(BaseTest, CaptiveIsFalse) {
+  ASSERT_FALSE(b->captive());
+}