2 * Copyright (c) 2022 Samsung Electronics Co., Ltd. All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <gtest/gtest.h>
23 class cirlce_operator_test : public ::testing::Test
26 bool initialize(void);
27 bool run(const std::string &command);
30 bool load(const std::string &file);
33 std::string _artifacts_path;
34 std::string _circle_operator_path;
38 bool cirlce_operator_test::initialize(void)
40 char *path = std::getenv("ARTIFACTS_PATH");
43 std::cerr << "ARTIFACTS_PATH not found" << std::endl;
46 _artifacts_path = path;
48 path = std::getenv("CIRCLE_OPERATOR_PATH");
51 std::cerr << "ARTIFACTS_BIN_PATH not found" << std::endl;
54 _circle_operator_path = path;
59 bool cirlce_operator_test::run(const std::string &command)
61 std::vector<char> buffer(260);
62 std::string result = "";
63 std::string cmd_err = command + " 2>&1";
64 FILE *pipe = popen(cmd_err.c_str(), "r");
71 while (fgets(&buffer[0], buffer.size(), pipe) != NULL)
84 std::cout << _result << std::endl;
89 bool cirlce_operator_test::load(const std::string &file)
91 std::ifstream tmp(file.c_str());
95 std::stringstream buffer;
96 buffer << tmp.rdbuf();
97 _result = buffer.str();
101 TEST_F(cirlce_operator_test, valid_names)
109 std::string model = _artifacts_path + "/Add_000.circle";
110 std::string command = _circle_operator_path + " --name " + model;
117 const auto pos = _result.find("ofm");
118 ASSERT_NE(std::string::npos, pos);
121 TEST_F(cirlce_operator_test, valid_codes)
129 std::string model = _artifacts_path + "/Add_000.circle";
130 std::string command = _circle_operator_path + " --code " + model;
137 const auto pos = _result.find("ADD");
138 ASSERT_NE(std::string::npos, pos);
141 TEST_F(cirlce_operator_test, invalid_option_NEG)
149 std::string model = _artifacts_path + "/Add_000.circle";
150 std::string command = _circle_operator_path + " --opname " + model;
157 const auto pos = _result.find("Invalid argument");
158 ASSERT_NE(std::string::npos, pos);
161 TEST_F(cirlce_operator_test, check_code_name)
169 std::string model = _artifacts_path + "/Add_000.circle";
170 std::string command = _circle_operator_path + " --code --name " + model;
177 const auto pos = _result.find("ofm");
178 ASSERT_NE(std::string::npos, pos);
179 const auto pos2 = _result.find("ADD");
180 ASSERT_NE(std::string::npos, pos2);
183 TEST_F(cirlce_operator_test, nonexist_file_NEG)
191 std::string model = _artifacts_path + "/non_exist_file.foo";
192 std::string command = _circle_operator_path + " --name " + model;
199 const auto pos = _result.find("ERROR");
200 ASSERT_NE(std::string::npos, pos);
203 TEST_F(cirlce_operator_test, invalid_file_NEG)
211 std::string model = _artifacts_path + "/Add_000.recipe";
212 std::string command = _circle_operator_path + " --name " + model;
219 const auto pos = _result.find("ERROR");
220 ASSERT_NE(std::string::npos, pos);
223 TEST_F(cirlce_operator_test, output_file)
231 std::string fileName("/tmp/a.txt");
232 std::remove(fileName.c_str());
233 std::string model = _artifacts_path + "/Add_000.circle";
234 std::string command = _circle_operator_path + " --code --output_path " + fileName + " " + model;
246 const auto pos = _result.find("ADD");
247 ASSERT_NE(std::string::npos, pos);