mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-30 10:47:35 +02:00
Use a mock to test locale support
This commit is contained in:
@ -43,6 +43,22 @@
|
|||||||
// Test that the library compiles if None is defined to 0 as done by xlib.h.
|
// Test that the library compiles if None is defined to 0 as done by xlib.h.
|
||||||
#define None 0
|
#define None 0
|
||||||
|
|
||||||
|
struct LocaleMock {
|
||||||
|
static LocaleMock *instance;
|
||||||
|
|
||||||
|
MOCK_METHOD0(localeconv, lconv *());
|
||||||
|
} *LocaleMock::instance;
|
||||||
|
|
||||||
|
namespace fmt {
|
||||||
|
namespace std {
|
||||||
|
using namespace ::std;
|
||||||
|
lconv *localeconv() {
|
||||||
|
return LocaleMock::instance ?
|
||||||
|
LocaleMock::instance->localeconv() : ::std::localeconv();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#include "fmt/format.h"
|
#include "fmt/format.h"
|
||||||
#include "fmt/time.h"
|
#include "fmt/time.h"
|
||||||
|
|
||||||
@ -1209,13 +1225,12 @@ TEST(FormatterTest, FormatOct) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(FormatterTest, FormatIntLocale) {
|
TEST(FormatterTest, FormatIntLocale) {
|
||||||
#ifndef _WIN32
|
ScopedMock<LocaleMock> mock;
|
||||||
const char *locale = "en_US.utf-8";
|
lconv lc = {};
|
||||||
#else
|
char sep[] = "--";
|
||||||
const char *locale = "English_United States";
|
lc.thousands_sep = sep;
|
||||||
#endif
|
EXPECT_CALL(mock, localeconv()).WillOnce(testing::Return(&lc));
|
||||||
if (std::setlocale(LC_ALL, locale))
|
EXPECT_EQ("1--234--567", format("{:n}", 1234567));
|
||||||
EXPECT_EQ("1,234,567", format("{:n}", 1234567));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(FormatterTest, FormatFloat) {
|
TEST(FormatterTest, FormatFloat) {
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
#define FMT_GTEST_EXTRA_H_
|
#define FMT_GTEST_EXTRA_H_
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <gtest/gtest.h>
|
#include <gmock/gmock.h>
|
||||||
|
|
||||||
#include "fmt/format.h"
|
#include "fmt/format.h"
|
||||||
|
|
||||||
@ -172,4 +172,10 @@ std::string read(fmt::File &f, std::size_t count);
|
|||||||
|
|
||||||
#endif // FMT_USE_FILE_DESCRIPTORS
|
#endif // FMT_USE_FILE_DESCRIPTORS
|
||||||
|
|
||||||
|
template <typename Mock>
|
||||||
|
struct ScopedMock : testing::StrictMock<Mock> {
|
||||||
|
ScopedMock() { Mock::instance = this; }
|
||||||
|
~ScopedMock() { Mock::instance = 0; }
|
||||||
|
};
|
||||||
|
|
||||||
#endif // FMT_GTEST_EXTRA_H_
|
#endif // FMT_GTEST_EXTRA_H_
|
||||||
|
@ -453,12 +453,6 @@ TEST(BufferedFileTest, FilenoNoRetry) {
|
|||||||
fileno_count = 0;
|
fileno_count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Mock>
|
|
||||||
struct ScopedMock : testing::StrictMock<Mock> {
|
|
||||||
ScopedMock() { Mock::instance = this; }
|
|
||||||
~ScopedMock() { Mock::instance = 0; }
|
|
||||||
};
|
|
||||||
|
|
||||||
struct TestMock {
|
struct TestMock {
|
||||||
static TestMock *instance;
|
static TestMock *instance;
|
||||||
} *TestMock::instance;
|
} *TestMock::instance;
|
||||||
|
Reference in New Issue
Block a user