Back to index

unity  6.0.0
Classes | Functions
test_introspection.cpp File Reference
#include <gtest/gtest.h>
#include <glib.h>
#include <memory>
#include <boost/foreach.hpp>
#include "Introspectable.h"
#include "DebugDBusInterface.h"

Go to the source code of this file.

Classes

class  MockIntrospectable
class  TestIntrospection

Functions

 TEST_F (TestIntrospection, TestTest)
 TEST_F (TestIntrospection, TestVariousRootQueries)
 TEST_F (TestIntrospection, TestAsteriskWildcard)
 TEST_F (TestIntrospection, TestRelativeAsteriskWildcard)
 TEST_F (TestIntrospection, TestAbsoluteQueries)
 TEST_F (TestIntrospection, TestMalformedRelativeQueries)
 TEST_F (TestIntrospection, TestSimpleRelativeQueries)
 TEST_F (TestIntrospection, TestComplexRelativeQueries)
 TEST_F (TestIntrospection, TestQueriesWithNoResults)
 TEST_F (TestIntrospection, TestQueriesWithParams)
 TEST_F (TestIntrospection, TestQueryTypeBool)
 TEST_F (TestIntrospection, TestQueryTypeInt)
 TEST_F (TestIntrospection, TestMalformedQueries)

Function Documentation

TEST_F ( TestIntrospection  ,
TestTest   
)

Definition at line 97 of file test_introspection.cpp.

{
  ASSERT_STREQ("Unity", root_->GetName().c_str());
}
TEST_F ( TestIntrospection  ,
TestVariousRootQueries   
)

Definition at line 102 of file test_introspection.cpp.

{
  std::list<Introspectable*> results;
  std::string query;

  results = GetIntrospectableNodesFromQuery(query, root_.get());
  ASSERT_EQ(1, results.size());
  EXPECT_STREQ("Unity", results.front()->GetName().c_str());

  query = "/";
  results = GetIntrospectableNodesFromQuery(query, root_.get());
  ASSERT_EQ(1, results.size());
  EXPECT_STREQ("Unity", results.front()->GetName().c_str());

  query = "/Unity";
  results = GetIntrospectableNodesFromQuery(query, root_.get());
  ASSERT_EQ(1, results.size());
  EXPECT_STREQ("Unity", results.front()->GetName().c_str());
}

Here is the call graph for this function:

TEST_F ( TestIntrospection  ,
TestAsteriskWildcard   
)

Definition at line 122 of file test_introspection.cpp.

{
  std::list<Introspectable*> results;
  std::string query = "/Unity/*";

  results = GetIntrospectableNodesFromQuery(query, root_.get());
  ASSERT_EQ(2, results.size());

  for(auto p : results)
  {
    ASSERT_TRUE(
      p->GetName() == "DashController" ||
      p->GetName() == "PanelController"
      );
  }
}

Here is the call graph for this function:

TEST_F ( TestIntrospection  ,
TestRelativeAsteriskWildcard   
)

Definition at line 139 of file test_introspection.cpp.

{
  std::list<Introspectable*> results;
  std::string query = "//DashController/*";

  results = GetIntrospectableNodesFromQuery(query, root_.get());
  ASSERT_EQ(3, results.size());

  for(auto p : results)
  {
    ASSERT_TRUE(p->GetName() == "Foo");
  }
}

Here is the call graph for this function:

TEST_F ( TestIntrospection  ,
TestAbsoluteQueries   
)

Definition at line 153 of file test_introspection.cpp.

{
  std::list<Introspectable*> results;
  std::string query = "/Unity/DashController";

  results = GetIntrospectableNodesFromQuery(query, root_.get());
  ASSERT_EQ(1, results.size());
  EXPECT_STREQ("DashController", results.front()->GetName().c_str());
}

Here is the call graph for this function:

TEST_F ( TestIntrospection  ,
TestMalformedRelativeQueries   
)

Definition at line 163 of file test_introspection.cpp.

