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 | |
| 21 | #include <boost/test/unit_test.hpp> |
| 22 | #include <boost/uuid/uuid.hpp> |
| 23 | #include <boost/uuid/uuid_io.hpp> |
| 24 | #include <boost/uuid/string_generator.hpp> |
| 25 | |
| 26 | #include <thrift/TUuid.h> |
| 27 | |
| 28 | using apache::thrift::TUuid; |
| 29 | |
| 30 | BOOST_AUTO_TEST_SUITE(TUuidBoostTest) |
| 31 | |
| 32 | BOOST_AUTO_TEST_CASE(compiler_directive) { |
| 33 | // Test if the macro is set as expected |
| 34 | #ifdef THRIFT_TUUID_SUPPORT_BOOST_UUID |
| 35 | BOOST_TEST(true); |
| 36 | #else |
| 37 | BOOST_TEST(false, "The 'THRIFT_TUUID_SUPPORT_BOOST_UUID' preprocessor directive must be set for these tests"); |
| 38 | #endif // THRIFT_TUUID_SUPPORT_BOOST_UUID |
| 39 | } |
| 40 | |
| 41 | BOOST_AUTO_TEST_CASE(from_boost_uuid_constructor) { |
| 42 | static boost::uuids::string_generator gen; |
| 43 | boost::uuids::uuid boost_uuid{gen("1f610073-db33-4d21-adf2-75460d4955cc")}; |
| 44 | BOOST_TEST(!boost_uuid.is_nil()); |
| 45 | const TUuid uuid{boost_uuid}; |
| 46 | BOOST_TEST(!uuid.is_nil()); |
| 47 | |
| 48 | BOOST_TEST(to_string(boost_uuid) == to_string(uuid)); |
| 49 | BOOST_TEST(to_string(uuid) == std::string{"1f610073-db33-4d21-adf2-75460d4955cc"}); |
| 50 | } |
| 51 | |
| 52 | BOOST_AUTO_TEST_CASE(from_boost_uuid_assignment) { |
| 53 | static boost::uuids::string_generator gen; |
| 54 | boost::uuids::uuid boost_uuid{gen("5cb719a4-cd15-4476-8bcc-f1834b2527ee")}; |
| 55 | BOOST_TEST(!boost_uuid.is_nil()); |
| 56 | TUuid uuid{}; |
| 57 | BOOST_TEST(uuid.is_nil()); |
| 58 | |
| 59 | uuid = boost_uuid; |
| 60 | |
| 61 | BOOST_TEST(to_string(boost_uuid) == to_string(uuid)); |
| 62 | BOOST_TEST(to_string(uuid) == std::string{"5cb719a4-cd15-4476-8bcc-f1834b2527ee"}); |
| 63 | } |
| 64 | |
| 65 | BOOST_AUTO_TEST_SUITE_END() |