From: bruceperens Date: Fri, 17 Jan 2014 23:50:41 +0000 (+0000) Subject: Make the first test, and fix destructor protection issue brought up in X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=93b8c1ae0d0ef3a1bc138d7784accadfb8f8a1f7;p=freetel-svn-tracking.git Make the first test, and fix destructor protection issue brought up in compiling the first test. git-svn-id: https://svn.code.sf.net/p/freetel/code@1371 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/freedv-server/CMakeLists.txt b/freedv-server/CMakeLists.txt index 1d7f491f..ee11e24d 100644 --- a/freedv-server/CMakeLists.txt +++ b/freedv-server/CMakeLists.txt @@ -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) diff --git a/freedv-server/source/drivers.h b/freedv-server/source/drivers.h index b474d9f6..f5676d1f 100644 --- a/freedv-server/source/drivers.h +++ b/freedv-server/source/drivers.h @@ -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 index 00000000..01c9ab08 --- /dev/null +++ b/freedv-server/source/test/base.cpp @@ -0,0 +1,28 @@ +// Tests for the Base class. +#include +#include + +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()); +}