--[[----------------------------------------------------------------------------

WFRxIndexStoreCheckTest.lua

--------------------------------------------------------------------------------

ADOBE CONFIDENTIAL
------------------
Copyright 2021 Adobe
All Rights Reserved.

NOTICE: All information contained herein is, and remains
the property of Adobe and its suppliers, if any. The intellectual
and technical concepts contained herein are proprietary to Adobe
and its suppliers and are protected by all applicable intellectual
property laws, including trade secret and copyright laws.
Dissemination of this information or reproduction of this material
is strictly forbidden unless prior written permission is obtained
from Adobe.

------------------------------------------------------------------------------]]

	-- Rx
local Rx = require 'Rx'

	-- WF.core.self_test
local WFRxTestCase = require 'WFRxTestCase'

	-- WF.core.utils
local KSTableUtils = require 'KSTableUtils'
local WFPlatformInfo = require 'WFPlatformInfo'
local WFTableMerge = require 'WFTableMerge'

	-- WF.sqlite.doc_store
local WFRxDocStore = require 'WFRxDocStore'
local WFRxIndexStore = require 'WFRxIndexStore'

--============================================================================--

local WFRxIndexStoreTest = {}

--------------------------------------------------------------------------------

local docStore, indexStore, coveragePath

local randomDocId = '7206c3ae9a094d69861ee8983e95085d'

--------------------------------------------------------------------------------

function WFRxIndexStoreTest.setUp( inCoveragePath )

	coveragePath = inCoveragePath

end

--------------------------------------------------------------------------------

