// Copyright 2007, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // // Author: wan@google.com (Zhanyong Wan) // Google Mock - a framework for writing C++ mock classes. // // This file tests the internal utilities. #include #include #include #include #include #include #include #include #include #include #if GTEST_OS_CYGWIN #include // For ssize_t. NOLINT #endif class ProtocolMessage; namespace proto2 { class Message; } // namespace proto2 namespace testing { namespace internal { namespace { using ::std::tr1::make_tuple; using ::std::tr1::tuple; TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContainsNoWord) { EXPECT_EQ("", ConvertIdentifierNameToWords("")); EXPECT_EQ("", ConvertIdentifierNameToWords("_")); EXPECT_EQ("", ConvertIdentifierNameToWords("__")); } TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContainsDigits) { EXPECT_EQ("1", ConvertIdentifierNameToWords("_1")); EXPECT_EQ("2", ConvertIdentifierNameToWords("2_")); EXPECT_EQ("34", ConvertIdentifierNameToWords("_34_")); EXPECT_EQ("34 56", ConvertIdentifierNameToWords("_34_56")); } TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContainsCamelCaseWords) { EXPECT_EQ("a big word", ConvertIdentifierNameToWords("ABigWord")); EXPECT_EQ("foo bar", ConvertIdentifierNameToWords("FooBar")); EXPECT_EQ("foo", ConvertIdentifierNameToWords("Foo_")); EXPECT_EQ("foo bar", ConvertIdentifierNameToWords("_Foo_Bar_")); EXPECT_EQ("foo and bar", ConvertIdentifierNameToWords("_Foo__And_Bar")); } TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContains_SeparatedWords) { EXPECT_EQ("foo bar", ConvertIdentifierNameToWords("foo_bar")); EXPECT_EQ("foo", ConvertIdentifierNameToWords("_foo_")); EXPECT_EQ("foo bar", ConvertIdentifierNameToWords("_foo_bar_")); EXPECT_EQ("foo and bar", ConvertIdentifierNameToWords("_foo__and_bar")); } TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameIsMixture) { EXPECT_EQ("foo bar 123", ConvertIdentifierNameToWords("Foo_bar123")); EXPECT_EQ("chapter 11 section 1", ConvertIdentifierNameToWords("_Chapter11Section_1_")); } // Tests that CompileAssertTypesEqual compiles when the type arguments are // equal. TEST(CompileAssertTypesEqual, CompilesWhenTypesAreEqual) { CompileAssertTypesEqual(); CompileAssertTypesEqual(); } // Tests that RemoveReference does not affect non-reference types. TEST(RemoveReferenceTest, DoesNotAffectNonReferenceType) { CompileAssertTypesEqual::type>(); CompileAssertTypesEqual::type>(); } // Tests that RemoveReference removes reference from reference types. TEST(RemoveReferenceTest, RemovesReference) { CompileAssertTypesEqual::type>(); CompileAssertTypesEqual::type>(); } // Tests GMOCK_REMOVE_REFERENCE_. template void TestGMockRemoveReference() { CompileAssertTypesEqual(); } TEST(RemoveReferenceTest, MacroVersion) { TestGMockRemoveReference(); TestGMockRemoveReference(); } // Tests that RemoveConst does not affect non-const types. TEST(RemoveConstTest, DoesNotAffectNonConstType) { CompileAssertTypesEqual::type>(); CompileAssertTypesEqual::type>(); } // Tests that RemoveConst removes const from const types. TEST(RemoveConstTest, RemovesConst) { CompileAssertTypesEqual::type>(); CompileAssertTypesEqual::type>(); CompileAssertTypesEqual::type>(); } // Tests GMOCK_REMOVE_CONST_. template void TestGMockRemoveConst() { CompileAssertTypesEqual(); } TEST(RemoveConstTest, MacroVersion) { TestGMockRemoveConst(); TestGMockRemoveConst(); TestGMockRemoveConst(); } // Tests that AddReference does not affect reference types. TEST(AddReferenceTest, DoesNotAffectReferenceType) { CompileAssertTypesEqual::type>(); CompileAssertTypesEqual::type>(); } // Tests that AddReference adds reference to non-reference types. TEST(AddReferenceTest, AddsReference) { CompileAssertTypesEqual::type>(); CompileAssertTypesEqual::type>(); } // Tests GMOCK_ADD_REFERENCE_. template void TestGMockAddReference() { CompileAssertTypesEqual(); } TEST(AddReferenceTest, MacroVersion) { TestGMockAddReference(); TestGMockAddReference(); } // Tests GMOCK_REFERENCE_TO_CONST_. template void TestGMockReferenceToConst() { CompileAssertTypesEqual(); } TEST(GMockReferenceToConstTest, Works) { TestGMockReferenceToConst(); TestGMockReferenceToConst(); TestGMockReferenceToConst(); TestGMockReferenceToConst(); } TEST(PointeeOfTest, WorksForSmartPointers) { CompileAssertTypesEqual >::type>(); } TEST(PointeeOfTest, WorksForRawPointers) { CompileAssertTypesEqual::type>(); CompileAssertTypesEqual::type>(); CompileAssertTypesEqual::type>(); } TEST(GetRawPointerTest, WorksForSmartPointers) { const char* const raw_p4 = new const char('a'); // NOLINT const internal::linked_ptr p4(raw_p4); EXPECT_EQ(raw_p4, GetRawPointer(p4)); } TEST(GetRawPointerTest, WorksForRawPointers) { int* p = NULL; // Don't use EXPECT_EQ as no NULL-testing magic on Symbian. EXPECT_TRUE(NULL == GetRawPointer(p)); int n = 1; EXPECT_EQ(&n, GetRawPointer(&n)); } class Base {}; class Derived : public Base {}; // Tests that ImplicitlyConvertible::value is a compile-time constant. TEST(ImplicitlyConvertibleTest, ValueIsCompileTimeConstant) { GMOCK_COMPILE_ASSERT_((ImplicitlyConvertible::value), const_true); GMOCK_COMPILE_ASSERT_((!ImplicitlyConvertible::value), const_false); } // Tests that ImplicitlyConvertible::value is true when T1 can // be implicitly converted to T2. TEST(ImplicitlyConvertibleTest, ValueIsTrueWhenConvertible) { EXPECT_TRUE((ImplicitlyConvertible::value)); EXPECT_TRUE((ImplicitlyConvertible::value)); EXPECT_TRUE((ImplicitlyConvertible::value)); EXPECT_TRUE((ImplicitlyConvertible::value)); EXPECT_TRUE((ImplicitlyConvertible::value)); EXPECT_TRUE((ImplicitlyConvertible::value)); } // Tests that ImplicitlyConvertible::value is false when T1 // cannot be implicitly converted to T2. TEST(ImplicitlyConvertibleTest, ValueIsFalseWhenNotConvertible) { EXPECT_FALSE((ImplicitlyConvertible::value)); EXPECT_FALSE((ImplicitlyConvertible::value)); EXPECT_FALSE((ImplicitlyConvertible::value)); EXPECT_FALSE((ImplicitlyConvertible::value)); } // Tests KindOf. TEST(KindOfTest, Bool) { EXPECT_EQ(kBool, GMOCK_KIND_OF_(bool)); // NOLINT } TEST(KindOfTest, Integer) { EXPECT_EQ(kInteger, GMOCK_KIND_OF_(char)); // NOLINT EXPECT_EQ(kInteger, GMOCK_KIND_OF_(signed char)); // NOLINT EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned char)); // NOLINT EXPECT_EQ(kInteger, GMOCK_KIND_OF_(short)); // NOLINT EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned short)); // NOLINT EXPECT_EQ(kInteger, GMOCK_KIND_OF_(int)); // NOLINT EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned int)); // NOLINT EXPECT_EQ(kInteger, GMOCK_KIND_OF_(long)); // NOLINT EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned long)); // NOLINT EXPECT_EQ(kInteger, GMOCK_KIND_OF_(wchar_t)); // NOLINT EXPECT_EQ(kInteger, GMOCK_KIND_OF_(Int64)); // NOLINT EXPECT_EQ(kInteger, GMOCK_KIND_OF_(UInt64)); // NOLINT EXPECT_EQ(kInteger, GMOCK_KIND_OF_(size_t)); // NOLINT #if GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_CYGWIN // ssize_t is not defined on Windows and possibly some other OSes. EXPECT_EQ(kInteger, GMOCK_KIND_OF_(ssize_t)); // NOLINT #endif } TEST(KindOfTest, FloatingPoint) { EXPECT_EQ(kFloatingPoint, GMOCK_KIND_OF_(float)); // NOLINT EXPECT_EQ(kFloatingPoint, GMOCK_KIND_OF_(double)); // NOLINT EX
/*
    ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
                 2011 Giovanni Di Sirio.

    This file is part of ChibiOS/RT.

    ChibiOS/RT 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 3 of the License, or
    (at your option) any later version.

    ChibiOS/RT 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 this program.  If not, see <http://www.gnu.org/licenses/>.
*/