{
  std::list<Introspectable*> results;
  std::string query = "Unity";

  results = GetIntrospectableNodesFromQuery(query, root_.get());
  ASSERT_EQ(1, results.size());
  EXPECT_STREQ("Unity", results.front()->GetName().c_str());

  query = "Foo";
  results = GetIntrospectableNodesFromQuery(query, root_.get());
  ASSERT_EQ(3, results.size());
  for(auto p : results)
  {
    EXPECT_STREQ("Foo", p->GetName().c_str());
  }
}

Here is the call graph for this function:

TEST_F ( TestIntrospection  ,
TestSimpleRelativeQueries   
)

Definition at line 181 of file test_introspection.cpp.

{
  std::list<Introspectable*> results;
  std::string query = "//Unity";

  results = GetIntrospectableNodesFromQuery(query, root_.get());
  ASSERT_EQ(1, results.size());
  EXPECT_STREQ("Unity", results.front()->GetName().c_str());

  query = "//Foo";
  results = GetIntrospectableNodesFromQuery(query, root_.get());
  ASSERT_EQ(3, results.size());
  for(auto p : results)
  {
    EXPECT_STREQ("Foo", p->GetName().c_str());
  }
}

Here is the call graph for this function:

TEST_F ( TestIntrospection  ,
TestComplexRelativeQueries   
)

Definition at line 199 of file test_introspection.cpp.

{
  std::list<Introspectable*> results;
  std::string query = "//DashController/Foo";

  results = GetIntrospectableNodesFromQuery(query, root_.get());
  ASSERT_EQ(3, results.size());
  for(auto p : results)
  {
    EXPECT_STREQ("Foo", p->GetName().c_str());
  }
}

Here is the call graph for this function:

TEST_F ( TestIntrospection  ,
TestQueriesWithNoResults   
)

Definition at line 212 of file test_introspection.cpp.

{
  std::list<Introspectable*> results;
  std::string query = "//Does/Not/Exist";

  results = GetIntrospectableNodesFromQuery(query, root_.get());
  ASSERT_EQ(0, results.size());

  query = "DoesNotEverExist";
  results = GetIntrospectableNodesFromQuery(query, root_.get());
  ASSERT_EQ(0, results.size());

  query = "/Does/Not/Ever/Exist";
  results = GetIntrospectableNodesFromQuery(query, root_.get());
  ASSERT_EQ(0, results.size());
}

Here is the call graph for this function:

TEST_F ( TestIntrospection  ,
TestQueriesWithParams   
)

Definition at line 229 of file test_introspection.cpp.

{
  std::list<Introspectable*> results;
  // this should find our root node:
  results = GetIntrospectableNodesFromQuery("/Unity[SomeProperty=SomeValue]", root_.get());
  ASSERT_EQ(1, results.size());
  EXPECT_STREQ("Unity", results.front()->GetName().c_str());
  // but this should find nothing:
  results = GetIntrospectableNodesFromQuery("/Unity[SomeProperty=SomeOtherValue]", root_.get());
  ASSERT_EQ(0, results.size());

  // make sure relative paths work:
  results = GetIntrospectableNodesFromQuery("//Foo[Name=Foo]", root_.get());
  ASSERT_EQ(3, results.size());
  for(auto p : results)
  {
    EXPECT_STREQ("Foo", p->GetName().c_str());
  }

  // make sure param queries work with descendant nodes as well:
  results = GetIntrospectableNodesFromQuery("/Unity[SomeProperty=SomeValue]/DashController[Name=DashController]/Foo", root_.get());
  ASSERT_EQ(3, results.size());
  for(auto p : results)
  {
    EXPECT_STREQ("Foo", p->GetName().c_str());
  }
}

Here is the call graph for this function:

TEST_F ( TestIntrospection  ,
TestQueryTypeBool   
)

Definition at line 257 of file test_introspection.cpp.

