simpleshot_sources = [
- 'task_runner.cpp'
+ 'simpleshot_utils.cpp'
]
simpleshot_inc = include_directories('.')
+
e = executable('simpleshot_runner',
- simpleshot_sources,
+ ['task_runner.cpp'] + simpleshot_sources,
dependencies: [app_utils_dep, nntrainer_dep, tflite_dep],
install: get_option('install-app'),
install_dir: application_install_dir
)
if get_option('enable-test')
+ simpleshot_test_dep = declare_dependency(
+ sources: simpleshot_sources,
+ include_directories: simpleshot_inc,
+ )
subdir('test')
endif
--- /dev/null
+// SPDX-License-Identifier: Apache-2.0
+/**
+ * Copyright (C) 2020 Jihoon Lee <jhoon.it.lee@samsung.com>
+ *
+ * @file utils.cpp
+ * @date 08 Jan 2021
+ * @brief This file contains simple utilities used across the application
+ * @see https://github.com/nnstreamer/nntrainer
+ * @author Jihoon Lee <jhoon.it.lee@samsung.com>
+ * @bug No known bugs except for NYI items
+ *
+ */
+#include <iostream>
+#include <regex>
+
+#include <simpleshot_utils.h>
+
+namespace simpleshot {
+
+namespace util {
+
+Entry getKeyValue(const std::string &input) {
+ Entry entry;
+ static const std::regex words_regex("[^\\s=]+");
+
+ std::string input_str(input);
+ input_str.erase(std::remove(input_str.begin(), input_str.end(), ' '),
+ input_str.end());
+ auto words_begin =
+ std::sregex_iterator(input_str.begin(), input_str.end(), words_regex);
+ auto words_end = std::sregex_iterator();
+
+ int nwords = std::distance(words_begin, words_end);
+ if (nwords != 2) {
+ throw std::invalid_argument("key, value is not found");
+ }
+
+ entry.key = words_begin->str();
+ entry.value = (++words_begin)->str();
+ return entry;
+}
+
+} // namespace util
+} // namespace simpleshot
--- /dev/null
+// SPDX-License-Identifier: Apache-2.0
+/**
+ * Copyright (C) 2020 Jihoon Lee <jhoon.it.lee@samsung.com>
+ *
+ * @file utils.h
+ * @date 08 Jan 2021
+ * @brief This file contains simple utilities used across the application
+ * @see https://github.com/nnstreamer/nntrainer
+ * @author Jihoon Lee <jhoon.it.lee@samsung.com>
+ * @bug No known bugs except for NYI items
+ *
+ */
+#include <string>
+
+namespace simpleshot {
+
+namespace util {
+
+struct Entry {
+ std::string key;
+ std::string value;
+};
+
+Entry getKeyValue(const std::string &input);
+
+} // namespace util
+} // namespace simpleshot
test_target = [
- 'mock_test',
+ 'simpleshot_utils'
]
foreach target: test_target
exe = executable(
target,
target + '.cpp',
- dependencies: gtest_dep_with_main,
+ dependencies: [gtest_dep_with_main, simpleshot_test_dep],
install: get_option('enable-test'),
install_dir: application_install_dir
)
+++ /dev/null
-// SPDX-License-Identifier: Apache-2.0
-/**
- * Copyright (C) 2020 Jihoon Lee <jhoon.it.lee@samsung.com>
- *
- * @file mock_test.cpp
- * @date 08 Jan 2021
- * @brief mock test for simpleshot application
- * @see https://github.com/nnstreamer/nntrainer
- * @author Jihoon Lee <jhoon.it.lee@samsung.com>
- * @note this will be deleted or moved as the application is building up
- * @bug No known bugs except for NYI items
- */
-
-#include <gtest/gtest.h>
-
-TEST(sample_test, test_01_p) { EXPECT_TRUE(true); }
--- /dev/null
+// SPDX-License-Identifier: Apache-2.0
+/**
+ * Copyright (C) 2020 Jihoon Lee <jhoon.it.lee@samsung.com>
+ *
+ * @file utils_test.cpp
+ * @date 08 Jan 2021
+ * @brief test for simpleshot utils
+ * @see https://github.com/nnstreamer/nntrainer
+ * @author Jihoon Lee <jhoon.it.lee@samsung.com>
+ * @bug No known bugs except for NYI items
+ */
+
+#include <gtest/gtest.h>
+#include <simpleshot_utils.h>
+
+namespace simpleshot {
+TEST(getKeyValue, parse_okay_p) {
+ {
+ util::Entry e = util::getKeyValue("abc=123");
+ EXPECT_EQ(e.key, "abc");
+ EXPECT_EQ(e.value, "123");
+ }
+ {
+ util::Entry e = util::getKeyValue("abc = 123");
+ EXPECT_EQ(e.key, "abc");
+ EXPECT_EQ(e.value, "123");
+ }
+ {
+ util::Entry e = util::getKeyValue("abc = 123");
+ EXPECT_EQ(e.key, "abc");
+ EXPECT_EQ(e.value, "123");
+ }
+ {
+ util::Entry e = util::getKeyValue("abc = 123");
+ EXPECT_EQ(e.key, "abc");
+ EXPECT_EQ(e.value, "123");
+ }
+}
+
+TEST(getKeyValue, invalid_format_01_n) {
+ EXPECT_THROW(util::getKeyValue("abc"), std::invalid_argument);
+}
+
+TEST(getKeyValue, invalid_format_02_n) {
+ EXPECT_THROW(util::getKeyValue("abc="), std::invalid_argument);
+}
+
+TEST(getKeyValue, invalid_format_03_n) {
+ EXPECT_THROW(util::getKeyValue("abc=1=2"), std::invalid_argument);
+}
+
+TEST(getKeyValue, invalid_format_04_n) {
+ EXPECT_THROW(util::getKeyValue("=12"), std::invalid_argument);
+}
+} // namespace simpleshot