Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BASE_TEST_TEST_UTIL_H_ | 5 #ifndef BASE_TEST_TEST_UTIL_H_ |
|
Paweł Hajdan Jr.
2011/06/10 17:00:51
nit: The #include guards should be updated.
Also,
Joao da Silva
2011/06/14 16:48:44
Done.
| |
| 6 #define BASE_TEST_TEST_UTIL_H_ | 6 #define BASE_TEST_TEST_UTIL_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 // Generic utilities used only by tests. | |
| 10 | |
| 11 #include <locale.h> | |
| 12 | |
| 13 #include <string> | 9 #include <string> |
| 14 | 10 |
| 11 #include "base/basictypes.h" | |
| 12 | |
| 15 namespace base { | 13 namespace base { |
| 16 | 14 |
| 17 #if defined(OS_POSIX) | |
| 18 | |
| 19 // Sets the given |locale| on construction, and restores the previous locale | 15 // Sets the given |locale| on construction, and restores the previous locale |
| 20 // on destruction. | 16 // on destruction. |
| 21 class ScopedSetLocale { | 17 class ScopedSetLocale { |
| 22 public: | 18 public: |
| 23 explicit ScopedSetLocale(const char* locale) { | 19 explicit ScopedSetLocale(const std::string& locale); |
|
Joao da Silva
2011/06/10 15:53:56
Done. I didn't use a StringPiece because is stores
| |
| 24 old_locale_ = setlocale(LC_ALL, NULL); | 20 ~ScopedSetLocale(); |
| 25 setlocale(LC_ALL, locale); | 21 |
| 26 } | 22 // Returns the locale that was set by the ctor. |
| 27 ~ScopedSetLocale() { | 23 // Can be NULL, if the locale requested isn't available. |
| 28 setlocale(LC_ALL, old_locale_.c_str()); | 24 const char* current_locale() const { |
| 25 return current_locale_; | |
| 29 } | 26 } |
| 30 | 27 |
| 31 private: | 28 private: |
| 32 std::string old_locale_; | 29 const char* prev_locale_; |
| 30 const char* current_locale_; | |
| 33 | 31 |
| 34 DISALLOW_COPY_AND_ASSIGN(ScopedSetLocale); | 32 DISALLOW_COPY_AND_ASSIGN(ScopedSetLocale); |
| 35 }; | 33 }; |
| 36 | 34 |
| 37 #endif | |
| 38 | |
| 39 } // namespace base | 35 } // namespace base |
| 40 | 36 |
| 41 #endif // BASE_TEST_TEST_UTIL_H_ | 37 #endif // BASE_TEST_TEST_UTIL_H_ |
| OLD | NEW |