local function tearDown()

	local obs = {}
	if coveragePath then
		if indexStore then
			obs[ #obs + 1 ] = indexStore:DEBUG_dumpCoverage( coveragePath )
		end
		coveragePath = nil
	end

	if indexStore then
		local oldIndexStore = indexStore
		obs[ #obs + 1 ] = indexStore:haltAndDelete()
			:tapOnCompleted( function()
				oldIndexStore:close()
			end )
		indexStore = nil
	end

	if docStore then
		local oldDocStore = docStore
		obs[ #obs + 1 ] = docStore:haltAndDelete()
			:tapOnCompleted( function()
				oldDocStore:close()
			end )
		docStore = nil
	end

	return Rx.Observable.concat( unpack( obs ) )
		:call( require 'WFRxRunUntilDone' )


end

WFRxIndexStoreTest.tearDown = tearDown

--==============================================================================
-- @mark Ongoing Table Reindex Monitoring
--==============================================================================

--[[
The following test is used to verify that there are no unintentional changes
to the index store table definitions. The test verifies the map function hash,
the sql schema hash, the doc value filter hash, and the relevant type and 
subtype tuples for each index store table; any changes to these values may 
require a reindex and an associated entry in WFRxIndexStoreSchemaVersionList.
]]--

function WFRxIndexStoreTest.rxTestReindexCheck( rxTest )

	rxTest:setTimeLimit( 5 )

	local catalogSpec
	
	local expectedTableInfo =
		{
			album_asset_v2 = {
				mapFunctionHash = "e1911888f28f1a9a7645af31b97cd9a7",
				relevantTypeSubtypeTuples = {
					{
						"album_asset",
						"NULL",
					},
				},
				sqlSchemaHash = "abb2b4babd963524da42badc899cc92b",
			},
			album_sync_status_ui = {
				docValueFilter = "f9e15cfef2d20a1b452d15476509b7a3",
				mapFunctionHash = "4c0d11b1ddae26d2bf0311a1569f00dc",
				relevantTypeSubtypeTuples = {
					{
						"album",
						"*",
					},
				},
				sqlSchemaHash = "166b8e1f847754722c3bf3b6eb558d5c",
			},
			albums = {
				mapFunctionHash = "505c615836cc280e596640fcdc42c9be",
				relevantTypeSubtypeTuples = {
					{
						"album",
						"collection",
					},
					{
						"album",
						"collection_set",
					},
				},
				sqlSchemaHash = "62565b5a47a8c9b9f247961deded9892",
			},
			archivedFiles = {
				mapFunctionHash = "93da033aac59498fa2d18eb6219da168",
				relevantTypeSubtypeTuples = {
					{
						"asset",
						"image",
					},
					{
						"asset",
						"video",
					},
					{
						"asset",
						"deleted_image",
					},
					{
						"asset",
						"deleted_video",
					},
				},
				sqlSchemaHash = "6f41641552bdcfe6a9630d593933d01f",
			},
			assetEnhanced = {
				mapFunctionHash = "f19377a195b5671b1fe5aacfc0c3f0fb",
				relevantTypeSubtypeTuples = {
					{
						"asset",
						"image",
					},
					{
						"asset",
						"video",
					},
				},
				sqlSchemaHash = "5ada4de514ae56ee417f3a72b9865dfe",
			},
			assetPathsAndInfo = {
				mapFunctionHash = "22d350a0bb25572d7886a7727c5eddea",
				relevantTypeSubtypeTuples = {
					{
						"asset",
						"image",
					},
					{
						"asset",
						"video",
					},
					{
						"asset",
						"deleted_image",
					},
					{
						"asset",
						"deleted_video",
					},
				},
				sqlSchemaHash = "23a33a22c24d188727e0b4a70a485292",
			},
			assetReferredCameraProfile = {
				mapFunctionHash = "6cae8ed802b4612a214b908b203bbb91",
				relevantTypeSubtypeTuples = {
					{
						"asset",
						"image",
					},
				},
				sqlSchemaHash = "42bb514a371a5d2721a986b1c38e7b73",
			},
			asset_importedByUser = {
				docValueFilter = "40978ec7b85325046f3e65585b6440c0",
				mapFunctionHash = "7e5b880b0f5298f244fcd74784f0b4a3",
				relevantTypeSubtypeTuples = {
					{
						"asset",
						"image",
					},
					{
						"asset",
						"video",
					},
				},
				sqlSchemaHash = "f79df49514d02662f2cf79c195dce4e5",
			},
			asset_sync_local_file_type_ui = {
				docValueFilter = "f50b4fc60d2210ee1bc68ef80bfd33ed",
				mapFunctionHash = "09c813016cd32230b6b5cc84445e5070",
				relevantTypeSubtypeTuples = {
					{
						"asset",
						"image",
					},
					{
						"asset",
						"video",
					},
					{
						"asset",
						"deleted_image",
					},
					{
						"asset",
						"deleted_video",
					},
				},
				sqlSchemaHash = "184acbf062a20bcb6eb881451394c0e5",
			},
			asset_sync_status_ui = {
				docValueFilter = "ae3e2c7680027fbb4d1b6b98bfdd38d1",
				mapFunctionHash = "230782dc201c82866d5d6fc223196bbb",
				relevantTypeSubtypeTuples = {
					{
						"asset",
						"*",
					},
				},
				sqlSchemaHash = "fe3362af115f11b18beeb73aa75cae2e",
			},
			assets = {
				mapFunctionHash = "efa1c84b3826a45a08ce5d6b5d486d2d",
				relevantTypeSubtypeTuples = {
					{
						"asset",
						"image",
					},
					{
						"asset",
						"video",
					},
					{
						"asset",
						"stack",
					},
				},
				sqlSchemaHash = "062baf4f6e5be5c2ef8a3aac83a8dd2f",
			},
			assetsNeedingCameraProfileLinks = {
				mapFunctionHash = "cb896a42525a4caeee12dbaedd812982",
				relevantTypeSubtypeTuples = {
					{
						"asset",
						"image",
					},
				},
				sqlSchemaHash = "1e4575668b89cec576d750955177764e",
			},
			assetsPendingRestore = {
				includeDocumentsFromSource = "catalog",
				mapFunctionHash = "2633b3347de725bc6c601c522866f777",
				relevantTypeSubtypeTuples = {
					{
						"asset",
						"image",
					},
					{
						"asset",
						"video",
					},
				},
				sqlSchemaHash = "664f5fdf0975ff8f8ec7cfd4fcf2f5b1",
			},
			blocked_uploads = {
				mapFunctionHash = "535edc6542dc787a7b93b6a8b747d52f",
				relevantTypeSubtypeTuples = {
					{
						"*",
						"*",
					},
				},
				sqlSchemaHash = "9d08da181b53f12af562faf2012a0b2b",
			},
			cameraModelsInUse = {
				docValueFilter = "5468b204381ed036a238258698cd7079",
				mapFunctionHash = "74d2c5a6d75b3e3818e74f59d52903e9",
				relevantTypeSubtypeTuples = {
					{
						"asset",
						"image",
					},
				},
				sqlSchemaHash = "39097a46308d1b5c0d3edd0f343399e1",
			},
			cameras = {
				mapFunctionHash = "330fc036975fd82b27558b1dad5faeed",
				relevantTypeSubtypeTuples = {
					{
						"asset",
						"*",
					},
				},
				sqlSchemaHash = "4198498e1e44475aee70a695d9f1251e",
			},
			captureDate = {
				mapFunctionHash = "084029467259a3b62c15662c87fa2fbb",
				relevantTypeSubtypeTuples = {
					{
						"asset",
						"*",
					},
				},
				sqlSchemaHash = "85b0abf7efea89784efc636dd1096ce5",
			},
			comment = {
				mapFunctionHash = "901fa6ddab7b7d09c441f077d47bb02c",
				relevantTypeSubtypeTuples = {
					{
						"comment",
						"user",
					},
				},
				sqlSchemaHash = "45a3f863bec049b3c57d5b9314fe573c",
			},
			conflicts = {
				mapFunctionHash = "c5005664c695badeffcae7d3ff25be98",
				relevantTypeSubtypeTuples = {
					{
						"*",
						"*",
					},
				},
				sqlSchemaHash = "86dbb5aa202777ec775aeb5b9198a21a",
			},
			customCameraProfiles = {
				mapFunctionHash = "8f1969600a018380ba349be56213b1b9",
				relevantTypeSubtypeTuples = {
					{
						"asset",
						"camera_profile",
					},
				},
				sqlSchemaHash = "91800711c76bce8c76d1015d25c98383",
			},
			editedDate = {
				mapFunctionHash = "8be01b2466f6e1435e1eba5f54624602",
				relevantTypeSubtypeTuples = {
					{
						"asset",
						"image",
					},
					{
						"asset",
						"video",
					},
				},
				sqlSchemaHash = "769b62f2a06c425b597627fa6dbbf0c8",
			},
			errors = {
				mapFunctionHash = "c4b7b9f445deb622e0b968d03fe35a6f",
				relevantTypeSubtypeTuples = {
					{
						"error",
						"*",
					},
				},
				sqlSchemaHash = "f2f1826efd3d98b0fb4edcc15cfc413e",
			},
			externalDevelopSettings = {
				mapFunctionHash = "13109e98398112756002efb62fa4aaa0",
				relevantTypeSubtypeTuples = {
					{
						"asset",
						"image",
					},
					{
						"asset",
						"video",
					},
					{
						"asset",
						"deleted_image",
					},
					{
						"asset",
						"deleted_video",
					},
					{
						"version",
						"edit",
					},
				},
				sqlSchemaHash = "f24ef0d368c4c03d602ace0ae643c3b2",
			},
			faces = {
				mapFunctionHash = "8be011a1c1e2d6a0fad5f4b1d56b8612",
				relevantTypeSubtypeTuples = {
					{
						"asset",
						"image",
					},
					{
						"asset",
						"video",
					},
				},
				sqlSchemaHash = "cd5faa297bc2a192f622bd6461c28001",
			},
			feedback_user = {
				mapFunctionHash = "eda8717d1f2fae3f310d9cd619b92572",
				relevantTypeSubtypeTuples = {
					{
						"feedbackuser",
						"NULL",
					},
				},
				sqlSchemaHash = "36e6399225ce7a527c2a997938bc49f1",
			},
			importSource = {
				mapFunctionHash = "aac5162a3c2df69d3157d4d619527a1d",
				relevantTypeSubtypeTuples = {
					{
						"asset",
						"image",
					},
					{
						"asset",
						"video",
					},
				},
				sqlSchemaHash = "d5852130d49dbe10721a7193ce797988",
			},
			importTime = {
				mapFunctionHash = "248cfb6873b2a796da3afb664ece4333",
				relevantTypeSubtypeTuples = {
					{
						"asset",
						"*",
					},
				},
				sqlSchemaHash = "97d01e0922d61b74587b7071f8795282",
			},
			keywords = {
				docValueFilter = "cf4862dd9434b1ec708123142aa41598",
				mapFunctionHash = "9d1297be4e528e5f222eff2363ead98c",
				relevantTypeSubtypeTuples = {
					{
						"asset",
						"*",
					},
				},
				sqlSchemaHash = "733845ff4443bb2d7a2647e3db2672db",
			},
			localStatusAndOzStatus = {
				mapFunctionHash = "8b9cb8c9f5e0fbb8c80ed502b9afabf7",
				relevantTypeSubtypeTuples = {
					{
						"asset",
						"*",
					},
					{
						"version",
						"*",
					},
				},
				sqlSchemaHash = "94741ea209d2c7226366cf979e11768b",
			},
			locations = {
				mapFunctionHash = "0ab024f7d0c18b127c573753472e46bf",
				relevantTypeSubtypeTuples = {
					{
						"asset",
						"*",
					},
				},
				sqlSchemaHash = "620560099738b950035e9c63c775a5cd",
			},
			mediaTypes = {
				mapFunctionHash = "cad3bd0661a12dc701e7279516978e93",
				relevantTypeSubtypeTuples = {
					{
						"asset",
						"*",
					},
				},
				sqlSchemaHash = "e78f07bbf93c37efcaa2954d95de6e4d",
			},
			modifiedTime = {
				mapFunctionHash = "4c288205a46e39085a83dc95bf6dc2b3",
				relevantTypeSubtypeTuples = {
					{
						"asset",
						"*",
					},
				},
				sqlSchemaHash = "4959b278e6f459eea0bb4c0760b77212",
			},
			needsBinaryUpload = {
				mapFunctionHash = "a8415503876f0d2ba2202c4779c59501",
				relevantTypeSubtypeTuples = {
					{
						"asset",
						"*",
					},
					{
						"version",
						"*",
					},
					{
						"watermark",
						"*",
					},
				},
				sqlSchemaHash = "35c3608ddcc0b5bdb43511530dad4ce3",
			},
			person = {
				mapFunctionHash = "8dfe45e975b1f1576b696358d9e051e4",
				relevantTypeSubtypeTuples = {
					{
						"asset",
						"person",
					},
				},
				sqlSchemaHash = "9370ad20dc35e227426cf5cd6ad02e99",
			},
			presetsAndProfiles = {
				mapFunctionHash = "61a7ff6a1cef7839a90a23718fc45d1f",
				relevantTypeSubtypeTuples = {
					{
						"asset",
						"preset",
					},
					{
						"asset",
						"profile",
					},
				},
				sqlSchemaHash = "ac589dc04f22c72a1fff6717b4b7ff3f",
			},
			project_albums = {
				mapFunctionHash = "a3428bc72e18e8da963649066e2ac58b",
				relevantTypeSubtypeTuples = {
					{
						"album",
						"project",
					},
				},
				sqlSchemaHash = "32945701f993a51c4ab9ecdda4bab41a",
			},
			quota_exceeded = {
				mapFunctionHash = "fd08c55b4f08b4e04a6843ceab6fd4e6",
				relevantTypeSubtypeTuples = {
					{
						"*",
						"*",
					},
				},
				sqlSchemaHash = "e55d172f9c2b356789463bed3ad18919",
			},
			ratings = {
				mapFunctionHash = "de6936a874d21a0e75faebe8c6c2b95a",
				relevantTypeSubtypeTuples = {
					{
						"asset",
						"*",
					},
				},
				sqlSchemaHash = "08595bfb8e0a585452ec90065a7a76ef",
			},
			reviews = {
				mapFunctionHash = "211eed2d351b6ae6a9c950a8c7f56e36",
				relevantTypeSubtypeTuples = {
					{
						"asset",
						"*",
					},
				},
				sqlSchemaHash = "230ba4b4df19601bb34c716a1f41ebda",
			},
			simple_updates = {
				mapFunctionHash = "4e4e2840f9a3a0d79c2f3833bbddf187",
				relevantTypeSubtypeTuples = {
					{
						"*",
						"*",
					},
				},
				sqlSchemaHash = "a7636781c7ed2775c800f8e24557ec0b",
			},
			space = {
				mapFunctionHash = "15a2070eb94057d13aa495201d1d703f",
				relevantTypeSubtypeTuples = {
					{
						"space",
						"shared",
					},
				},
				sqlSchemaHash = "97d6630ff419fc66696ba4970a746701",
			},
			space_album = {
				mapFunctionHash = "73d59901ab06c4bc981e1231bdbea3b8",
				relevantTypeSubtypeTuples = {
					{
						"space_album",
						"NULL",
					},
				},
				sqlSchemaHash = "2d7e700309224e8ab1587c0ed0223bb9",
			},
			space_invite = {
				mapFunctionHash = "e7ad77eb3968bd0f8e3bc31bbcd33436",
				relevantTypeSubtypeTuples = {
					{
						"spaceinvite",
						"request",
					},
					{
						"spaceinvite",
						"single_use",
					},
				},
				sqlSchemaHash = "fda3a72b6300175c403ec72af3c893b9",
			},
			space_user = {
				mapFunctionHash = "2e021becb81d2d904345ce7f87d3bb43",
				relevantTypeSubtypeTuples = {
					{
						"space_user",
						"NULL",
					},
				},
				sqlSchemaHash = "7674dbe1698fac94d46b8edf8054c062",
			},
			spacefavorite = {
				mapFunctionHash = "2539cc65d5e2309072f9d8d43eb89f21",
				relevantTypeSubtypeTuples = {
					{
						"favorite",
						"user",
					},
				},
				sqlSchemaHash = "500e322239776c7a7a6a734cdabd5f4b",
			},
			stack_assets = {
				mapFunctionHash = "a5a9f09de89919eca5aa194709bb948f",
				relevantTypeSubtypeTuples = {
					{
						"stack_asset",
						"NULL",
					},
				},
				sqlSchemaHash = "26a194be3b57586eb423fdb837311e68",
			},
			stacks = {
				mapFunctionHash = "ff285a6784c97188ec2d4ed6b35e5abb",
				relevantTypeSubtypeTuples = {
					{
						"asset",
						"stack",
					},
				},
				sqlSchemaHash = "47e28c82c99cf73282210b1c3cc36f58",
			},
			staleNegatives = {
				mapFunctionHash = "9968185eec6434347ccc3db9783309a0",
				relevantTypeSubtypeTuples = {
					{
						"asset",
						"*",
					},
				},
				sqlSchemaHash = "5927bf0c3a53147bf38b601468bfc9fe",
			},
			trashAssets = {
				includeDocumentsFromSource = "catalog",
				mapFunctionHash = "5d66f724fc1e60745499f14215cd74e7",
				relevantTypeSubtypeTuples = {
					{
						"asset",
						"deleted_image",
					},
					{
						"asset",
						"deleted_video",
					},
				},
				sqlSchemaHash = "cd9708796afee3da76ef1aa3f5080eb0",
			},
			versions = {
				mapFunctionHash = "dba14c05c5490379186fba9ed65a8e31",
				relevantTypeSubtypeTuples = {
					{
						"version",
						"*",
					},
				},
				sqlSchemaHash = "dec02f84839cb5888ee265061f1dad00",
			},
			watermark = {
				mapFunctionHash = "a00c252e5ccbb24244b16ba1598a775b",
				relevantTypeSubtypeTuples = {
					{
						"watermark",
						"text",
					},
				},
				sqlSchemaHash = "71e87ac674fd360566a256ee257952a0",
			}
		}

	if WFPlatformInfo.isDesktop then
		catalogSpec = "WFCatIndexDefinitions.lua"
	else
		catalogSpec = "LrmCatalogIndexDefinitions.lua"

		-- some table names and map fn hashes are different for mobile
		local mobileExpectedTableInfo = {
			album_asset = {
				mapFunctionHash = "32c5ad85de301f168958bbe91b10aa14",
				relevantTypeSubtypeTuples = {
					{
						"album_asset",
						"NULL",
					},
				},
				sqlSchemaHash = "ab305e1e09bf667554f6e741b063233f",
			},
			albums = {
				mapFunctionHash = "3221301cb11143526d7ec01df3f06961",
				relevantTypeSubtypeTuples = {
					{
						"album",
						"collection",
					},
					{
						"album",
						"collection_set",
					},
					{
						"album",
						"topic",
					},
					{
						"album",
						"cluster",
					},
				},
				sqlSchemaHash = "d7c6c56ff1e2bb8ee14b481e1aecee0b",
			},
			assetProfileLinks = {
				mapFunctionHash = "e032cd296ac1b881c551d2d9436fb587",
				relevantTypeSubtypeTuples = {
					{
						"asset",
						"image",
					},
					{
						"asset",
						"video",
					},
				},
				sqlSchemaHash = "c02150c9b98e60dc7534f81df0316134",
			},
			avatarCacheReferences = {
				mapFunctionHash = "7ac6e9567df35d1119e6fc0548833a19",
				relevantTypeSubtypeTuples = {
					{
						"feedbackuser",
						"NULL",
					},
				},
				sqlSchemaHash = "1a54790dfd79312739739cc790fa1c9e",
			},
			blocked_uploads = {
				mapFunctionHash = "535edc6542dc787a7b93b6a8b747d52f",
				relevantTypeSubtypeTuples = {
					{
						"*",
						"*",
					},
				},
				sqlSchemaHash = "986409327852993407573ed583fcb279",
			},
			cacheReferences = {
				mapFunctionHash = "16fa7c8a32d0ac55502e873dffb91e9d",
				relevantTypeSubtypeTuples = {
					{
						"asset",
						"image",
					},
					{
						"asset",
						"deleted_image",
					},
					{
						"asset",
						"video",
					},
					{
						"asset",
						"deleted_video",
					},
					{
						"version",
						"edit",
					},
				},
				sqlSchemaHash = "df9faacbc52f024b9fe042fe3051de08",
			},
			coreInfo = {
				mapFunctionHash = "75a6aca51e1a539b8960864f28270e9e",
				relevantTypeSubtypeTuples = {
					{
						"asset",
						"image",
					},
					{
						"asset",
						"video",
					},
				},
				sqlSchemaHash = "208d43dc75376dca2abc38c51c95fae4",
			},
			faces = {
				mapFunctionHash = "3dad7952aba39fb3fbecac9b33d08065",
				relevantTypeSubtypeTuples = {
					{
						"asset",
						"image",
					},
					{
						"asset",
						"video",
					},
				},
				sqlSchemaHash = "0615a0fb8995a7d97b69baf3ddb2b93a",
			},
			keywords = {
				mapFunctionHash = "bb9a32e0e51241bb7ba21dab5d9d2c21",
				relevantTypeSubtypeTuples = {
					{
						"asset",
						"image",
					},
					{
						"asset",
						"video",
					},
				},
				sqlSchemaHash = "9cb9b65623e93fc84069f599f5ff20b0",
			},
			persons = {
				mapFunctionHash = "849cbe33104770b79b8db996d4d645b9",
				relevantTypeSubtypeTuples = {
					{
						"asset",
						"person",
					},
				},
				sqlSchemaHash = "76d1dd87cc373c776e8cd9e04618584b",
			},
			presetsProfiles = {
				mapFunctionHash = "3dcd3b27a48ac0535e8f468cb053a19e",
				relevantTypeSubtypeTuples = {
					{
						"asset",
						"preset",
					},
					{
						"asset",
						"profile",
					},
					{
						"asset",
						"camera_profile",
					},
				},
				sqlSchemaHash = "d3ee26b367695d324ee04668b78ace7c",
			},
			profileRegistration = {
				mapFunctionHash = "3c7e4f9d1144e36cd45790e6fe5f1d7d",
				relevantTypeSubtypeTuples = {
					{
						"asset",
						"camera_profile",
					},
					{
						"profile",
						"NULL",
					},
				},
				sqlSchemaHash = "495b822a0e58e8e3b148972192a58ee8",
			},
			renditionRevisions = {
				mapFunctionHash = "0ac408eed1588bac28627714d490f28f",
				relevantTypeSubtypeTuples = {
					{
						"asset",
						"image",
					},
					{
						"asset",
						"video",
					},
					{
						"version",
						"edit",
					},
				},
				sqlSchemaHash = "c7e25f8bc92d93e9ee93317924e756a4",
			},
			trashAssets = {
				mapFunctionHash = "4360bd32c5a624a5bf94781f22f5cf1f",
				relevantTypeSubtypeTuples = {
					{
						"asset",
						"deleted_image",
					},
					{
						"asset",
						"deleted_video",
					},
				},
				sqlSchemaHash = "aa472b3995a570a2b84d9a154ab93ecf",
			}
		}

		for tableName, tableInfo in pairs( mobileExpectedTableInfo ) do
			expectedTableInfo[ tableName ] = tableInfo
		end

		if WFPlatformInfo.isAndroid then

			-- LrAndroid has three additional tables compared to LriOS.
			
			-- LrAndroid generates different hashes for all map functions
			-- due to platform difference in sring.dump.
			
			-- Some Android tables don't include video assets, or have
			-- slightly different table schemas.
			
			local androidExpectedTableInfoOverlays = {
				album_asset = {
					mapFunctionHash = "d5a9493db8860cf3915a91bc46cfb89f",
				},
				albums = {
					mapFunctionHash = "84884465d087f06d9503c851ead07187",
				},
				assetProfileLinks = {
					mapFunctionHash = "0047392a9b9c2851917f81f67d1b06e3",
				},
				avatarCacheReferences = {
					mapFunctionHash = "080575065cd5da4958d6db7c44935f12",
				},
				blocked_uploads = {
					mapFunctionHash = "4b9e73fd3d759211db03ab7c3cb2c910",
				},
				cacheReferences = {
					mapFunctionHash = "a42f4d166b3135136f24cdffd764d90d",
					sqlSchemaHash = "c844d3de6e7883726f200f4c84da27bf",
				},
				comment = {
					mapFunctionHash = "be043e7102d68853ab545603c0698a48",
				},
				coreInfo = {
					mapFunctionHash = "a61b2aa6bcb4f462649cf6c0b05d4eaf",
					sqlSchemaHash = "e145bebb3267cea4ed071f1ec0ebbba5",
				},
				conflicts = {
					mapFunctionHash = "bde508c953647e5e843750f47d231257",
				},
				CustomCameraProfiles = {
					mapFunctionHash = "87f11037c6848b249964e3b6c48cfe4c",
					relevantTypeSubtypeTuples = {
						{
							"asset",
							"camera_profile",
						},
					},
					sqlSchemaHash = "15eb16040b63bced5cf95fbf6472cebc",
				},
				coreMD5 = {
					mapFunctionHash = "b05f1c0e2e4d651a404d9676d456d25d",
					relevantTypeSubtypeTuples = {
						{
							"asset",
							"image",
						},
						{
							"asset",
							"video",
						},
					},
					sqlSchemaHash = "6a6545de4d1df65cd8a406c29d667dc5",
				},
				errors = {
					mapFunctionHash = "20524d67289c6cc88f7230d1150f3684",
				},
				faces = {
					mapFunctionHash = "9af74b0d97c3ab403e76945282ef61ba",
					sqlSchemaHash = "9bfc216a39c939f504e545eb4629f8d5",
				},
				feedback_user = {
					mapFunctionHash = "9c6136315ab2d9934bfd30e7d64e4d16",
				},
				importSource = {
					mapFunctionHash = "34d09fbf3c116d908543ef32c770701f",
				},
				keywords = {
					mapFunctionHash = "4bf89f250bb8140d6a7dcb963f328eef",
				},
				needsBinaryUpload = {
					mapFunctionHash = "e3e3c20b96e896207fcd5a63ae405db4",
				},
				persons = {
					mapFunctionHash = "596ab1f273fb0c30fc03ba51da8258f8",
					sqlSchemaHash = "631cb1b6b232aada1def9f7a3289297e",
				},
				presetsProfiles = {
					mapFunctionHash = "c243f41d0f5578d39bbccf83eaac8e11",
					relevantTypeSubtypeTuples = {
						{
							"asset",
							"preset",
						},
						{
							"asset",
							"profile",
						},
					},
					sqlSchemaHash = "ca3a69e6054d26eb748f35a1e919244c",
				},
				profileRegistration = {
					mapFunctionHash = "86a04c429a4324437fe2b14f82c32475",
				},
				quota_exceeded = {
					mapFunctionHash = "e7c5770476fd7651974eabdcbd34a892",
				},
				renditionRevisions = {
					mapFunctionHash = "520cdaed584f57091f2aab1e74939930",
				},
				similar_person = {
					mapFunctionHash = "be94d9d908b8c371c61f9ca75c8dd8a6",
					relevantTypeSubtypeTuples = {
						{
							"asset",
							"person",
						},
					},
					sqlSchemaHash = "1389556f94729938b1e806cc91277918",
				},
				space = {
					mapFunctionHash = "9bd2170c63d383305a38d680d663b52f",
				},
				space_album = {
					mapFunctionHash = "b6fed362d28a0db7d80107b84ce47329",
				},
				space_invite = {
					mapFunctionHash = "a3d2f759a7d482a5368d4bbb25fb48c5",
				},
				space_user = {
					mapFunctionHash = "73633b1e23c29fe170d87d4a00bf15c2",
				},
				spacefavorite = {
					mapFunctionHash = "7d98e695c66055ec94236da9be08b5e7",
				},
				trashAssets = {
					mapFunctionHash = "54fe5eee6b7f52d4c5ebe4c2de51a3af",
					sqlSchemaHash = "e3e6ae30c48b51f79831bf58b585cbf9",
				},
				versions = {
					mapFunctionHash = "3c5a129aee2ac3111f076ff38dcc1387",
				},
				watermark = {
					mapFunctionHash = "897c63cc3da04a4ebb24794a66f96027",
				}
			}
			
			expectedTableInfo = WFTableMerge.applyOverlay( expectedTableInfo, androidExpectedTableInfoOverlays )

			local androidExpectedTableInfo = {
				presetsProfiles = {
					mapFunctionHash = "c243f41d0f5578d39bbccf83eaac8e11",
					relevantTypeSubtypeTuples = {
						{
							"asset",
							"preset",
						},
						{
							"asset",
							"profile",
						},
					},
					sqlSchemaHash = "ca3a69e6054d26eb748f35a1e919244c",
				}

			}
			
			for tableName, tableInfo in pairs( androidExpectedTableInfo ) do
				expectedTableInfo[ tableName ] = tableInfo
			end

		end

	end

	docStore = WFRxDocStore( ':memory:' )
	indexStore = WFRxIndexStore( docStore, catalogSpec )

	-- dummy doc and query, needs to work for all platforms.
	-- The query makes sure the index store is up to date.
	
	rxTest:waitFor(
		docStore:setDocValue {
			_id = randomDocId,
			type = "album",
			subtype = "collection",
			name = "foo",
		} )

	rxTest:waitFor(
		indexStore:query( {
			sql = [[SELECT count(*) FROM albums]],
			quiesceUntilUpToDate = true,
			} )
		:take( 1 ) )

	local obs = rxTest:observe( indexStore:DEBUG_getReindexingTableInfo()
	
			:map( function( tableInfo )
			
				local mismatches = {}
			
				for tblName, tblInfo in pairs( tableInfo ) do
				
					for k, actualValue in pairs( tblInfo ) do
					
						local expectedValue = KSTableUtils.derefOpt( expectedTableInfo, tblName, k )
					
						if ( type( expectedValue ) == 'table' and not KSTableUtils.deepEquals( expectedValue, actualValue ) )
								or ( type( expectedValue ) ~= 'table' and expectedValue ~= actualValue ) then
					
							local mismatchesForTable = mismatches[ tblName ] or {}
							mismatchesForTable[ k ] = actualValue
							mismatches[ tblName ] = mismatchesForTable
						
						end
					
					end
					
				end
				
				return mismatches
				
			end ) )

	obs:expectData( {} )

end

--------------------------------------------------------------------------------

return WFRxTestCase.wrapSuite( WFRxIndexStoreTest )
