Skip to content

Commit

Permalink
Fix bug in server where creating an object will populate optional res…
Browse files Browse the repository at this point in the history
…ources
  • Loading branch information
Sean Kelly authored and Sean Kelly committed Apr 5, 2016
1 parent 7d3aa77 commit 1ddde03
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
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
2 changes: 1 addition & 1 deletion core/src/server/lwm2m_server_xml_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -1444,7 +1444,7 @@ static int xmlif_AddDefaultsForMissingMandatoryValues(Lwm2mContextType * context
{
continue;
}
if (resourceDefinition->DefaultValueNode == NULL && resourceDefinition->MaximumInstances > 1 && resourceDefinition->MinimumInstances == 0)
if (resourceDefinition->DefaultValueNode == NULL || resourceDefinition->MaximumInstances > 1 || resourceDefinition->MinimumInstances == 0)
{
continue; // don't add default values for optional multiple instance resources
}
Expand Down

0 comments on commit 1ddde03

Please sign in to comment.