Import stringize_macros from Chromium.

Committing the originals to make further reviews cleaner.

TBR=bjornv
BUG=webrtc:1395

Review URL: https://webrtc-codereview.appspot.com/1106005

git-svn-id: http://webrtc.googlecode.com/svn/trunk@3509 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
andrew@webrtc.org 2013-02-13 23:37:14 +00:00
parent a8ef811fe5
commit 45eab19e7d
2 changed files with 60 additions and 0 deletions

View File

@ -0,0 +1,31 @@
// Copyright (c) 2010 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 defines preprocessor macros for stringizing preprocessor
// symbols (or their output) and manipulating preprocessor symbols
// that define strings.
#ifndef BASE_STRINGS_STRINGIZE_MACROS_H_
#define BASE_STRINGS_STRINGIZE_MACROS_H_
#include "build/build_config.h"
// This is not very useful as it does not expand defined symbols if
// called directly. Use its counterpart without the _NO_EXPANSION
// suffix, below.
#define STRINGIZE_NO_EXPANSION(x) #x
// Use this to quote the provided parameter, first expanding it if it
// is a preprocessor symbol.
//
// For example, if:
// #define A FOO
// #define B(x) myobj->FunctionCall(x)
//
// Then:
// STRINGIZE(A) produces "FOO"
// STRINGIZE(B(y)) produces "myobj->FunctionCall(y)"
#define STRINGIZE(x) STRINGIZE_NO_EXPANSION(x)
#endif // BASE_STRINGS_STRINGIZE_MACROS_H_

View File

@ -0,0 +1,29 @@
// Copyright (c) 2010 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.
#include "base/strings/stringize_macros.h"
#include "testing/gtest/include/gtest/gtest.h"
// Macros as per documentation in header file.
#define PREPROCESSOR_UTIL_UNITTEST_A FOO
#define PREPROCESSOR_UTIL_UNITTEST_B(x) myobj->FunctionCall(x)
#define PREPROCESSOR_UTIL_UNITTEST_C "foo"
TEST(StringizeTest, Ansi) {
EXPECT_STREQ(
"PREPROCESSOR_UTIL_UNITTEST_A",
STRINGIZE_NO_EXPANSION(PREPROCESSOR_UTIL_UNITTEST_A));
EXPECT_STREQ(
"PREPROCESSOR_UTIL_UNITTEST_B(y)",
STRINGIZE_NO_EXPANSION(PREPROCESSOR_UTIL_UNITTEST_B(y)));
EXPECT_STREQ(
"PREPROCESSOR_UTIL_UNITTEST_C",
STRINGIZE_NO_EXPANSION(PREPROCESSOR_UTIL_UNITTEST_C));
EXPECT_STREQ("FOO", STRINGIZE(PREPROCESSOR_UTIL_UNITTEST_A));
EXPECT_STREQ("myobj->FunctionCall(y)",
STRINGIZE(PREPROCESSOR_UTIL_UNITTEST_B(y)));
EXPECT_STREQ("\"foo\"", STRINGIZE(PREPROCESSOR_UTIL_UNITTEST_C));
}