Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
dc9190f2
Commit
dc9190f2
authored
Oct 18, 2017
by
Jisi Liu
Committed by
GitHub
Oct 18, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3769 from pherl/io_win32
Remove C++11 only usages in io_win32 tests.
parents
c4f59dcc
cc58be61
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
13 deletions
+21
-13
io_win32_unittest.cc
src/google/protobuf/stubs/io_win32_unittest.cc
+21
-13
No files found.
src/google/protobuf/stubs/io_win32_unittest.cc
View file @
dc9190f2
...
...
@@ -34,7 +34,7 @@
//
// This file is only used on Windows, it's empty on other platforms.
#if defined(_
WIN32
)
#if defined(_
MSC_VER
)
#define WIN32_LEAN_AND_MEAN
#include <errno.h>
...
...
@@ -47,6 +47,7 @@
#include <windows.h>
#include <google/protobuf/stubs/io_win32.h>
#include <google/protobuf/stubs/scoped_ptr.h>
#include <google/protobuf/testing/googletest.h>
#include <gtest/gtest.h>
...
...
@@ -61,13 +62,12 @@ namespace win32 {
namespace
{
using
std
::
string
;
using
std
::
unique_ptr
;
using
std
::
wstring
;
class
IoWin32Test
:
public
::
testing
::
Test
{
public
:
void
SetUp
()
override
;
void
TearDown
()
override
;
void
SetUp
();
void
TearDown
();
protected
:
bool
CreateAllUnder
(
wstring
path
);
...
...
@@ -83,21 +83,31 @@ class IoWin32Test : public ::testing::Test {
EXPECT_FALSE(wtest_tmpdir.empty()); \
}
namespace
{
void
StripTrailingSlashes
(
string
*
str
)
{
int
i
=
str
->
size
()
-
1
;
for
(;
i
>=
0
&&
((
*
str
)[
i
]
==
'/'
||
(
*
str
)[
i
]
==
'\\'
);
--
i
)
{}
str
->
resize
(
i
+
1
);
}
}
// namespace
void
IoWin32Test
::
SetUp
()
{
test_tmpdir
=
string
(
TestTempDir
());
wtest_tmpdir
.
clear
();
if
(
test_tmpdir
.
empty
())
{
const
char
*
test_tmpdir_env
=
getenv
(
"TEST_TMPDIR"
);
if
(
test_tmpdir_env
!=
nullptr
&&
*
test_tmpdir_env
)
{
if
(
test_tmpdir_env
!=
NULL
&&
*
test_tmpdir_env
)
{
test_tmpdir
=
string
(
test_tmpdir_env
);
}
// Only Bazel defines TEST_TMPDIR, CMake does not, so look for other
// suitable environment variables.
if
(
test_tmpdir
.
empty
())
{
for
(
const
char
*
name
:
{
"TEMP"
,
"TMP"
})
{
static
const
char
*
names
[]
=
{
"TEMP"
,
"TMP"
};
for
(
int
i
=
0
;
i
<
sizeof
(
names
)
/
sizeof
(
names
[
0
]);
++
i
)
{
const
char
*
name
=
names
[
i
];
test_tmpdir_env
=
getenv
(
name
);
if
(
test_tmpdir_env
!=
nullptr
&&
*
test_tmpdir_env
)
{
if
(
test_tmpdir_env
!=
NULL
&&
*
test_tmpdir_env
)
{
test_tmpdir
=
string
(
test_tmpdir_env
);
break
;
}
...
...
@@ -128,9 +138,7 @@ void IoWin32Test::SetUp() {
}
}
while
(
test_tmpdir
.
back
()
==
'/'
||
test_tmpdir
.
back
()
==
'\\'
)
{
test_tmpdir
.
pop_back
();
}
StripTrailingSlashes
(
&
test_tmpdir
);
test_tmpdir
+=
"
\\
io_win32_unittest.tmp"
;
// CreateDirectoryA's limit is 248 chars, see MSDN.
...
...
@@ -185,7 +193,7 @@ bool IoWin32Test::DeleteAllUnder(wstring path) {
path
=
wstring
(
L"
\\\\
?
\\
"
)
+
path
;
}
// Append "\" if necessary.
if
(
path
.
back
()
!=
'\\'
)
{
if
(
path
[
path
.
size
()
-
1
]
!=
'\\'
)
{
path
.
push_back
(
'\\'
);
}
...
...
@@ -326,7 +334,7 @@ TEST_F(IoWin32Test, ChdirTest) {
TEST_F
(
IoWin32Test
,
AsWindowsPathTest
)
{
DWORD
size
=
GetCurrentDirectoryW
(
0
,
NULL
);
unique_ptr
<
wchar_t
[]
>
cwd_str
(
new
wchar_t
[
size
]);
scoped_array
<
wchar_t
>
cwd_str
(
new
wchar_t
[
size
]);
EXPECT_GT
(
GetCurrentDirectoryW
(
size
,
cwd_str
.
get
()),
0
);
wstring
cwd
=
wstring
(
L"
\\\\
?
\\
"
)
+
cwd_str
.
get
();
...
...
@@ -363,5 +371,5 @@ TEST_F(IoWin32Test, AsWindowsPathTest) {
}
// namespace protobuf
}
// namespace google
#endif // defined(_
WIN32
)
#endif // defined(_
MSC_VER
)
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