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
566456e9
Commit
566456e9
authored
8 years ago
by
Steven Murray
Browse files
Options
Downloads
Patches
Plain Diff
Added PollDatabaseCmdLineArgsTest unit-tests
parent
c1b06cd0
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
catalogue/CMakeLists.txt
+2
-0
2 additions, 0 deletions
catalogue/CMakeLists.txt
catalogue/PollDatabaseCmdLineArgs.cpp
+3
-2
3 additions, 2 deletions
catalogue/PollDatabaseCmdLineArgs.cpp
catalogue/PollDatabaseCmdLineArgsTest.cpp
+125
-0
125 additions, 0 deletions
catalogue/PollDatabaseCmdLineArgsTest.cpp
with
130 additions
and
2 deletions
catalogue/CMakeLists.txt
+
2
−
0
View file @
566456e9
...
...
@@ -228,6 +228,8 @@ set (CATALOGUE_CMD_LINE_UNIT_TESTS_LIB_SRC_FILES
DropSchemaCmdLineArgsTest.cpp
LockSchemaCmdLineArgs.cpp
LockSchemaCmdLineArgsTest.cpp
PollDatabaseCmdLineArgs.cpp
PollDatabaseCmdLineArgsTest.cpp
UnlockSchemaCmdLineArgs.cpp
UnlockSchemaCmdLineArgsTest.cpp
)
...
...
This diff is collapsed.
Click to expand it.
catalogue/PollDatabaseCmdLineArgs.cpp
+
3
−
2
View file @
566456e9
...
...
@@ -31,7 +31,8 @@ namespace catalogue {
// constructor
//------------------------------------------------------------------------------
PollDatabaseCmdLineArgs
::
PollDatabaseCmdLineArgs
(
const
int
argc
,
char
*
const
*
const
argv
)
:
help
(
false
)
{
help
(
false
),
numberOfSecondsToKeepPolling
(
0
)
{
static
struct
option
longopts
[]
=
{
{
"help"
,
no_argument
,
NULL
,
'h'
},
...
...
@@ -86,7 +87,7 @@ PollDatabaseCmdLineArgs::PollDatabaseCmdLineArgs(const int argc, char *const *co
// Check the number of arguments
if
(
nbArgs
!=
2
)
{
exception
::
CommandLineNotParsed
ex
;
ex
.
getMessage
()
<<
"Wrong number of command-line arguments: excepted=
1
actual="
<<
nbArgs
;
ex
.
getMessage
()
<<
"Wrong number of command-line arguments: excepted=
2
actual="
<<
nbArgs
;
throw
ex
;
}
...
...
This diff is collapsed.
Click to expand it.
catalogue/PollDatabaseCmdLineArgsTest.cpp
0 → 100644
+
125
−
0
View file @
566456e9
/*
* The CERN Tape Archive(CTA) project
* Copyright(C) 2015 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#include
"common/exception/Exception.hpp"
#include
"catalogue/PollDatabaseCmdLineArgs.hpp"
#include
<gtest/gtest.h>
#include
<list>
namespace
unitTests
{
class
cta_catalogue_PollDatabaseCmdLineArgsTest
:
public
::
testing
::
Test
{
protected:
struct
Argcv
{
int
argc
;
char
**
argv
;
Argcv
()
:
argc
(
0
),
argv
(
NULL
)
{
}
};
typedef
std
::
list
<
Argcv
*>
ArgcvList
;
ArgcvList
m_argsList
;
/**
* Creates a duplicate string using the new operator.
*/
char
*
dupString
(
const
char
*
str
)
{
const
size_t
len
=
strlen
(
str
);
char
*
duplicate
=
new
char
[
len
+
1
];
strncpy
(
duplicate
,
str
,
len
);
duplicate
[
len
]
=
'\0'
;
return
duplicate
;
}
virtual
void
SetUp
()
{
// Allow getopt_long to be called again
optind
=
0
;
}
virtual
void
TearDown
()
{
// Allow getopt_long to be called again
optind
=
0
;
for
(
ArgcvList
::
const_iterator
itor
=
m_argsList
.
begin
();
itor
!=
m_argsList
.
end
();
itor
++
)
{
for
(
int
i
=
0
;
i
<
(
*
itor
)
->
argc
;
i
++
)
{
delete
[]
(
*
itor
)
->
argv
[
i
];
}
delete
[]
(
*
itor
)
->
argv
;
delete
*
itor
;
}
}
};
TEST_F
(
cta_catalogue_PollDatabaseCmdLineArgsTest
,
help_short
)
{
using
namespace
cta
::
catalogue
;
Argcv
*
args
=
new
Argcv
();
m_argsList
.
push_back
(
args
);
args
->
argc
=
2
;
args
->
argv
=
new
char
*
[
3
];
args
->
argv
[
0
]
=
dupString
(
"cta-database-poll"
);
args
->
argv
[
1
]
=
dupString
(
"-h"
);
args
->
argv
[
2
]
=
NULL
;
PollDatabaseCmdLineArgs
cmdLine
(
args
->
argc
,
args
->
argv
);
ASSERT_TRUE
(
cmdLine
.
help
);
ASSERT_TRUE
(
cmdLine
.
dbConfigPath
.
empty
());
ASSERT_EQ
(
0
,
cmdLine
.
numberOfSecondsToKeepPolling
);
}
TEST_F
(
cta_catalogue_PollDatabaseCmdLineArgsTest
,
help_long
)
{
using
namespace
cta
::
catalogue
;
Argcv
*
args
=
new
Argcv
();
m_argsList
.
push_back
(
args
);
args
->
argc
=
2
;
args
->
argv
=
new
char
*
[
3
];
args
->
argv
[
0
]
=
dupString
(
"cta-database-poll"
);
args
->
argv
[
1
]
=
dupString
(
"--help"
);
args
->
argv
[
2
]
=
NULL
;
PollDatabaseCmdLineArgs
cmdLine
(
args
->
argc
,
args
->
argv
);
ASSERT_TRUE
(
cmdLine
.
help
);
ASSERT_TRUE
(
cmdLine
.
dbConfigPath
.
empty
());
ASSERT_EQ
(
0
,
cmdLine
.
numberOfSecondsToKeepPolling
);
}
TEST_F
(
cta_catalogue_PollDatabaseCmdLineArgsTest
,
all_args
)
{
using
namespace
cta
::
catalogue
;
Argcv
*
args
=
new
Argcv
();
m_argsList
.
push_back
(
args
);
args
->
argc
=
3
;
args
->
argv
=
new
char
*
[
4
];
args
->
argv
[
0
]
=
dupString
(
"cta-database-poll"
);
args
->
argv
[
1
]
=
dupString
(
"dbConfigPath"
);
args
->
argv
[
2
]
=
dupString
(
"1234"
);
args
->
argv
[
3
]
=
NULL
;
PollDatabaseCmdLineArgs
cmdLine
(
args
->
argc
,
args
->
argv
);
ASSERT_FALSE
(
cmdLine
.
help
);
ASSERT_EQ
(
std
::
string
(
"dbConfigPath"
),
cmdLine
.
dbConfigPath
);
ASSERT_EQ
(
1234
,
cmdLine
.
numberOfSecondsToKeepPolling
);
}
}
// namespace unitTests
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