Home | History | Annotate | Download | only in base
      1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 //
      5 // Unit tests for stringize_macros.h
      6 
      7 #include "base/stringize_macros.h"
      8 
      9 #include "testing/gtest/include/gtest/gtest.h"
     10 
     11 // Macros as per documentation in header file.
     12 #define PREPROCESSOR_UTIL_UNITTEST_A FOO
     13 #define PREPROCESSOR_UTIL_UNITTEST_B(x) myobj->FunctionCall(x)
     14 #define PREPROCESSOR_UTIL_UNITTEST_C "foo"
     15 
     16 TEST(StringizeTest, Ansi) {
     17   EXPECT_STREQ(
     18       "PREPROCESSOR_UTIL_UNITTEST_A",
     19       STRINGIZE_NO_EXPANSION(PREPROCESSOR_UTIL_UNITTEST_A));
     20   EXPECT_STREQ(
     21       "PREPROCESSOR_UTIL_UNITTEST_B(y)",
     22       STRINGIZE_NO_EXPANSION(PREPROCESSOR_UTIL_UNITTEST_B(y)));
     23   EXPECT_STREQ(
     24       "PREPROCESSOR_UTIL_UNITTEST_C",
     25       STRINGIZE_NO_EXPANSION(PREPROCESSOR_UTIL_UNITTEST_C));
     26 
     27   EXPECT_STREQ("FOO", STRINGIZE(PREPROCESSOR_UTIL_UNITTEST_A));
     28   EXPECT_STREQ("myobj->FunctionCall(y)",
     29                STRINGIZE(PREPROCESSOR_UTIL_UNITTEST_B(y)));
     30   EXPECT_STREQ("\"foo\"", STRINGIZE(PREPROCESSOR_UTIL_UNITTEST_C));
     31 }
     32 
     33 #if defined(OS_WIN)
     34 
     35 TEST(StringizeTest, Wide) {
     36   EXPECT_STREQ(
     37       L"PREPROCESSOR_UTIL_UNITTEST_A",
     38       LSTRINGIZE_NO_EXPANSION(PREPROCESSOR_UTIL_UNITTEST_A));
     39   EXPECT_STREQ(
     40       L"PREPROCESSOR_UTIL_UNITTEST_B(y)",
     41       LSTRINGIZE_NO_EXPANSION(PREPROCESSOR_UTIL_UNITTEST_B(y)));
     42   EXPECT_STREQ(
     43       L"PREPROCESSOR_UTIL_UNITTEST_C",
     44       LSTRINGIZE_NO_EXPANSION(PREPROCESSOR_UTIL_UNITTEST_C));
     45 
     46   EXPECT_STREQ(L"FOO", LSTRINGIZE(PREPROCESSOR_UTIL_UNITTEST_A));
     47   EXPECT_STREQ(L"myobj->FunctionCall(y)",
     48                LSTRINGIZE(PREPROCESSOR_UTIL_UNITTEST_B(y)));
     49   EXPECT_STREQ(L"\"foo\"", LSTRINGIZE(PREPROCESSOR_UTIL_UNITTEST_C));
     50 }
     51 
     52 TEST(ToLStringTest, Main) {
     53   EXPECT_STREQ(L"blat", TO_L_STRING_NO_EXPANSION("blat"));
     54 
     55   EXPECT_STREQ(L"foo", TO_L_STRING(PREPROCESSOR_UTIL_UNITTEST_C));
     56   EXPECT_STREQ(L"blat", TO_L_STRING("blat"));
     57 }
     58 
     59 #endif  // defined(OS_WIN)
     60