/**
 * @file    LPC13xx/serial_lld.h
 * @brief   LPC13xx low level serial driver header.
 *
 * @addtogroup SERIAL
 * @{
 */

#ifndef _SERIAL_LLD_H_
#define _SERIAL_LLD_H_

#if HAL_USE_SERIAL || defined(__DOXYGEN__)

/*===========================================================================*/
/* Driver constants.                                                         */
/*===========================================================================*/

#define IIR_SRC_MASK    0x0F
#define IIR_SRC_NONE    0x01
#define IIR_SRC_MODEM   0x00
#define IIR_SRC_TX      0x02
#define IIR_SRC_RX      0x04
#define IIR_SRC_ERROR   0x06
#define IIR_SRC_TIMEOUT 0x0C

#define IER_RBR         1
#define IER_THRE        2
#define IER_STATUS      4

#define LCR_WL5         0
#define LCR_WL6         1
#define LCR_WL7         2
#define LCR_WL8         3
#define LCR_STOP1       0
#define LCR_STOP2       4
#define LCR_NOPARITY    0
#define LCR_PARITYODD   0x08
#define LCR_PARITYEVEN  0x18
#define LCR_PARITYONE   0x28
#define LCR_PARITYZERO  0x38
#define LCR_BREAK_ON    0x40
#define LCR_DLAB        0x80

