From: 박종현/On-Device Lab(SR)/Staff Engineer/삼성전자 Date: Fri, 21 Jun 2019 00:00:09 +0000 (+0900) Subject: [hermes-std] Initial commit (#3893) X-Git-Tag: nncc_backup~327 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=441784a927d76a2cd5e4ea036de0dab1ba5870a6;p=platform%2Fcore%2Fml%2Fnnfw.git [hermes-std] Initial commit (#3893) This commit introduces hermes-std which includes basic hermes extensions such as console reporter. Signed-off-by: Jonghyun Park --- diff --git a/contrib/hermes-std/.FORMATCHECKED b/contrib/hermes-std/.FORMATCHECKED new file mode 100644 index 0000000..e69de29 diff --git a/contrib/hermes-std/CMakeLists.txt b/contrib/hermes-std/CMakeLists.txt new file mode 100644 index 0000000..c38b9c4 --- /dev/null +++ b/contrib/hermes-std/CMakeLists.txt @@ -0,0 +1,26 @@ +file(GLOB_RECURSE SOURCES "src/*.cpp") +file(GLOB_RECURSE TESTS "src/*.test.cpp") +list(REMOVE_ITEM SOURCES ${TESTS}) + +add_library(hermes_std STATIC ${SOURCES}) +set_target_properties(hermes_std PROPERTIES POSITION_INDEPENDENT_CODE ON) +target_include_directories(hermes_std PUBLIC include) +target_link_libraries(hermes_std PUBLIC hermes) +target_link_libraries(hermes_std PRIVATE stdex) +# Let's apply nncc common compile options +# +# NOTE This will enable strict compilation (warnings as error). +# Please refer to the top-level CMakeLists.txt for details +target_link_libraries(hermes_std PRIVATE nncc_common) +target_link_libraries(hermes_std PUBLIC nncc_coverage) + +if(NOT ENABLE_TEST) + return() +endif(NOT ENABLE_TEST) + +# Google Test is mandatory for internal testing +nncc_find_package(GTest REQUIRED) + +GTest_AddTest(hermes_std_test ${TESTS}) +target_link_libraries(hermes_std_test stdex) +target_link_libraries(hermes_std_test hermes_std) diff --git a/contrib/hermes-std/README.md b/contrib/hermes-std/README.md new file mode 100644 index 0000000..f5f4b86 --- /dev/null +++ b/contrib/hermes-std/README.md @@ -0,0 +1,3 @@ +# hermes-std + +_hermes-std_ is a collection of **primitive** _hermes_ extensions. diff --git a/contrib/hermes-std/include/hermes/ConsoleReporter.h b/contrib/hermes-std/include/hermes/ConsoleReporter.h new file mode 100644 index 0000000..e09dd57 --- /dev/null +++ b/contrib/hermes-std/include/hermes/ConsoleReporter.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __HERMES_STD_CONSOLE_REPORTER_H__ +#define __HERMES_STD_CONSOLE_REPORTER_H__ + +#include + +namespace hermes +{ + +/** + * @brief Print messages into standard console + */ +struct ConsoleReporter final : public hermes::Sink +{ + void notify(const Message *m) final; +}; + +} // namespace hermes + +#endif // __HERMES_STD_CONSOLE_REPORTER_H__ diff --git a/contrib/hermes-std/src/ConsoleReporter.cpp b/contrib/hermes-std/src/ConsoleReporter.cpp new file mode 100644 index 0000000..3cc9f09 --- /dev/null +++ b/contrib/hermes-std/src/ConsoleReporter.cpp @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "hermes/ConsoleReporter.h" + +#include + +namespace hermes +{ + +void ConsoleReporter::notify(const hermes::Message *m) +{ + for (uint32_t n = 0; n < m->text()->lines(); ++n) + { + std::cout << m->text()->line(n) << std::endl; + } +} + +} // namespace hermes diff --git a/contrib/hermes-std/src/ConsoleReporter.test.cpp b/contrib/hermes-std/src/ConsoleReporter.test.cpp new file mode 100644 index 0000000..c2e1f1c --- /dev/null +++ b/contrib/hermes-std/src/ConsoleReporter.test.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "hermes/ConsoleReporter.h" + +#include + +#include + +#include + +TEST(ConsoleReporterTest, constructor) +{ + hermes::ConsoleReporter r; + + SUCCEED(); +} + +TEST(ConsoleReporterTest, notify) +{ + hermes::Message m; + { + std::stringstream ss; + + ss << "Hello" << std::endl; + + m.text(stdex::make_unique(ss)); + } + + hermes::ConsoleReporter r; + + ASSERT_NO_THROW(r.notify(&m)); +}