From 86c27c24e145d949f6d9f2b28c654279498feaa9 Mon Sep 17 00:00:00 2001 From: Sean Kelly Date: Tue, 5 Apr 2016 15:17:42 +1200 Subject: [PATCH 1/2] Fix bug in server where creating an object will populate optional resources Signed-off-by: Sean Kelly --- api/tests/test_write_operation.cc | 34 +++++++++++++++++++++ core/src/server/lwm2m_server_xml_handlers.c | 4 +++ 2 files changed, 38 insertions(+) diff --git a/api/tests/test_write_operation.cc b/api/tests/test_write_operation.cc index 1fccdb9..2f3f69e 100644 --- a/api/tests/test_write_operation.cc +++ b/api/tests/test_write_operation.cc @@ -349,6 +349,40 @@ TEST_F(TestWriteOperationWithConnectedServerAndClientSession, AwaServerWriteOper AwaServerWriteOperation_Free(&writeOperation); } +TEST_F(TestWriteOperationWithConnectedServerAndClientSession, AwaServerWriteOperation_Perform_put_with_optional_resource_should_not_create_optional_resource) +{ + ObjectDescription object = { 1000, "Object1000", 0, 1, + { + ResourceDescription(0, "MandatoryResource", AwaResourceType_Integer, 1, 1, AwaResourceOperations_ReadWrite), + ResourceDescription(1, "OptionalResource", AwaResourceType_Integer, 0, 1, AwaResourceOperations_ReadWrite), + }}; + EXPECT_EQ(AwaError_Success, Define(client_session_, object)); + EXPECT_EQ(AwaError_Success, Define(server_session_, object)); + + WaitForClientDefinition(AwaObjectDefinition_GetID(object.GetDefinition())); + + AwaServerWriteOperation * writeOperation = AwaServerWriteOperation_New(server_session_, AwaWriteMode_Replace); ASSERT_TRUE(NULL != writeOperation); + AwaInteger value = 123456789; + EXPECT_EQ(AwaError_Success, AwaServerWriteOperation_CreateObjectInstance(writeOperation, "/1000/0")); + EXPECT_EQ(AwaError_Success, AwaServerWriteOperation_AddValueAsInteger(writeOperation, "/1000/0/0", value)); + EXPECT_EQ(AwaError_Success, AwaServerWriteOperation_Perform(writeOperation, global::clientEndpointName, defaults::timeout)); + AwaServerWriteOperation_Free(&writeOperation); + + + AwaClientGetOperation * getOperation = AwaClientGetOperation_New(client_session_); + EXPECT_TRUE(getOperation != NULL); + EXPECT_EQ(AwaError_Success, AwaClientGetOperation_AddPath(getOperation, "/1000/0")); + EXPECT_EQ(AwaError_Success, AwaClientGetOperation_Perform(getOperation, defaults::timeout)); + + const AwaClientGetResponse * getResponse = AwaClientGetOperation_GetResponse(getOperation); + EXPECT_TRUE(getResponse != NULL); + + ASSERT_TRUE(AwaClientGetResponse_ContainsPath(getResponse, "/1000/0/0")); + ASSERT_FALSE(AwaClientGetResponse_ContainsPath(getResponse, "/1000/0/1")); + + AwaClientGetOperation_Free(&getOperation); +} + TEST_F(TestWriteOperationWithConnectedServerAndClientSession, AwaServerWriteOperation_Perform_post_existing_object_instance_should_succeed) { ObjectDescription object = { 1000, "Object1000", 0, 1, diff --git a/core/src/server/lwm2m_server_xml_handlers.c b/core/src/server/lwm2m_server_xml_handlers.c index ae7dd45..d6fc3ca 100644 --- a/core/src/server/lwm2m_server_xml_handlers.c +++ b/core/src/server/lwm2m_server_xml_handlers.c @@ -1448,6 +1448,10 @@ static int xmlif_AddDefaultsForMissingMandatoryValues(Lwm2mContextType * context { continue; // don't add default values for optional multiple instance resources } + if (resourceDefinition->MinimumInstances == 0) + { + continue; // don't add default values for optional resources + } Lwm2mTreeNode * child = Lwm2mTreeNode_GetFirstChild(node); while(child != NULL) From c1b218684d9e9fb1b4a00c5612d9a9b1db93707b Mon Sep 17 00:00:00 2001 From: Sean Kelly Date: Tue, 5 Apr 2016 16:29:29 +1200 Subject: [PATCH 2/2] Fix tools tests for create Signed-off-by: Sean Kelly --- tools/tests/python/test_awa_server.py | 2 +- tools/tests/python/test_awa_server_write.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/tests/python/test_awa_server.py b/tools/tests/python/test_awa_server.py index 77e5f2d..d1c920a 100644 --- a/tools/tests/python/test_awa_server.py +++ b/tools/tests/python/test_awa_server.py @@ -386,7 +386,7 @@ def test_read_write_only_resource(self): # test that we can't read from a write only resource customObjects = ( CustomObject("Object1001", 1001, False, "single", ( - CustomResource("Resource100", 100, "string", "single", "optional", "w"), + CustomResource("Resource100", 100, "string", "single", "mandatory", "w"), )), ) diff --git a/tools/tests/python/test_awa_server_write.py b/tools/tests/python/test_awa_server_write.py index a9b16e8..f0c37cf 100644 --- a/tools/tests/python/test_awa_server_write.py +++ b/tools/tests/python/test_awa_server_write.py @@ -182,7 +182,7 @@ def test_create_object_instance_with_id(self): customObjects = ( tools_common.CustomObject("Object1001", 1001, False, "single", ( - tools_common.CustomResource("Resource100", 100, "string", "single", "optional", "rw"), + tools_common.CustomResource("Resource100", 100, "string", "single", "mandatory", "rw"), )), ) params = tools_common.create_define_command(customObjects) @@ -202,7 +202,7 @@ def test_create_multiple_object_instances_for_single_instance_object(self): customObjects = ( tools_common.CustomObject("Object1001", 1001, False, "single", ( - tools_common.CustomResource("Resource100", 100, "string", "single", "optional", "rw"), + tools_common.CustomResource("Resource100", 100, "string", "single", "mandatory", "rw"), )), ) params = tools_common.create_define_command(customObjects) @@ -237,7 +237,7 @@ def test_create_object_instance_with_non_zero_id(self): customObjects = ( tools_common.CustomObject("Object1001", 1001, False, "single", ( - tools_common.CustomResource("Resource100", 100, "string", "single", "optional", "rw"), + tools_common.CustomResource("Resource100", 100, "string", "single", "mandatory", "rw"), )), ) params = tools_common.create_define_command(customObjects) @@ -261,7 +261,7 @@ def test_create_object_instance_without_id(self): customObjects = ( tools_common.CustomObject("Object1001", 1001, False, "single", ( - tools_common.CustomResource("Resource100", 100, "string", "single", "optional", "rw"), + tools_common.CustomResource("Resource100", 100, "string", "single", "mandatory", "rw"), )), ) params = tools_common.create_define_command(customObjects)