Skip to content

Commit

Permalink
Merge pull request #105 from seank-img/server-fix
Browse files Browse the repository at this point in the history
Fix bug in server where creating an object will populate optional resources.
  • Loading branch information
Roland Bewick committed Apr 5, 2016
2 parents 099462f + c1b2186 commit c9f69f2
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
34 changes: 34 additions & 0 deletions api/tests/test_write_operation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions core/src/server/lwm2m_server_xml_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tools/tests/python/test_awa_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
)),
)

Expand Down
8 changes: 4 additions & 4 deletions tools/tests/python/test_awa_server_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit c9f69f2

Please sign in to comment.