Home | History | Annotate | Download | only in tests
      1 // Copyright 2015 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 namespace blink {
      6 
      7 // Simple global constants.
      8 const char kHelloWorldConstant[] = "Hello world!";
      9 // Make sure a one-character constant doesn't get mangled.
     10 const float kE = 2.718281828;
     11 // Some constants start with a capital letter already.
     12 const int kSpeedOfLightInMetresPerSecond = 299792458;
     13 
     14 // Already Chrome style, so shouldn't change.
     15 const float kPi = 3.141592654;
     16 
     17 class C {
     18  public:
     19   // Static class constants.
     20   static const int kUsefulConstant = 8;
     21   // Note: s_ prefix should not be retained.
     22   static const int kStaticConstant = 9;
     23   // Note: m_ prefix should not be retained even though the proper prefix is s_.
     24   static const int kSuperNumber = 42;
     25 
     26   // Not a constant even though it has static storage duration.
     27   static const char* current_event_;
     28 
     29   static int Function();
     30 
     31   static void FunctionWithConstant() {
     32     const int kFunctionConstant = 4;
     33     const int kFunctionConstantFromExpression = 4 + 6;
     34     const int kFunctionConstantFromOtherConsts =
     35         kFunctionConstant + kFunctionConstantFromExpression;
     36     // These don't do the right thing right now, but names like this don't
     37     // exist in blink (hopefully).
     38     const int kShould_be_renamed_to_a_const = 9 - 2;
     39     const int kShould_also_be_renamed_to_a_const =
     40         kFunctionConstant + kFunctionConstantFromOtherConsts;
     41     const int not_compile_time_const = kFunctionConstant + Function();
     42   }
     43 };
     44 
     45 void F() {
     46   // Constant in function body.
     47   static const char kStaticString[] = "abc";
     48   // Constant-style naming, since it's initialized with a literal.
     49   const char* const kNonStaticStringConstant = "def";
     50   // Not constant-style naming, since it's not initialized with a literal.
     51   const char* const non_static_string_unconstant = kNonStaticStringConstant;
     52 }
     53 
     54 }  // namespace blink
     55