File indexing completed on 2024-05-19 05:42:03

0001 // ct_lvtclp_logicalpostprocessutil.t.cpp                             -*-C++-*-
0002 
0003 /*
0004 // Copyright 2023 Codethink Ltd <codethink@codethink.co.uk>
0005 // SPDX-License-Identifier: Apache-2.0
0006 //
0007 // Licensed under the Apache License, Version 2.0 (the "License");
0008 // you may not use this file except in compliance with the License.
0009 // You may obtain a copy of the License at
0010 //
0011 //     http://www.apache.org/licenses/LICENSE-2.0
0012 //
0013 // Unless required by applicable law or agreed to in writing, software
0014 // distributed under the License is distributed on an "AS IS" BASIS,
0015 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0016 // See the License for the specific language governing permissions and
0017 // limitations under the License.
0018 */
0019 
0020 #include <ct_lvtclp_logicalpostprocessutil.h>
0021 
0022 #include <ct_lvtmdb_fileobject.h>
0023 #include <ct_lvtmdb_namespaceobject.h>
0024 #include <ct_lvtmdb_objectstore.h>
0025 #include <ct_lvtmdb_typeobject.h>
0026 
0027 #include <ct_lvtclp_testutil.h>
0028 #include <ct_lvtshr_graphenums.h>
0029 
0030 #include <filesystem>
0031 #include <initializer_list>
0032 #include <string>
0033 
0034 #include <catch2-local-includes.h>
0035 
0036 namespace {
0037 
0038 using namespace Codethink::lvtclp;
0039 using namespace Codethink::lvtmdb;
0040 using namespace Codethink;
0041 
0042 std::string fileNameFromQName(std::string qualifiedName)
0043 {
0044     return std::filesystem::path(std::move(qualifiedName)).filename().string();
0045 }
0046 
0047 void checkFileSelection(const std::initializer_list<std::string>& classFiles,
0048                         std::string className,
0049                         const std::string& classQName,
0050                         std::string nmspcName,
0051                         std::string nmspcQName,
0052                         const std::string& expectedFileResult)
0053 {
0054     ObjectStore session;
0055 
0056     session.withRWLock([&] {
0057         NamespaceObject *obj = session.getOrAddNamespace(nmspcQName, nmspcName, nullptr);
0058         TypeObject *udt = session.getOrAddType(classQName,
0059                                                className,
0060                                                lvtshr::UDTKind::Struct,
0061                                                lvtshr::AccessSpecifier::e_public,
0062                                                obj,
0063                                                nullptr,
0064                                                nullptr);
0065         obj->withRWLock([&] {
0066             obj->addType(udt);
0067         });
0068 
0069         // set up database
0070         for (const std::string& fileQName : classFiles) {
0071             FileObject *file =
0072                 session.getOrAddFile(fileQName, fileNameFromQName(fileQName), true, std::string{}, nullptr, nullptr);
0073             file->withRWLock([&] {
0074                 file->addType(udt);
0075             });
0076             udt->withRWLock([&] {
0077                 udt->addFile(file);
0078             });
0079         }
0080     });
0081 
0082     REQUIRE(LogicalPostProcessUtil::postprocess(session, false));
0083 
0084     TypeObject *udt = nullptr;
0085     FileObject *expected = nullptr;
0086 
0087     session.withROLock([&] {
0088         udt = session.getType(classQName);
0089         expected = session.getFile(expectedFileResult);
0090     });
0091     // check results
0092     REQUIRE(udt);
0093 
0094     udt->withROLock([&] {
0095         const auto files = udt->files();
0096         REQUIRE(files.size() == 1);
0097         REQUIRE(expected);
0098         REQUIRE(files.front() == expected);
0099     });
0100 }
0101 
0102 } // namespace
0103 
0104 TEST_CASE("UsesBslmaAllocator")
0105 {
0106     std::initializer_list<std::string> files{
0107         "bdl/bdlc/bdlc_flathashtable.h",
0108         "bdl/bdlc/bdlc_packedintarray.h",
0109         "bdl/bdlc/bdlc_bitarray.h",
0110         "bdl/bdlc/bdlc_flathashmap.h",
0111         "bdl/bdlt/bdlt_calendar.h",
0112         "bdl/bdlt/bdlt_packedcalendar.h",
0113         "bdl/bdlf/bdlf_memfn.h",
0114         "bdl/bdlcc/bdlcc_cache.h",
0115         "bdl/bdlcc/bdlcc_stripedunorderedmultimap.h",
0116         "bdl/bdlcc/bdlcc_stripedunorderedcontainerimpl.h",
0117         "bsl/bsltf/bsltf_movablealloctesttype.h",
0118         "bsl/bsltf/bsltf_allocemplacabletesttype.h",
0119         "bsl/bsltf/bsltf_alloctesttype.h",
0120         "bsl/bsltf/bsltf_nonoptionalalloctesttype.h",
0121         "bsl/bsltf/bsltf_allocargumenttype.h",
0122         "bsl/bsltf/bsltf_wellbehavedmoveonlyalloctesttype.h",
0123         "bsl/bsltf/bsltf_moveonlyalloctesttype.h",
0124         "bsl/bsltf/bsltf_allocbitwisemoveabletesttype.h",
0125         "bsl/bslmt/bslmt_threadgroup.h",
0126         "bsl/bslalg/bslalg_constructorproxy.h",
0127         "bsl/bslstl/bslstl_hashtable.h",
0128         "bsl/bslstl/bslstl_unorderedmap.h",
0129         "bsl/bslstl/bslstl_unorderedmultimap.h",
0130         "bsl/bslstl/bslstl_pair.h",
0131         "bsl/bslstl/bslstl_multimap.h",
0132         "bsl/bslstl/bslstl_string.h",
0133         "bsl/bslstl/bslstl_unorderedmultiset.h",
0134         "bsl/bslstl/bslstl_stringbuf.h",
0135         "bsl/bslstl/bslstl_sharedptrallocateinplacerep.h",
0136         "bsl/bslstl/bslstl_set.h",
0137         "bsl/bslstl/bslstl_istringstream.h",
0138         "bsl/bslstl/bslstl_stringstream.h",
0139         "bsl/bslstl/bslstl_unorderedset.h",
0140         "bsl/bslstl/bslstl_map.h",
0141         "bsl/bslstl/bslstl_list.h",
0142         "bsl/bslstl/bslstl_sharedptr.h",
0143         "bsl/bslstl/bslstl_multiset.h",
0144         "bsl/bslstl/bslstl_ostringstream.h",
0145         "bsl/bslstl/bslstl_deque.h",
0146         "bsl/bslstl/bslstl_vector.h",
0147         "bsl/bslma/bslma_stdallocator.h",
0148         "bsl/bslma/bslma_sharedptroutofplacerep.h",
0149         "bsl/bslma/bslma_sharedptrinplacerep.h",
0150         "bsl/bslma/bslma_usesbslmaallocator.h",
0151         "bdl/bdlbb/bdlbb_blob.h",
0152         "bsl/bslx/bslx_testoutstream.h",
0153         "bsl/bslx/bslx_byteoutstream.h",
0154         "bdl/bdlc/bdlc_compactedarray.h",
0155         "bdl/bdlt/bdlt_timetable.h",
0156         "bsl/bslstp/bslstp_hashset.h",
0157         "bbl/bbldc/bbldc_calendardaterangedaycountadapter.h",
0158         "bdl/bdlde/bdlde_quotedprintableencoder.h",
0159         "bsl/bslstl/bslstl_boyermoorehorspoolsearcher.h",
0160         "bsl/bslstp/bslstp_hashmap.h",
0161         "bbl/bbldc/bbldc_perioddaterangedaycountadapter.h",
0162         "bdl/bdlt/bdlt_calendarcache.h",
0163         "bdl/bdlcc/bdlcc_stripedunorderedmap.h",
0164         "bdl/bdlt/bdlt_timetablecache.h",
0165         "bdl/bdlma/bdlma_defaultdeleter.h",
0166         "bdl/bdlc/bdlc_flathashset.h",
0167         "bdl/bdlcc/bdlcc_deque.h",
0168     };
0169 
0170     return checkFileSelection(files,
0171                               "UsesBslmaAllocator",
0172                               "BloombergLP::bslma::UsesBslmaAllocator",
0173                               "bslma",
0174                               "BloombergLP::bslma",
0175                               "bsl/bslma/bslma_usesbslmaallocator.h");
0176 }
0177 
0178 TEST_CASE("IsBitwiseMoveable")
0179 {
0180     std::initializer_list<std::string> files{
0181         "bdl/bdlc/bdlc_bitarray.h",
0182         "bdl/bdlt/bdlt_dayofweekset.h",
0183         "bdl/bdlf/bdlf_memfn.h",
0184         "bsl/bslh/bslh_siphashalgorithm.h",
0185         "bsl/bslh/bslh_hash.h",
0186         "bsl/bslh/bslh_spookyhashalgorithm.h",
0187         "bsl/bslmf/bslmf_isbitwisemoveable.h",
0188         "bsl/bsltf/bsltf_allocbitwisemoveabletesttype.h",
0189         "bsl/bsltf/bsltf_bitwisemoveabletesttype.h",
0190         "bsl/bslalg/bslalg_constructorproxy.h",
0191         "bsl/bslstl/bslstl_hashtable.h",
0192         "bsl/bslstl/bslstl_unorderedmap.h",
0193         "bsl/bslstl/bslstl_unorderedmultimap.h",
0194         "bsl/bslstl/bslstl_pair.h",
0195         "bsl/bslstl/bslstl_bidirectionalnodepool.h",
0196         "bsl/bslstl/bslstl_list.h",
0197         "bsl/bslstl/bslstl_sharedptr.h",
0198         "bsl/bslstl/bslstl_deque.h",
0199         "bsl/bslstl/bslstl_vector.h",
0200         "bsl/bslma/bslma_managedptr_members.h",
0201         "bsl/bslma/bslma_managedptrdeleter.h",
0202         "bsl/bslma/bslma_managedptr.h",
0203         "bsl/bslma/bslma_managedptr_pairproxy.h",
0204         "bdl/bdlbb/bdlbb_blob.h",
0205         "bsl/bslh/bslh_wyhashalgorithm.h",
0206     };
0207 
0208     return checkFileSelection(files,
0209                               "IsBitwiseMoveable",
0210                               "BloombergLP::bslmf::IsBitwiseMoveable",
0211                               "bslmf",
0212                               "BloombergLP::bslmf",
0213                               "bsl/bslmf/bslmf_isbitwisemoveable.h");
0214 }
0215 
0216 TEST_CASE("IsTriviallyCopyable")
0217 {
0218     std::initializer_list<std::string> files{
0219         "bdl/bdlt/bdlt_datetimeinterval.h",
0220         "bdl/bdlt/bdlt_date.h",
0221         "bdl/bdlt/bdlt_timetz.h",
0222         "bdl/bdlt/bdlt_time.h",
0223         "bdl/bdlt/bdlt_datetimetz.h",
0224         "bdl/bdlt/bdlt_datetime.h",
0225         "bdl/bdlt/bdlt_datetz.h",
0226         "bdl/bdlf/bdlf_memfn.h",
0227         "bsl/bslh/bslh_hash.h",
0228         "bsl/bslmf/bslmf_istriviallycopyable.h",
0229         "bsl/bslalg/bslalg_dequeiterator.h",
0230         "bsl/bslstl/bslstl_pair.h",
0231         "bsl/bslstl/bslstl_equalto.h",
0232         "bsl/bslstl/bslstl_hash.h",
0233         "bsl/bslstl/bslstl_ownerless.h",
0234         "bsl/bslstl/bslstl_typeindex.h",
0235     };
0236 
0237     return checkFileSelection(files,
0238                               "is_trivially_copyable",
0239                               "bsl::is_trivially_copyable",
0240                               "bsl",
0241                               "bsl",
0242                               "bsl/bslmf/bslmf_istriviallycopyable.h");
0243 }