代码拉取完成,页面将自动刷新
diff --git a/frameworks/libs/distributeddb/test/unittest/common/common/distributeddb_tools_unit_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/common/distributeddb_tools_unit_test.cpp
index 3494f7df0..1881542ac 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/common/distributeddb_tools_unit_test.cpp
+++ b/frameworks/libs/distributeddb/test/unittest/common/common/distributeddb_tools_unit_test.cpp
@@ -731,6 +731,34 @@ void DistributedDBToolsUnitTest::BlockSync(RelationalStoreDelegate &delegate, co
}
}
+void DistributedDBToolsUnitTest::BlockSync(RelationalStoreDelegate &delegate, const Query &query,
+ DistributedDB::SyncMode syncMode, const std::vector<DistributedDB::DBStatus> exceptStatus,
+ const std::vector<std::string> &devices)
+{
+ std::map<std::string, std::vector<TableStatus>> statusMap;
+ SyncStatusCallback callBack = [&statusMap](
+ const std::map<std::string, std::vector<TableStatus>> &devicesMap) {
+ statusMap = devicesMap;
+ };
+ DBStatus callStatus = delegate.Sync(devices, syncMode, query, callBack, true);
+ EXPECT_EQ(callStatus, OK);
+ QueryExpression queryExpression = GetQueryInfo::GetQueryExpression(query);
+ std::vector<std::string> syncTables;
+ if (queryExpression.IsUseFromTables()) {
+ syncTables = queryExpression.GetTables();
+ } else {
+ syncTables = {queryExpression.GetTableName()};
+ }
+ for (const auto &tablesRes : statusMap) {
+ ASSERT_EQ(tablesRes.second.size(), syncTables.size());
+ ASSERT_EQ(exceptStatus.size(), syncTables.size());
+ for (uint32_t i = 0; i < syncTables.size(); i++) {
+ EXPECT_EQ(tablesRes.second[i].status, exceptStatus[i]);
+ EXPECT_EQ(tablesRes.second[i].tableName, syncTables[i]);
+ }
+ }
+}
+
KvStoreObserverUnitTest::KvStoreObserverUnitTest() : callCount_(0), isCleared_(false)
{}
diff --git a/frameworks/libs/distributeddb/test/unittest/common/common/distributeddb_tools_unit_test.h b/frameworks/libs/distributeddb/test/unittest/common/common/distributeddb_tools_unit_test.h
index beb1dd8f1..ff4b3bd33 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/common/distributeddb_tools_unit_test.h
+++ b/frameworks/libs/distributeddb/test/unittest/common/common/distributeddb_tools_unit_test.h
@@ -235,6 +235,10 @@ public:
static void BlockSync(DistributedDB::RelationalStoreDelegate &delegate, const DistributedDB::Query &query,
DistributedDB::SyncMode syncMode, DistributedDB::DBStatus exceptStatus,
const std::vector<std::string> &devices);
+
+ static void BlockSync(DistributedDB::RelationalStoreDelegate &delegate, const DistributedDB::Query &query,
+ DistributedDB::SyncMode syncMode, const std::vector<DistributedDB::DBStatus> exceptStatus,
+ const std::vector<std::string> &devices);
private:
static int OpenMockMultiDb(DatabaseInfo &dbInfo, DistributedDB::OpenDbProperties &properties);
diff --git a/frameworks/libs/distributeddb/test/unittest/common/storage/distributeddb_rdb_collaboration_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/storage/distributeddb_rdb_collaboration_test.cpp
index b9e154d49..143987a8b 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/storage/distributeddb_rdb_collaboration_test.cpp
+++ b/frameworks/libs/distributeddb/test/unittest/common/storage/distributeddb_rdb_collaboration_test.cpp
@@ -2387,4 +2387,45 @@ HWTEST_F(DistributedDBRDBCollaborationTest, InvalidSync004, TestSize.Level0)
DBStatus callStatus = delegate_->Sync({deviceB_->GetDeviceId()}, SYNC_MODE_PUSH_ONLY, query, nullptr, true);
EXPECT_EQ(callStatus, INVALID_ARGS);
}
+
+/**
+ * @tc.name: InvalidSync005
+ * @tc.desc: Test sync with table witch non-existent table on the other end
+ * @tc.type: FUNC
+ * @tc.require:
+ * @tc.author: liaoyonghuang
+ */
+HWTEST_F(DistributedDBRDBCollaborationTest, InvalidSync005, TestSize.Level0)
+{
+ /**
+ * @tc.steps: step1. Init DB and create table "DEVICE_SYNC_TABLE" on both ends
+ * @tc.expected: step1.ok
+ */
+ ASSERT_NO_FATAL_FAILURE(InitDelegate());
+ auto schema = GetSchema();
+ auto distributedSchema = RDBDataGenerator::ParseSchema(schema, true);
+ deviceB_->SetDistributedSchema(distributedSchema);
+ EXPECT_EQ(delegate_->CreateDistributedTable(DEVICE_SYNC_TABLE, TableSyncType::DEVICE_COOPERATION), OK);
+ auto tableSchema = GetTableSchema();
+ ASSERT_EQ(RDBDataGenerator::InsertVirtualLocalDBData(0, 1, deviceB_, tableSchema), E_OK);
+ ASSERT_EQ(RDBDataGenerator::PrepareVirtualDeviceEnv(tableSchema.name, db_, deviceB_), E_OK);
+ /**
+ * @tc.steps: step2. Create a new table locally
+ * @tc.expected: step2.ok
+ */
+ std::string tableName = "newTable";
+ std::string sql = "CREATE TABLE IF NOT EXISTS " + tableName + "(integer_field1 INTEGER, integer_field2 INT);";
+ ASSERT_EQ(SQLiteUtils::ExecuteRawSQL(db_, sql), E_OK);
+ EXPECT_EQ(delegate_->CreateDistributedTable(tableName, TableSyncType::DEVICE_COOPERATION), OK);
+ auto newDistributedSchema = GetDistributedSchema(tableName, {"integer_field1", "integer_field2"});
+ distributedSchema.tables.push_back(newDistributedSchema.tables.front());
+ EXPECT_EQ(delegate_->SetDistributedSchema(distributedSchema), OK);
+ /**
+ * @tc.steps: step3. Sync with DEVICE_SYNC_TABLE and new table
+ * @tc.expected: step3. return SCHEMA_MISMATCH
+ */
+ Query query = Query::Select().FromTable({DEVICE_SYNC_TABLE, tableName});
+ DistributedDBToolsUnitTest::BlockSync(*delegate_, query, SYNC_MODE_PUSH_ONLY, {OK, SCHEMA_MISMATCH},
+ {deviceB_->GetDeviceId()});
+}
}
\ No newline at end of file
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。