Skip to content

Commit 550e357

Browse files
committed
WL15081: Add connector version macros
Change-Id: Ic1457b9b9178647ca17ce21ca39058b20063aa30
1 parent 4d53c5a commit 550e357

File tree

4 files changed

+53
-18
lines changed

4 files changed

+53
-18
lines changed

VersionInfo.cmake.in

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved.
22
#
33
# This program is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License, version 2.0, as
@@ -27,6 +27,8 @@
2727
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2828

2929

30+
SET(CONCPP_VERSION "@CONCPP_VERSION@")
31+
SET(CONCPP_VERSION_NUMBER @CONCPP_VERSION_NUMBER@)
3032
SET(CONNECTOR_MAJOR "@CONCPP_VERSION_MAJOR@")
3133
SET(CONNECTOR_MINOR "@CONCPP_VERSION_MINOR@")
3234
SET(CONNECTOR_PATCH "@CONCPP_VERSION_MICRO@")
@@ -36,18 +38,6 @@ SET(CONNECTOR_QUALITY "GA")
3638
# Bump this every time we change the API/ABI
3739
SET(MYSQLCPPCONN_SOVERSION "@JDBC_ABI_VERSION_MAJOR@")
3840

39-
IF(CONNECTOR_MINOR LESS 10)
40-
SET(CONNECTOR_MINOR_PADDED "0${CONNECTOR_MINOR}")
41-
ELSE(CONNECTOR_MINOR LESS 10)
42-
SET(CONNECTOR_MINOR_PADDED "${CONNECTOR_MINOR}")
43-
ENDIF(CONNECTOR_MINOR LESS 10)
44-
45-
# If driver survives 100th patch this has to be changed
46-
IF(CONNECTOR_PATCH LESS 10)
47-
SET(CONNECTOR_PATCH_PADDED "000${CONNECTOR_PATCH}")
48-
ELSE(CONNECTOR_PATCH LESS 10)
49-
SET(CONNECTOR_PATCH_PADDED "00${CONNECTOR_PATCH}")
50-
ENDIF(CONNECTOR_PATCH LESS 10)
5141

5242
SET(CONNECTOR_BASE_VERSION "${CONNECTOR_MAJOR}.${CONNECTOR_MINOR}")
5343
SET(CONNECTOR_BASE_PREVIOUS "1.0")

cppconn/version_info.h.cmake

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program is free software; you can redistribute it and/or modify
55
* it under the terms of the GNU General Public License, version 2.0, as
@@ -34,8 +34,14 @@
3434
#define MYCPPCONN_DM_MINOR_VERSION @CONNECTOR_MINOR@
3535
#define MYCPPCONN_DM_PATCH_VERSION @CONNECTOR_PATCH@
3636

37-
#define MYCPPCONN_DM_VERSION "@CONNECTOR_MAJOR@.@CONNECTOR_MINOR_PADDED@.@CONNECTOR_PATCH_PADDED@"
38-
#define MYCPPCONN_DM_VERSION_ID @CONNECTOR_MAJOR@@CONNECTOR_MINOR_PADDED@@CONNECTOR_PATCH_PADDED@
37+
#define MYCPPCONN_DM_VERSION "@CONCPP_VERSION@"
38+
#define MYCPPCONN_DM_VERSION_ID @CONCPP_VERSION_NUMBER@
39+
40+
#define MYSQL_CONCPP_VERSION_MAJOR @CONNECTOR_MAJOR@
41+
#define MYSQL_CONCPP_VERSION_MINOR @CONNECTOR_MINOR@
42+
#define MYSQL_CONCPP_VERSION_MICRO @CONNECTOR_PATCH@
43+
44+
#define MYSQL_CONCPP_VERSION_NUMBER @CONCPP_VERSION_NUMBER@
3945

4046

4147
/* Driver version info */

test/unit/classes/connection.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4254,7 +4254,41 @@ void connection::normalize_ssl_options()
42544254

42554255
}
42564256

4257+
void connection::macro_version()
4258+
{/*
4259+
Check if version is set and correct
4260+
*/
4261+
#if !defined(MYSQL_CONCPP_VERSION_NUMBER)
4262+
SKIP("MYSQL_CONCPP_VERSION_NUMBER macro not defined");
4263+
#else
4264+
4265+
#if !defined(MYSQL_CONCPP_VERSION_MAJOR)
4266+
FAIL("MYSQL_CONCPP_VERSION_MAJOR macro not defined");
4267+
#elif !defined(MYSQL_CONCPP_VERSION_MINOR)
4268+
FAIL("MYSQL_CONCPP_VERSION_MINOR macro not defined");
4269+
#elif !defined(MYSQL_CONCPP_VERSION_MICRO)
4270+
FAIL("MYSQL_CONCPP_VERSION_MICRO macro not defined");
4271+
#endif
4272+
4273+
ASSERT_EQUALS(MYSQL_CONCPP_VERSION_NUMBER, MYCPPCONN_DM_VERSION_ID);
4274+
4275+
std::stringstream version_orig, version_generated, version_old;
4276+
4277+
version_orig << std::setfill('0')
4278+
<< MYSQL_CONCPP_VERSION_MAJOR
4279+
<< std::setw(2) << MYSQL_CONCPP_VERSION_MINOR
4280+
<< std::setw(4) << MYSQL_CONCPP_VERSION_MICRO;
42574281

4282+
version_generated << MYSQL_CONCPP_VERSION_NUMBER;
4283+
4284+
version_old << MYCPPCONN_DM_VERSION_ID;
4285+
4286+
ASSERT_EQUALS(version_orig.str(), version_generated.str());
4287+
4288+
ASSERT_EQUALS(version_orig.str(), version_old.str());
4289+
4290+
#endif
4291+
}
42584292

42594293
} /* namespace connection */
42604294
} /* namespace testsuite */

test/unit/classes/connection.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class connection : public unit_fixture
9898
TEST_CASE(tls_deprecation);
9999
TEST_CASE(fido_test);
100100
TEST_CASE(normalize_ssl_options);
101+
TEST_CASE(macro_version);
101102
}
102103

103104
/**
@@ -307,16 +308,20 @@ class connection : public unit_fixture
307308
*
308309
*/
309310
void normalize_ssl_options();
310-
311+
311312
/*
312313
* Test for checking fido connection.
313314
*
314315
*/
315316
void fido_test();
316317

318+
/*
319+
* Test version macros.
320+
*
321+
*/
322+
void macro_version();
317323
};
318324

319-
320325
REGISTER_FIXTURE(connection);
321326
} /* namespace classes */
322327
} /* namespace testsuite */

0 commit comments

Comments
 (0)