diff options
Diffstat (limited to 'compiler/circlechef/tools')
-rw-r--r-- | compiler/circlechef/tools/console/CMakeLists.txt | 9 | ||||
-rw-r--r-- | compiler/circlechef/tools/console/Driver.cpp | 10 | ||||
-rw-r--r-- | compiler/circlechef/tools/console/Driver.test.cpp | 41 | ||||
-rw-r--r-- | compiler/circlechef/tools/file/Driver.cpp | 6 | ||||
-rw-r--r-- | compiler/circlechef/tools/reverse/Driver.cpp | 6 |
5 files changed, 62 insertions, 10 deletions
diff --git a/compiler/circlechef/tools/console/CMakeLists.txt b/compiler/circlechef/tools/console/CMakeLists.txt index 10168fca3..faf0a94f0 100644 --- a/compiler/circlechef/tools/console/CMakeLists.txt +++ b/compiler/circlechef/tools/console/CMakeLists.txt @@ -1,3 +1,12 @@ add_executable(circlechef Driver.cpp) target_link_libraries(circlechef circlechef_core) target_link_libraries(circlechef safemain) + +if(NOT ENABLE_TEST) + return() +endif(NOT ENABLE_TEST) + +nnas_find_package(GTest REQUIRED) + +GTest_AddTest(circlechef_test Driver.test.cpp Driver.cpp) +target_link_libraries(circlechef_test circlechef_core) diff --git a/compiler/circlechef/tools/console/Driver.cpp b/compiler/circlechef/tools/console/Driver.cpp index 0909f5927..6aa4c3cc5 100644 --- a/compiler/circlechef/tools/console/Driver.cpp +++ b/compiler/circlechef/tools/console/Driver.cpp @@ -22,7 +22,7 @@ #include <iostream> -int entry(int argc, char **argv) +int entry_stream(std::istream &is) { int32_t model_version = 1; @@ -30,7 +30,7 @@ int entry(int argc, char **argv) // Read a model recipe from standard input { - google::protobuf::io::IstreamInputStream iis{&std::cin}; + google::protobuf::io::IstreamInputStream iis{&is}; if (!google::protobuf::TextFormat::Parse(&iis, &model_recipe)) { std::cerr << "ERROR: Failed to parse recipe" << std::endl; @@ -56,3 +56,9 @@ int entry(int argc, char **argv) return 0; } + +int entry(int, char **) +{ + // forward to entry_stream + return entry_stream(std::cin); +} diff --git a/compiler/circlechef/tools/console/Driver.test.cpp b/compiler/circlechef/tools/console/Driver.test.cpp new file mode 100644 index 000000000..d8e4e657e --- /dev/null +++ b/compiler/circlechef/tools/console/Driver.test.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2021 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 <gtest/gtest.h> + +// entry function to test from Driver.cpp +int entry_stream(std::istream &is); + +TEST(CircleChefDriverTest, entry_empty_NEG) +{ + std::istringstream empty_input(""); + + ASSERT_EQ(0, entry_stream(empty_input)); +} + +TEST(CircleChefDriverTest, entry_invaid_NEG) +{ + std::istringstream empty_input("invalid: input"); + + ASSERT_NE(0, entry_stream(empty_input)); +} + +TEST(CircleChefDriverTest, entry_invaid_version_NEG) +{ + std::istringstream empty_input("version: 9999"); + + ASSERT_NE(0, entry_stream(empty_input)); +} diff --git a/compiler/circlechef/tools/file/Driver.cpp b/compiler/circlechef/tools/file/Driver.cpp index bcc0c7ae9..9c4256b40 100644 --- a/compiler/circlechef/tools/file/Driver.cpp +++ b/compiler/circlechef/tools/file/Driver.cpp @@ -28,10 +28,8 @@ int entry(int argc, char **argv) { arser::Arser arser; - arser.add_argument("recipe") - .type(arser::DataType::STR) - .help("Source recipe file path to convert"); - arser.add_argument("circle").type(arser::DataType::STR).help("Target circle file path"); + arser.add_argument("recipe").help("Source recipe file path to convert"); + arser.add_argument("circle").help("Target circle file path"); try { diff --git a/compiler/circlechef/tools/reverse/Driver.cpp b/compiler/circlechef/tools/reverse/Driver.cpp index 8a2b85fc7..c8ef07c6f 100644 --- a/compiler/circlechef/tools/reverse/Driver.cpp +++ b/compiler/circlechef/tools/reverse/Driver.cpp @@ -25,10 +25,8 @@ int entry(int argc, char **argv) { arser::Arser arser; - arser.add_argument("circle") - .type(arser::DataType::STR) - .help("Source circle file path to convert"); - arser.add_argument("recipe").type(arser::DataType::STR).help("Target recipe file path"); + arser.add_argument("circle").help("Source circle file path to convert"); + arser.add_argument("recipe").help("Target recipe file path"); try { |