SQLiteDynamicStorage.cpp (1409B)
1 // Copyright (c) Microsoft Corporation. 2 // Licensed under the MIT License. 3 #include "pch.h" 4 #include "TestCommon.h" 5 #include <AppInstallerErrors.h> 6 #include <winget/SQLiteDynamicStorage.h> 7 #include <winget/SQLiteWrapper.h> 8 #include <winget/SQLiteStatementBuilder.h> 9 #include <winget/SQLiteVersion.h> 10 11 using namespace AppInstaller::SQLite; 12 using namespace std::string_literals; 13 14 TEST_CASE("SQLiteDynamicStorage_UpgradeDetection", "[sqlite_dynamic]") 15 { 16 TestCommon::TempFile tempFile{ "repolibtest_tempdb"s, ".db"s }; 17 INFO("Using temporary file named: " << tempFile.GetPath()); 18 19 // Create a database with version 1.0 20 SQLiteDynamicStorage storage{ tempFile.GetPath(), Version{ 1, 0 } }; 21 22 { 23 auto transactionLock = storage.TryBeginTransaction("test", false); 24 REQUIRE(transactionLock); 25 } 26 27 // Update the database to version 2.0 28 { 29 Connection connection = Connection::Create(tempFile, Connection::OpenDisposition::Create); 30 Version version{ 2, 0 }; 31 version.SetSchemaVersion(connection); 32 } 33 34 REQUIRE(storage.GetVersion() == Version{ 1, 0 }); 35 36 auto transactionLock = storage.TryBeginTransaction("test", false); 37 REQUIRE(!transactionLock); 38 39 REQUIRE(storage.GetVersion() == Version{ 2, 0 }); 40 41 transactionLock = storage.TryBeginTransaction("test", false); 42 REQUIRE(transactionLock); 43 }