Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
googletest
Project
Overview
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
googletest
Commits
fe787609
Commit
fe787609
authored
Feb 27, 2010
by
vladlosev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Makes all samples compile with -Wall -Wshadow -Werror.
parent
70eceaf8
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
49 additions
and
49 deletions
+49
-49
CMakeLists.txt
CMakeLists.txt
+3
-3
sample2.cc
samples/sample2.cc
+7
-7
sample2.h
samples/sample2.h
+6
-6
sample2_unittest.cc
samples/sample2_unittest.cc
+1
-1
sample3-inl.h
samples/sample3-inl.h
+25
-25
sample3_unittest.cc
samples/sample3_unittest.cc
+3
-3
sample5_unittest.cc
samples/sample5_unittest.cc
+4
-4
No files found.
CMakeLists.txt
View file @
fe787609
...
@@ -36,12 +36,12 @@ find_package(Threads)
...
@@ -36,12 +36,12 @@ find_package(Threads)
# Defines the compiler/linker flags used to build gtest. You can
# Defines the compiler/linker flags used to build gtest. You can
# tweak these definitions to suit your need.
# tweak these definitions to suit your need.
if
(
MSVC
)
if
(
MSVC
)
set
(
cxx_base
"
${
CMAKE_CXX_FLAGS
}
-GS -W4 -WX -wd4275 -nologo -J
set
(
cxx_base
"
${
CMAKE_CXX_FLAGS
}
-GS -W4 -WX -wd4275 -nologo -J
-Zi
-
Zi -
D_UNICODE -DUNICODE -DWIN32 -D_WIN32 -DSTRICT
-D_UNICODE -DUNICODE -DWIN32 -D_WIN32 -DSTRICT
-DWIN32_LEAN_AND_MEAN"
)
-DWIN32_LEAN_AND_MEAN"
)
set
(
cxx_default
"
${
cxx_base
}
-EHsc -D_HAS_EXCEPTIONS=1"
)
set
(
cxx_default
"
${
cxx_base
}
-EHsc -D_HAS_EXCEPTIONS=1"
)
else
()
else
()
set
(
cxx_base
"
${
CMAKE_CXX_FLAGS
}
"
)
set
(
cxx_base
"
${
CMAKE_CXX_FLAGS
}
-Wall -Werror -Wshadow
"
)
if
(
CMAKE_USE_PTHREADS_INIT
)
# The pthreads library is available.
if
(
CMAKE_USE_PTHREADS_INIT
)
# The pthreads library is available.
set
(
cxx_base
"
${
cxx_base
}
-DGTEST_HAS_PTHREAD=1"
)
set
(
cxx_base
"
${
cxx_base
}
-DGTEST_HAS_PTHREAD=1"
)
...
...
samples/sample2.cc
View file @
fe787609
...
@@ -36,21 +36,21 @@
...
@@ -36,21 +36,21 @@
#include <string.h>
#include <string.h>
// Clones a 0-terminated C string, allocating memory using new.
// Clones a 0-terminated C string, allocating memory using new.
const
char
*
MyString
::
CloneCString
(
const
char
*
c_string
)
{
const
char
*
MyString
::
CloneCString
(
const
char
*
a_
c_string
)
{
if
(
c_string
==
NULL
)
return
NULL
;
if
(
a_
c_string
==
NULL
)
return
NULL
;
const
size_t
len
=
strlen
(
c_string
);
const
size_t
len
=
strlen
(
a_
c_string
);
char
*
const
clone
=
new
char
[
len
+
1
];
char
*
const
clone
=
new
char
[
len
+
1
];
memcpy
(
clone
,
c_string
,
len
+
1
);
memcpy
(
clone
,
a_
c_string
,
len
+
1
);
return
clone
;
return
clone
;
}
}
// Sets the 0-terminated C string this MyString object
// Sets the 0-terminated C string this MyString object
// represents.
// represents.
void
MyString
::
Set
(
const
char
*
c_string
)
{
void
MyString
::
Set
(
const
char
*
a_
c_string
)
{
// Makes sure this works when c_string == c_string_
// Makes sure this works when c_string == c_string_
const
char
*
const
temp
=
MyString
::
CloneCString
(
c_string
);
const
char
*
const
temp
=
MyString
::
CloneCString
(
a_
c_string
);
delete
[]
c_string_
;
delete
[]
c_string_
;
c_string_
=
temp
;
c_string_
=
temp
;
}
}
samples/sample2.h
View file @
fe787609
...
@@ -40,13 +40,13 @@
...
@@ -40,13 +40,13 @@
// A simple string class.
// A simple string class.
class
MyString
{
class
MyString
{
private
:
private
:
const
char
*
c_string_
;
const
char
*
c_string_
;
const
MyString
&
operator
=
(
const
MyString
&
rhs
);
const
MyString
&
operator
=
(
const
MyString
&
rhs
);
public
:
public
:
// Clones a 0-terminated C string, allocating memory using new.
// Clones a 0-terminated C string, allocating memory using new.
static
const
char
*
CloneCString
(
const
char
*
c_string
);
static
const
char
*
CloneCString
(
const
char
*
a_
c_string
);
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
//
//
...
@@ -56,8 +56,8 @@ class MyString {
...
@@ -56,8 +56,8 @@ class MyString {
MyString
()
:
c_string_
(
NULL
)
{}
MyString
()
:
c_string_
(
NULL
)
{}
// Constructs a MyString by cloning a 0-terminated C string.
// Constructs a MyString by cloning a 0-terminated C string.
explicit
MyString
(
const
char
*
c_string
)
:
c_string_
(
NULL
)
{
explicit
MyString
(
const
char
*
a_
c_string
)
:
c_string_
(
NULL
)
{
Set
(
c_string
);
Set
(
a_
c_string
);
}
}
// Copy c'tor
// Copy c'tor
...
@@ -72,14 +72,14 @@ class MyString {
...
@@ -72,14 +72,14 @@ class MyString {
~
MyString
()
{
delete
[]
c_string_
;
}
~
MyString
()
{
delete
[]
c_string_
;
}
// Gets the 0-terminated C string this MyString object represents.
// Gets the 0-terminated C string this MyString object represents.
const
char
*
c_string
()
const
{
return
c_string_
;
}
const
char
*
c_string
()
const
{
return
c_string_
;
}
size_t
Length
()
const
{
size_t
Length
()
const
{
return
c_string_
==
NULL
?
0
:
strlen
(
c_string_
);
return
c_string_
==
NULL
?
0
:
strlen
(
c_string_
);
}
}
// Sets the 0-terminated C string this MyString object represents.
// Sets the 0-terminated C string this MyString object represents.
void
Set
(
const
char
*
c_string
);
void
Set
(
const
char
*
c_string
);
};
};
...
...
samples/sample2_unittest.cc
View file @
fe787609
...
@@ -71,7 +71,7 @@ TEST(MyString, DefaultConstructor) {
...
@@ -71,7 +71,7 @@ TEST(MyString, DefaultConstructor) {
// </TechnicalDetails>
// </TechnicalDetails>
EXPECT_STREQ
(
NULL
,
s
.
c_string
());
EXPECT_STREQ
(
NULL
,
s
.
c_string
());
EXPECT_EQ
(
0
,
s
.
Length
());
EXPECT_EQ
(
0
u
,
s
.
Length
());
}
}
const
char
kHelloString
[]
=
"Hello, world!"
;
const
char
kHelloString
[]
=
"Hello, world!"
;
...
...
samples/sample3-inl.h
View file @
fe787609
...
@@ -51,23 +51,23 @@ class QueueNode {
...
@@ -51,23 +51,23 @@ class QueueNode {
public
:
public
:
// Gets the element in this node.
// Gets the element in this node.
const
E
&
element
()
const
{
return
element_
;
}
const
E
&
element
()
const
{
return
element_
;
}
// Gets the next node in the queue.
// Gets the next node in the queue.
QueueNode
*
next
()
{
return
next_
;
}
QueueNode
*
next
()
{
return
next_
;
}
const
QueueNode
*
next
()
const
{
return
next_
;
}
const
QueueNode
*
next
()
const
{
return
next_
;
}
private
:
private
:
// Creates a node with a given element value. The next pointer is
// Creates a node with a given element value. The next pointer is
// set to NULL.
// set to NULL.
QueueNode
(
const
E
&
element
)
:
element_
(
element
),
next_
(
NULL
)
{}
QueueNode
(
const
E
&
an_element
)
:
element_
(
an_
element
),
next_
(
NULL
)
{}
// We disable the default assignment operator and copy c'tor.
// We disable the default assignment operator and copy c'tor.
const
QueueNode
&
operator
=
(
const
QueueNode
&
);
const
QueueNode
&
operator
=
(
const
QueueNode
&
);
QueueNode
(
const
QueueNode
&
);
QueueNode
(
const
QueueNode
&
);
E
element_
;
E
element_
;
QueueNode
*
next_
;
QueueNode
*
next_
;
};
};
template
<
typename
E
>
// E is the element type.
template
<
typename
E
>
// E is the element type.
...
@@ -84,8 +84,8 @@ public:
...
@@ -84,8 +84,8 @@ public:
void
Clear
()
{
void
Clear
()
{
if
(
size_
>
0
)
{
if
(
size_
>
0
)
{
// 1. Deletes every node.
// 1. Deletes every node.
QueueNode
<
E
>
*
node
=
head_
;
QueueNode
<
E
>*
node
=
head_
;
QueueNode
<
E
>
*
next
=
node
->
next
();
QueueNode
<
E
>*
next
=
node
->
next
();
for
(;
;)
{
for
(;
;)
{
delete
node
;
delete
node
;
node
=
next
;
node
=
next
;
...
@@ -103,19 +103,19 @@ public:
...
@@ -103,19 +103,19 @@ public:
size_t
Size
()
const
{
return
size_
;
}
size_t
Size
()
const
{
return
size_
;
}
// Gets the first element of the queue, or NULL if the queue is empty.
// Gets the first element of the queue, or NULL if the queue is empty.
QueueNode
<
E
>
*
Head
()
{
return
head_
;
}
QueueNode
<
E
>*
Head
()
{
return
head_
;
}
const
QueueNode
<
E
>
*
Head
()
const
{
return
head_
;
}
const
QueueNode
<
E
>*
Head
()
const
{
return
head_
;
}
// Gets the last element of the queue, or NULL if the queue is empty.
// Gets the last element of the queue, or NULL if the queue is empty.
QueueNode
<
E
>
*
Last
()
{
return
last_
;
}
QueueNode
<
E
>*
Last
()
{
return
last_
;
}
const
QueueNode
<
E
>
*
Last
()
const
{
return
last_
;
}
const
QueueNode
<
E
>*
Last
()
const
{
return
last_
;
}
// Adds an element to the end of the queue. A copy of the element is
// Adds an element to the end of the queue. A copy of the element is
// created using the copy constructor, and then stored in the queue.
// created using the copy constructor, and then stored in the queue.
// Changes made to the element in the queue doesn't affect the source
// Changes made to the element in the queue doesn't affect the source
// object, and vice versa.
// object, and vice versa.
void
Enqueue
(
const
E
&
element
)
{
void
Enqueue
(
const
E
&
element
)
{
QueueNode
<
E
>
*
new_node
=
new
QueueNode
<
E
>
(
element
);
QueueNode
<
E
>*
new_node
=
new
QueueNode
<
E
>
(
element
);
if
(
size_
==
0
)
{
if
(
size_
==
0
)
{
head_
=
last_
=
new_node
;
head_
=
last_
=
new_node
;
...
@@ -129,19 +129,19 @@ public:
...
@@ -129,19 +129,19 @@ public:
// Removes the head of the queue and returns it. Returns NULL if
// Removes the head of the queue and returns it. Returns NULL if
// the queue is empty.
// the queue is empty.
E
*
Dequeue
()
{
E
*
Dequeue
()
{
if
(
size_
==
0
)
{
if
(
size_
==
0
)
{
return
NULL
;
return
NULL
;
}
}
const
QueueNode
<
E
>
*
const
old_head
=
head_
;
const
QueueNode
<
E
>*
const
old_head
=
head_
;
head_
=
head_
->
next_
;
head_
=
head_
->
next_
;
size_
--
;
size_
--
;
if
(
size_
==
0
)
{
if
(
size_
==
0
)
{
last_
=
NULL
;
last_
=
NULL
;
}
}
E
*
element
=
new
E
(
old_head
->
element
());
E
*
element
=
new
E
(
old_head
->
element
());
delete
old_head
;
delete
old_head
;
return
element
;
return
element
;
...
@@ -151,9 +151,9 @@ public:
...
@@ -151,9 +151,9 @@ public:
// returns the result in a new queue. The original queue is not
// returns the result in a new queue. The original queue is not
// affected.
// affected.
template
<
typename
F
>
template
<
typename
F
>
Queue
*
Map
(
F
function
)
const
{
Queue
*
Map
(
F
function
)
const
{
Queue
*
new_queue
=
new
Queue
();
Queue
*
new_queue
=
new
Queue
();
for
(
const
QueueNode
<
E
>
*
node
=
head_
;
node
!=
NULL
;
node
=
node
->
next_
)
{
for
(
const
QueueNode
<
E
>*
node
=
head_
;
node
!=
NULL
;
node
=
node
->
next_
)
{
new_queue
->
Enqueue
(
function
(
node
->
element
()));
new_queue
->
Enqueue
(
function
(
node
->
element
()));
}
}
...
@@ -161,13 +161,13 @@ public:
...
@@ -161,13 +161,13 @@ public:
}
}
private
:
private
:
QueueNode
<
E
>
*
head_
;
// The first node of the queue.
QueueNode
<
E
>*
head_
;
// The first node of the queue.
QueueNode
<
E
>
*
last_
;
// The last node of the queue.
QueueNode
<
E
>*
last_
;
// The last node of the queue.
size_t
size_
;
// The number of elements in the queue.
size_t
size_
;
// The number of elements in the queue.
// We disallow copying a queue.
// We disallow copying a queue.
Queue
(
const
Queue
&
);
Queue
(
const
Queue
&
);
const
Queue
&
operator
=
(
const
Queue
&
);
const
Queue
&
operator
=
(
const
Queue
&
);
};
};
#endif // GTEST_SAMPLES_SAMPLE3_INL_H_
#endif // GTEST_SAMPLES_SAMPLE3_INL_H_
samples/sample3_unittest.cc
View file @
fe787609
...
@@ -122,7 +122,7 @@ class QueueTest : public testing::Test {
...
@@ -122,7 +122,7 @@ class QueueTest : public testing::Test {
// Tests the default c'tor.
// Tests the default c'tor.
TEST_F
(
QueueTest
,
DefaultConstructor
)
{
TEST_F
(
QueueTest
,
DefaultConstructor
)
{
// You can access data in the test fixture here.
// You can access data in the test fixture here.
EXPECT_EQ
(
0
,
q0_
.
Size
());
EXPECT_EQ
(
0
u
,
q0_
.
Size
());
}
}
// Tests Dequeue().
// Tests Dequeue().
...
@@ -133,13 +133,13 @@ TEST_F(QueueTest, Dequeue) {
...
@@ -133,13 +133,13 @@ TEST_F(QueueTest, Dequeue) {
n
=
q1_
.
Dequeue
();
n
=
q1_
.
Dequeue
();
ASSERT_TRUE
(
n
!=
NULL
);
ASSERT_TRUE
(
n
!=
NULL
);
EXPECT_EQ
(
1
,
*
n
);
EXPECT_EQ
(
1
,
*
n
);
EXPECT_EQ
(
0
,
q1_
.
Size
());
EXPECT_EQ
(
0
u
,
q1_
.
Size
());
delete
n
;
delete
n
;
n
=
q2_
.
Dequeue
();
n
=
q2_
.
Dequeue
();
ASSERT_TRUE
(
n
!=
NULL
);
ASSERT_TRUE
(
n
!=
NULL
);
EXPECT_EQ
(
2
,
*
n
);
EXPECT_EQ
(
2
,
*
n
);
EXPECT_EQ
(
1
,
q2_
.
Size
());
EXPECT_EQ
(
1
u
,
q2_
.
Size
());
delete
n
;
delete
n
;
}
}
...
...
samples/sample5_unittest.cc
View file @
fe787609
...
@@ -171,24 +171,24 @@ class QueueTest : public QuickTest {
...
@@ -171,24 +171,24 @@ class QueueTest : public QuickTest {
// Tests the default constructor.
// Tests the default constructor.
TEST_F
(
QueueTest
,
DefaultConstructor
)
{
TEST_F
(
QueueTest
,
DefaultConstructor
)
{
EXPECT_EQ
(
0
,
q0_
.
Size
());
EXPECT_EQ
(
0
u
,
q0_
.
Size
());
}
}
// Tests Dequeue().
// Tests Dequeue().
TEST_F
(
QueueTest
,
Dequeue
)
{
TEST_F
(
QueueTest
,
Dequeue
)
{
int
*
n
=
q0_
.
Dequeue
();
int
*
n
=
q0_
.
Dequeue
();
EXPECT_TRUE
(
n
==
NULL
);
EXPECT_TRUE
(
n
==
NULL
);
n
=
q1_
.
Dequeue
();
n
=
q1_
.
Dequeue
();
EXPECT_TRUE
(
n
!=
NULL
);
EXPECT_TRUE
(
n
!=
NULL
);
EXPECT_EQ
(
1
,
*
n
);
EXPECT_EQ
(
1
,
*
n
);
EXPECT_EQ
(
0
,
q1_
.
Size
());
EXPECT_EQ
(
0
u
,
q1_
.
Size
());
delete
n
;
delete
n
;
n
=
q2_
.
Dequeue
();
n
=
q2_
.
Dequeue
();
EXPECT_TRUE
(
n
!=
NULL
);
EXPECT_TRUE
(
n
!=
NULL
);
EXPECT_EQ
(
2
,
*
n
);
EXPECT_EQ
(
2
,
*
n
);
EXPECT_EQ
(
1
,
q2_
.
Size
());
EXPECT_EQ
(
1
u
,
q2_
.
Size
());
delete
n
;
delete
n
;
}
}
...
...
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