diff options
author | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-28 13:23:23 +0000 |
---|---|---|
committer | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-28 13:23:23 +0000 |
commit | 2fb8c53c9df2604b691f754f2e9f678a2d093221 (patch) | |
tree | 4c2da06e5dd4e4e04e3b15b9a94ee0f707b5793f /mojo/public/c | |
parent | 992d2c81e7f412fb652de4f4cbd5a8aac5d56cd7 (diff) | |
download | chromium_src-2fb8c53c9df2604b691f754f2e9f678a2d093221.zip chromium_src-2fb8c53c9df2604b691f754f2e9f678a2d093221.tar.gz chromium_src-2fb8c53c9df2604b691f754f2e9f678a2d093221.tar.bz2 |
Mojo: Split off the C++ parts of mojo/public/c/system macros.h to their own file.
(Also split the tests.)
R=darin@chromium.org
Review URL: https://codereview.chromium.org/216073002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@260114 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo/public/c')
-rw-r--r-- | mojo/public/c/system/macros.h | 50 | ||||
-rw-r--r-- | mojo/public/c/tests/system/core_perftest.cc | 2 | ||||
-rw-r--r-- | mojo/public/c/tests/system/macros_unittest.cc | 48 |
3 files changed, 52 insertions, 48 deletions
diff --git a/mojo/public/c/system/macros.h b/mojo/public/c/system/macros.h index d89ca02..4be0249 100644 --- a/mojo/public/c/system/macros.h +++ b/mojo/public/c/system/macros.h @@ -26,58 +26,14 @@ #define MOJO_WARN_UNUSED_RESULT #endif -// C++-only macros ------------------------------------------------------------- - +// This macro is currently C++-only, but we want to use it in the C core.h. #ifdef __cplusplus - -// Annotate a virtual method indicating it must be overriding a virtual method -// in the parent class. Use like: -// virtual void foo() OVERRIDE; -#if defined(_MSC_VER) || defined(__clang__) -#define MOJO_OVERRIDE override -#else -#define MOJO_OVERRIDE -#endif - -// A macro to disallow the copy constructor and operator= functions. -// This should be used in the private: declarations for a class. -#define MOJO_DISALLOW_COPY_AND_ASSIGN(TypeName) \ - TypeName(const TypeName&); \ - void operator=(const TypeName&) - // Used to assert things at compile time. namespace mojo { template <bool> struct CompileAssert {}; } #define MOJO_COMPILE_ASSERT(expr, msg) \ typedef ::mojo::CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1] - -// Used to calculate the number of elements in an array. -// (See |arraysize()| in Chromium's base/basictypes.h for more details.) -namespace mojo { -template <typename T, size_t N> -char (&ArraySizeHelper(T (&array)[N]))[N]; -#if !defined(_MSC_VER) -template <typename T, size_t N> -char (&ArraySizeHelper(const T (&array)[N]))[N]; +#else +#define MOJO_COMPILE_ASSERT(expr, msg) #endif -} // namespace mojo -#define MOJO_ARRAYSIZE(array) (sizeof(::mojo::ArraySizeHelper(array))) - -// Used to make a type move-only in C++03. See Chromium's base/move.h for more -// details. -#define MOJO_MOVE_ONLY_TYPE_FOR_CPP_03(type, rvalue_type) \ - private: \ - struct rvalue_type { \ - explicit rvalue_type(type* object) : object(object) {} \ - type* object; \ - }; \ - type(type&); \ - void operator=(type&); \ - public: \ - operator rvalue_type() { return rvalue_type(this); } \ - type Pass() { return type(rvalue_type(this)); } \ - typedef void MoveOnlyTypeForCPP03; \ - private: - -#endif // __cplusplus #endif // MOJO_PUBLIC_C_SYSTEM_MACROS_H_ diff --git a/mojo/public/c/tests/system/core_perftest.cc b/mojo/public/c/tests/system/core_perftest.cc index 53ac6b8..0d2f411 100644 --- a/mojo/public/c/tests/system/core_perftest.cc +++ b/mojo/public/c/tests/system/core_perftest.cc @@ -11,7 +11,7 @@ #include <stdint.h> #include <stdio.h> -#include "mojo/public/c/system/macros.h" +#include "mojo/public/cpp/system/macros.h" #include "mojo/public/tests/test_support.h" #include "mojo/public/tests/test_utils.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/mojo/public/c/tests/system/macros_unittest.cc b/mojo/public/c/tests/system/macros_unittest.cc new file mode 100644 index 0000000..5225b67 --- /dev/null +++ b/mojo/public/c/tests/system/macros_unittest.cc @@ -0,0 +1,48 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This file tests the C Mojo system macros and consists of "positive" tests, +// i.e., those verifying that things work (without compile errors, or even +// warnings if warnings are treated as errors). +// TODO(vtl): Fix no-compile tests (which are all disabled; crbug.com/105388) +// and write some "negative" tests. + +#include "mojo/public/c/system/macros.h" + +#include <assert.h> +#include <stdint.h> +#include <stdlib.h> + +#include "testing/gtest/include/gtest/gtest.h" + +namespace mojo { +namespace { + +TEST(MacrosTest, AllowUnused) { + // Test that no warning/error is issued even though |x| is unused. + int x MOJO_ALLOW_UNUSED = 123; +} + +int MustUseReturnedResult() MOJO_WARN_UNUSED_RESULT; +int MustUseReturnedResult() { + return 456; +} + +TEST(MacrosTest, WarnUnusedResult) { + if (!MustUseReturnedResult()) + abort(); +} + +// First test |MOJO_COMPILE_ASSERT()| in a global scope. +MOJO_COMPILE_ASSERT(sizeof(int64_t) == 2 * sizeof(int32_t), + bad_compile_assert_failure_in_global_scope); + +TEST(MacrosTest, CompileAssert) { + // Then in a local scope. + MOJO_COMPILE_ASSERT(sizeof(int32_t) == 2 * sizeof(int16_t), + bad_compile_assert_failure); +} + +} // namespace +} // namespace mojo |