Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.

Commit ccbf161

Browse files
authored
Merge pull request #523 from openweave/feature/add_wdm_update_server_test
add wdm update server test
2 parents f452cc5 + 4380785 commit ccbf161

File tree

8 files changed

+876
-6
lines changed

8 files changed

+876
-6
lines changed

src/lib/profiles/data-management/Current/SubscriptionClient.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ class SubscriptionClient
403403
friend class TestTdm;
404404
friend class TestWdm;
405405
friend class WdmUpdateEncoderTest;
406+
friend class WdmUpdateServerTest;
406407
friend class MockWdmSubscriptionInitiatorImpl;
407408
friend class TraitDataSink;
408409
friend class TraitSchemaEngine;

src/lib/profiles/data-management/Current/SubscriptionEngine.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ class SubscriptionEngine
356356
friend class NotificationEngine;
357357
friend class TestTdm;
358358
friend class TestWdm;
359+
friend class WdmUpdateServerTest;
359360

360361
nl::Weave::WeaveExchangeManager * mExchangeMgr;
361362
void * mAppState;

src/lib/profiles/data-management/Current/TraitData.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,7 @@ class TraitUpdatableDataSink : public TraitDataSink, protected TraitSchemaEngine
831831
private:
832832
friend class SubscriptionClient;
833833
friend class UpdateEncoder;
834+
friend class WdmUpdateServerTest;
834835