#define FCR_ENABLE      1
#define FCR_RXRESET     2
#define FCR_TXRESET     4
#define FCR_TRIGGER0    0
#define FCR_TRIGGER1    0x40
#define FCR_TRIGGER2    0x80
#define FCR_TRIGGER3    0xC0

#define LSR_RBR_FULL    1
#define LSR_OVERRUN     2
#define LSR_PARITY      4
#define LSR_FRAMING     8
#define LSR_BREAK       0x10
#define LSR_THRE        0x20
#define LSR_TEMT        0x40
#define LSR_RXFE        0x80

#define TER_ENABLE      0x80

/*===========================================================================*/
/* Driver pre-compile time settings.                                         */
/*===========================================================================*/

/**
 * @brief   UART0 driver enable switch.
 * @details If set to @p TRUE the support for UART0 is included.
 * @note    The default is @p TRUE .
 */
#if !defined(LPC13xx_SERIAL_USE_UART0) || defined(__DOXYGEN__)
#define LPC13xx_SERIAL_USE_UART0            TRUE
#endif

/**
 * @brief   FIFO preload parameter.
 * @details Configuration parameter, this values defines how many bytes are
 *          preloaded in the HW transmit FIFO for each interrupt, the maximum
 *          value is 16 the minimum is 1.
 * @note    An high value reduces the number of interrupts generated but can
 *          also increase the worst case interrupt response time because the
 *          preload loops.
 */
