summaryrefslogtreecommitdiff
path: root/tools/policy_table_validator
diff options
context:
space:
mode:
authorHerasym Oleh <oolleehh@gmail.com>2015-12-25 12:30:50 +0200
committerHerasym Oleh <oolleehh@gmail.com>2015-12-25 12:30:50 +0200
commit3db17ce4390bdf66c8048095e39cb3350280e1be (patch)
tree116c28bbbd46bd557ddfa1204c983ab526dbb955 /tools/policy_table_validator
parent193bfe7d37c59a68b23a1007ba37eb19271d45ef (diff)
downloadsdl_core-3db17ce4390bdf66c8048095e39cb3350280e1be.tar.gz
Add tests in tools & 3rd-party-static.
Add tests in 3rd-party-static/test/. Add tests in tools/intergern/test/. Add tests in tools/policy_table_validator/. Related: APPLINK-20109
Diffstat (limited to 'tools/policy_table_validator')
-rw-r--r--tools/policy_table_validator/CMakeLists.txt27
-rw-r--r--tools/policy_table_validator/main.cpp83
2 files changed, 110 insertions, 0 deletions
diff --git a/tools/policy_table_validator/CMakeLists.txt b/tools/policy_table_validator/CMakeLists.txt
new file mode 100644
index 0000000000..2a372d7ffa
--- /dev/null
+++ b/tools/policy_table_validator/CMakeLists.txt
@@ -0,0 +1,27 @@
+#set( CMAKE_VERBOSE_MAKEFILE on )
+
+include_directories(
+ ${CMAKE_SOURCE_DIR}/src/components/policy/src/policy/
+ ${CMAKE_SOURCE_DIR}/src/components/rpc_base/include/
+ ${CMAKE_SOURCE_DIR}/src/components/utils/include/
+ ${JSONCPP_INCLUDE_DIRECTORY}
+)
+
+
+link_directories (
+ ${CMAKE_BINARY_DIR}/src/components/policy/src/policy/policy_table/table_struct/
+ ${CMAKE_BINARY_DIR}/src/components/rpc_base/
+)
+
+
+set(LIBRARIES
+ policy_struct
+ rpc_base
+)
+
+set (SOURCES
+ main.cpp
+)
+
+add_executable(policyValidator ${SOURCES})
+target_link_libraries(policyValidator ${LIBRARIES})
diff --git a/tools/policy_table_validator/main.cpp b/tools/policy_table_validator/main.cpp
new file mode 100644
index 0000000000..16454ca128
--- /dev/null
+++ b/tools/policy_table_validator/main.cpp
@@ -0,0 +1,83 @@
+#include <iostream>
+#include <cstdlib>
+#include "policy_table/table_struct/types.h"
+
+#include "json/reader.h"
+#include "utils/file_system.h"
+
+namespace policy_table = rpc::policy_table_interface_base;
+
+enum ResultCode {
+ SUCCES = 0,
+ MISSED_FILE_NAME,
+ READ_ERROR,
+ PARSE_ERROR,
+ PT_TYPE_ERROR
+};
+
+rpc::policy_table_interface_base::PolicyTableType StringToPolicyTableType(const std::string& str_pt_type) {
+ if (str_pt_type == "PT_PRELOADED") {
+ return rpc::policy_table_interface_base::PT_PRELOADED;
+ }
+ if (str_pt_type == "PT_SNAPSHOT") {
+ return rpc::policy_table_interface_base::PT_SNAPSHOT;
+ }
+ if (str_pt_type == "PT_UPDATE") {
+ return rpc::policy_table_interface_base::PT_UPDATE;
+ }
+ return rpc::policy_table_interface_base::INVALID_PT_TYPE;
+}
+
+void help() {
+ std::cout << "Usage:" << std::endl <<
+ "./policy_validator {Policy table type} {file_name}" << std::endl;
+ std::cout << "Policy table types:"
+ "\t PT_PRELOADED , PT_UPDATE , PT_SNAPSHOT" <<std::endl;
+}
+
+int main(int argc, char** argv) {
+ if (argc != 3) {
+ // TODO(AKutsan): No filename
+ help();
+ exit(MISSED_FILE_NAME);
+ }
+ std::string pt_type_str = argv[1];
+ std::string file_name = argv[2];
+ std::string json_string;
+ rpc::policy_table_interface_base::PolicyTableType pt_type;
+ pt_type = StringToPolicyTableType(pt_type_str);
+ if (rpc::policy_table_interface_base::PolicyTableType::INVALID_PT_TYPE
+ == pt_type) {
+ std::cout << "Invalid policy table type: " << pt_type_str << std::endl;
+ exit(PT_TYPE_ERROR);
+ }
+ bool read_result = file_system::ReadFile(file_name, json_string);
+ if (false == read_result) {
+ std::cout << "Read file error: " << file_name << std::endl;
+ exit(READ_ERROR);
+ }
+
+ Json::Reader reader;
+ Json::Value value;
+
+ bool parce_result = reader.parse(json_string, value);
+ if (false == parce_result) {
+ std::cout << "Json parce fails" << std::endl;
+ exit(PARSE_ERROR);
+ }
+ std::cout << "DEFAULT_POLICY" << std::endl;
+ policy_table::Table table(&value);
+ table.SetPolicyTableType(pt_type);
+ bool is_valid = table.is_valid();
+ if (true == is_valid ) {
+ std::cout << "Table is valid" << std::endl;
+ exit(SUCCES);
+ }
+
+ std::cout << "Table is not valid" << std::endl;
+ rpc::ValidationReport report("policy_table");
+ table.ReportErrors(&report);
+ std::cout << "Errors: " << std::endl << rpc::PrettyFormat(report) << std::endl;
+
+ return SUCCES;
+}