CJCombrink | 4b90909 | 2024-04-27 19:51:39 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | |
| 20 | #include <boost/test/unit_test.hpp> |
| 21 | |
| 22 | BOOST_AUTO_TEST_SUITE(TUuidBoostTestNoDirective) |
| 23 | |
| 24 | BOOST_AUTO_TEST_CASE(compiler_directive_not_set) { |
| 25 | // Test if the macro is set as expected |
| 26 | #ifdef THRIFT_TUUID_SUPPORT_BOOST_UUID |
| 27 | BOOST_TEST(false, "The 'THRIFT_TUUID_SUPPORT_BOOST_UUID' preprocessor must NOT be set for these tests"); |
| 28 | #else |
| 29 | BOOST_TEST(true); |
| 30 | #endif // THRIFT_TUUID_SUPPORT_BOOST_UUID |
| 31 | } |
| 32 | BOOST_AUTO_TEST_SUITE_END() |
| 33 | |
| 34 | // This inclusion order is unconventional: This test specifcially tests that |
| 35 | // the THRIFT_TUUID_SUPPORT_BOOST_UUID directive can be set before including the header |
| 36 | // to enable boost::uuid support without causing linking or other errors with |
| 37 | // the compiled thrift library. |
| 38 | |
| 39 | #define THRIFT_TUUID_SUPPORT_BOOST_UUID |
| 40 | #define THRIFT_TUUID_BOOST_CONSTRUCTOR_EXPLICIT |
| 41 | |
| 42 | #include <boost/uuid/uuid_io.hpp> |
| 43 | #include <boost/uuid/string_generator.hpp> |
| 44 | |
| 45 | #include <thrift/TUuid.h> |
| 46 | using apache::thrift::TUuid; |
| 47 | |
| 48 | BOOST_AUTO_TEST_SUITE(TUuidBoostTestNoDirective) |
| 49 | |
| 50 | BOOST_AUTO_TEST_CASE(compiler_directive_set) { |
| 51 | // Test if the macro is set as expected |
| 52 | #ifdef THRIFT_TUUID_SUPPORT_BOOST_UUID |
| 53 | BOOST_TEST(true); |
| 54 | #else |
| 55 | BOOST_TEST(false, "The 'THRIFT_TUUID_SUPPORT_BOOST_UUID' preprocessor must now be set for these tests"); |
| 56 | #endif // THRIFT_TUUID_SUPPORT_BOOST_UUID |
| 57 | } |
| 58 | |
| 59 | BOOST_AUTO_TEST_CASE(from_boost_uuid_constructor) { |
| 60 | static boost::uuids::string_generator gen; |
| 61 | boost::uuids::uuid boost_uuid{gen("5cb719a4-cd15-4476-8bcc-f1834b2527ee")}; |
| 62 | BOOST_TEST(!boost_uuid.is_nil()); |
| 63 | const TUuid uuid{boost_uuid}; |
| 64 | BOOST_TEST(!uuid.is_nil()); |
| 65 | |
| 66 | BOOST_TEST(to_string(boost_uuid) == to_string(uuid)); |
| 67 | BOOST_TEST(to_string(uuid) == std::string{"5cb719a4-cd15-4476-8bcc-f1834b2527ee"}); |
| 68 | } |
| 69 | |
| 70 | BOOST_AUTO_TEST_CASE(from_boost_uuid_assignment) { |
| 71 | static boost::uuids::string_generator gen; |
| 72 | boost::uuids::uuid boost_uuid{gen("1f610073-db33-4d21-adf2-75460d4955cc")}; |
| 73 | BOOST_TEST(!boost_uuid.is_nil()); |
| 74 | TUuid uuid{}; |
| 75 | BOOST_TEST(uuid.is_nil()); |
| 76 | |
| 77 | uuid = TUuid{boost_uuid}; |
| 78 | |
| 79 | BOOST_TEST(to_string(boost_uuid) == to_string(uuid)); |
| 80 | BOOST_TEST(to_string(uuid) == std::string{"1f610073-db33-4d21-adf2-75460d4955cc"}); |
| 81 | } |
| 82 | BOOST_AUTO_TEST_SUITE_END() |