Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
fmt
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
fmt
Commits
73c84374
Commit
73c84374
authored
Apr 01, 2020
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Follow naming conventions
parent
e588b02b
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
45 deletions
+46
-45
include/fmt/os.h
include/fmt/os.h
+9
-8
test/os-test.cc
test/os-test.cc
+2
-2
test/posix-mock-test.cc
test/posix-mock-test.cc
+35
-35
No files found.
include/fmt/os.h
View file @
73c84374
...
...
@@ -345,15 +345,15 @@ long getpagesize();
#ifdef FMT_LOCALE
// A "C" numeric locale.
class
L
ocale
{
class
l
ocale
{
private:
# ifdef _WIN32
using
locale_t
=
_locale_t
;
static
void
freelocale
(
locale_t
loc
ale
)
{
_free_locale
(
locale
);
}
static
void
freelocale
(
locale_t
loc
)
{
_free_locale
(
loc
);
}
static
double
strtod_l
(
const
char
*
nptr
,
char
**
endptr
,
_locale_t
loc
ale
)
{
return
_strtod_l
(
nptr
,
endptr
,
loc
ale
);
static
double
strtod_l
(
const
char
*
nptr
,
char
**
endptr
,
_locale_t
loc
)
{
return
_strtod_l
(
nptr
,
endptr
,
loc
);
}
# endif
...
...
@@ -361,10 +361,10 @@ class Locale {
public:
using
type
=
locale_t
;
Locale
(
const
L
ocale
&
)
=
delete
;
void
operator
=
(
const
L
ocale
&
)
=
delete
;
locale
(
const
l
ocale
&
)
=
delete
;
void
operator
=
(
const
l
ocale
&
)
=
delete
;
L
ocale
()
{
l
ocale
()
{
# ifndef _WIN32
locale_
=
FMT_SYSTEM
(
newlocale
(
LC_NUMERIC_MASK
,
"C"
,
nullptr
));
# else
...
...
@@ -372,7 +372,7 @@ class Locale {
# endif
if
(
!
locale_
)
FMT_THROW
(
system_error
(
errno
,
"cannot create locale"
));
}
~
L
ocale
()
{
freelocale
(
locale_
);
}
~
l
ocale
()
{
freelocale
(
locale_
);
}
type
get
()
const
{
return
locale_
;
}
...
...
@@ -385,6 +385,7 @@ class Locale {
return
result
;
}
};
using
Locale
FMT_DEPRECATED_ALIAS
=
locale
;
#endif // FMT_LOCALE
FMT_END_NAMESPACE
...
...
test/os-test.cc
View file @
73c84374
...
...
@@ -489,9 +489,9 @@ TEST(FileTest, Fdopen) {
# ifdef FMT_LOCALE
TEST
(
LocaleTest
,
Strtod
)
{
fmt
::
Locale
locale
;
fmt
::
locale
loc
;
const
char
*
start
=
"4.2"
,
*
ptr
=
start
;
EXPECT_EQ
(
4.2
,
loc
ale
.
strtod
(
ptr
));
EXPECT_EQ
(
4.2
,
loc
.
strtod
(
ptr
));
EXPECT_EQ
(
start
+
3
,
ptr
);
}
# endif
...
...
test/posix-mock-test.cc
View file @
73c84374
...
...
@@ -53,7 +53,7 @@ std::size_t read_nbyte;
std
::
size_t
write_nbyte
;
bool
sysconf_error
;
enum
FStatSimulation
{
NONE
,
MAX_SIZE
,
ERROR
}
fstat_sim
;
enum
{
NONE
,
MAX_SIZE
,
ERROR
}
fstat_sim
;
}
// namespace
#define EMULATE_EINTR(func, error_result) \
...
...
@@ -437,33 +437,33 @@ TEST(BufferedFileTest, FilenoNoRetry) {
}
#endif // FMT_USE_FCNTL
struct
TestM
ock
{
static
TestM
ock
*
instance
;
}
*
TestM
ock
::
instance
;
struct
test_m
ock
{
static
test_m
ock
*
instance
;
}
*
test_m
ock
::
instance
;
TEST
(
ScopedMock
,
Scope
)
{
{
ScopedMock
<
TestM
ock
>
mock
;
EXPECT_EQ
(
&
mock
,
TestM
ock
::
instance
);
TestM
ock
&
copy
=
mock
;
ScopedMock
<
test_m
ock
>
mock
;
EXPECT_EQ
(
&
mock
,
test_m
ock
::
instance
);
test_m
ock
&
copy
=
mock
;
static_cast
<
void
>
(
copy
);
}
EXPECT_EQ
(
nullptr
,
TestM
ock
::
instance
);
EXPECT_EQ
(
nullptr
,
test_m
ock
::
instance
);
}
#ifdef FMT_LOCALE
typedef
fmt
::
Locale
::
type
LocaleT
ype
;
typedef
fmt
::
locale
::
type
locale_t
ype
;
struct
LocaleM
ock
{
static
LocaleM
ock
*
instance
;
MOCK_METHOD3
(
newlocale
,
LocaleT
ype
(
int
category_mask
,
const
char
*
locale
,
LocaleT
ype
base
));
MOCK_METHOD1
(
freelocale
,
void
(
LocaleT
ype
locale
));
struct
locale_m
ock
{
static
locale_m
ock
*
instance
;
MOCK_METHOD3
(
newlocale
,
locale_t
ype
(
int
category_mask
,
const
char
*
locale
,
locale_t
ype
base
));
MOCK_METHOD1
(
freelocale
,
void
(
locale_t
ype
locale
));
MOCK_METHOD3
(
strtod_l
,
double
(
const
char
*
nptr
,
char
**
endptr
,
LocaleT
ype
locale
));
}
*
LocaleM
ock
::
instance
;
double
(
const
char
*
nptr
,
char
**
endptr
,
locale_t
ype
locale
));
}
*
locale_m
ock
::
instance
;
# ifdef _MSC_VER
# pragma warning(push)
...
...
@@ -474,15 +474,15 @@ struct LocaleMock {
# endif
_locale_t
_create_locale
(
int
category
,
const
char
*
locale
)
{
return
LocaleM
ock
::
instance
->
newlocale
(
category
,
locale
,
0
);
return
locale_m
ock
::
instance
->
newlocale
(
category
,
locale
,
0
);
}
void
_free_locale
(
_locale_t
locale
)
{
LocaleM
ock
::
instance
->
freelocale
(
locale
);
locale_m
ock
::
instance
->
freelocale
(
locale
);
}
double
_strtod_l
(
const
char
*
nptr
,
char
**
endptr
,
_locale_t
locale
)
{
return
LocaleM
ock
::
instance
->
strtod_l
(
nptr
,
endptr
,
locale
);
return
locale_m
ock
::
instance
->
strtod_l
(
nptr
,
endptr
,
locale
);
}
# ifdef __clang__
# pragma clang diagnostic pop
...
...
@@ -503,26 +503,26 @@ typedef int FreeLocaleResult;
typedef
void
FreeLocaleResult
;
# endif
FreeLocaleResult
freelocale
(
LocaleT
ype
locale
)
FMT_LOCALE_THROW
{
LocaleM
ock
::
instance
->
freelocale
(
locale
);
FreeLocaleResult
freelocale
(
locale_t
ype
locale
)
FMT_LOCALE_THROW
{
locale_m
ock
::
instance
->
freelocale
(
locale
);
return
FreeLocaleResult
();
}
double
strtod_l
(
const
char
*
nptr
,
char
**
endptr
,
LocaleT
ype
locale
)
FMT_LOCALE_THROW
{
return
LocaleM
ock
::
instance
->
strtod_l
(
nptr
,
endptr
,
locale
);
locale_t
ype
locale
)
FMT_LOCALE_THROW
{
return
locale_m
ock
::
instance
->
strtod_l
(
nptr
,
endptr
,
locale
);
}
# undef FMT_LOCALE_THROW
# ifndef _WIN32
locale_t
test
::
newlocale
(
int
category_mask
,
const
char
*
locale
,
locale_t
base
)
{
return
LocaleM
ock
::
instance
->
newlocale
(
category_mask
,
locale
,
base
);
return
locale_m
ock
::
instance
->
newlocale
(
category_mask
,
locale
,
base
);
}
TEST
(
LocaleTest
,
LocaleMock
)
{
ScopedMock
<
LocaleM
ock
>
mock
;
LocaleType
locale
=
reinterpret_cast
<
LocaleT
ype
>
(
11
);
ScopedMock
<
locale_m
ock
>
mock
;
locale_type
locale
=
reinterpret_cast
<
locale_t
ype
>
(
11
);
EXPECT_CALL
(
mock
,
newlocale
(
222
,
StrEq
(
"foo"
),
locale
));
FMT_SYSTEM
(
newlocale
(
222
,
"foo"
,
locale
));
}
...
...
@@ -532,26 +532,26 @@ TEST(LocaleTest, Locale) {
# ifndef LC_NUMERIC_MASK
enum
{
LC_NUMERIC_MASK
=
LC_NUMERIC
};
# endif
ScopedMock
<
LocaleM
ock
>
mock
;
LocaleType
impl
=
reinterpret_cast
<
LocaleT
ype
>
(
42
);
ScopedMock
<
locale_m
ock
>
mock
;
locale_type
impl
=
reinterpret_cast
<
locale_t
ype
>
(
42
);
EXPECT_CALL
(
mock
,
newlocale
(
LC_NUMERIC_MASK
,
StrEq
(
"C"
),
nullptr
))
.
WillOnce
(
Return
(
impl
));
EXPECT_CALL
(
mock
,
freelocale
(
impl
));
fmt
::
Locale
locale
;
EXPECT_EQ
(
impl
,
loc
ale
.
get
());
fmt
::
locale
loc
;
EXPECT_EQ
(
impl
,
loc
.
get
());
}
TEST
(
LocaleTest
,
Strtod
)
{
ScopedMock
<
LocaleM
ock
>
mock
;
ScopedMock
<
locale_m
ock
>
mock
;
EXPECT_CALL
(
mock
,
newlocale
(
_
,
_
,
_
))
.
WillOnce
(
Return
(
reinterpret_cast
<
LocaleT
ype
>
(
42
)));
.
WillOnce
(
Return
(
reinterpret_cast
<
locale_t
ype
>
(
42
)));
EXPECT_CALL
(
mock
,
freelocale
(
_
));
fmt
::
Locale
locale
;
fmt
::
locale
loc
;
const
char
*
str
=
"4.2"
;
char
end
=
'x'
;
EXPECT_CALL
(
mock
,
strtod_l
(
str
,
_
,
loc
ale
.
get
()))
EXPECT_CALL
(
mock
,
strtod_l
(
str
,
_
,
loc
.
get
()))
.
WillOnce
(
testing
::
DoAll
(
testing
::
SetArgPointee
<
1
>
(
&
end
),
Return
(
777
)));
EXPECT_EQ
(
777
,
loc
ale
.
strtod
(
str
));
EXPECT_EQ
(
777
,
loc
.
strtod
(
str
));
EXPECT_EQ
(
&
end
,
str
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment