diff options
author | agaliuzov <agaliuzov@luxoft.com> | 2016-04-23 06:36:28 -0700 |
---|---|---|
committer | agaliuzov <agaliuzov@luxoft.com> | 2016-04-23 06:44:17 -0700 |
commit | 2d288fbefa3c6ec00debf84d8ea192be3a5b3042 (patch) | |
tree | f94075c21508417c52f71ea78d62511b72f930a5 /tools | |
parent | 301bd6dc13653009553fbedfbc0eabb0c710e195 (diff) | |
parent | 60726ea9c1fbcd094d443149230704c38a2c62da (diff) | |
download | sdl_core-2d288fbefa3c6ec00debf84d8ea192be3a5b3042.tar.gz |
Merge branch 'master' into develop
Diffstat (limited to 'tools')
-rw-r--r-- | tools/CMakeLists.txt | 5 | ||||
-rw-r--r-- | tools/policy_table_validator/CMakeLists.txt | 27 | ||||
-rw-r--r-- | tools/policy_table_validator/main.cpp | 83 |
3 files changed, 115 insertions, 0 deletions
diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 2834dce387..557c23f4e7 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -20,3 +20,8 @@ ExternalProject_Add_Step(intergen forcebuild COMMAND ${CMAKE_COMMAND} -E echo "Force intergen build" DEPENDEES update DEPENDERS build ALWAYS 1) + +if(BUILD_TESTS) + add_subdirectory(intergen/test) +endif() +add_subdirectory(policy_table_validator) 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; +} |