| 
									
										
										
										
											2020-05-12 12:54:18 +02:00
										 |  |  | /****************************************************************************
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** Copyright (C) 2020 The Qt Company Ltd. | 
					
						
							|  |  |  | ** Contact: https://www.qt.io/licensing/
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** This file is part of Qt Creator. | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** Commercial License Usage | 
					
						
							|  |  |  | ** Licensees holding valid commercial Qt licenses may use this file in | 
					
						
							|  |  |  | ** accordance with the commercial license agreement provided with the | 
					
						
							|  |  |  | ** Software or, alternatively, in accordance with the terms contained in | 
					
						
							|  |  |  | ** a written agreement between you and The Qt Company. For licensing terms | 
					
						
							|  |  |  | ** and conditions see https://www.qt.io/terms-conditions. For further
 | 
					
						
							|  |  |  | ** information use the contact form at https://www.qt.io/contact-us.
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** GNU General Public License Usage | 
					
						
							|  |  |  | ** Alternatively, this file may be used under the terms of the GNU | 
					
						
							|  |  |  | ** General Public License version 3 as published by the Free Software | 
					
						
							|  |  |  | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT | 
					
						
							|  |  |  | ** included in the packaging of this file. Please review the following | 
					
						
							|  |  |  | ** information to ensure the GNU General Public License requirements will | 
					
						
							|  |  |  | ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ****************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "googletest.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-24 18:10:55 +01:00
										 |  |  | #include "sqlitedatabasemock.h"
 | 
					
						
							| 
									
										
										
										
											2020-05-12 12:54:18 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <lastchangedrowid.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class LastChangedRowId : public testing::Test | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | protected: | 
					
						
							| 
									
										
										
										
											2021-03-24 18:10:55 +01:00
										 |  |  |     NiceMock<SqliteDatabaseMock> mockSqliteDatabase; | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     Sqlite::LastChangedRowId<1> lastRowId{mockSqliteDatabase, "main", "foo"}; | 
					
						
							| 
									
										
										
										
											2020-05-12 12:54:18 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(LastChangedRowId, SetUpdateHookInContructor) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     EXPECT_CALL(mockSqliteDatabase, setUpdateHook(_, _)); | 
					
						
							| 
									
										
										
										
											2020-05-12 12:54:18 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     Sqlite::LastChangedRowId<1> lastRowId{mockSqliteDatabase, "main", "foo"}; | 
					
						
							| 
									
										
										
										
											2020-05-12 12:54:18 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(LastChangedRowId, ResetUpdateHookInDestructor) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     EXPECT_CALL(mockSqliteDatabase, resetUpdateHook()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(LastChangedRowId, GetMinusOneAsRowIdIfNoCallbackWasCalled) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     ASSERT_THAT(lastRowId.lastRowId, -1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(LastChangedRowId, CallbackSetsLastRowId) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     lastRowId("main", "foo", 42); | 
					
						
							| 
									
										
										
										
											2020-05-12 12:54:18 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(lastRowId.lastRowId, 42); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(LastChangedRowId, CallbackChecksDatabaseName) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     lastRowId("main", "foo", 33); | 
					
						
							| 
									
										
										
										
											2020-05-12 17:05:33 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     lastRowId("temp", "foo", 42); | 
					
						
							| 
									
										
										
										
											2020-05-12 12:54:18 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-12 17:05:33 +02:00
										 |  |  |     ASSERT_THAT(lastRowId.lastRowId, 33); | 
					
						
							| 
									
										
										
										
											2020-05-12 12:54:18 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(LastChangedRowId, CallbackChecksTableName) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     lastRowId("main", "foo", 33); | 
					
						
							| 
									
										
										
										
											2020-05-12 17:05:33 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     lastRowId("main", "bar", 42); | 
					
						
							| 
									
										
										
										
											2020-05-12 12:54:18 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-12 17:05:33 +02:00
										 |  |  |     ASSERT_THAT(lastRowId.lastRowId, 33); | 
					
						
							| 
									
										
										
										
											2020-05-12 12:54:18 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(LastChangedRowId, LastCallSetsRowId) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     lastRowId("main", "foo", 42); | 
					
						
							|  |  |  |     lastRowId("main", "foo", 33); | 
					
						
							| 
									
										
										
										
											2020-05-12 12:54:18 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     lastRowId("main", "foo", 66); | 
					
						
							| 
									
										
										
										
											2020-05-12 12:54:18 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(lastRowId.lastRowId, 66); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(LastChangedRowId, TakeLastRowId) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     lastRowId("main", "foo", 42); | 
					
						
							| 
									
										
										
										
											2020-05-12 12:54:18 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     auto id = lastRowId.takeLastRowId(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(id, 42); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(LastChangedRowId, TakeLastRowIdResetsRowIdToMinusOne) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     lastRowId("main", "foo", 42); | 
					
						
							| 
									
										
										
										
											2020-05-12 12:54:18 +02:00
										 |  |  |     lastRowId.takeLastRowId(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     auto id = lastRowId.takeLastRowId(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(id, -1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-12 17:05:33 +02:00
										 |  |  | class LastChangedRowIdWithTwoTables : public testing::Test | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | protected: | 
					
						
							| 
									
										
										
										
											2021-03-24 18:10:55 +01:00
										 |  |  |     NiceMock<SqliteDatabaseMock> mockSqliteDatabase; | 
					
						
							| 
									
										
										
										
											2020-05-12 17:05:33 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     Sqlite::LastChangedRowId<2> lastRowId{mockSqliteDatabase, "main", "foo", "bar"}; | 
					
						
							| 
									
										
										
										
											2020-05-12 17:05:33 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(LastChangedRowIdWithTwoTables, SetUpdateHookInContructor) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     EXPECT_CALL(mockSqliteDatabase, setUpdateHook(_, _)); | 
					
						
							| 
									
										
										
										
											2020-05-12 17:05:33 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     Sqlite::LastChangedRowId<2> lastRowId{mockSqliteDatabase, "main", "foo", "bar"}; | 
					
						
							| 
									
										
										
										
											2020-05-12 17:05:33 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(LastChangedRowIdWithTwoTables, ResetUpdateHookInDestructor) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     EXPECT_CALL(mockSqliteDatabase, resetUpdateHook()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(LastChangedRowIdWithTwoTables, GetMinusOneAsRowIdIfNoCallbackWasCalled) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     ASSERT_THAT(lastRowId.lastRowId, -1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(LastChangedRowIdWithTwoTables, CallbackSetsLastRowIdFirstTable) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     lastRowId("main", "foo", 42); | 
					
						
							| 
									
										
										
										
											2020-05-12 17:05:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(lastRowId.lastRowId, 42); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(LastChangedRowIdWithTwoTables, CallbackSetsLastRowIdSecondTable) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     lastRowId("main", "bar", 66); | 
					
						
							| 
									
										
										
										
											2020-05-12 17:05:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(lastRowId.lastRowId, 66); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(LastChangedRowIdWithTwoTables, CallbackChecksDatabaseName) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     lastRowId("main", "foo", 33); | 
					
						
							| 
									
										
										
										
											2020-05-12 17:05:33 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     lastRowId("temp", "foo", 42); | 
					
						
							| 
									
										
										
										
											2020-05-12 17:05:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(lastRowId.lastRowId, 33); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(LastChangedRowIdWithTwoTables, CallbackChecksTableName) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     lastRowId("main", "foo", 33); | 
					
						
							| 
									
										
										
										
											2020-05-12 17:05:33 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     lastRowId("main", "zoo", 42); | 
					
						
							| 
									
										
										
										
											2020-05-12 17:05:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(lastRowId.lastRowId, 33); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(LastChangedRowIdWithTwoTables, LastCallSetsRowId) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     lastRowId("main", "foo", 42); | 
					
						
							| 
									
										
										
										
											2020-05-12 17:05:33 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     lastRowId("main", "bar", 66); | 
					
						
							| 
									
										
										
										
											2020-05-12 17:05:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(lastRowId.lastRowId, 66); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(LastChangedRowIdWithTwoTables, TakeLastRowId) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     lastRowId("main", "foo", 42); | 
					
						
							| 
									
										
										
										
											2020-05-12 17:05:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     auto id = lastRowId.takeLastRowId(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(id, 42); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(LastChangedRowIdWithTwoTables, TakeLastRowIdResetsRowIdToMinusOne) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     lastRowId("main", "foo", 42); | 
					
						
							| 
									
										
										
										
											2020-05-12 17:05:33 +02:00
										 |  |  |     lastRowId.takeLastRowId(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     auto id = lastRowId.takeLastRowId(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(id, -1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class LastChangedRowIdWithThreeTables : public testing::Test | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | protected: | 
					
						
							| 
									
										
										
										
											2021-03-24 18:10:55 +01:00
										 |  |  |     NiceMock<SqliteDatabaseMock> mockSqliteDatabase; | 
					
						
							| 
									
										
										
										
											2020-05-12 17:05:33 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     Sqlite::LastChangedRowId<3> lastRowId{mockSqliteDatabase, "main", "foo", "bar", "too"}; | 
					
						
							| 
									
										
										
										
											2020-05-12 17:05:33 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(LastChangedRowIdWithThreeTables, SetUpdateHookInContructor) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     EXPECT_CALL(mockSqliteDatabase, setUpdateHook(_, _)); | 
					
						
							| 
									
										
										
										
											2020-05-12 17:05:33 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     Sqlite::LastChangedRowId<3> lastRowId{mockSqliteDatabase, "main", "foo", "bar", "too"}; | 
					
						
							| 
									
										
										
										
											2020-05-12 17:05:33 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(LastChangedRowIdWithThreeTables, ResetUpdateHookInDestructor) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     EXPECT_CALL(mockSqliteDatabase, resetUpdateHook()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(LastChangedRowIdWithThreeTables, GetMinusOneAsRowIdIfNoCallbackWasCalled) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     ASSERT_THAT(lastRowId.lastRowId, -1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(LastChangedRowIdWithThreeTables, CallbackSetsLastRowIdFirstTable) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     lastRowId("main", "foo", 42); | 
					
						
							| 
									
										
										
										
											2020-05-12 17:05:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(lastRowId.lastRowId, 42); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(LastChangedRowIdWithThreeTables, CallbackSetsLastRowIdSecondTable) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     lastRowId("main", "bar", 42); | 
					
						
							| 
									
										
										
										
											2020-05-12 17:05:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(lastRowId.lastRowId, 42); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(LastChangedRowIdWithThreeTables, CallbackSetsLastRowIdThirdTable) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     lastRowId("main", "too", 42); | 
					
						
							| 
									
										
										
										
											2020-05-12 17:05:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(lastRowId.lastRowId, 42); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(LastChangedRowIdWithThreeTables, CallbackChecksDatabaseName) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     lastRowId("main", "foo", 33); | 
					
						
							| 
									
										
										
										
											2020-05-12 17:05:33 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     lastRowId("temp", "foo", 42); | 
					
						
							| 
									
										
										
										
											2020-05-12 17:05:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(lastRowId.lastRowId, 33); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(LastChangedRowIdWithThreeTables, CallbackChecksTableName) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     lastRowId("main", "foo", 33); | 
					
						
							| 
									
										
										
										
											2020-05-12 17:05:33 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     lastRowId("main", "zoo", 42); | 
					
						
							| 
									
										
										
										
											2020-05-12 17:05:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(lastRowId.lastRowId, 33); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(LastChangedRowIdWithThreeTables, LastCallSetsRowId) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     lastRowId("main", "bar", 42); | 
					
						
							|  |  |  |     lastRowId("main", "too", 33); | 
					
						
							| 
									
										
										
										
											2020-05-12 17:05:33 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     lastRowId("main", "too", 66); | 
					
						
							| 
									
										
										
										
											2020-05-12 17:05:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(lastRowId.lastRowId, 66); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(LastChangedRowIdWithThreeTables, TakeLastRowId) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     lastRowId("main", "foo", 42); | 
					
						
							| 
									
										
										
										
											2020-05-12 17:05:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     auto id = lastRowId.takeLastRowId(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(id, 42); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(LastChangedRowIdWithThreeTables, TakeLastRowIdResetsRowIdToMinusOne) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     lastRowId("main", "foo", 42); | 
					
						
							| 
									
										
										
										
											2020-05-12 17:05:33 +02:00
										 |  |  |     lastRowId.takeLastRowId(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     auto id = lastRowId.takeLastRowId(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(id, -1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-16 14:53:58 +02:00
										 |  |  | class LastChangedRowIdWithNoDatabaseAndTable : public testing::Test | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | protected: | 
					
						
							| 
									
										
										
										
											2021-03-24 18:10:55 +01:00
										 |  |  |     NiceMock<SqliteDatabaseMock> mockSqliteDatabase; | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     Sqlite::LastChangedRowId<> lastRowId{mockSqliteDatabase}; | 
					
						
							| 
									
										
										
										
											2020-05-16 14:53:58 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(LastChangedRowIdWithNoDatabaseAndTable, SetUpdateHookInContructor) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     EXPECT_CALL(mockSqliteDatabase, setUpdateHook(_, _)); | 
					
						
							| 
									
										
										
										
											2020-05-16 14:53:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     Sqlite::LastChangedRowId<> lastRowId{mockSqliteDatabase}; | 
					
						
							| 
									
										
										
										
											2020-05-16 14:53:58 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(LastChangedRowIdWithNoDatabaseAndTable, ResetUpdateHookInDestructor) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     EXPECT_CALL(mockSqliteDatabase, resetUpdateHook()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(LastChangedRowIdWithNoDatabaseAndTable, GetMinusOneAsRowIdIfNoCallbackWasCalled) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     ASSERT_THAT(lastRowId.lastRowId, -1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(LastChangedRowIdWithNoDatabaseAndTable, CallbackSetsLastRowId) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     lastRowId(42); | 
					
						
							| 
									
										
										
										
											2020-05-16 14:53:58 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(lastRowId.lastRowId, 42); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(LastChangedRowIdWithNoDatabaseAndTable, LastCallSetsRowId) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     lastRowId(42); | 
					
						
							|  |  |  |     lastRowId(33); | 
					
						
							| 
									
										
										
										
											2020-05-16 14:53:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     lastRowId(66); | 
					
						
							| 
									
										
										
										
											2020-05-16 14:53:58 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(lastRowId.lastRowId, 66); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(LastChangedRowIdWithNoDatabaseAndTable, TakeLastRowId) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     lastRowId(42); | 
					
						
							| 
									
										
										
										
											2020-05-16 14:53:58 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     auto id = lastRowId.takeLastRowId(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(id, 42); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(LastChangedRowIdWithNoDatabaseAndTable, TakeLastRowIdResetsRowIdToMinusOne) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     lastRowId(42); | 
					
						
							| 
									
										
										
										
											2020-05-16 14:53:58 +02:00
										 |  |  |     lastRowId.takeLastRowId(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     auto id = lastRowId.takeLastRowId(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(id, -1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class LastChangedRowIdWithNoTable : public testing::Test | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | protected: | 
					
						
							| 
									
										
										
										
											2021-03-24 18:10:55 +01:00
										 |  |  |     NiceMock<SqliteDatabaseMock> mockSqliteDatabase; | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     Sqlite::LastChangedRowId<> lastRowId{mockSqliteDatabase, "main"}; | 
					
						
							| 
									
										
										
										
											2020-05-16 14:53:58 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(LastChangedRowIdWithNoTable, SetUpdateHookInContructor) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     EXPECT_CALL(mockSqliteDatabase, setUpdateHook(_, _)); | 
					
						
							| 
									
										
										
										
											2020-05-16 14:53:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     Sqlite::LastChangedRowId<> lastRowId{mockSqliteDatabase, "main"}; | 
					
						
							| 
									
										
										
										
											2020-05-16 14:53:58 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(LastChangedRowIdWithNoTable, ResetUpdateHookInDestructor) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     EXPECT_CALL(mockSqliteDatabase, resetUpdateHook()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(LastChangedRowIdWithNoTable, GetMinusOneAsRowIdIfNoCallbackWasCalled) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     ASSERT_THAT(lastRowId.lastRowId, -1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(LastChangedRowIdWithNoTable, CallbackSetsLastRowId) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     lastRowId("main", 42); | 
					
						
							| 
									
										
										
										
											2020-05-16 14:53:58 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(lastRowId.lastRowId, 42); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(LastChangedRowIdWithNoTable, CallbackChecksDatabaseName) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     lastRowId("main", 33); | 
					
						
							| 
									
										
										
										
											2020-05-16 14:53:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     lastRowId("temp", 42); | 
					
						
							| 
									
										
										
										
											2020-05-16 14:53:58 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(lastRowId.lastRowId, 33); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(LastChangedRowIdWithNoTable, LastCallSetsRowId) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     lastRowId("main", 42); | 
					
						
							|  |  |  |     lastRowId("main", 33); | 
					
						
							| 
									
										
										
										
											2020-05-16 14:53:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     lastRowId("main", 66); | 
					
						
							| 
									
										
										
										
											2020-05-16 14:53:58 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(lastRowId.lastRowId, 66); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(LastChangedRowIdWithNoTable, TakeLastRowId) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     lastRowId("main", 42); | 
					
						
							| 
									
										
										
										
											2020-05-16 14:53:58 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     auto id = lastRowId.takeLastRowId(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(id, 42); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(LastChangedRowIdWithNoTable, TakeLastRowIdResetsRowIdToMinusOne) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     lastRowId("main", 42); | 
					
						
							| 
									
										
										
										
											2020-05-16 14:53:58 +02:00
										 |  |  |     lastRowId.takeLastRowId(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     auto id = lastRowId.takeLastRowId(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(id, -1); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-05-26 20:31:07 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | TEST_F(LastChangedRowIdWithNoTable, LastRowIdIsNotValidForNegativeValues) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto isValid = lastRowId.lastRowIdIsValid(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_FALSE(isValid); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(LastChangedRowIdWithNoTable, LastRowIdIsValidForNull) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     lastRowId("main", 0); | 
					
						
							| 
									
										
										
										
											2020-05-26 20:31:07 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     auto isValid = lastRowId.lastRowIdIsValid(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_TRUE(isValid); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(LastChangedRowIdWithNoTable, LastRowIdIsValidForPositiveValues) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-06-05 19:55:10 +02:00
										 |  |  |     lastRowId("main", 777); | 
					
						
							| 
									
										
										
										
											2020-05-26 20:31:07 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     auto isValid = lastRowId.lastRowIdIsValid(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_TRUE(isValid); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-12 12:54:18 +02:00
										 |  |  | } // namespace
 |