Add testcase for callbacks

Change-Id: Iff1ddb9c18b5384d05a4d2dbfba95ade8cc1783c
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
diff --git a/src/test/.gitignore b/src/test/.gitignore
index c3c7a0c..9c5e674 100644
--- a/src/test/.gitignore
+++ b/src/test/.gitignore
@@ -7,3 +7,5 @@
 /propertywatchtest
 /propertywatchgentest.hpp
 /propertywatchgentest
+/callbackgentest.hpp
+/callbackgentest
diff --git a/src/test/Makefile.am b/src/test/Makefile.am
index fe66203..f4e2e46 100644
--- a/src/test/Makefile.am
+++ b/src/test/Makefile.am
@@ -104,3 +104,28 @@
 	${gtest_ldadd} \
 	${SDBUSPLUS_LIBS} \
 	$(builddir)/../propertywatch.o
+
+check_PROGRAMS += callbackgentest
+callbackgentest_SOURCES = \
+	callbackgentest.cpp
+callbackgentest_CXXFLAGS = \
+	$(gtest_cflags)
+callbackgentest_LDFLAGS = \
+	$(OESDK_TESTCASE_FLAGS)
+callbackgentest_LDADD = \
+	${gtest_ldadd}
+
+BUILT_SOURCES += callbackgentest.hpp
+CLEANFILES += callbackgentest.hpp
+
+CALLBACK_TEST_GEN_DEPS = \
+	templates/callbackgentest.mako.hpp \
+	yaml/callbackgentest
+
+callbackgentest.hpp: $(CALLBACK_TEST_GEN_DEPS)
+	$(AM_V_GEN) $(PYTHON) $(PDMGEN) \
+		-t callbackgentest.mako.hpp \
+		-p "${TEMPLATESEARCH}" \
+		-d yaml/callbackgentest \
+		-o $(builddir)/$@ \
+		generate-cpp
diff --git a/src/test/callbackgentest.cpp b/src/test/callbackgentest.cpp
new file mode 100644
index 0000000..77fe60a
--- /dev/null
+++ b/src/test/callbackgentest.cpp
@@ -0,0 +1,35 @@
+#include <array>
+#include <string>
+#include <gtest/gtest.h>
+#include "data_types.hpp"
+
+using namespace phosphor::dbus::monitoring;
+
+using Index = std::map<std::tuple<size_t, size_t, size_t>, size_t>;
+
+#include "callbackgentest.hpp"
+
+const std::array<std::tuple<std::string, size_t>, 4> expectedCallbacks =
+{
+    {
+        std::tuple<std::string, size_t>{"int32_t", 0},
+        std::tuple<std::string, size_t>{"int32_t", 0},
+        std::tuple<std::string, size_t>{"std::string", 1},
+        std::tuple<std::string, size_t>{"std::string", 2},
+    }
+};
+
+TEST(CallbackGenTest, CallbacksSameSize)
+{
+    ASSERT_EQ(sizeof(expectedCallbacks), sizeof(callbacks));
+}
+
+TEST(CallbackGenTest, CallbacksSameContent)
+{
+    size_t i;
+    for (i = 0; i < expectedCallbacks.size(); ++i)
+    {
+        ASSERT_EQ(callbacks[i],
+                  expectedCallbacks[i]);
+    }
+}
diff --git a/src/test/templates/callbackgentest.mako.hpp b/src/test/templates/callbackgentest.mako.hpp
new file mode 100644
index 0000000..f387c23
--- /dev/null
+++ b/src/test/templates/callbackgentest.mako.hpp
@@ -0,0 +1,17 @@
+auto storageCount = ${len(instances)};
+
+const std::array<Index, ${len(instancegroups)}> indicies = {{
+% for g in instancegroups:
+    {
+    % for i in g.members:
+        {Index::key_type{${i[0]}, ${i[2]}, ${i[3]}}, ${i[5]}},
+    % endfor
+    },
+% endfor
+}};
+
+const std::array<std::tuple<std::string, size_t>, ${len(callbacks)}> callbacks = {{
+% for c in callbacks:
+    std::tuple<std::string, size_t>{"${c.datatype}", ${c.instances}},
+% endfor
+}};
diff --git a/src/test/yaml/callbackgentest/one.yaml b/src/test/yaml/callbackgentest/one.yaml
new file mode 100644
index 0000000..e94b262
--- /dev/null
+++ b/src/test/yaml/callbackgentest/one.yaml
@@ -0,0 +1,62 @@
+# Validate two callbacks that share an index
+# and a single callback with its own index.
+#
+# Expecting three callbacks pointing at two indicies.
+
+- name: test path group 1
+  class: group
+  group: path
+  members:
+    - meta: path
+      path: /xyz/openbmc_project/testing/inst4
+
+- name: test path group 2
+  class: group
+  group: path
+  members:
+    - meta: path
+      path: /xyz/openbmc_project/testing/inst4
+    - meta: path
+      path: /xyz/openbmc_project/testing/inst6
+
+- name: test property group 1
+  class: group
+  group: property
+  type: int32
+  members:
+    - interface: xyz.openbmc_project.Sensor.Iface1
+      meta: property
+      property: Value
+
+- name: test property group 2
+  class: group
+  group: property
+  type: string
+  members:
+    - interface: xyz.openbmc_project.Sensor.Iface3
+      meta: property
+      property: Value2
+
+- name: test journal callback 1
+  class: callback
+  callback: journal
+  paths: test path group 1
+  properties: test property group 1
+  severity: INFO
+  message: Hello world from PDM!
+
+- name: test journal callback 2
+  class: callback
+  callback: journal
+  paths: test path group 1
+  properties: test property group 1
+  severity: INFO
+  message: Hello world from PDM!
+
+- name: test journal callback 3
+  class: callback
+  callback: journal
+  paths: test path group 2
+  properties: test property group 2
+  severity: INFO
+  message: Hello world from PDM!
diff --git a/src/test/yaml/callbackgentest/two.yaml b/src/test/yaml/callbackgentest/two.yaml
new file mode 100644
index 0000000..6037f43
--- /dev/null
+++ b/src/test/yaml/callbackgentest/two.yaml
@@ -0,0 +1,27 @@
+# Validate the same callback name works in differnt config files.
+
+- name: test path group 1
+  class: group
+  group: path
+  members:
+    - meta: path
+      path: /xyz/openbmc_project/testing/inst4
+    - meta: path
+      path: /xyz/openbmc_project/testing/inst6
+
+- name: test property group 1
+  class: group
+  group: property
+  type: string
+  members:
+    - interface: xyz.openbmc_project.Sensor.Iface3
+      meta: property
+      property: Value2
+
+- name: test journal callback 1
+  class: callback
+  callback: journal
+  paths: test path group 1
+  properties: test property group 1
+  severity: INFO
+  message: Hello world from PDM!