{
  std::list<Introspectable*> results;

  // These are all equivilent and should return the root item and nothing more:
  std::list<std::string> queries = {"/Unity[BoolPropertyTrue=True]",
                                    "/Unity[BoolPropertyTrue=true]",
                                    "/Unity[BoolPropertyTrue=trUE]",
                                    "/Unity[BoolPropertyTrue=yes]",
                                    "/Unity[BoolPropertyTrue=ON]",
                                    "/Unity[BoolPropertyTrue=1]"};

  for(auto query : queries)
  {
    results = GetIntrospectableNodesFromQuery(query, root_.get());
    ASSERT_EQ(1, results.size());
    EXPECT_STREQ("Unity", results.front()->GetName().c_str());
  }

  // For boolean properties, anything that's not True, Yes, On or 1 is treated as false:
  queries = {"/Unity[BoolPropertyTrue=False]",
            "/Unity[BoolPropertyTrue=fAlSE]",
            "/Unity[BoolPropertyTrue=No]",
            "/Unity[BoolPropertyTrue=OFF]",
            "/Unity[BoolPropertyTrue=0]",
            "/Unity[BoolPropertyTrue=ThereWasAManFromNantucket]"};
  for(auto query : queries)
  {
    results = GetIntrospectableNodesFromQuery(query, root_.get());
    ASSERT_EQ(0, results.size());
  }
}

Here is the call graph for this function:

TEST_F ( TestIntrospection  ,
TestQueryTypeInt   
)

Definition at line 290 of file test_introspection.cpp.

{
  std::list<Introspectable*> results;

  // these should all select the root Unity node:
  std::list<std::string> queries = {"/Unity[BytePropertyPos=12]",
                                    "/Unity[Int16PropertyPos=1012]",
                                    "/Unity[Int16PropertyNeg=-1034]",
                                    "/Unity[UInt16PropertyPos=1056]",
                                    "/Unity[Int32PropertyPos=100012]",
                                    "/Unity[Int32PropertyNeg=-100034]",
                                    "/Unity[UInt32PropertyPos=100056]",
                                    "/Unity[Int64PropertyPos=100000012]",
                                    "/Unity[Int64PropertyNeg=-100000034]",
                                    "/Unity[UInt64PropertyPos=100000056]"};
  for(auto query : queries)
  {
    results = GetIntrospectableNodesFromQuery(query, root_.get());
    ASSERT_EQ(1, results.size()) << "Failing query: " << query;
    EXPECT_STREQ("Unity", results.front()->GetName().c_str());
  }

  // but these shouldn't:
  queries = {"/Unity[BytePropertyPos=1234]",
            "/Unity[Int16PropertyPos=0]",
            "/Unity[Int16PropertyNeg=-0]",
            "/Unity[Int16PropertyNeg=-]",
            "/Unity[UInt16PropertyPos=-1056]",
            "/Unity[Int32PropertyPos=999999999999999]",
            "/Unity[Int32PropertyNeg=Garbage]",
            "/Unity[UInt32PropertyPos=-23]"};
  for(auto query : queries)
  {
    results = GetIntrospectableNodesFromQuery(query, root_.get());
    ASSERT_EQ(0, results.size());
  }
}

Here is the call graph for this function:

TEST_F ( TestIntrospection  ,
TestMalformedQueries   
)

Definition at line 328 of file test_introspection.cpp.

{
  // this should work - we have not yet specified a parameter to test against.
  std::list<Introspectable*> results = GetIntrospectableNodesFromQuery("/Unity[", root_.get());
  ASSERT_EQ(1, results.size());

  std::list<std::string> queries = {"/Unity[BoolPropertyTrue",
                                  "/Unity[BoolPropertyTrue=",
                                  "/Unity[BoolPropertyTrue=]",
                                  "/Unity[BytePropertyPos=",
                                  "/Unity[BytePropertyPos=]",
                                  "/Unity[Int16PropertyPos=",
                                  "/Unity[Int16PropertyPos=]",
                                  "/Unity[Int16PropertyNeg=",
                                  "/Unity[Int16PropertyNeg=]",
                                  "/Unity[UInt16PropertyPos[=]]",
                                  "/Unity[Int32PropertyPos[[",
                                  "/Unity[Int32PropertyNeg]",
                                  "/Unity[UInt32PropertyPos=[",
                                  "/Unity[Int64PropertyPos[[",
                                  "/Unity[Int64PropertyNeg",
                                  "/Unity[UInt64PropertyPos]"};

  for (std::string query : queries)
  {
    results = GetIntrospectableNodesFromQuery(query, root_.get());
    ASSERT_EQ(0, results.size()) << "Failing query: " << query;
  }
}

Here is the call graph for this function: