Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-cppinttest
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue 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
caosdb
Software
caosdb-cppinttest
Commits
c7b84d36
Verified
Commit
c7b84d36
authored
3 years ago
by
Timm Fitschen
Browse files
Options
Downloads
Patches
Plain Diff
DRAFT: setup tests with conan
parent
076b79ca
No related branches found
No related tags found
No related merge requests found
Pipeline
#9841
failed
3 years ago
Stage: info
Stage: setup
Stage: build
Stage: test
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
test/CMakeLists.txt
+44
-5
44 additions, 5 deletions
test/CMakeLists.txt
test/test_connection.cpp
+27
-32
27 additions, 32 deletions
test/test_connection.cpp
with
71 additions
and
37 deletions
test/CMakeLists.txt
+
44
−
5
View file @
c7b84d36
...
...
@@ -18,15 +18,51 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# append all the test cases here (file name without the ".cpp" suffix)
#######################################################################
### append test cases here (file name without the ".cpp" suffix)
#######################################################################
set
(
test_cases
test_connection
)
#find_package(caosdb REQUIRED)
#message(STATUS "Found libcaosdb: ${caosdb_DIR}")
#######################################################
### Linting with clang-tidy and include-what-you-use
#######################################################
option
(
LINTING
"clang-tidy and iwye"
ON
)
if
(
LINTING
)
find_program
(
iwyu
NAMES include-what-you-use iwyu
PATHS
${
CMAKE_SOURCE_DIR
}
/tools/include-what-you-use/
${
iwyu_os
}
/bin
)
if
(
NOT iwyu
)
message
(
WARNING
"include-what-you-use: Not found"
)
else
()
message
(
STATUS
"include-what-you-use:
${
iwyu
}
"
)
set
(
_CMAKE_CXX_INCLUDE_WHAT_YOU_USE
${
iwyu
}
"-Xiwyu"
"--no_fwd_decls"
"-Xiwyu"
"--cxx17ns"
)
endif
()
find_program
(
clang_tidy NAMES clang-tidy clang-tidy-11
)
if
(
NOT clang_tidy
)
message
(
WARNING
"clang-tidy: Not found"
)
else
()
message
(
STATUS
"clang-tidy:
${
clang_tidy
}
"
)
set
(
_CMAKE_CXX_CLANG_TIDY
"
${
clang_tidy
}
"
"--header-filter=caosdb/.*[^
\(
\.pb\.h
\)
]$"
"--warnings-as-errors=*"
"--fix"
)
set
(
_CMAKE_CXX_CLANG_TIDY_CHECKS
"--checks=*,-fuchsia-*,-llvm-include-order,-llvmlibc-*,-cert-err58-cpp,-cppcoreguidelines-avoid-non-const-global-variables,-cppcoreguidelines-owning-memory,-modernize-use-trailing-return-type,-google-readability-avoid-underscore-in-googletest-name,-cppcoreguidelines-avoid-magic-numbers,-readability-magic-numbers,-cppcoreguidelines-avoid-goto,-hicpp-avoid-goto"
)
endif
()
else
()
message
(
STATUS
"LINTING is OFF"
)
endif
()
###################################################
### Set up tests using GoogleTest (GTest)
###################################################
#include(FetchGTest)
# add special cmake functions for gtest
include
(
GoogleTest REQUIRED
)
...
...
@@ -41,7 +77,10 @@ foreach (i RANGE "${len_test_cases}")
${
CONAN_LIBS_OPENSSL
}
${
CONAN_LIBS_C-ARES
}
${
CONAN_LIBS_BZIP2
}
${
CONAN_LIBS_PROTOBUF
}
${
CONAN_LIBS_ZLIB
}
)
target_include_directories
(
${
test_case_name
}
PUBLIC
${
CONAN_INCLUDE_DIRS
}
)
set_target_properties
(
${
test_case_name
}
PROPERTIES CXX_CLANG_TIDY
""
)
set_target_properties
(
${
test_case_name
}
PROPERTIES
CXX_CLANG_TIDY
"
${
_CMAKE_CXX_CLANG_TIDY
}
;
${
_CMAKE_CXX_CLANG_TIDY_CHECKS
}
"
CXX_INCLUDE_WHAT_YOU_USE
"
${
_CMAKE_CXX_INCLUDE_WHAT_YOU_USE
}
"
)
gtest_discover_tests
(
${
test_case_name
}
PROPERTIES
LABELS
"caosdb-cpplib-int-tests"
)
...
...
This diff is collapsed.
Click to expand it.
test/test_connection.cpp
+
27
−
32
View file @
c7b84d36
...
...
@@ -19,67 +19,60 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#include
"caosdb/connection.h"
#include
"caosdb/authentication.h"
#include
<gtest/gtest-message.h>
#include
<gtest/gtest-test-part.h>
#include
<memory>
#include
"gtest/gtest_pred_impl.h"
#include
"caosdb/utils.h"
using
caosdb
::
connection
::
InsecureCaosDBConnectionConfig
;
using
caosdb
::
connection
::
SslCaosDBConnectionConfig
;
using
caosdb
::
connection
::
PemFileCACertProvider
;
using
caosdb
::
connection
::
CaosDBConnection
;
#include
<gtest/gtest-message.h>
// for Message
#include
<gtest/gtest-test-part.h>
// for SuiteApiResolver, TestPartResult
#include
<memory>
// for make_shared, allocator, shared_ptr
#include
<string>
// for string
#include
"caosdb/authentication.h"
// for PlainPasswordAuthenticator
#include
"caosdb/connection.h"
// for InsecureCaosDBConnectionConfig
#include
"caosdb/exceptions.h"
// for AuthenticationError, ConnectionError
#include
"caosdb/info.h"
// for VersionInfo
#include
"caosdb/utils.h"
// for get_env_var
#include
"gtest/gtest_pred_impl.h"
// for Test, TEST, EXPECT_EQ, EXPECT_THROW
namespace
caosdb
::
connection
{
using
caosdb
::
exceptions
::
AuthenticationError
;
using
caosdb
::
exceptions
::
ConnectionError
;
using
caosdb
::
authentication
::
PlainPasswordAuthenticator
;
using
caosdb
::
info
::
v1alpha1
::
VersionInfo
;
TEST
(
test_connection
,
config_somehost_25323
)
{
auto
port
=
25323
;
auto
h
ost
=
"somehost"
;
auto
config
=
std
::
make_unique
<
InsecureCaosDBConnectionConfig
>
(
h
ost
,
port
);
const
auto
*
pH
ost
=
"somehost"
;
auto
config
=
std
::
make_unique
<
InsecureCaosDBConnectionConfig
>
(
pH
ost
,
port
);
ASSER
T_EQ
(
h
ost
,
config
->
getHost
());
ASSER
T_EQ
(
port
,
config
->
getPort
());
EXPEC
T_EQ
(
pH
ost
,
config
->
getHost
());
EXPEC
T_EQ
(
port
,
config
->
getPort
());
}
TEST
(
test_connection
,
connect_somehost_42347_fails
)
{
auto
port
=
42347
;
auto
h
ost
=
"somehost"
;
auto
config
=
std
::
make_shared
<
InsecureCaosDBConnectionConfig
>
(
h
ost
,
port
);
const
auto
*
pH
ost
=
"somehost"
;
auto
config
=
std
::
make_shared
<
InsecureCaosDBConnectionConfig
>
(
pH
ost
,
port
);
CaosDBConnection
connection
(
config
);
// TODO ConnectionError
ASSERT_THROW
(
connection
.
getVersionInfo
(),
std
::
runtime_error
);
EXPECT_THROW
(
connection
.
getVersionInfo
(),
ConnectionError
);
}
TEST
(
test_connection
,
connection_insecure_authentication_error
)
{
auto
port
=
8080
;
const
auto
host
=
caosdb
::
utils
::
get_env_var
(
"CAOSDB_SERVER_HOST"
,
"localhost"
);
auto
major
=
0
;
auto
minor
=
5
;
auto
config
=
std
::
make_shared
<
InsecureCaosDBConnectionConfig
>
(
host
,
port
);
auto
connection
=
CaosDBConnection
(
config
);
// TODO AuthenticationError
ASSERT_THROW
(
connection
.
getVersionInfo
(),
std
::
runtime_error
);
EXPECT_THROW
(
connection
.
getVersionInfo
(),
AuthenticationError
);
}
TEST
(
test_connection
,
connection_ssl_authentication_error
)
{
auto
port
=
8443
;
const
auto
host
=
caosdb
::
utils
::
get_env_var
(
"CAOSDB_SERVER_HOST"
,
"localhost"
);
const
auto
path
=
caosdb
::
utils
::
get_env_var
(
"CAOSDB_SERVER_CA_PEM"
,
std
::
string
());
auto
major
=
0
;
auto
minor
=
5
;
auto
ssloptions
=
std
::
make_shared
<
PemFileCACertProvider
>
(
path
);
auto
config
=
std
::
make_shared
<
SslCaosDBConnectionConfig
>
(
host
,
port
,
ssloptions
);
auto
connection
=
CaosDBConnection
(
config
);
// TODO AuthenticationError
ASSERT_THROW
(
connection
.
getVersionInfo
(),
std
::
runtime_error
);
EXPECT_THROW
(
connection
.
getVersionInfo
(),
AuthenticationError
);
}
TEST
(
test_connection
,
connection_ssl_authentication_success
)
{
...
...
@@ -98,6 +91,8 @@ TEST(test_connection, connection_ssl_authentication_success) {
auto
connection
=
CaosDBConnection
(
config
);
auto
v_info
=
connection
.
getVersionInfo
();
ASSER
T_EQ
(
major
,
v_info
.
m
ajor
());
ASSER
T_EQ
(
minor
,
v_info
.
m
inor
());
EXPEC
T_EQ
(
major
,
v_info
->
GetM
ajor
());
EXPEC
T_EQ
(
minor
,
v_info
->
GetM
inor
());
}
}
//namespace caosdb::connection
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