Skip to content

Commit

Permalink
Merge pull request #210 from seank-img/explore-fix
Browse files Browse the repository at this point in the history
Fix server and client explore tool
  • Loading branch information
David Antliff committed Jun 28, 2016
2 parents c532b47 + 5961ebe commit 7ff6d6b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
51 changes: 51 additions & 0 deletions tools/tests/gtest/test_tools_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,57 @@ TEST_F(TestToolsCommon, PrintAllObjectDefinitions_handles_null_iterator)
PrintAllObjectDefinitions(NULL, false);
}

TEST_F(TestToolsCommon,ResourceOperationToString_handles_valid_input)
{
const char * output = NULL;
std::string expectedOutput = "ReadOnly";

output = ResourceOperationToString(AwaResourceOperations_ReadOnly);

ASSERT_STREQ(expectedOutput.c_str(), output);
}

TEST_F(TestToolsCommon,ResourceOperationToString_handles_invalid_input)
{
const char * output = NULL;
std::string expectedOutput = "BAD OPERATION";


output = ResourceOperationToString((AwaResourceOperations)-10);

ASSERT_STREQ(expectedOutput.c_str(), output);

output = ResourceOperationToString((AwaResourceOperations)(AwaResourceOperations_LAST+1));

ASSERT_STREQ(expectedOutput.c_str(), output);
}

TEST_F(TestToolsCommon,ResourceTypeToString_handles_valid_input)
{
const char * output = NULL;
std::string expectedOutput = "Time";

output = ResourceTypeToString(AwaResourceType_Time);

ASSERT_STREQ(expectedOutput.c_str(), output);
}

TEST_F(TestToolsCommon,ResourceTypeToString_handles_invalid_input)
{
const char * output = NULL;
std::string expectedOutput = "BAD TYPE";


output = ResourceTypeToString((AwaResourceType)-10);

ASSERT_STREQ(expectedOutput.c_str(), output);

output = ResourceTypeToString((AwaResourceType)(30));

ASSERT_STREQ(expectedOutput.c_str(), output);
}


} // namespace Awa


Expand Down
7 changes: 4 additions & 3 deletions tools/tools_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,14 @@ const char * ResourceOperationToString(AwaResourceOperations operation)
"Execute",
};

if (sizeof(table) / sizeof(table[0]) != AwaResourceOperations_LAST)
if (sizeof(table) / sizeof(table[0]) != AwaResourceOperations_LAST + 1)
{
Error("ResourceOperationToString table is wrong size!\n");
Error("ResourceOperationToString table is wrong size!");
}
else
{
if ((operation >= 0) && (operation < AwaResourceOperations_LAST))
operation += 1; //AwaResourceOperations_Invalid does not start at 0, so offset required.
if ((operation >= 0) && (operation < AwaResourceOperations_LAST + 1))
{
result = table[operation];
}
Expand Down

0 comments on commit 7ff6d6b

Please sign in to comment.