#if !defined(LPC13xx_SERIAL_FIFO_PRELOAD) || defined(__DOXYGEN__)
#define LPC13xx_SERIAL_FIFO_PRELOAD         16
#endif

/**
 * @brief   UART0 PCLK divider.
 */
#if !defined(LPC13xx_SERIAL_UART0CLKDIV) || defined(__DOXYGEN__)
#define LPC13xx_SERIAL_UART0CLKDIV          1
#endif

/**
 * @brief   UART0 interrupt priority level setting.
 */
#if !defined(LPC13xx_SERIAL_UART0_IRQ_PRIORITY) || defined(__DOXYGEN__)
#define LPC13xx_SERIAL_UART0_IRQ_PRIORITY   3
#endif

/*===========================================================================*/
/* Derived constants and error checks.                                       */
/*===========================================================================*/

#if (LPC13xx_SERIAL_UART0CLKDIV < 1) || (LPC11xx_SERIAL_UART0CLKDIV > 255)
#error "invalid LPC13xx_SERIAL_UART0CLKDIV setting"
#endif

#if (LPC13xx_SERIAL_FIFO_PRELOAD < 1) || (LPC13xx_SERIAL_FIFO_PRELOAD > 16)
#error "invalid LPC13xx_SERIAL_FIFO_PRELOAD setting"
#endif

/**
 * @brief   UART0 clock.
 */
#define  LPC13xx_SERIAL_UART0_PCLK                                          \
  (LPC13xx_MAINCLK / LPC13xx_SERIAL_UART0CLKDIV)

/*===========================================================================*/
/* Driver data structures and types.                                         */
/*===========================================================================*/

/**
 * @brief   LPC13xx Serial Driver configuration structure.
 * @details An instance of this structure must be passed to @p sdStart()
 *          in order to configure and start a serial driver operations.
 */
typedef struct {
  /**
   * @brief Bit rate.
   */
  uint32_t                  sc_speed;
  /**
   * @brief Initialization value for the LCR register.
   */
  uint32_t                  sc_lcr;
  /**
   * @brief Initialization value for the FCR register.
   */
  uint32_t                  sc_fcr;
} SerialConfig;

/**
 * @brief   @p SerialDriver specific data.
 */
#define _serial_driver_data                                                 \
  _base_asynchronous_channel_data                                           \
  /* Driver state.*/                                                        \
  sdstate_t                 state;                                          \
  /* Input queue.*/                                                         \
  InputQueue                iqueue;                                         \
  /* Output queue.*/                                                        \
  OutputQueue               oqueue;                                         \
  /* Input circular buffer.*/                                               \
  uint8_t                   ib[SERIAL_BUFFERS_SIZE];                        \
  /* Output circular buffer.*/                                              \
  uint8_t                   ob[SERIAL_BUFFERS_SIZE];                        \
  /* End of the mandatory fields.*/                                         \
  /* Pointer to the USART registers block.*/                                \
  LPC_UART_TypeDef        *uart;

/*===========================================================================*/
/* Driver macros.                                                            */
/*===========================================================================*/

/*===========================================================================*/
/* External declarations.                                                    */
/*===========================================================================*/

#if LPC13xx_SERIAL_USE_UART0 && !defined(__DOXYGEN__)
extern SerialDriver SD1;
#endif

#ifdef __cplusplus
extern "C" {
#endif
  void sd_lld_init(void);
  void sd_lld_start(SerialDriver *sdp, const SerialConfig *config);
  void sd_lld_stop(SerialDriver *sdp);
#ifdef __cplusplus
}
#endif

#endif /* HAL_USE_SERIAL */

#endif /* _SERIAL_LLD_H_ */

