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

0001 // ct_lvtclp_testsourcefile.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 // This file is for tests specific to adding SourceFiles to the database
0021 
0022 #include <ct_lvtmdb_fileobject.h>
0023 #include <ct_lvtmdb_objectstore.h>
0024 
0025 #include <ct_lvtclp_testutil.h>
0026 
0027 #include <catch2-local-includes.h>
0028 
0029 using namespace Codethink::lvtclp;
0030 using namespace Codethink::lvtmdb;
0031 
0032 const PyDefaultGilReleasedContext defaultGilContextForTesting;
0033 
0034 TEST_CASE("Source file")
0035 {
0036     // test ClpUtil::writeSourceFile
0037     const static char *empty = "";
0038     Codethink::lvtmdb::ObjectStore session;
0039     REQUIRE(Test_Util::runOnCode(session, empty, "test/SourceFile.cpp"));
0040 
0041     FileObject *source = nullptr;
0042     session.withROLock([&] {
0043         source = session.getFile("test/SourceFile.cpp");
0044     });
0045 
0046     REQUIRE(source);
0047     source->withROLock([&] {
0048         REQUIRE(source->name() == "SourceFile.cpp");
0049         REQUIRE(!source->isHeader());
0050     });
0051 }