835836
/**
836837
* Checks if a DataVersion is more recent than the one currently stored in the Sink.
@@ -965,6 +966,7 @@ class TraitDataSource : private TraitSchemaEngine::IGetDataDelegate
965966
const TraitSchemaEngine * mSchemaEngine;
966967

967968
private:
969+
friend class WdmUpdateServerTest;
968970
// Current version of the data in this source.
969971
uint64_t mVersion;
970972
// Tracks whether SetDirty was called within a Lock/Unlock 'session'

src/test-apps/Makefile.am

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ check_PROGRAMS += \
364364
TestPathStore \
365365
TestWdmUpdateEncoder \
366366
TestWdmUpdateResponse \
367+
TestWdmUpdateServer \
367368
$(NULL)
368369

369370
if WEAVE_BUILD_WARM
@@ -479,6 +480,7 @@ local_test_programs += \
479480
TestPathStore \
480481
TestWdmUpdateEncoder \
481482
TestWdmUpdateResponse \
483+
TestWdmUpdateServer \
482484
$(NULL)
483485
endif
484486

@@ -1263,6 +1265,22 @@ TestWdmUpdateResponse_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/
12631265
TestWdmUpdateResponse_LDFLAGS = $(AM_CPPFLAGS)
12641266
TestWdmUpdateResponse_LDADD = libWeaveTestCommon.a $(COMMON_LDADD)
12651267

1268+
TestWdmUpdateServer_SOURCES = TestWdmUpdateServer.cpp \
1269+
MockSinkTraits.cpp \
1270+
MockSourceTraits.cpp \
1271+
schema/nest/test/trait/TestATrait.cpp \
1272+
schema/nest/test/trait/TestBTrait.cpp \
1273+
schema/nest/test/trait/TestETrait.cpp \
1274+
schema/nest/test/trait/TestCommon.cpp \
1275+
schema/weave/trait/security/BoltLockSettingsTrait.cpp \
1276+
schema/weave/trait/telemetry/NetworkWiFiTelemetryTrait.cpp \
1277+
MockWdmNodeOptions.cpp \
1278+
TestPersistedStorageImplementation.cpp
1279+
1280+
TestWdmUpdateServer_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/src/test-apps/schema
1281+
TestWdmUpdateServer_LDFLAGS = $(AM_CPPFLAGS)
1282+
TestWdmUpdateServer_LDADD = libWeaveTestCommon.a $(COMMON_LDADD)
1283+
12661284
TestFabricStateDelegate_SOURCES = TestFabricStateDelegate.cpp TestPersistedStorageImplementation.cpp
12671285
TestFabricStateDelegate_LDFLAGS = $(AM_CPPFLAGS)
12681286
TestFabricStateDelegate_LDADD = libWeaveTestCommon.a $(COMMON_LDADD)

src/test-apps/MockSinkTraits.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ namespace Weave {
8686
namespace Profiles {
8787
namespace DataManagement_Current {
8888
class WdmUpdateEncoderTest;
89+
class WdmUpdateServerTest;
8990
} // namespace DataManagement_Current
9091
} // namespace Profiles
9192
} // namespace Weave
@@ -107,7 +108,7 @@ class TestATraitUpdatableDataSink : public MockTraitUpdatableDataSink
107108

108109
private:
109110
friend class nl::Weave::Profiles::DataManagement_Current::WdmUpdateEncoderTest;
110-
111+
friend class nl::Weave::Profiles::DataManagement_Current::WdmUpdateServerTest;
111112
void SetNullifiedPath(nl::Weave::Profiles::DataManagement::PropertyPathHandle aHandle, bool isNull);
112113
WEAVE_ERROR SetData(nl::Weave::Profiles::DataManagement::PropertyPathHandle aHandle, nl::Weave::TLV::TLVReader &aReader, bool aIsNull) __OVERRIDE;
113114
WEAVE_ERROR SetLeafData(nl::Weave::Profiles::DataManagement::PropertyPathHandle aLeafHandle, nl::Weave::TLV::TLVReader &aReader) __OVERRIDE;

src/test-apps/MockSourceTraits.cpp

Lines changed: 207 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,8 +1626,12 @@ void TestATraitDataSource::OnCustomCommand(nl::Weave::Profiles::DataManagement::
16261626
}
16271627
}
16281628

1629-
TestBTraitDataSource::TestBTraitDataSource()
1630-
: TraitDataSource(&TestBTrait::TraitSchema)
1629+
TestBTraitDataSource::TestBTraitDataSource():
1630+
#if WDM_ENABLE_PUBLISHER_UPDATE_SERVER_SUPPORT
1631+
TraitUpdatableDataSource(&TestBTrait::TraitSchema)
1632+
#else
1633+
TraitDataSource(&TestBTrait::TraitSchema)
1634+
#endif
16311635
{
16321636
SetVersion(200);
16331637
taa = TestATrait::ENUM_A_VALUE_1;
@@ -1651,6 +1655,207 @@ TestBTraitDataSource::TestBTraitDataSource()
16511655
MOCK_strlcpy(tbc_seac, "hallo", sizeof(tbc_seac));
16521656
}
16531657

1658+
#if WDM_ENABLE_PUBLISHER_UPDATE_SERVER_SUPPORT
1659+
WEAVE_ERROR
1660+
TestBTraitDataSource::SetLeafData(PropertyPathHandle aLeafHandle, TLVReader &aReader)
1661+
{
1662+
WEAVE_ERROR err = WEAVE_NO_ERROR;
1663+
1664+
switch (aLeafHandle) {
1665+
//
1666+
// TestATrait
1667+
//
1668+
1669+
case TestBTrait::kPropertyHandle_TaA:
1670+
int32_t next_taa;
1671+
err = aReader.Get(next_taa);
1672+
SuccessOrExit(err);
1673+
if (next_taa != taa)
1674+
{
1675+
WeaveLogDetail(DataManagement, "<< ta_a is changed from %u to %u", taa, next_taa);
1676+
taa = next_taa;
1677+
}
1678+
1679+
WeaveLogDetail(DataManagement, "<< ta_a = %u", taa);
1680+
break;
1681+
1682+
case TestBTrait::kPropertyHandle_TaB:
1683+
int32_t next_tab;
1684+
err = aReader.Get(next_tab);
1685+
SuccessOrExit(err);
1686+
if (next_tab != tab)
1687+
{
1688+
WeaveLogDetail(DataManagement, "<< ta_b is changed from %u to %u", tab, next_tab);
1689+
tab = next_tab;
1690+
}
1691+
1692+
WeaveLogDetail(DataManagement, "<< ta_b = %u", tab);
1693+
break;
1694+
1695+
case TestBTrait::kPropertyHandle_TaC:
1696+
uint32_t next_tac;
1697+
err = aReader.Get(next_tac);
1698+
SuccessOrExit(err);
1699+
if (next_tac != tac)
1700+
{
1701+
WeaveLogDetail(DataManagement, "<< ta_c is changed from %u to %u", tac, next_tac);
1702+
tac = next_tac;
1703+
}
1704+
1705+
WeaveLogDetail(DataManagement, "<< ta_c = %u", tac);
1706+
break;
1707+
1708+
case TestBTrait::kPropertyHandle_TaD_SaA:
1709+
uint32_t next_tad_saa;
1710+
err = aReader.Get(next_tad_saa);
1711+
SuccessOrExit(err);
1712+
if (next_tad_saa != tad_saa)
1713+
{
1714+
WeaveLogDetail(DataManagement, "<< ta_d.sa_a is changed from %u to %u", tad_saa, next_tad_saa);
1715+
tad_saa = next_tad_saa;
1716+
}
1717+
1718+
WeaveLogDetail(DataManagement, "<< ta_d.sa_a = %u", tad_saa);
1719+
break;
1720+
1721+
case TestBTrait::kPropertyHandle_TaD_SaB:
1722+
bool next_tad_sab;
1723+
err = aReader.Get(next_tad_sab);
1724+
SuccessOrExit(err);
1725+
if (next_tad_sab != tad_sab)
1726+
{
1727+
WeaveLogDetail(DataManagement, "<< ta_d.sa_b is changed from %u to %u", tad_sab, next_tad_sab);
1728+
tad_sab = next_tad_sab;
1729+
}
1730+
1731+
WeaveLogDetail(DataManagement, "<< ta_d.sa_b = %u", tad_sab);
1732+
break;
1733+
1734+
case TestBTrait::kPropertyHandle_TaE:
1735+
{
1736+
TLVType outerType;
1737+
uint32_t i = 0;
1738+
1739+
err = aReader.EnterContainer(outerType);
1740+
SuccessOrExit(err);
1741+
1742+
while (((err = aReader.Next()) == WEAVE_NO_ERROR) && (i < (sizeof(tae) / sizeof(tae[0])))) {
1743+
uint32_t next_tae;
1744+
err = aReader.Get(next_tae);
1745+
SuccessOrExit(err);
1746+
if (tae[i] != next_tae)
1747+
{
1748+
WeaveLogDetail(DataManagement, "<< ta_e[%u] is changed from %u to %u", i, tae[i], next_tae);
1749+
tae[i] = next_tae;
1750+
}
1751+
1752+
WeaveLogDetail(DataManagement, "<< ta_e[%u] = %u", i, tae[i]);
1753+
i++;
1754+
}
1755+
1756+
err = aReader.ExitContainer(outerType);
1757+
break;
1758+
}
1759+
1760+
case TestBTrait::kPropertyHandle_TaP:
1761+
err = aReader.Get(tap);
1762+
SuccessOrExit(err);
1763+
1764+
WeaveLogDetail(DataManagement, "<< ta_p = %" PRId64, tap);
1765+
break;
1766+
1767+
//
1768+
// TestBTrait
1769+
//
1770+
1771+
case TestBTrait::kPropertyHandle_TbA:
1772+
uint32_t next_tba;
1773+
err = aReader.Get(next_tba);
1774+
SuccessOrExit(err);
1775+
if (tba != next_tba)
1776+
{
1777+
WeaveLogDetail(DataManagement, "<< tb_a is changed from %u to %u", tba, next_tba);
1778+
tba = next_tba;
1779+
}
1780+
1781+
WeaveLogDetail(DataManagement, "<< tb_a = %u", tba);
1782+
break;
1783+
1784+
case TestBTrait::kPropertyHandle_TbB_SbA:
1785+
char next_tbb_sba[10];
1786+
err = aReader.GetString(next_tbb_sba, 10);
1787+
SuccessOrExit(err);
1788+
if (strncmp(tbb_sba, next_tbb_sba, 10))
1789+
{
1790+
WeaveLogDetail(DataManagement, "<< tb_b.sb_a is changed from %s to %s", tbb_sba, next_tbb_sba);
1791+
memcpy(tbb_sba, next_tbb_sba, 10);
1792+
}
1793+
1794+
WeaveLogDetail(DataManagement, "<< tb_b.sb_a = %s", tbb_sba);
1795+
break;
1796+
1797+
case TestBTrait::kPropertyHandle_TbB_SbB:
1798+
uint32_t next_tbb_sbb;
1799+
err = aReader.Get(next_tbb_sbb);
1800+
SuccessOrExit(err);
1801+
if (tbb_sbb != next_tbb_sbb)
1802+
{
1803+
WeaveLogDetail(DataManagement, "<< tb_b.sb_b is changed from %u to %u", tbb_sbb, next_tbb_sbb);
1804+
tbb_sbb = next_tbb_sbb;
1805+
}
1806+
1807+
WeaveLogDetail(DataManagement, "<< tb_b.sb_b = %u", tbb_sbb);
1808+
break;
1809+
1810+
case TestBTrait::kPropertyHandle_TbC_SaA:
1811+
uint32_t next_tbc_saa;
1812+
err = aReader.Get(next_tbc_saa);
1813+
SuccessOrExit(err);
1814+
if (tbc_saa != next_tbc_saa)
1815+
{
1816+
WeaveLogDetail(DataManagement, "<< tb_c.sa_a is changed from %u to %u", tbc_saa, next_tbc_saa);
1817+
tbc_saa = next_tbc_saa;
1818+
}
1819+
1820+
WeaveLogDetail(DataManagement, "<< tb_c.sa_a = %u", tbc_saa);
1821+
break;
1822+
1823+
case TestBTrait::kPropertyHandle_TbC_SaB:
1824+
bool next_tbc_sab;
1825+
err = aReader.Get(next_tbc_sab);
1826+
SuccessOrExit(err);
1827+
if (tbc_sab != next_tbc_sab)
1828+
{
1829+
WeaveLogDetail(DataManagement, "<< tb_c.sa_b is changed from %u to %u", tbc_sab, next_tbc_sab);
1830+
tbc_sab = next_tbc_sab;
1831+
}
1832+
1833+
WeaveLogDetail(DataManagement, "<< tb_c.sa_b = %u", tbc_sab);
1834+
break;
1835+
1836+
case TestBTrait::kPropertyHandle_TbC_SeaC:
1837+
char next_tbc_seac[10];
1838+
err = aReader.GetString(next_tbc_seac, 10);
1839+
SuccessOrExit(err);
1840+
if (strncmp(tbc_seac, next_tbc_seac, 10))
1841+
{
1842+
WeaveLogDetail(DataManagement, "<< tb_c.sea_c is changed from \"%s\" to \"%s\"", tbc_seac, next_tbc_seac);
1843+
memcpy(tbc_seac, next_tbc_seac, 10);
1844+
}
1845+
1846+
WeaveLogDetail(DataManagement, "<< tb_c.sea_c = \"%s\"", tbc_seac);
1847+
break;
1848+
1849+
default:
1850+
WeaveLogDetail(DataManagement, "<< TestBTrait UNKNOWN! %08x", aLeafHandle);
1851+
}
1852+
1853+
exit:
1854+
return err;
1855+
}
1856+
1857+
#endif // WDM_ENABLE_PUBLISHER_UPDATE_SERVER_SUPPORT
1858+
16541859
void TestBTraitDataSource::Mutate()
16551860
{
16561861
Lock();

src/test-apps/MockSourceTraits.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,18 +195,26 @@ class TestATraitDataSource :
195195
uint32_t mTestCounter;
196196
};
197197

198-
class TestBTraitDataSource : public nl::Weave::Profiles::DataManagement::TraitDataSource
198+
class TestBTraitDataSource:
199+
#if WDM_ENABLE_PUBLISHER_UPDATE_SERVER_SUPPORT
200+
public nl::Weave::Profiles::DataManagement::TraitUpdatableDataSource
201+
#else
202+
public nl::Weave::Profiles::DataManagement::TraitDataSource
203+
#endif
199204
{
200205
public:
201206
TestBTraitDataSource();
202207
void Mutate();
203208

204209
private:
210+
#if WDM_ENABLE_PUBLISHER_UPDATE_SERVER_SUPPORT
211+
WEAVE_ERROR SetLeafData(nl::Weave::Profiles::DataManagement::PropertyPathHandle aLeafHandle, nl::Weave::TLV::TLVReader &aReader) __OVERRIDE;
212+
#endif // WDM_ENABLE_PUBLISHER_UPDATE_SERVER_SUPPORT
205213
WEAVE_ERROR GetLeafData(nl::Weave::Profiles::DataManagement::PropertyPathHandle aLeafHandle, uint64_t aTagToWrite, nl::Weave::TLV::TLVWriter &aWriter) __OVERRIDE;
206214
WEAVE_ERROR GetNextDictionaryItemKey(nl::Weave::Profiles::DataManagement::PropertyPathHandle aDictionaryHandle, uintptr_t &aContext, nl::Weave::Profiles::DataManagement::PropertyDictionaryKey &aKey) __OVERRIDE;
207215

208-
Schema::Nest::Test::Trait::TestATrait::EnumA taa;
209-
Schema::Nest::Test::Trait::TestCommon::CommonEnumA tab;
216+
int32_t taa;
217+
int32_t tab;
210218
uint32_t tac;
211219
uint32_t tad_saa;
212220
bool tad_sab;

0 commit comments

Comments
 (0)