/** @} */
of // array. } TEST(NativeArrayTest, TypeMembersAreCorrect) { StaticAssertTypeEq::value_type>(); StaticAssertTypeEq::value_type>(); StaticAssertTypeEq::const_iterator>(); StaticAssertTypeEq::const_iterator>(); } TEST(NativeArrayTest, MethodsWork) { const int a[3] = { 0, 1, 2 }; NativeArray na(a, 3, kCopy); ASSERT_EQ(3, na.size()); EXPECT_EQ(3, na.end() - na.begin()); NativeArray::const_iterator it = na.begin(); EXPECT_EQ(0, *it); ++it; EXPECT_EQ(1, *it); it++; EXPECT_EQ(2, *it); ++it; EXPECT_EQ(na.end(), it); EXPECT_THAT(na, Eq(na)); NativeArray na2(a, 3, kReference); EXPECT_THAT(na, Eq(na2)); const int b1[3] = { 0, 1, 1 }; const int b2[4] = { 0, 1, 2, 3 }; EXPECT_THAT(na, Not(Eq(NativeArray(b1, 3, kReference)))); EXPECT_THAT(na, Not(Eq(NativeArray(b2, 4, kCopy)))); } TEST(NativeArrayTest, WorksForTwoDimensionalArray) { const char a[2][3] = { "hi", "lo" }; NativeArray na(a, 2, kReference); ASSERT_EQ(2, na.size()); EXPECT_EQ(a, na.begin()); } // Tests StlContainerView. TEST(StlContainerViewTest, WorksForStlContainer) { StaticAssertTypeEq, StlContainerView >::type>(); StaticAssertTypeEq&, StlContainerView >::const_reference>(); typedef std::vector Chars; Chars v1; const Chars& v2(StlContainerView::ConstReference(v1)); EXPECT_EQ(&v1, &v2); v1.push_back('a'); Chars v3 = StlContainerView::Copy(v1); EXPECT_THAT(v3, Eq(v3)); } TEST(StlContainerViewTest, WorksForStaticNativeArray) { StaticAssertTypeEq, StlContainerView::type>(); StaticAssertTypeEq, StlContainerView::type>(); StaticAssertTypeEq, StlContainerView::type>(); StaticAssertTypeEq, StlContainerView::const_reference>(); int a1[3] = { 0, 1, 2 }; NativeArray a2 = StlContainerView::ConstReference(a1); EXPECT_EQ(3, a2.size()); EXPECT_EQ(a1, a2.begin()); const NativeArray a3 = StlContainerView::Copy(a1); ASSERT_EQ(3, a3.size()); EXPECT_EQ(0, a3.begin()[0]); EXPECT_EQ(1, a3.begin()[1]); EXPECT_EQ(2, a3.begin()[2]); // Makes sure a1 and a3 aren't aliases. a1[0] = 3; EXPECT_EQ(0, a3.begin()[0]); } TEST(StlContainerViewTest, WorksForDynamicNativeArray) { StaticAssertTypeEq, StlContainerView >::type>(); StaticAssertTypeEq, StlContainerView, int> >::type>(); StaticAssertTypeEq, StlContainerView >::const_reference>(); int a1[3] = { 0, 1, 2 }; const int* const p1 = a1; NativeArray a2 = StlContainerView >:: ConstReference(make_tuple(p1, 3)); EXPECT_EQ(3, a2.size()); EXPECT_EQ(a1, a2.begin()); const NativeArray a3 = StlContainerView >:: Copy(make_tuple(static_cast(a1), 3)); ASSERT_EQ(3, a3.size()); EXPECT_EQ(0, a3.begin()[0]); EXPECT_EQ(1, a3.begin()[1]); EXPECT_EQ(2, a3.begin()[2]); // Makes sure a1 and a3 aren't aliases. a1[0] = 3; EXPECT_EQ(0, a3.begin()[0]); } } // namespace } // namespace internal } // namespace testing