Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cta
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dCache
cta
Commits
aebd9461
Commit
aebd9461
authored
11 years ago
by
Steven Murray
Browse files
Options
Downloads
Patches
Plain Diff
Added the following unit test:
castor/utils/UtilsTest.
parent
06a7a1d0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
castor/server/DaemonTest.cpp
+1
-1
1 addition, 1 deletion
castor/server/DaemonTest.cpp
castor/utils/UtilsTest.cpp
+203
-0
203 additions, 0 deletions
castor/utils/UtilsTest.cpp
test/CMakeLists.txt
+1
-0
1 addition, 0 deletions
test/CMakeLists.txt
with
205 additions
and
1 deletion
castor/server/DaemonTest.cpp
+
1
−
1
View file @
aebd9461
...
...
@@ -19,7 +19,7 @@
*
*
*
* @author
Castor Dev team, castor-dev
@cern.ch
* @author
Steven.Murray
@cern.ch
*****************************************************************************/
#include
"castor/log/DummyLogger.hpp"
...
...
This diff is collapsed.
Click to expand it.
castor/utils/UtilsTest.cpp
0 → 100644
+
203
−
0
View file @
aebd9461
/******************************************************************************
* castor/utils/UtilsTest.cpp
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
* @author Steven.Murray@cern.ch
*****************************************************************************/
#include
"castor/utils/utils.hpp"
#include
<gtest/gtest.h>
#include
<list>
#include
<stdlib.h>
#include
<string>
#include
<sys/time.h>
#include
<unistd.h>
#include
<vector>
namespace
UnitTests
{
/**
* Tests the good day senario of passing a multi-column string to the
* splitString() method.
*/
TEST
(
castor_utils
,
testGoodDaySplitString
)
{
using
namespace
castor
::
utils
;
const
std
::
string
line
(
"col0 col1 col2 col3 col4 col5 col6 col7"
);
std
::
vector
<
std
::
string
>
columns
;
ASSERT_NO_THROW
(
splitString
(
line
,
' '
,
columns
));
ASSERT_EQ
((
std
::
vector
<
std
::
string
>::
size_type
)
8
,
columns
.
size
());
ASSERT_EQ
(
std
::
string
(
"col0"
),
columns
[
0
]);
ASSERT_EQ
(
std
::
string
(
"col1"
),
columns
[
1
]);
ASSERT_EQ
(
std
::
string
(
"col2"
),
columns
[
2
]);
ASSERT_EQ
(
std
::
string
(
"col3"
),
columns
[
3
]);
ASSERT_EQ
(
std
::
string
(
"col4"
),
columns
[
4
]);
ASSERT_EQ
(
std
::
string
(
"col5"
),
columns
[
5
]);
ASSERT_EQ
(
std
::
string
(
"col6"
),
columns
[
6
]);
ASSERT_EQ
(
std
::
string
(
"col7"
),
columns
[
7
]);
}
/**
* Test the case of an empty string being passed to the splitString() method.
*/
TEST
(
castor_utls
,
testSplitStringWithEmptyString
)
{
using
namespace
castor
::
utils
;
const
std
::
string
emptyString
;
std
::
vector
<
std
::
string
>
columns
;
ASSERT_NO_THROW
(
splitString
(
emptyString
,
' '
,
columns
));
ASSERT_EQ
((
std
::
vector
<
std
::
string
>::
size_type
)
0
,
columns
.
size
());
}
/**
* Test the case of a non-empty string containing no separator character
* passed to the splitString() method.
*/
TEST
(
castor_utils
,
testSplitStringWithNoSeparatorInString
)
{
using
namespace
castor
::
utils
;
const
std
::
string
stringContainingNoSeparator
=
"stringContainingNoSeparator"
;
std
::
vector
<
std
::
string
>
columns
;
ASSERT_NO_THROW
(
splitString
(
stringContainingNoSeparator
,
' '
,
columns
));
ASSERT_EQ
((
std
::
vector
<
std
::
string
>::
size_type
)
1
,
columns
.
size
());
ASSERT_EQ
(
stringContainingNoSeparator
,
columns
[
0
]);
}
TEST
(
castor_utils
,
testTimevalGreaterThan_BigSecSmallSec_BigUsecSmallUsec
)
{
using
namespace
castor
::
utils
;
const
timeval
bigger
=
{
6
,
5
};
const
timeval
smaller
=
{
5
,
4
};
const
bool
expected
=
true
;
ASSERT_EQ
(
expected
,
timevalGreaterThan
(
bigger
,
smaller
));
}
TEST
(
castor_utils
,
testTimevalGreaterThan_BigSecSmallSec_BigUsecSmallUsec_swapped
)
{
using
namespace
castor
::
utils
;
const
timeval
bigger
=
{
6
,
5
};
const
timeval
smaller
=
{
5
,
4
};
const
bool
expected
=
false
;
ASSERT_EQ
(
expected
,
timevalGreaterThan
(
smaller
,
bigger
));
}
TEST
(
castor_utils
,
testTimevalGreaterThan_BigSecSmallSec_SmallUsecBigUsec
)
{
using
namespace
castor
::
utils
;
const
timeval
bigger
=
{
4
,
3
};
const
timeval
smaller
=
{
2
,
7
};
const
bool
expected
=
true
;
ASSERT_EQ
(
expected
,
timevalGreaterThan
(
bigger
,
smaller
));
}
TEST
(
castor_utils
,
testTimevalGreaterThan_BigSecSmallSec_SmallUsecBigUsec_swapped
)
{
using
namespace
castor
::
utils
;
const
timeval
bigger
=
{
4
,
3
};
const
timeval
smaller
=
{
2
,
7
};
const
bool
expected
=
false
;
ASSERT_EQ
(
expected
,
timevalGreaterThan
(
smaller
,
bigger
));
}
TEST
(
castor_utils
,
testTimevalGreaterThan_EqualSec_EqualUsec
)
{
using
namespace
castor
::
utils
;
const
timeval
a
=
{
8
,
9
};
const
timeval
b
=
{
8
,
9
};
const
bool
expected
=
false
;
ASSERT_EQ
(
expected
,
timevalGreaterThan
(
a
,
b
));
}
TEST
(
castor_utils
,
testTimevalAbsDiff_BigSecSmallSec_BigUsecSmallUsec
)
{
using
namespace
castor
::
utils
;
const
timeval
bigger
=
{
6
,
5
};
const
timeval
smaller
=
{
5
,
4
};
const
timeval
expected
=
{
1
,
1
};
const
timeval
actual
=
timevalAbsDiff
(
bigger
,
smaller
);
const
bool
isAMatch
=
expected
.
tv_sec
==
actual
.
tv_sec
&&
expected
.
tv_usec
==
actual
.
tv_usec
;
ASSERT_EQ
(
true
,
isAMatch
);
}
TEST
(
castor_utils
,
testTimevalAbsDiff_BigSecSmallSec_BigUsecSmallUsec_swapped
)
{
using
namespace
castor
::
utils
;
const
timeval
bigger
=
{
6
,
5
};
const
timeval
smaller
=
{
5
,
4
};
const
timeval
expected
=
{
1
,
1
};
const
timeval
actual
=
timevalAbsDiff
(
smaller
,
bigger
);
const
bool
isAMatch
=
expected
.
tv_sec
==
actual
.
tv_sec
&&
expected
.
tv_usec
==
actual
.
tv_usec
;
ASSERT_EQ
(
true
,
isAMatch
);
}
TEST
(
castor_utils
,
testTimevalAbsDiff_BigSecSmallSec_SmallUsecBigUsec
)
{
using
namespace
castor
::
utils
;
const
timeval
bigger
=
{
4
,
3
};
const
timeval
smaller
=
{
2
,
7
};
const
timeval
expected
=
{
1
,
999996
};
const
timeval
actual
=
timevalAbsDiff
(
bigger
,
smaller
);
const
bool
isAMatch
=
expected
.
tv_sec
==
actual
.
tv_sec
&&
expected
.
tv_usec
==
actual
.
tv_usec
;
ASSERT_EQ
(
true
,
isAMatch
);
}
TEST
(
castor_utils
,
testTimevalAbsDiff_BigSecSmallSec_SmallUsecBigUsec_swapped
)
{
using
namespace
castor
::
utils
;
const
timeval
bigger
=
{
4
,
3
};
const
timeval
smaller
=
{
2
,
7
};
const
timeval
expected
=
{
1
,
999996
};
const
timeval
actual
=
timevalAbsDiff
(
smaller
,
bigger
);
const
bool
isAMatch
=
expected
.
tv_sec
==
actual
.
tv_sec
&&
expected
.
tv_usec
==
actual
.
tv_usec
;
ASSERT_EQ
(
true
,
isAMatch
);
}
TEST
(
castor_utils
,
testTimevalAbsDiff_EqualSec_EqualUsec
)
{
using
namespace
castor
::
utils
;
const
timeval
a
=
{
8
,
9
};
const
timeval
b
=
{
8
,
9
};
const
timeval
expected
=
{
0
,
0
};
const
timeval
actual
=
timevalAbsDiff
(
a
,
b
);
const
bool
isAMatch
=
expected
.
tv_sec
==
actual
.
tv_sec
&&
expected
.
tv_usec
==
actual
.
tv_usec
;
ASSERT_EQ
(
true
,
isAMatch
);
}
TEST
(
castor_utils
,
testTimevalToDouble
)
{
using
namespace
castor
::
utils
;
const
timeval
tv
=
{
1234
,
999992
};
const
double
expected
=
1234.999992
;
const
double
actual
=
timevalToDouble
(
tv
);
ASSERT_EQ
(
expected
,
actual
);
}
}
// namespace UnitTests
This diff is collapsed.
Click to expand it.
test/CMakeLists.txt
+
1
−
0
View file @
aebd9461
...
...
@@ -35,6 +35,7 @@ add_executable(castorUnitTests
../castor/tape/tapeserver/exception/ExceptionTest.cpp
../castor/tape/tapeserver/file/StructuresTest.cpp
../castor/tape/tapeserver/threading/ThreadingTests.cpp
../castor/utils/UtilsTest.cpp
)
set_property
(
SOURCE ../SCSI/StructuresTest.cpp
PROPERTY COMPILE_FLAGS -fno-strict-aliasing
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment